riscv: improve link and support ARCH_WANT_LD_ORPHAN_WARN
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
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
@@ -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
PATCH v2 2/5 riscv: vmlinux.lds.S: explicitly catch .rela.dyn symbols
In reply to Jisheng ZhangWhen 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
@@ -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
PATCH v2 3/5 riscv: vmlinux.lds.S: explicitly catch .riscv.attributes sections
In reply to Jisheng ZhangWhen 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
@@ -146,6 +146,7 @@ SECTIONS STABS_DEBUG DWARF_DEBUG ELF_DETAILS + .riscv.attributes 0 : { *(.riscv.attributes) } DISCARDS }
Signature · 1 line
2.38.1
PATCH v2 4/5 riscv: vmlinux.lds.S: explicitly catch .init.bss sections from EFI stub
In reply to Jisheng ZhangWhen 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
@@ -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
PATCH v2 5/5 riscv: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL
In reply to Jisheng ZhangNow, 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
@@ -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
Re: [PATCH v2 1/5] riscv: lds: define RUNTIME_DISCARD_EXIT
In reply to Jisheng ZhangQuoted 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 missingRUNTIME_DISCARD_EXIT, because the DISCARD sits at the end of the linker script. Add the missingRUNTIME_DISCARD_EXITdefine so that it still works if we move DISCARD up or even at the beginning of the linker script.Signed-off-by Jisheng Zhang <[email protected]>Suggested-by Masahiro Yamada <[email protected]>
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
Re: [PATCH v2 5/5] riscv: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL
In reply to Jisheng ZhangQuoted 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.Signed-off-by Jisheng Zhang <[email protected]>
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@@ -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 MMUSignature · 1 line
2.38.1
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 missingRUNTIME_DISCARD_EXITas suggested by Masahiro.Similar as other architectures such as x86, arm64 and so on, enable
ARCH_WANT_LD_ORPHAN_WARNto 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 selectsARCH_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