Skip to contentSkip to conversation

x86/purgatory: Remove LTO flags

PATCH Applied Song Liu 4 participants 5 messages Sep 14, 2023 – Sep 17, 2023

Subsystems (3)
lore
Share & tools
lore

Song Liu

author
#0 lore raw

PATCH v3 1/1 x86/purgatory: Remove LTO flags

-flto* implies -ffunction-sections. With LTO enabled, ld.lld generates multiple .text sections for purgatory.ro:

$ readelf -S purgatory.ro  | grep " .text"
  [ 1] .text             PROGBITS         0000000000000000  00000040
  [ 7] .text.purgatory   PROGBITS         0000000000000000  000020e0
  [ 9] .text.warn        PROGBITS         0000000000000000  000021c0
  [13] .text.sha256_upda PROGBITS         0000000000000000  000022f0
  [15] .text.sha224_upda PROGBITS         0000000000000000  00002be0
  [17] .text.sha256_fina PROGBITS         0000000000000000  00002bf0
  [19] .text.sha224_fina PROGBITS         0000000000000000  00002cc0

This cause WARNING from kexec_purgatory_setup_sechdrs():

WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
kexec_load_purgatory+0x37f/0x390

Fix this by disabling LTO for purgatory.

We could also fix this with an explicit linker script to rejoin .text.* sections back into .text. However, given the benefit of LTOing pugatory is small, simply disable the production of more .text.* sections for now.

Fixes b33fff07e3e3 ("x86, build: allow LTO to be selected")
Cc Ricardo Ribalda <[email protected]>
Cc Sami Tolvanen <[email protected]>

---
AFAICT, x86 is the only arch that supports LTO and purgatory.

Changes in v3:
1. Fix "Fixes" tag. (Nick Desaulniers)
2. Add description of an alternative fix, with linker script. (Nick Desaulniers)

Changes in v2:
1. Use CC_FLAGS_LTO instead of hardcode -flto. (Nick Desaulniers)

---
 arch/x86/purgatory/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/purgatory/Makefile +4 -0
index c2a29be35c01..08aa0f25f12a 100644
@@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
 # optimization flags.
 KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
 
+# When LTO is enabled, llvm emits many text sections, which is not supported
+# by kexec. Remove -flto=* flags.
+KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
+
 # When linking purgatory.ro 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 -z nodefaultlib
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 15 lines · Song Liu

-flto* implies -ffunction-sections. With LTO enabled, ld.lld generates multiple .text sections for purgatory.ro:

$ readelf -S purgatory.ro  | grep " .text"
  [ 1] .text             PROGBITS         0000000000000000  00000040
  [ 7] .text.purgatory   PROGBITS         0000000000000000  000020e0
  [ 9] .text.warn        PROGBITS         0000000000000000  000021c0
  [13] .text.sha256_upda PROGBITS         0000000000000000  000022f0
  [15] .text.sha224_upda PROGBITS         0000000000000000  00002be0
  [17] .text.sha256_fina PROGBITS         0000000000000000  00002bf0
  [19] .text.sha224_fina PROGBITS         0000000000000000  00002cc0

This cause WARNING from kexec_purgatory_setup_sechdrs():

Quoted 7 lines
WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
kexec_load_purgatory+0x37f/0x390

Fix this by disabling LTO for purgatory.

We could also fix this with an explicit linker script to rejoin .text.* sections back into .text. However, given the benefit of LTOing pugatory

s/pugatory/purgatory/

(maybe the x86 maintainers can apply that fixup if/when picked up)

Quoted 10 lines

is small, simply disable the production of more .text.* sections for now.

Fixes b33fff07e3e3 ("x86, build: allow LTO to be selected")
Cc Ricardo Ribalda <[email protected]>
Cc Sami Tolvanen <[email protected]>

Thanks for the patch!

Quoted 33 lines

---
AFAICT, x86 is the only arch that supports LTO and purgatory.

Changes in v3:
1. Fix "Fixes" tag. (Nick Desaulniers)
2. Add description of an alternative fix, with linker script. (Nick Desaulniers)

Changes in v2:
1. Use CC_FLAGS_LTO instead of hardcode -flto. (Nick Desaulniers)

---
 arch/x86/purgatory/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/purgatory/Makefile +4 -1
index c2a29be35c01..08aa0f25f12a 100644
@@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
 # optimization flags.
 KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
 
+# When LTO is enabled, llvm emits many text sections, which is not supported
+# by kexec. Remove -flto=* flags.
+KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
+
 # When linking purgatory.ro 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 -z nodefaultlib
--

2.34.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by on v3 1/1
#2 lore raw
In reply to Song Liu
Quoted 52 lines · Song Liu

-flto* implies -ffunction-sections. With LTO enabled, ld.lld generates multiple .text sections for purgatory.ro:

$ readelf -S purgatory.ro  | grep " .text"
  [ 1] .text             PROGBITS         0000000000000000  00000040
  [ 7] .text.purgatory   PROGBITS         0000000000000000  000020e0
  [ 9] .text.warn        PROGBITS         0000000000000000  000021c0
  [13] .text.sha256_upda PROGBITS         0000000000000000  000022f0
  [15] .text.sha224_upda PROGBITS         0000000000000000  00002be0
  [17] .text.sha256_fina PROGBITS         0000000000000000  00002bf0
  [19] .text.sha224_fina PROGBITS         0000000000000000  00002cc0

This cause WARNING from kexec_purgatory_setup_sechdrs():

WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
kexec_load_purgatory+0x37f/0x390

Fix this by disabling LTO for purgatory.

We could also fix this with an explicit linker script to rejoin .text.* sections back into .text. However, given the benefit of LTOing pugatory is small, simply disable the production of more .text.* sections for now.

Fixes b33fff07e3e3 ("x86, build: allow LTO to be selected")
Cc Ricardo Ribalda <[email protected]>
Cc Sami Tolvanen <[email protected]>

---
AFAICT, x86 is the only arch that supports LTO and purgatory.

Changes in v3:
1. Fix "Fixes" tag. (Nick Desaulniers)
2. Add description of an alternative fix, with linker script. (Nick Desaulniers)

Changes in v2:
1. Use CC_FLAGS_LTO instead of hardcode -flto. (Nick Desaulniers)

---
 arch/x86/purgatory/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/purgatory/Makefile +0 -0
index c2a29be35c01..08aa0f25f12a 100644

arch/x86/purgatory/Makefile CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY · line 28

Quoted 10 lines
arch/x86/purgatory/Makefile +4 -0
@@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
 # optimization flags.
 KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
 
+# When LTO is enabled, llvm emits many text sections, which is not supported
+# by kexec. Remove -flto=* flags.
+KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
+
 # When linking purgatory.ro 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 -z nodefaultlib

LGTM, thanks for the patch!

Sami

merge bot Applied
#3 lore raw
In reply to Song Liu
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     f7d2101197488fdd2106ca21346733562f398765
Gitweb:        https://git.kernel.org/tip/f7d2101197488fdd2106ca21346733562f398765
Author:        Song Liu <[email protected]>
AuthorDate:    Thu, 14 Sep 2023 10:01:38 -07:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 15 Sep 2023 10:31:26 +02:00

x86/purgatory: Remove LTO flags

-flto* implies -ffunction-sections. With LTO enabled, ld.lld generates multiple .text sections for purgatory.ro:

  $ readelf -S purgatory.ro  | grep " .text"
    [ 1] .text             PROGBITS         0000000000000000  00000040
    [ 7] .text.purgatory   PROGBITS         0000000000000000  000020e0
    [ 9] .text.warn        PROGBITS         0000000000000000  000021c0
    [13] .text.sha256_upda PROGBITS         0000000000000000  000022f0
    [15] .text.sha224_upda PROGBITS         0000000000000000  00002be0
    [17] .text.sha256_fina PROGBITS         0000000000000000  00002bf0
    [19] .text.sha224_fina PROGBITS         0000000000000000  00002cc0

This causes WARNING from kexec_purgatory_setup_sechdrs():

  WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
  kexec_load_purgatory+0x37f/0x390

Fix this by disabling LTO for purgatory.

[ AFAICT, x86 is the only arch that supports LTO and purgatory. ]

We could also fix this with an explicit linker script to rejoin .text.* sections back into .text. However, given the benefit of LTOing purgatory is small, simply disable the production of more .text.* sections for now.

---
 arch/x86/purgatory/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/purgatory/Makefile +4 -0
index c2a29be..08aa0f2 100644
@@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
 # optimization flags.
 KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
 
+# When LTO is enabled, llvm emits many text sections, which is not supported
+# by kexec. Remove -flto=* flags.
+KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
+
 # When linking purgatory.ro 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 -z nodefaultlib
merge bot Applied
#4 lore raw
In reply to Song Liu
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     75b2f7e4c9e0fd750a5a27ca9736d1daa7a3762a
Gitweb:        https://git.kernel.org/tip/75b2f7e4c9e0fd750a5a27ca9736d1daa7a3762a
Author:        Song Liu <[email protected]>
AuthorDate:    Thu, 14 Sep 2023 10:01:38 -07:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Sun, 17 Sep 2023 09:49:03 +02:00

x86/purgatory: Remove LTO flags

-flto* implies -ffunction-sections. With LTO enabled, ld.lld generates multiple .text sections for purgatory.ro:

  $ readelf -S purgatory.ro  | grep " .text"
    [ 1] .text             PROGBITS         0000000000000000  00000040
    [ 7] .text.purgatory   PROGBITS         0000000000000000  000020e0
    [ 9] .text.warn        PROGBITS         0000000000000000  000021c0
    [13] .text.sha256_upda PROGBITS         0000000000000000  000022f0
    [15] .text.sha224_upda PROGBITS         0000000000000000  00002be0
    [17] .text.sha256_fina PROGBITS         0000000000000000  00002bf0
    [19] .text.sha224_fina PROGBITS         0000000000000000  00002cc0

This causes WARNING from kexec_purgatory_setup_sechdrs():

  WARNING: CPU: 26 PID: 110894 at kernel/kexec_file.c:919
  kexec_load_purgatory+0x37f/0x390

Fix this by disabling LTO for purgatory.

[ AFAICT, x86 is the only arch that supports LTO and purgatory. ]

We could also fix this with an explicit linker script to rejoin .text.* sections back into .text. However, given the benefit of LTOing purgatory is small, simply disable the production of more .text.* sections for now.

---
 arch/x86/purgatory/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/purgatory/Makefile +4 -0
index c2a29be..08aa0f2 100644
@@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
 # optimization flags.
 KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
 
+# When LTO is enabled, llvm emits many text sections, which is not supported
+# by kexec. Remove -flto=* flags.
+KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
+
 # When linking purgatory.ro 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 -z nodefaultlib