build: pass -no-pie to LDFLAGS
RFC PATCH 1/1 build: pass -no-pie to LDFLAGS
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.
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
--- build/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
build/common.mk +1 -1
@@ -61,7 +61,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 -no-pie # Needs to pick up test-provided obj-perenv and obj-perarch DEPS-$(1) = $(head-$(1)) \
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 23 lines · Wei Liu
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.
Example error message:
/usr/bin/ld: /local/work/xtf.git/arch/x86/boot/head_pv64.o: relocationR_X86_64_32Sagainst symbolstart_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 statusSigned-off-by Wei Liu <[email protected]>--- build/common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)build/common.mk +0
-0
build/common.mk CFLAGS_$(1) := $$(CFLAGS_$($(1)_arch)) $$(COMMON_CFLAGS-$(1)) -DCONFIG_ENV_$(1) · line 65
Quoted 6 lines
build/common.mk +1
-1@@ -61,7 +61,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 -no-pie
Eh, we definitely need something more sophisticated than this. We need to detect if -pie is really supported by the compiler.
But before I spend more time on this, I would like to hear other people's opinion.
Wei.
Quoted 5 lines
build/common.mk +0
-0# Needs to pick up test-provided obj-perenv and obj-perarch DEPS-$(1) = $(head-$(1)) \Signature · 1 line
2.11.0
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 31.01.17 at 14:22, <[email protected]> wrote:
Starting from
ee3e265688, $(CC) is used for linking. That means all default $(CC) flags coming from distro takes effect.
First of all I think $(CC) containing any flags is wrong - that's what $(CFLAGS) is for. Or are you saying the compiler's built in default is to generate PIE? And then in an environment like xtf or the hypervisor (or kernels in general) such preset flags should imo simply be discarded. I.e. CFLAGS should start out all blank.
So if PIE simply is the compiler default, I'd suppose there's a way to find out, and that could be leveraged for adding -no-pie. Otherwise conditional option adding will need to be used (not sure whether xtf has already inherited Xen's macros for this).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 31.01.17 at 14:22, <[email protected]> wrote:
Starting from
ee3e265688, $(CC) is used for linking. That means all default $(CC) flags coming from distro takes effect.First of all I think $(CC) containing any flags is wrong - that's what $(CFLAGS) is for. Or are you saying the compiler's built in default is to generate PIE?
I believe Wei is referring to this latter case.
Quoted 3 lines
And then in an environment like xtf or the hypervisor
(or kernels in general) such preset flags should imo simply be discarded. I.e. CFLAGS should start out all blank.
The XTF build system constructs $(CFLAGS) itself.
Quoted 4 lines
So if PIE simply is the compiler default, I'd suppose there's a way to find out, and that could be leveraged for adding -no-pie. Otherwise conditional option adding will need to be used (not sure whether xtf has already inherited Xen's macros for this).
I haven't needed any of the conditional option logic yet, which is why nothing is there. If we can't unconditionally use -no-pie, then it looks like we will need to gain some conditional logic.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 7 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 31.01.17 at 14:22, <[email protected]> wrote:
Starting from
ee3e265688, $(CC) is used for linking. That means all default $(CC) flags coming from distro takes effect.First of all I think $(CC) containing any flags is wrong - that's what $(CFLAGS) is for. Or are you saying the compiler's built in default is to generate PIE? And then in an environment like xtf or the hypervisor
The latter.
Quoted 3 lines
(or kernels in general) such preset flags should imo simply be discarded. I.e. CFLAGS should start out all blank.
No, emptying CFLAGS won't work because -pie is not there.
I suspect it is added to gcc specs, but I can't parse the output of gcc -dumpspecs.
See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=835148
Quoted 1 line
gcc-6 6.2.0-7 uploaded to unstable on Tue 18 Oct 2016 defaults to PIE,
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel