x86/purgatory: Make sure we fail the build if purgatory.ro has missing symbols
PATCH 1/1 x86/purgatory: Make sure we fail the build if purgatory.ro has missing symbols
Since we link purgatory.ro with -r aka we enable "incremental linking" no checks for unresolved symbols is done while linking purgatory.ro.
Changes to the sha256 code has caused the purgatory in 5.4-rc1 to have a missing symbol on memzero_explicit, yet things still happily build.
This commit adds an extra check for unresolved symbols by calling ld without -r before running bin2c to generate kexec-purgatory.c.
This causes a build of 5.4-rc1 with this patch added to fail as it should:
CHK arch/x86/purgatory/purgatory.ro
ld: arch/x86/purgatory/purgatory.ro: in function `sha256_transform':
sha256.c:(.text+0x1c0c): undefined reference to `memzero_explicit' make[2]: *** [arch/x86/purgatory/Makefile:72:
arch/x86/purgatory/kexec-purgatory.c] Error 1
make[1]: *** [scripts/Makefile.build:509: arch/x86/purgatory] Error 2
make: *** [Makefile:1650: arch/x86] Error 2
This will help us catch missing symbols in the purgatory sooner.
Note this commit also removes --no-undefined from LDFLAGS_purgatory.ro as that has no effect.
--- arch/x86/purgatory/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/purgatory/Makefile +7 -1
@@ -14,7 +14,7 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE CFLAGS_sha256.o := -D__DISABLE_EXPORTS -LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib +LDFLAGS_purgatory.ro := -e purgatory_start -r -nostdlib -z nodefaultlib targets += purgatory.ro KASAN_SANITIZE := n
@@ -60,10 +60,16 @@ $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE targets += kexec-purgatory.c +# Since we link purgatory.ro with -r unresolved symbols are not checked, +# so we check this before generating kexec-purgatory.c instead +quiet_cmd_check_purgatory = CHK $< + cmd_check_purgatory = ld -e purgatory_start $< + quiet_cmd_bin2c = BIN2C $@ cmd_bin2c = $(objtree)/scripts/bin2c kexec_purgatory < $< > $@ $(obj)/kexec-purgatory.c: $(obj)/purgatory.ro FORCE + $(call if_changed,check_purgatory) $(call if_changed,bin2c) obj-$(CONFIG_KEXEC_FILE) += kexec-purgatory.o
Signature · 1 line
2.23.0
Quoted 43 lines · Hans de Goede
Since we link purgatory.ro with -r aka we enable "incremental linking" no checks for unresolved symbols is done while linking purgatory.ro.
Changes to the sha256 code has caused the purgatory in 5.4-rc1 to have a missing symbol on
memzero_explicit, yet things still happily build.This commit adds an extra check for unresolved symbols by calling ld without -r before running bin2c to generate
kexec-purgatory.c.This causes a build of 5.4-rc1 with this patch added to fail as it should:
CHK
arch/x86/purgatory/purgatory.ro
ld:arch/x86/purgatory/purgatory.ro: in function `sha256_transform':
sha256.c:(.text+0x1c0c): undefined reference to `memzero_explicit' make[2]: *** [arch/x86/purgatory/Makefile:72:
arch/x86/purgatory/kexec-purgatory.c] Error 1
make[1]: *** [scripts/Makefile.build:509:arch/x86/purgatory] Error 2
make: *** [Makefile:1650:arch/x86] Error 2This will help us catch missing symbols in the purgatory sooner.
Note this commit also removes --no-undefined from LDFLAGS_purgatory.ro as that has no effect.
Signed-off-by Hans de Goede <[email protected]>--- arch/x86/purgatory/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/x86/purgatory/Makefile +1
-1@@ -14,7 +14,7 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE CFLAGS_sha256.o := -D__DISABLE_EXPORTS -LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib +LDFLAGS_purgatory.ro := -e purgatory_start -r -nostdlib -z nodefaultlib targets += purgatory.ro KASAN_SANITIZE := n
arch/x86/purgatory/Makefile $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE · line 66
Quoted 7 lines
arch/x86/purgatory/Makefile +4
-0@@ -60,10 +60,16 @@ $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE targets += kexec-purgatory.c +# Since we link purgatory.ro with -r unresolved symbols are not checked, +# so we check this before generating kexec-purgatory.c instead +quiet_cmd_check_purgatory = CHK $< + cmd_check_purgatory = ld -e purgatory_start $<
I think this should be $(LD) -e ... so that using a cross compile prefix (like x86_64-linux-) or an alternative linker like ld.lld works properly.
Quoted 12 lines
arch/x86/purgatory/Makefile +2
-0+ quiet_cmd_bin2c = BIN2C $@ cmd_bin2c = $(objtree)/scripts/bin2c kexec_purgatory < $< > $@ $(obj)/kexec-purgatory.c: $(obj)/purgatory.ro FORCE + $(call if_changed,check_purgatory) $(call if_changed,bin2c) obj-$(CONFIG_KEXEC_FILE) += kexec-purgatory.oSignature · 1 line
2.23.0
Cheers,
Nathan
HI,
Quoted 47 lines · Nathan Chancellor
Quoted 46 lines · Hans de Goede
Since we link purgatory.ro with -r aka we enable "incremental linking" no checks for unresolved symbols is done while linking purgatory.ro.
Changes to the sha256 code has caused the purgatory in 5.4-rc1 to have a missing symbol on
memzero_explicit, yet things still happily build.This commit adds an extra check for unresolved symbols by calling ld without -r before running bin2c to generate
kexec-purgatory.c.This causes a build of 5.4-rc1 with this patch added to fail as it should:
CHK
arch/x86/purgatory/purgatory.ro
ld:arch/x86/purgatory/purgatory.ro: in function `sha256_transform':
sha256.c:(.text+0x1c0c): undefined reference to `memzero_explicit' make[2]: *** [arch/x86/purgatory/Makefile:72:
arch/x86/purgatory/kexec-purgatory.c] Error 1
make[1]: *** [scripts/Makefile.build:509:arch/x86/purgatory] Error 2
make: *** [Makefile:1650:arch/x86] Error 2This will help us catch missing symbols in the purgatory sooner.
Note this commit also removes --no-undefined from LDFLAGS_purgatory.ro as that has no effect.
Signed-off-by Hans de Goede <[email protected]>--- arch/x86/purgatory/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/x86/purgatory/Makefile +1
-1@@ -14,7 +14,7 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE CFLAGS_sha256.o := -D__DISABLE_EXPORTS -LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib +LDFLAGS_purgatory.ro := -e purgatory_start -r -nostdlib -z nodefaultlib targets += purgatory.ro KASAN_SANITIZE := n@@ -60,10 +60,16 @@ $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE targets += kexec-purgatory.c
Quoted 7 lines
arch/x86/purgatory/Makefile $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE · line 66
Quoted 4 lines
arch/x86/purgatory/Makefile +4
-0+# Since we link purgatory.ro with -r unresolved symbols are not checked, +# so we check this before generating kexec-purgatory.c instead +quiet_cmd_check_purgatory = CHK $< + cmd_check_purgatory = ld -e purgatory_start $<I think this should be $(LD) -e ... so that using a cross compile prefix (like x86_64-linux-) or an alternative linker like ld.lld works properly.
Good point, also the ld command is actually outputting an a.out file which is also something which we do not want.
I will prepare a new version fixing both.
Regards,
Hans
Quoted 58 lines · Hans de Goede
HI,
Quoted 47 lines · Nathan Chancellor
Quoted 46 lines · Hans de Goede
Since we link purgatory.ro with -r aka we enable "incremental linking" no checks for unresolved symbols is done while linking purgatory.ro.
Changes to the sha256 code has caused the purgatory in 5.4-rc1 to have a missing symbol on
memzero_explicit, yet things still happily build.This commit adds an extra check for unresolved symbols by calling ld without -r before running bin2c to generate
kexec-purgatory.c.This causes a build of 5.4-rc1 with this patch added to fail as it should:
CHK
arch/x86/purgatory/purgatory.ro
ld:arch/x86/purgatory/purgatory.ro: in function `sha256_transform':
sha256.c:(.text+0x1c0c): undefined reference to `memzero_explicit' make[2]: *** [arch/x86/purgatory/Makefile:72:
arch/x86/purgatory/kexec-purgatory.c] Error 1
make[1]: *** [scripts/Makefile.build:509:arch/x86/purgatory] Error 2
make: *** [Makefile:1650:arch/x86] Error 2This will help us catch missing symbols in the purgatory sooner.
Note this commit also removes --no-undefined from LDFLAGS_purgatory.ro as that has no effect.
Signed-off-by Hans de Goede <[email protected]>--- arch/x86/purgatory/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/x86/purgatory/Makefile +1
-1@@ -14,7 +14,7 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE CFLAGS_sha256.o := -D__DISABLE_EXPORTS -LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib +LDFLAGS_purgatory.ro := -e purgatory_start -r -nostdlib -z nodefaultlib targets += purgatory.ro KASAN_SANITIZE := n@@ -60,10 +60,16 @@ $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE targets += kexec-purgatory.cQuoted 7 lines
arch/x86/purgatory/Makefile $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE · line 66
Quoted 4 lines
arch/x86/purgatory/Makefile +4
-0+# Since we link purgatory.ro with -r unresolved symbols are not checked, +# so we check this before generating kexec-purgatory.c instead +quiet_cmd_check_purgatory = CHK $< + cmd_check_purgatory = ld -e purgatory_start $<I think this should be $(LD) -e ... so that using a cross compile prefix (like x86_64-linux-) or an alternative linker like ld.lld works properly.
Quoted 8 lines
Good point, also the ld command is actually outputting an a.out file which is also something which we do not want.
I will prepare a new version fixing both.
Regards,
Hans
We could just use $(NM) -u, right?
HI,
Quoted 62 lines · Arvind Sankar
Quoted 61 lines · Hans de Goede
HI,
Quoted 47 lines · Nathan Chancellor
Quoted 46 lines · Hans de Goede
Since we link purgatory.ro with -r aka we enable "incremental linking" no checks for unresolved symbols is done while linking purgatory.ro.
Changes to the sha256 code has caused the purgatory in 5.4-rc1 to have a missing symbol on
memzero_explicit, yet things still happily build.This commit adds an extra check for unresolved symbols by calling ld without -r before running bin2c to generate
kexec-purgatory.c.This causes a build of 5.4-rc1 with this patch added to fail as it should:
CHK
arch/x86/purgatory/purgatory.ro
ld:arch/x86/purgatory/purgatory.ro: in function `sha256_transform':
sha256.c:(.text+0x1c0c): undefined reference to `memzero_explicit' make[2]: *** [arch/x86/purgatory/Makefile:72:
arch/x86/purgatory/kexec-purgatory.c] Error 1
make[1]: *** [scripts/Makefile.build:509:arch/x86/purgatory] Error 2
make: *** [Makefile:1650:arch/x86] Error 2This will help us catch missing symbols in the purgatory sooner.
Note this commit also removes --no-undefined from LDFLAGS_purgatory.ro as that has no effect.
Signed-off-by Hans de Goede <[email protected]>--- arch/x86/purgatory/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/x86/purgatory/Makefile +1
-1@@ -14,7 +14,7 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE CFLAGS_sha256.o := -D__DISABLE_EXPORTS -LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib +LDFLAGS_purgatory.ro := -e purgatory_start -r -nostdlib -z nodefaultlib targets += purgatory.ro KASAN_SANITIZE := n@@ -60,10 +60,16 @@ $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE targets += kexec-purgatory.cQuoted 7 lines
arch/x86/purgatory/Makefile $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE · line 66
Quoted 4 lines
arch/x86/purgatory/Makefile +4
-0+# Since we link purgatory.ro with -r unresolved symbols are not checked, +# so we check this before generating kexec-purgatory.c instead +quiet_cmd_check_purgatory = CHK $< + cmd_check_purgatory = ld -e purgatory_start $<I think this should be $(LD) -e ... so that using a cross compile prefix (like x86_64-linux-) or an alternative linker like ld.lld works properly.
Good point, also the ld command is actually outputting an a.out file which is also something which we do not want.
Quoted 7 lines
Quoted 5 lines
I will prepare a new version fixing both.
Regards,
Hans
We could just use $(NM) -u, right?
That would require wrapping it in some shell code like this (untested):
SHOULD_BE_EMPTY=$(nm -u purgatory.ro); if [ "$SHOULD_BE_EMPTY" == "" ]; then true; else false; fi
And then escaping the $ in there and in injecting $(NM) into it, IMHO it is easier to just do:
$(LD) $PURGATORY_LDFLAGS) purgatory.ro -o /dev/null
Also it seems better to actually use the linker for this test then usig an other tool which may have subtly different semantics.
Regards,
Hans