Skip to contentSkip to conversation

riscv: improve link and support ARCH_WANT_LD_ORPHAN_WARN

PATCH Applied Jisheng Zhang 4 participants 9 messages Jan 19, 2023 – Feb 22, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover riscv: improve link and support ARCH_WANT_LD_ORPHAN_WARN

This series tries to improve link time handling of riscv:
patch1 adds the missing RUNTIME_DISCARD_EXIT as suggested by Masahiro.

Similar as other architectures such as x86, arm64 and so on, enable ARCH_WANT_LD_ORPHAN_WARN to enable linker orphan warnings to prevent from missing any new sections in future. So the following two patches are preparation ones, and the last patch finally selects ARCH_WANT_LD_ORPHAN_WARN

Since v1:
- add one more patch to catch .init.bss from EFI stub

Jisheng Zhang (5):
riscv: lds: define RUNTIME_DISCARD_EXIT
riscv: vmlinux.lds.S: explicitly catch .rela.dyn symbols
riscv: vmlinux.lds.S: explicitly catch .riscv.attributes sections
riscv: vmlinux.lds.S: explicitly catch .init.bss sections from EFI
stub
riscv: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL

 arch/riscv/Kconfig              | 1 +
 arch/riscv/kernel/vmlinux.lds.S | 9 +++++++++
 2 files changed, 10 insertions(+)
Signature · 7 lines
2.38.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

PATCH v2 1/5 riscv: lds: define RUNTIME_DISCARD_EXIT

riscv discards .exit.* sections at run-time but doesn't define RUNTIME_DISCARD_EXIT. However, the .exit.* sections are still allocated and kept even if the generic DISCARDS would discard the sections due to missing RUNTIME_DISCARD_EXIT, because the DISCARD sits at the end of the linker script. Add the missing RUNTIME_DISCARD_EXIT define so that it still works if we move DISCARD up or even at the beginning of the linker script.

---
 arch/riscv/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/kernel/vmlinux.lds.S +1 -0
index 4e6c88aa4d87..07c19f2a288c 100644
@@ -5,6 +5,7 @@
  */
 
 #define RO_EXCEPTION_TABLE_ALIGN	4
+#define RUNTIME_DISCARD_EXIT
 
 #ifdef CONFIG_XIP_KERNEL
 #include "vmlinux-xip.lds.S"
Signature · 7 lines
2.38.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

PATCH v2 2/5 riscv: vmlinux.lds.S: explicitly catch .rela.dyn symbols

In reply to Jisheng Zhang

When enabling linker orphan section warning, I got warnings similar as below:
riscv64-linux-gnu-ld: warning: orphan section .rela.text' from init/main.o' being placed in section `.rela.dyn'

Use the approach similar as ARM64 does and declare it in vmlinux.lds.S

---
 arch/riscv/kernel/vmlinux.lds.S | 4 ++++
 1 file changed, 4 insertions(+)
arch/riscv/kernel/vmlinux.lds.S +4 -0
index 07c19f2a288c..6a250313b752 100644
@@ -97,6 +97,10 @@ SECTIONS
 		*(.rel.dyn*)
 	}
 
+	.rela.dyn : {
+		*(.rela*)
+	}
+
 	__init_data_end = .;
 
 	. = ALIGN(8);
Signature · 7 lines
2.38.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#4 lore raw

PATCH v2 3/5 riscv: vmlinux.lds.S: explicitly catch .riscv.attributes sections

In reply to Jisheng Zhang

When enabling linker orphan section warning, I got warnings similar as below:
riscv64-linux-gnu-ld: warning: orphan section .riscv.attributes' from init/main.o' being placed in section `.riscv.attributes'

While I don't see any usage of .riscv.attributes sections' in kernel now, just catch the sections so that we can enable linker orphan section warning.

---
 arch/riscv/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/kernel/vmlinux.lds.S +1 -0
index 6a250313b752..7eb3d25d0dae 100644
@@ -146,6 +146,7 @@ SECTIONS
 	STABS_DEBUG
 	DWARF_DEBUG
 	ELF_DETAILS
+	.riscv.attributes 0 : { *(.riscv.attributes) }
 
 	DISCARDS
 }
Signature · 1 line
2.38.1
#5 lore raw

PATCH v2 4/5 riscv: vmlinux.lds.S: explicitly catch .init.bss sections from EFI stub

In reply to Jisheng Zhang

When enabling linker orphan section warning, I got warnings similar as below:
ld.lld: warning:
./drivers/firmware/efi/libstub/lib.a(efi-stub-helper.stub.o):(.init.bss) is being placed in '.init.bss'

