]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
build: disable PIE during linking if necessary
authorWei Liu <wei.liu2@citrix.com>
Wed, 1 Feb 2017 16:21:14 +0000 (16:21 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 1 Feb 2017 16:31:48 +0000 (16:31 +0000)
Starting from ee3e265688, $(CC) is used for linking. That means all
default $(CC) flags coming from distro takes effect.

On Debian Stretch, gcc contains -pie by default, which makes the final
object fail to link. We need to explicitly disable PIE when linking.
Since not all versions of gcc support -no-pie, test its availability
before adding.

Example error message:

/usr/bin/ld: /local/work/xtf.git/arch/x86/boot/head_pv64.o: relocation R_X86_64_32S against symbol `start_info' can not be used when making a shared object;
recompile with -fPIC
/usr/bin/ld: /local/work/xtf.git/arch/x86/entry_64-pv64.o: relocation R_X86_64_32S against `.text' can not be used when making a shared object; recompile with
-fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
build/common.mk

index 7c4870e05a9a2a6a15dce6c8864dd131b4724e72..a60bb55dd1b691f17bb9356662e1b28ce70d97b4 100644 (file)
@@ -50,6 +50,13 @@ obj-perarch :=
 obj-perenv  :=
 include $(ROOT)/build/files.mk
 
+
+cc-option = $(shell if [ -z "`echo 'int p=1;' | $(CC) $(1) -S -o /dev/null -x c - 2>&1`" ]; \
+                       then echo y; else echo n; fi)
+
+# Disable PIE, but need to check if compiler supports it
+LDFLAGS-$(call cc-option,-no-pie) += -no-pie
+
 # Run once per environment to set up some common bits & pieces
 define PERENV_setup
 
@@ -61,7 +68,7 @@ CFLAGS_$(1) := $$(CFLAGS_$($(1)_arch)) $$(COMMON_CFLAGS-$(1)) -DCONFIG_ENV_$(1)
 
 link-$(1) := $(ROOT)/arch/x86/link-$(1).lds
 
-LDFLAGS_$(1) := -Wl,-T,$$(link-$(1)) -nostdlib
+LDFLAGS_$(1) := -Wl,-T,$$(link-$(1)) -nostdlib $(LDFLAGS-y)
 
 # Needs to pick up test-provided obj-perenv and obj-perarch
 DEPS-$(1) = $(head-$(1)) \