xen/build: Fix build failure from LDFLAGS mismatch
PATCH 1/1 xen/build: Fix build failure from LDFLAGS mismatch
In a GNU compatbile makefile, $(LDFLAGS) are passed to $(CC), not $(LD).
In a default CentOS 7 build environment, $(LDFLAGS) is set to -Wl,-z,relro, which causes the Xen build to explode with:
ld: unrecognized option '-Wl,-z,relro'
ld: use the --help option for usage information
It turns out that many downstreams identify this as a breakage in Xen's build system and bodge around it in various ways, mostly by unsetting all of $(CFLAGS), $(AFLAGS) and $(LDFLAGS).
However, that is a security issue because it means that tools/ is not built with the distro-wide hardening flags that are otherwise expected of packages (relro, _FORTIFY_SOURCE, stack-protector, etc).
tools/ specifically should honour the packaging environment's choice of flags, while xen/ must not pass $(LDFLAGS) to $(LD), and should not be influenced by the others either.
---
CC: Anthony PERARD <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Wei Liu <[email protected]>
RFC, because CFLAGS/AFLAGS need nuking too, and they're rather more entangled. I expect this to cause some disgreement, but Xen is behaving in a very nonstandard way even among embedded projects and all downstreams are suffering security problems as a consequence.
--- xen/Makefile | 2 ++ 1 file changed, 2 insertions(+)
xen/Makefile +2 -0
@@ -254,6 +254,8 @@ export KBUILD_DEFCONFIG := $(ARCH)_defconfig # reparsing Config.mk by e.g. arch/x86/boot/. export XEN_TREEWIDE_CFLAGS := $(CFLAGS) +LDFLAGS := + # CLANG_FLAGS needs to be calculated before calling Kconfig ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),) CLANG_FLAGS :=
Signature · 1 line
2.11.0
Quoted 1 line · Andrew Cooper
In a GNU compatbile makefile, $(LDFLAGS) are passed to $(CC), not $(LD).
I have to admit that I have always been puzzled by this anomaly.
Quoted 6 lines
In a default CentOS 7 build environment, $(LDFLAGS) is set to -Wl,-z,relro, which causes the Xen build to explode with:
ld: unrecognized option '-Wl,-z,relro'
ld: use the --help option for usage information
Quoted 7 lines
It turns out that many downstreams identify this as a breakage in Xen's build system and bodge around it in various ways, mostly by unsetting all of $(CFLAGS), $(AFLAGS) and $(LDFLAGS).
However, that is a security issue because it means that
tools/is not built with the distro-wide hardening flags that are otherwise expected of packages (relro,_FORTIFY_SOURCE, stack-protector, etc).
This "security issue" is introduced by them, I would say. They simply shouldn't build everything in one go, but rather build "tools" with the flags left intact and "xen" with the flags suitably pruned. (We do build "xen" separately, albeit for different reasons.) The way ./Config.mk works this would look to be advisable anyway. And xen/Makefile should perhaps arrange for Config.mk to skip this massaging when including it.
Quoted 3 lines
tools/specifically should honour the packaging environment's choice of flags, while xen/ must not pass $(LDFLAGS) to $(LD), and should not be influenced by the others either.
I'm not convinced of the last part of what you say. Why should it be impossible to say "make CFLAGS=... xen" just like "make CC=... xen" can be used?
xen/Makefile export KBUILD_DEFCONFIG := $(ARCH)_defconfig · line 257
Quoted 7 lines
xen/Makefile +1
-0@@ -254,6 +254,8 @@ export KBUILD_DEFCONFIG := $(ARCH)_defconfig # reparsing Config.mk by e.g. arch/x86/boot/. export XEN_TREEWIDE_CFLAGS := $(CFLAGS) +LDFLAGS :=
Instead of this, why don't we do away with the few uses of $(LDFLAGS)? If I haven't overlooked anything, there are exactly two lines (three if also counting a comment) which would need changing.
Or why don't we transform -Wl,... into the form understood by $(LD)? -z relro, for example, looks to be benign to the linking of Xen, the more that this option can also be enabled by default and we haven't found a need to disable it (afaics this option solely determines which linker script to use when none was specified).
Jan
Hi Andrew,
Quoted 3 lines · Andrew Cooper
In a GNU compatbile makefile, $(LDFLAGS) are passed to $(CC), not $(LD).
You mean because CC is used for linking or even when compiling object files ?
If not, what is the expected way to pass linker flags ?
Quoted 45 lines
In a default CentOS 7 build environment, $(LDFLAGS) is set to -Wl,-z,relro, which causes the Xen build to explode with:
ld: unrecognized option '-Wl,-z,relro'
ld: use the --help option for usage informationIt turns out that many downstreams identify this as a breakage in Xen's build system and bodge around it in various ways, mostly by unsetting all of $(CFLAGS), $(AFLAGS) and $(LDFLAGS).
However, that is a security issue because it means that
tools/is not built with the distro-wide hardening flags that are otherwise expected of packages (relro,_FORTIFY_SOURCE, stack-protector, etc).
tools/specifically should honour the packaging environment's choice of flags, while xen/ must not pass $(LDFLAGS) to $(LD), and should not be influenced by the others either.Signed-off-by Andrew Cooper <[email protected]>---
CC: Anthony PERARD <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Juergen Gross <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Wei Liu <[email protected]>RFC, because CFLAGS/AFLAGS need nuking too, and they're rather more entangled. I expect this to cause some disgreement, but Xen is behaving in a very nonstandard way even among embedded projects and all downstreams are suffering security problems as a consequence.
---
xen/Makefile | 2 ++1 file changed, 2 insertions(+)xen/Makefile +0
-0
xen/Makefile export KBUILD_DEFCONFIG := $(ARCH)_defconfig · line 258
Quoted 5 lines
xen/Makefile +2
-0@@ -254,6 +254,8 @@ export KBUILD_DEFCONFIG := $(ARCH)_defconfig # reparsing Config.mk by e.g. arch/x86/boot/. export XEN_TREEWIDE_CFLAGS := $(CFLAGS) +LDFLAGS := +
This would require a comment in the Makefile to explain why this is done.
Also how could anybody specify linker specific flags if this is done ?
Regards
Bertrand
Quoted 6 lines
xen/Makefile +0
-0# CLANG_FLAGS needs to be calculated before calling Kconfig ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
CLANG_FLAGS:=Signature · 1 line
2.11.0