Catch the sections so that we can enable linker orphan section warning.

---
 arch/riscv/kernel/vmlinux.lds.S | 3 +++
 1 file changed, 3 insertions(+)
arch/riscv/kernel/vmlinux.lds.S +3 -0
index 7eb3d25d0dae..b2813b5e47a0 100644
@@ -87,6 +87,9 @@ SECTIONS
 	/* Start of init data section */
 	__init_data_begin = .;
 	INIT_DATA_SECTION(16)
+	.init.bss : {
+		*(.init.bss)	/* from the EFI stub */
+	}
 	.exit.data :
 	{
 		EXIT_DATA
Signature · 7 lines
2.38.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#6 lore raw

PATCH v2 5/5 riscv: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL

In reply to Jisheng Zhang

Now, after that all the sections are explicitly described and declared in vmlinux.lds.S, we can enable ld orphan warnings for !XIP_KERNEL to prevent from missing any new sections in future.

---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index e2b656043abf..335e0c45cced 100644
@@ -46,6 +46,7 @@ config RISCV
 	select ARCH_WANT_FRAME_POINTERS
 	select ARCH_WANT_GENERAL_HUGETLB
 	select ARCH_WANT_HUGE_PMD_SHARE if 64BIT
+	select ARCH_WANT_LD_ORPHAN_WARN if !XIP_KERNEL
 	select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE
 	select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU
 	select BUILDTIME_TABLE_SORT if MMU
Signature · 7 lines
2.38.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] riscv: lds: define RUNTIME_DISCARD_EXIT

In reply to Jisheng Zhang
Quoted 10 lines · Jisheng Zhang

riscv discards .exit.* sections at run-time but doesn't define RUNTIME_DISCARD_EXIT. However, the .exit.* sections are still allocated and kept even if the generic DISCARDS would discard the sections due to missing RUNTIME_DISCARD_EXIT, because the DISCARD sits at the end of the linker script. Add the missing RUNTIME_DISCARD_EXIT define so that it still works if we move DISCARD up or even at the beginning of the linker script.

Thought I left one of these against v1, either way:

Thanks,
Conor.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by on v2 5/5
#7 lore raw

Re: [PATCH v2 5/5] riscv: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL

In reply to Jisheng Zhang
Quoted 5 lines · Jisheng Zhang

Now, after that all the sections are explicitly described and declared in vmlinux.lds.S, we can enable ld orphan warnings for !XIP_KERNEL to prevent from missing any new sections in future.

Warnings that the automation picked up are now gone in v2, thanks!

Quoted 19 lines
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
index e2b656043abf..335e0c45cced 100644
@@ -46,6 +46,7 @@ config RISCV
 	select ARCH_WANT_FRAME_POINTERS
 	select ARCH_WANT_GENERAL_HUGETLB
 	select ARCH_WANT_HUGE_PMD_SHARE if 64BIT
+	select ARCH_WANT_LD_ORPHAN_WARN if !XIP_KERNEL
 	select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE
 	select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU
 	select BUILDTIME_TABLE_SORT if MMU
Signature · 1 line
2.38.1
#8 lore raw
In reply to Jisheng Zhang
This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This series was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 10 lines · On Thu, 19 Jan 2023 23:54:12 +0800 you wrote:

This series tries to improve link time handling of riscv:
patch1 adds the missing RUNTIME_DISCARD_EXIT as suggested by Masahiro.

Similar as other architectures such as x86, arm64 and so on, enable ARCH_WANT_LD_ORPHAN_WARN to enable linker orphan warnings to prevent from missing any new sections in future. So the following two patches are preparation ones, and the last patch finally selects ARCH_WANT_LD_ORPHAN_WARN

[...]

Here is the summary with links:
- [v2,1/5] riscv: lds: define RUNTIME_DISCARD_EXIT

    https://git.kernel.org/riscv/c/7e92586c28a5
  - [v2,2/5] riscv: vmlinux.lds.S: explicitly catch .rela.dyn symbols
    https://git.kernel.org/riscv/c/e5973191a8e3
  - [v2,3/5] riscv: vmlinux.lds.S: explicitly catch .riscv.attributes sections
    https://git.kernel.org/riscv/c/b13e64d94149
  - [v2,4/5] riscv: vmlinux.lds.S: explicitly catch .init.bss sections from EFI stub
    https://git.kernel.org/riscv/c/0ed0031b093b
  - [v2,5/5] riscv: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL
    https://git.kernel.org/riscv/c/f4b71bff8d85

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html