Skip to contentSkip to conversation

riscv: improve link and support ARCH_WANT_LD_ORPHAN_WARN

PATCH Superseded Jisheng Zhang 3 participants 9 messages Jan 16, 2023 – Jan 17, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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 patches, and the last patch finally selects ARCH_WANT_LD_ORPHAN_WARN

Jisheng Zhang (4):
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: select ARCH_WANT_LD_ORPHAN_WARN for !XIP_KERNEL

 arch/riscv/Kconfig              | 1 +
 arch/riscv/kernel/vmlinux.lds.S | 6 ++++++
 2 files changed, 7 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 1/4 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
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] riscv: lds: define RUNTIME_DISCARD_EXIT

Quoted 19 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.

---
 arch/riscv/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/kernel/vmlinux.lds.S +0 -0
index 4e6c88aa4d87..07c19f2a288c 100644

arch/riscv/kernel/vmlinux.lds.S line 11

Quoted 7 lines
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"

Since the diff is identical to:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

Your commit message is better anyways.

Thanks,
Conor.

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

#3 lore raw

Re: [PATCH 1/4] riscv: lds: define RUNTIME_DISCARD_EXIT

Quoted 22 lines · Conor Dooley
Quoted 21 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.

---
 arch/riscv/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/kernel/vmlinux.lds.S +0 -0
index 4e6c88aa4d87..07c19f2a288c 100644
@@ -5,6 +5,7 @@
  */
 
Quoted 8 lines

arch/riscv/kernel/vmlinux.lds.S line 11

Quoted 5 lines
arch/riscv/kernel/vmlinux.lds.S +1 -0
 #define RO_EXCEPTION_TABLE_ALIGN	4
+#define RUNTIME_DISCARD_EXIT
 
 #ifdef CONFIG_XIP_KERNEL
 #include "vmlinux-xip.lds.S"

Since the diff is identical to:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

OOPS, I didn't notice you submitted the patch which did similar about RUNTIME_DISCARD_EXIT, then I'd like to recall patch1. I expected some review comments for remainning patch2\3\4, I will send v2 which will both address possible review comments and remove patch1

Quoted 2 lines

Your commit message is better anyways.

If you like it, you can take it into your v2 patch;)

Thanks

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

#4 lore raw

Re: [PATCH 1/4] riscv: lds: define RUNTIME_DISCARD_EXIT

Quoted 32 lines · Jisheng Zhang
Quoted 22 lines · Conor Dooley
Quoted 21 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.

---
 arch/riscv/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/kernel/vmlinux.lds.S +0 -0
index 4e6c88aa4d87..07c19f2a288c 100644
@@ -5,6 +5,7 @@
  */
 
Quoted 8 lines

arch/riscv/kernel/vmlinux.lds.S line 11

Quoted 5 lines
arch/riscv/kernel/vmlinux.lds.S +1 -0
 #define RO_EXCEPTION_TABLE_ALIGN	4
+#define RUNTIME_DISCARD_EXIT
 
 #ifdef CONFIG_XIP_KERNEL
 #include "vmlinux-xip.lds.S"

Since the diff is identical to:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

Quoted 5 lines

OOPS, I didn't notice you submitted the patch which did similar about RUNTIME_DISCARD_EXIT, then I'd like to recall patch1. I expected some review comments for remainning patch2\3\4, I will send v2 which will both address possible review comments and remove patch1

Nah, keep your patch in the series.
I'll mark mine as superseded in patchwork.

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

#5 lore raw

PATCH 2/4 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
#6 lore raw

PATCH 3/4 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' usage 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 · 7 lines
2.38.1


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

PATCH 4/4 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
#8 lore raw

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

Hey Jisheng,

Quoted 14 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.

---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +0 -0
index e2b656043abf..335e0c45cced 100644

arch/riscv/Kconfig config RISCV · line 49

Quoted 4 lines
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

Enabling this points out a bunch of warnings in the efi stub:
https://gist.github.com/conor-pwbot/145c5536268aec641671592a4cced32c

Would you mind sorting those out prior to enabling the warning?

Thanks,
Conor.

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