Commit e4160b2e authored by Hans de Goede's avatar Hans de Goede Committed by Borislav Petkov
Browse files

x86/purgatory: Fail the build if has missing symbols

Linking with -r enables "incremental linking"; this means
no checks for unresolved symbols are done while linking

A change 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.

Add 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/
  ld: arch/x86/purgatory/ 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/ arch/x86/purgatory] Error 2
  make: *** [Makefile:1650: arch/x86] Error 2

Also remove --no-undefined from as that has no

Signed-off-by: default avatarHans de Goede <>
Signed-off-by: default avatarBorislav Petkov <>
parent e2ac07c0
......@@ -14,8 +14,12 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
CFLAGS_sha256.o := -D__DISABLE_EXPORTS := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib
targets +=
# When linking with -r unresolved symbols are not checked,
# also link a purgatory.chk binary without -r to check for unresolved symbols.
PURGATORY_LDFLAGS := -e purgatory_start -nostdlib -z nodefaultlib := -r $(PURGATORY_LDFLAGS)
targets += purgatory.chk
# Sanitizer, etc. runtimes are unavailable and cannot be linked here.
......@@ -61,12 +65,15 @@ CFLAGS_string.o += $(PURGATORY_CFLAGS)
$(call if_changed,ld)
$(obj)/purgatory.chk: $(obj)/ FORCE
$(call if_changed,ld)
targets += kexec-purgatory.c
quiet_cmd_bin2c = BIN2C $@
cmd_bin2c = $(objtree)/scripts/bin2c kexec_purgatory < $< > $@
$(obj)/kexec-purgatory.c: $(obj)/ FORCE
$(obj)/kexec-purgatory.c: $(obj)/ $(obj)/purgatory.chk FORCE
$(call if_changed,bin2c)
obj-$(CONFIG_KEXEC_FILE) += kexec-purgatory.o
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment