Closed ZeroChaos- closed 4 months ago
just a guess, but is it possible -specs should only be passed to CC and not LD?
I think you are correct. The spec file is used by GCC and nothing else. Here is the description of the option:
"Process file after the compiler reads in the standard specs file, in order to override the defaults which the gcc driver program uses when determining what switches to pass to cc1, cc1plus, as, ld, etc."
https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#Overall-Options
Having it in LDFLAGS should be invalid.
Just a FYI, here are the relevant bits:
https://github.com/openwrt/openwrt/blob/master/include/hardening.mk#L22 https://github.com/openwrt/openwrt/blob/master/include/hardened-ld-pie.specs
The reason this works elsewhere, but not here should be because the build system is invoking ld directly rather than abusing GCC for it. What the specfile does is pass "-pie" to ld unless -no-pie
, -static
, -r
or -shared
is being passed to ld. It also bypasses any build system interference with LDFLAGS
, but only when GCC is touching them.
After thinking about it, the right thing to do here should be two fold. The first is to apply this patch to stop passing -specs
to LD when it should go to GCC:
diff --git a/include/hardening.mk b/include/hardening.mk
index 60f39428e8..95d6b59dca 100644
--- a/include/hardening.mk
+++ b/include/hardening.mk
@@ -18,8 +18,8 @@ ifdef CONFIG_PKG_CHECK_FORMAT_SECURITY
endif
ifdef CONFIG_PKG_ASLR_PIE
ifeq ($(strip $(PKG_ASLR_PIE)),1)
- TARGET_CFLAGS += $(FPIC)
- TARGET_LDFLAGS += $(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs
+ TARGET_CFLAGS += $(FPIC) -specs=$(INCLUDE_DIR)/hardened-ld-pie.specs
+ TARGET_LDFLAGS += $(FPIC)
endif
endif
ifdef CONFIG_PKG_CC_STACKPROTECTOR_REGULAR
The second is to write some sort of macro that can be called on packages that invoke ld directly to add -pie
to LDFLAGS
when CONFIG_PKG_ASLR_PIE
is set. Hopefully, this will be sufficient to make things work. If not, the build system needs to be patched to abuse the compiler to invoke ld.
Is this still an issue?
sure is
There's already PKG_ASLR_PIE:=0 because of this.
I can't reproduce. Is this on 18.06?
I found this on master, but it's also broken in openwrt-19.07
Xtables-addons 2.14 - Linux 4.14.169
if [ -n "/home/zero/development/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.14.169" ]; then make -C /home/zero/development/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.14.169 M=/home/zero/development/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/xtables-addons-2.14/extensions modules; fi;
make[7]: Entering directory '/home/zero/development/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/linux-4.14.169'
LD [M] /home/zero/development/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_generic/xtables-addons-2.14/extensions/LUA/xt_LUA.o
mips-openwrt-linux-musl-ld: unrecognized option '-specs=/home/zero/development/openwrt/include/hardened-ld-pie.specs'
mips-openwrt-linux-musl-ld: use the --help option for usage information
Is this MIPS-only? Can we leave ASLR turned on for everything else?
18.06 is EOL.
The actual error is "mips-openwrt-linux-musl-ld: unrecognized option '-specs=/home/zero/development/openwrt/include/hardened-ld-pie.specs'" but here is context: