Skip to contentSkip to conversation

x86/boot: Discard .discard.unreachable for arch/x86/boot/compressed/vmlinux

PATCH Applied Fangrui Song 6 participants 8 messages May 20, 2020 – May 22, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/boot: Discard .discard.unreachable for arch/x86/boot/compressed/vmlinux

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

---
 arch/x86/boot/compressed/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/boot/compressed/vmlinux.lds.S +2 -0
index 0dc5c2b9614b..8f1025d1f681 100644
@@ -74,4 +74,6 @@ SECTIONS
 #endif
 	. = ALIGN(PAGE_SIZE);	/* keep ZO size page aligned */
 	_end = .;
+
+	DISCARDS
 }
Signature · 1 line
2.26.2.761.g0e0b3e54be-goog
Tested-by on v1 1/1
#1 lore raw
Quoted 36 lines · Fangrui Song

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

---
 arch/x86/boot/compressed/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/boot/compressed/vmlinux.lds.S +2 -0
index 0dc5c2b9614b..8f1025d1f681 100644
@@ -74,4 +74,6 @@ SECTIONS
 #endif
 	. = ALIGN(PAGE_SIZE);	/* keep ZO size page aligned */
 	_end = .;
+
+	DISCARDS
 }
Signature · 1 line
2.26.2.761.g0e0b3e54be-goog

Thanks! Maybe add a note in the commit message that the section is generated from unreachable() annotations when CONFIG_STACK_VALIDATION is enabled.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Fangrui Song
Quoted 11 lines · Fangrui Song' via Clang Built Linux

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

Quoted 7 lines

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

Yay macro usage! :)

Signature · 1 line
Kees Cook
Tested-by
#3 lore raw
Quoted 16 lines · Kees Cook
Quoted 14 lines · Fangrui Song' via Clang Built Linux

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Quoted 9 lines
Quoted 4 lines

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

Yay macro usage! :)

Feel free to add...

Linux v5.7-rc6+ with Clang and LLD v10.0.1-rc1

...together with one more patches in the x86/boot area:

x86/boot: Correct relocation destination on old linkers

Next run will include:

x86/boot: Add .text.startup to setup.ld (v2)

- Sedat -

[1] https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.1-rc1

maintainer
#4 lore raw
Quoted 37 lines · Sedat Dilek
Quoted 16 lines · Kees Cook
Quoted 14 lines · Fangrui Song' via Clang Built Linux

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Quoted 9 lines
Quoted 4 lines

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

Yay macro usage! :)

Feel free to add...

Linux v5.7-rc6+ with Clang and LLD v10.0.1-rc1

...together with one more patches in the x86/boot area:

x86/boot: Correct relocation destination on old linkers

Quoted 7 lines

Next run will include:

x86/boot: Add .text.startup to setup.ld (v2)

- Sedat -

[1] https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.1-rc1

Thanks, I'll queue this up.

#5 lore raw
Quoted 41 lines · Ard Biesheuvel
Quoted 39 lines · Sedat Dilek
Quoted 16 lines · Kees Cook
Quoted 14 lines · Fangrui Song' via Clang Built Linux

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Quoted 9 lines
Quoted 4 lines

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

Yay macro usage! :)

Feel free to add...

Linux v5.7-rc6+ with Clang and LLD v10.0.1-rc1

...together with one more patches in the x86/boot area:

x86/boot: Correct relocation destination on old linkers

Next run will include:

Quoted 7 lines
Quoted 5 lines

x86/boot: Add .text.startup to setup.ld (v2)

- Sedat -

[1] https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.1-rc1

Thanks, I'll queue this up.

Just FYI:
It's in tip.git#x86/build already.

- Sedat -

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=x86/build&id=d6ee6529436a15a0541aff6e1697989ee7dc2c44

maintainer
#6 lore raw
Quoted 49 lines · Sedat Dilek
Quoted 47 lines · Ard Biesheuvel
Quoted 44 lines · Sedat Dilek
Quoted 16 lines · Kees Cook
Quoted 14 lines · Fangrui Song' via Clang Built Linux

In the latest efi tree, ce5e3f909fc0ed67e58367b9c56a54c20a51080b "efi/printf: Add 64-bit and 8-bit integer support", arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section from drivers/firmware/efi/libstub/vsprintf.stub.o

.discard.unreachable contains an R_X86_64_PC32 relocation, which will be warned by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time.

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Quoted 9 lines
Quoted 4 lines

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable

Yay macro usage! :)

Feel free to add...

Linux v5.7-rc6+ with Clang and LLD v10.0.1-rc1

...together with one more patches in the x86/boot area:

x86/boot: Correct relocation destination on old linkers

Next run will include:

x86/boot: Add .text.startup to setup.ld (v2)

- Sedat -

[1] https://github.com/llvm/llvm-project/releases/tag/llvmorg-10.0.1-rc1

Quoted 8 lines
Quoted 1 line

Thanks, I'll queue this up.

Just FYI:
It's in tip.git#x86/build already.

- Sedat -

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=x86/build&id=d6ee6529436a15a0541aff6e1697989ee7dc2c44

Thanks for the head's up. I'll remove it from my branch again.

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

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

Commit-ID:     d6ee6529436a15a0541aff6e1697989ee7dc2c44
Gitweb:        https://git.kernel.org/tip/d6ee6529436a15a0541aff6e1697989ee7dc2c44
Author:        Fangrui Song <[email protected]>
AuthorDate:    Wed, 20 May 2020 11:20:10 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Fri, 22 May 2020 12:42:07 +02:00

x86/boot: Discard .discard.unreachable for arch/x86/boot/compressed/vmlinux

With commit

ce5e3f909fc0 ("efi/printf: Add 64-bit and 8-bit integer support")

arch/x86/boot/compressed/vmlinux may have an undesired .discard.unreachable section coming from drivers/firmware/efi/libstub/vsprintf.stub.o. That section gets generated from unreachable() annotations when CONFIG_STACK_VALIDATION is enabled.

.discard.unreachable contains an R_X86_64_PC32 relocation which will be warned about by LLD: a non-SHF_ALLOC section (.discard.unreachable) is not part of the memory image, thus conceptually the distance between a non-SHF_ALLOC and a SHF_ALLOC is not a constant which can be resolved at link time:

% ld.lld -m elf_x86_64 -T arch/x86/boot/compressed/vmlinux.lds ... -o arch/x86/boot/compressed/vmlinux ld.lld: warning: vsprintf.c:(.discard.unreachable+0x0): has non-ABS relocation R_X86_64_PC32 against symbol ''

Reuse the DISCARDS macro which includes .discard.* to drop .discard.unreachable.

[ bp: Massage and complete the commit message. ]

---
 arch/x86/boot/compressed/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/boot/compressed/vmlinux.lds.S +2 -0
index 508cfa6..1031af1 100644
@@ -73,4 +73,6 @@ SECTIONS
 #endif
 	. = ALIGN(PAGE_SIZE);	/* keep ZO size page aligned */
 	_end = .;
+
+	DISCARDS
 }