linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] powerpc: build / linker improvements
@ 2022-09-16  4:07 Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 1/7] powerpc: move __end_rodata to cover arch read-only sections Nicholas Piggin
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

This series is mainly about moving more things out of writable and
executable memory, and slightly moving the linker script in the
direction of the binutils ld internal linker script as we do.

Thanks,
Nick

Since v1:
- Move sys_call_table data.rel.ro patch to the end.
- And fix the changelog in that patch, the relocations were a red herring.
- Update the changelog in the __end_rodata patch.
- Align __end_rodata to strict align size.

Nicholas Piggin (7):
  powerpc: move __end_rodata to cover arch read-only sections
  powerpc/32/build: move got1/got2 sections out of text
  powerpc/build: move got, toc, plt, branch_lt sections to read-only
  powerpc/build: move .data.rel.ro, .sdata2 to read-only
  powerpc/64/build: only include .opd with ELFv1
  powerpc/64/build: merge .got and .toc input sections
  powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE

 arch/powerpc/kernel/systbl.S             |  4 ++
 arch/powerpc/kernel/vmlinux.lds.S        | 85 +++++++++++++++---------
 arch/powerpc/mm/book3s32/mmu.c           |  2 +-
 arch/powerpc/mm/book3s64/hash_pgtable.c  |  2 +-
 arch/powerpc/mm/book3s64/radix_pgtable.c |  6 +-
 arch/powerpc/mm/pgtable_32.c             |  7 +-
 6 files changed, 66 insertions(+), 40 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/7] powerpc: move __end_rodata to cover arch read-only sections
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 2/7] powerpc/32/build: move got1/got2 sections out of text Nicholas Piggin
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

powerpc has a number of read-only sections and tables that are put after
RO_DATA(). Move the __end_rodata symbol to cover these as well.

Setting memory to read-only at boot is done using __init_begin, change
that that to use __end_rodata. This removes the requirement for the init
section to follow read-only data.

This makes is_kernel_rodata() exactly cover the read-only region, as
well as other things using __end_rodata (e.g., kernel/dma/debug.c).
Boot dmesg also prints the rodata size more accurately.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S        | 3 +++
 arch/powerpc/mm/book3s32/mmu.c           | 2 +-
 arch/powerpc/mm/book3s64/hash_pgtable.c  | 2 +-
 arch/powerpc/mm/book3s64/radix_pgtable.c | 6 +++---
 arch/powerpc/mm/pgtable_32.c             | 7 ++++---
 5 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index fe22d940412f..d81e4392da26 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -210,6 +210,9 @@ SECTIONS
 	}
 #endif
 
+	. = ALIGN(STRICT_ALIGN_SIZE);
+	__end_rodata = .;
+
 /*
  * Init sections discarded at runtime
  */
diff --git a/arch/powerpc/mm/book3s32/mmu.c b/arch/powerpc/mm/book3s32/mmu.c
index a96b73006dfb..e13b883e4e5b 100644
--- a/arch/powerpc/mm/book3s32/mmu.c
+++ b/arch/powerpc/mm/book3s32/mmu.c
@@ -240,7 +240,7 @@ void mmu_mark_rodata_ro(void)
 	for (i = 0; i < nb; i++) {
 		struct ppc_bat *bat = BATS[i];
 
-		if (bat_addrs[i].start < (unsigned long)__init_begin)
+		if (bat_addrs[i].start < (unsigned long)__end_rodata)
 			bat[1].batl = (bat[1].batl & ~BPP_RW) | BPP_RX;
 	}
 
diff --git a/arch/powerpc/mm/book3s64/hash_pgtable.c b/arch/powerpc/mm/book3s64/hash_pgtable.c
index ae008b9df0e6..28332001bd87 100644
--- a/arch/powerpc/mm/book3s64/hash_pgtable.c
+++ b/arch/powerpc/mm/book3s64/hash_pgtable.c
@@ -541,7 +541,7 @@ void hash__mark_rodata_ro(void)
 	unsigned long start, end, pp;
 
 	start = (unsigned long)_stext;
-	end = (unsigned long)__init_begin;
+	end = (unsigned long)__end_rodata;
 
 	pp = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL_ROX), HPTE_USE_KERNEL_KEY);
 
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 698274109c91..eb3c56975c37 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -228,7 +228,7 @@ void radix__mark_rodata_ro(void)
 	unsigned long start, end;
 
 	start = (unsigned long)_stext;
-	end = (unsigned long)__init_begin;
+	end = (unsigned long)__end_rodata;
 
 	radix__change_memory_range(start, end, _PAGE_WRITE);
 }
@@ -259,8 +259,8 @@ print_mapping(unsigned long start, unsigned long end, unsigned long size, bool e
 static unsigned long next_boundary(unsigned long addr, unsigned long end)
 {
 #ifdef CONFIG_STRICT_KERNEL_RWX
-	if (addr < __pa_symbol(__init_begin))
-		return __pa_symbol(__init_begin);
+	if (addr < __pa_symbol(__end_rodata))
+		return __pa_symbol(__end_rodata);
 #endif
 	return end;
 }
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index 3ac73f9fb5d5..5c02fd08d61e 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -158,10 +158,11 @@ void mark_rodata_ro(void)
 	}
 
 	/*
-	 * mark .text and .rodata as read only. Use __init_begin rather than
-	 * __end_rodata to cover NOTES and EXCEPTION_TABLE.
+	 * mark text and rodata as read only. __end_rodata is set by
+	 * powerpc's linker script and includes tables and data
+	 * requiring relocation which are not put in RO_DATA.
 	 */
-	numpages = PFN_UP((unsigned long)__init_begin) -
+	numpages = PFN_UP((unsigned long)__end_rodata) -
 		   PFN_DOWN((unsigned long)_stext);
 
 	set_memory_ro((unsigned long)_stext, numpages);
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/7] powerpc/32/build: move got1/got2 sections out of text
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 1/7] powerpc: move __end_rodata to cover arch read-only sections Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only Nicholas Piggin
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

Following the example from the binutils default linker script, move
.got1 and .got2 out of .text, to just after RO_DATA.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index d81e4392da26..607b17b1e785 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -122,14 +122,6 @@ SECTIONS
 		*(.sfpr);
 		MEM_KEEP(init.text)
 		MEM_KEEP(exit.text)
-
-#ifdef CONFIG_PPC32
-		*(.got1)
-		__got2_start = .;
-		*(.got2)
-		__got2_end = .;
-#endif /* CONFIG_PPC32 */
-
 	} :text
 
 	. = ALIGN(PAGE_SIZE);
@@ -139,7 +131,16 @@ SECTIONS
 	/* Read-only data */
 	RO_DATA(PAGE_SIZE)
 
-#ifdef CONFIG_PPC64
+#ifdef CONFIG_PPC32
+	.got1 : AT(ADDR(.got1) - LOAD_OFFSET) {
+		*(.got1)
+	}
+	.got2 : AT(ADDR(.got2) - LOAD_OFFSET) {
+		__got2_start = .;
+		*(.got2)
+		__got2_end = .;
+	}
+#else /* CONFIG_PPC32 */
 	SOFT_MASK_TABLE(8)
 	RESTART_TABLE(8)
 
@@ -190,7 +191,7 @@ SECTIONS
 		*(__rfi_flush_fixup)
 		__stop___rfi_flush_fixup = .;
 	}
-#endif /* CONFIG_PPC64 */
+#endif /* CONFIG_PPC32 */
 
 #ifdef CONFIG_PPC_BARRIER_NOSPEC
 	. = ALIGN(8);
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 1/7] powerpc: move __end_rodata to cover arch read-only sections Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 2/7] powerpc/32/build: move got1/got2 sections out of text Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-09-17 20:15   ` kernel test robot
  2022-09-16  4:07 ` [PATCH v2 4/7] powerpc/build: move .data.rel.ro, .sdata2 " Nicholas Piggin
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

This moves linker-related tables from .data to read-only area.
Relocations are performed at early boot time before memory is protected,
after which there should be no modifications required.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S | 42 ++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 607b17b1e785..16c4389d498d 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -131,6 +131,10 @@ SECTIONS
 	/* Read-only data */
 	RO_DATA(PAGE_SIZE)
 
+	.branch_lt : AT(ADDR(.branch_lt) - LOAD_OFFSET) {
+		*(.branch_lt)
+	}
+
 #ifdef CONFIG_PPC32
 	.got1 : AT(ADDR(.got1) - LOAD_OFFSET) {
 		*(.got1)
@@ -140,7 +144,30 @@ SECTIONS
 		*(.got2)
 		__got2_end = .;
 	}
+	.got : AT(ADDR(.got) - LOAD_OFFSET) SPECIAL {
+		*(.got)
+		*(.got.plt)
+	}
+	.plt : AT(ADDR(.plt) - LOAD_OFFSET) SPECIAL {
+		/* XXX: is .plt (and .got.plt) required? */
+		*(.plt)
+	}
+
 #else /* CONFIG_PPC32 */
+	.toc1 : AT(ADDR(.toc1) - LOAD_OFFSET) {
+		*(.toc1)
+	}
+
+	.got : AT(ADDR(.got) - LOAD_OFFSET) ALIGN(256) {
+		*(.got)
+#ifndef CONFIG_RELOCATABLE
+		__prom_init_toc_start = .;
+		arch/powerpc/kernel/prom_init.o*(.toc)
+		__prom_init_toc_end = .;
+#endif
+		*(.toc)
+	}
+
 	SOFT_MASK_TABLE(8)
 	RESTART_TABLE(8)
 
@@ -327,26 +354,11 @@ SECTIONS
 		*(.data.rel*)
 		*(SDATA_MAIN)
 		*(.sdata2)
-		*(.got.plt) *(.got)
-		*(.plt)
-		*(.branch_lt)
 	}
 #else
 	.data : AT(ADDR(.data) - LOAD_OFFSET) {
 		DATA_DATA
 		*(.data.rel*)
-		*(.toc1)
-		*(.branch_lt)
-	}
-
-	.got : AT(ADDR(.got) - LOAD_OFFSET) ALIGN(256) {
-		*(.got)
-#ifndef CONFIG_RELOCATABLE
-		__prom_init_toc_start = .;
-		arch/powerpc/kernel/prom_init.o*(.toc)
-		__prom_init_toc_end = .;
-#endif
-		*(.toc)
 	}
 #endif
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 4/7] powerpc/build: move .data.rel.ro, .sdata2 to read-only
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
                   ` (2 preceding siblings ...)
  2022-09-16  4:07 ` [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 5/7] powerpc/64/build: only include .opd with ELFv1 Nicholas Piggin
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

.sdata2 is a readonly small data section for ppc32, and .data.rel.ro
is data that needs relocating but is read-only after that so these
can both be moved to the read only memory region.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 16c4389d498d..ae0814063900 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -131,6 +131,16 @@ SECTIONS
 	/* Read-only data */
 	RO_DATA(PAGE_SIZE)
 
+#ifdef CONFIG_PPC32
+	.sdata2 : AT(ADDR(.sdata2) - LOAD_OFFSET) {
+		*(.sdata2)
+	}
+#endif
+
+	.data.rel.ro : AT(ADDR(.data.rel.ro) - LOAD_OFFSET) {
+		*(.data.rel.ro*)
+	}
+
 	.branch_lt : AT(ADDR(.branch_lt) - LOAD_OFFSET) {
 		*(.branch_lt)
 	}
@@ -348,19 +358,13 @@ SECTIONS
 	. = ALIGN(PAGE_SIZE);
 	_sdata = .;
 
-#ifdef CONFIG_PPC32
 	.data : AT(ADDR(.data) - LOAD_OFFSET) {
 		DATA_DATA
 		*(.data.rel*)
+#ifdef CONFIG_PPC32
 		*(SDATA_MAIN)
-		*(.sdata2)
-	}
-#else
-	.data : AT(ADDR(.data) - LOAD_OFFSET) {
-		DATA_DATA
-		*(.data.rel*)
-	}
 #endif
+	}
 
 	/* The initial task and kernel stack */
 	INIT_TASK_DATA_SECTION(THREAD_ALIGN)
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 5/7] powerpc/64/build: only include .opd with ELFv1
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
                   ` (3 preceding siblings ...)
  2022-09-16  4:07 ` [PATCH v2 4/7] powerpc/build: move .data.rel.ro, .sdata2 " Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-09-16  4:07 ` [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections Nicholas Piggin
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

ELFv2 does not use function descriptors so .opd is not required.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index ae0814063900..737825ae2ae0 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -181,11 +181,13 @@ SECTIONS
 	SOFT_MASK_TABLE(8)
 	RESTART_TABLE(8)
 
+#ifdef CONFIG_PPC64_ELF_ABI_V1
 	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
 		__start_opd = .;
 		KEEP(*(.opd))
 		__end_opd = .;
 	}
+#endif
 
 	. = ALIGN(8);
 	__stf_entry_barrier_fixup : AT(ADDR(__stf_entry_barrier_fixup) - LOAD_OFFSET) {
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
                   ` (4 preceding siblings ...)
  2022-09-16  4:07 ` [PATCH v2 5/7] powerpc/64/build: only include .opd with ELFv1 Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-09-16 18:45   ` Christophe Leroy
  2022-09-16  4:07 ` [PATCH v2 7/7] powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE Nicholas Piggin
  2022-10-04 13:24 ` [PATCH v2 0/7] powerpc: build / linker improvements Michael Ellerman
  7 siblings, 1 reply; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

Follow the binutils ld internal linker script and merge .got and .toc
input sections in the .got output section.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 737825ae2ae0..3d96d51c8a5f 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -169,13 +169,12 @@ SECTIONS
 	}
 
 	.got : AT(ADDR(.got) - LOAD_OFFSET) ALIGN(256) {
-		*(.got)
+		*(.got .toc)
 #ifndef CONFIG_RELOCATABLE
 		__prom_init_toc_start = .;
 		arch/powerpc/kernel/prom_init.o*(.toc)
 		__prom_init_toc_end = .;
 #endif
-		*(.toc)
 	}
 
 	SOFT_MASK_TABLE(8)
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 7/7] powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
                   ` (5 preceding siblings ...)
  2022-09-16  4:07 ` [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections Nicholas Piggin
@ 2022-09-16  4:07 ` Nicholas Piggin
  2022-10-04 13:24 ` [PATCH v2 0/7] powerpc: build / linker improvements Michael Ellerman
  7 siblings, 0 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-16  4:07 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman, Christophe Leroy; +Cc: Nicholas Piggin

Const function pointers by convention live in .data.rel.ro if they need
to be relocated. Now that .data.rel.ro is linked into the read-only
region, put them in the right section. This doesn't make much practical
difference, but it will make the C conversion of sys_call_table a
smaller change as far as linking goes.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/systbl.S | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/kernel/systbl.S b/arch/powerpc/kernel/systbl.S
index cb3358886203..0bec33e86f50 100644
--- a/arch/powerpc/kernel/systbl.S
+++ b/arch/powerpc/kernel/systbl.S
@@ -12,7 +12,11 @@
 
 #include <asm/ppc_asm.h>
 
+#ifdef CONFIG_RELOCATABLE
+.section .data.rel.ro,"aw"
+#else
 .section .rodata,"a"
+#endif
 
 #ifdef CONFIG_PPC64
 	.p2align	3
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections
  2022-09-16  4:07 ` [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections Nicholas Piggin
@ 2022-09-16 18:45   ` Christophe Leroy
  2022-09-17  6:36     ` Michael Ellerman
  0 siblings, 1 reply; 14+ messages in thread
From: Christophe Leroy @ 2022-09-16 18:45 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev, Michael Ellerman



Le 16/09/2022 à 06:07, Nicholas Piggin a écrit :
> Follow the binutils ld internal linker script and merge .got and .toc
> input sections in the .got output section.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>   arch/powerpc/kernel/vmlinux.lds.S | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
> index 737825ae2ae0..3d96d51c8a5f 100644
> --- a/arch/powerpc/kernel/vmlinux.lds.S
> +++ b/arch/powerpc/kernel/vmlinux.lds.S
> @@ -169,13 +169,12 @@ SECTIONS
>   	}
>   
>   	.got : AT(ADDR(.got) - LOAD_OFFSET) ALIGN(256) {
> -		*(.got)
> +		*(.got .toc)

At the begining I was thinking that this change would jeopardise the 
below, but in fact the #ifdef below is pointless, because prom_init.o is 
built only when CONFIG_PPC_OF_BOOT_TRAMPOLINE is selected but 
CONFIG_PPC_OF_BOOT_TRAMPOLINE selects CONFIG_RELOCATABLE

So all __prom_init_toc_ stuff can go away :

arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_start[];
arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_end[];
arch/powerpc/kernel/prom_init_check.sh:__prom_init_toc_start 
__prom_init_toc_end btext_setup_display TOC.
arch/powerpc/kernel/vmlinux.lds.S:              __prom_init_toc_start = .;
arch/powerpc/kernel/vmlinux.lds.S:              __prom_init_toc_end = .;


>   #ifndef CONFIG_RELOCATABLE
>   		__prom_init_toc_start = .;
>   		arch/powerpc/kernel/prom_init.o*(.toc)
>   		__prom_init_toc_end = .;
>   #endif
> -		*(.toc)
>   	}
>   
>   	SOFT_MASK_TABLE(8)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections
  2022-09-16 18:45   ` Christophe Leroy
@ 2022-09-17  6:36     ` Michael Ellerman
  0 siblings, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2022-09-17  6:36 UTC (permalink / raw)
  To: Christophe Leroy, Nicholas Piggin, linuxppc-dev

Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> Le 16/09/2022 à 06:07, Nicholas Piggin a écrit :
>> Follow the binutils ld internal linker script and merge .got and .toc
>> input sections in the .got output section.
>> 
>> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>> ---
>>   arch/powerpc/kernel/vmlinux.lds.S | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>> 
>> diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
>> index 737825ae2ae0..3d96d51c8a5f 100644
>> --- a/arch/powerpc/kernel/vmlinux.lds.S
>> +++ b/arch/powerpc/kernel/vmlinux.lds.S
>> @@ -169,13 +169,12 @@ SECTIONS
>>   	}
>>   
>>   	.got : AT(ADDR(.got) - LOAD_OFFSET) ALIGN(256) {
>> -		*(.got)
>> +		*(.got .toc)
>
> At the begining I was thinking that this change would jeopardise the 
> below, but in fact the #ifdef below is pointless, because prom_init.o is 
> built only when CONFIG_PPC_OF_BOOT_TRAMPOLINE is selected but 
> CONFIG_PPC_OF_BOOT_TRAMPOLINE selects CONFIG_RELOCATABLE
>
> So all __prom_init_toc_ stuff can go away :
>
> arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_start[];
> arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_end[];
> arch/powerpc/kernel/prom_init_check.sh:__prom_init_toc_start 
> __prom_init_toc_end btext_setup_display TOC.
> arch/powerpc/kernel/vmlinux.lds.S:              __prom_init_toc_start = .;
> arch/powerpc/kernel/vmlinux.lds.S:              __prom_init_toc_end = .;

Yes you're right.

Missed cleanup by me in 24d33ac5b8ff ("powerpc/64s: Make prom_init require RELOCATABLE").

I'll send a patch tomorrow.

cheers

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only
  2022-09-16  4:07 ` [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only Nicholas Piggin
@ 2022-09-17 20:15   ` kernel test robot
  2022-09-19  5:39     ` Michael Ellerman
  0 siblings, 1 reply; 14+ messages in thread
From: kernel test robot @ 2022-09-17 20:15 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev, Michael Ellerman, Christophe Leroy
  Cc: llvm, kbuild-all, Nicholas Piggin

Hi Nicholas,

I love your patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on linus/master v6.0-rc5 next-20220916]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Nicholas-Piggin/powerpc-build-linker-improvements/20220916-121310
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-microwatt_defconfig (https://download.01.org/0day-ci/archive/20220918/202209180437.4U3soljK-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install powerpc cross compiling tool for clang build
        # apt-get install binutils-powerpc-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/6c034c08f8d0addb6fecba38c9c428b1c4df7c29
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Nicholas-Piggin/powerpc-build-linker-improvements/20220916-121310
        git checkout 6c034c08f8d0addb6fecba38c9c428b1c4df7c29
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> ld.lld: error: ./arch/powerpc/kernel/vmlinux.lds:46: { expected, but got SPECIAL
   >>>  .got : AT(ADDR(.got) - (0xc0000000 -0x00000000)) SPECIAL {
   >>>                                                   ^

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only
  2022-09-17 20:15   ` kernel test robot
@ 2022-09-19  5:39     ` Michael Ellerman
  2022-09-20 10:50       ` Nicholas Piggin
  0 siblings, 1 reply; 14+ messages in thread
From: Michael Ellerman @ 2022-09-19  5:39 UTC (permalink / raw)
  To: kernel test robot, Nicholas Piggin, linuxppc-dev, Christophe Leroy
  Cc: llvm, kbuild-all, Nicholas Piggin

kernel test robot <lkp@intel.com> writes:
> Hi Nicholas,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on powerpc/next]
> [also build test ERROR on linus/master v6.0-rc5 next-20220916]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Nicholas-Piggin/powerpc-build-linker-improvements/20220916-121310
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
> config: powerpc-microwatt_defconfig (https://download.01.org/0day-ci/archive/20220918/202209180437.4U3soljK-lkp@intel.com/config)
> compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install powerpc cross compiling tool for clang build
>         # apt-get install binutils-powerpc-linux-gnu
>         # https://github.com/intel-lab-lkp/linux/commit/6c034c08f8d0addb6fecba38c9c428b1c4df7c29
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Nicholas-Piggin/powerpc-build-linker-improvements/20220916-121310
>         git checkout 6c034c08f8d0addb6fecba38c9c428b1c4df7c29
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash
                                                    ^^^^^

> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
>>> ld.lld: error: ./arch/powerpc/kernel/vmlinux.lds:46: { expected, but got SPECIAL
>    >>>  .got : AT(ADDR(.got) - (0xc0000000 -0x00000000)) SPECIAL {
>    >>>                                                   ^

I guess SPECIAL is a binutils ld ism?

I can't find it documented anywhere.

Presumably we can just not use it, given we never did before?

cheers

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only
  2022-09-19  5:39     ` Michael Ellerman
@ 2022-09-20 10:50       ` Nicholas Piggin
  0 siblings, 0 replies; 14+ messages in thread
From: Nicholas Piggin @ 2022-09-20 10:50 UTC (permalink / raw)
  To: Michael Ellerman, kernel test robot, linuxppc-dev, Christophe Leroy
  Cc: llvm, kbuild-all

On Mon Sep 19, 2022 at 3:39 PM AEST, Michael Ellerman wrote:
> kernel test robot <lkp@intel.com> writes:
> > Hi Nicholas,
> >
> > I love your patch! Yet something to improve:
> >
> > [auto build test ERROR on powerpc/next]
> > [also build test ERROR on linus/master v6.0-rc5 next-20220916]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> >
> > url:    https://github.com/intel-lab-lkp/linux/commits/Nicholas-Piggin/powerpc-build-linker-improvements/20220916-121310
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
> > config: powerpc-microwatt_defconfig (https://download.01.org/0day-ci/archive/20220918/202209180437.4U3soljK-lkp@intel.com/config)
> > compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install powerpc cross compiling tool for clang build
> >         # apt-get install binutils-powerpc-linux-gnu
> >         # https://github.com/intel-lab-lkp/linux/commit/6c034c08f8d0addb6fecba38c9c428b1c4df7c29
> >         git remote add linux-review https://github.com/intel-lab-lkp/linux
> >         git fetch --no-tags linux-review Nicholas-Piggin/powerpc-build-linker-improvements/20220916-121310
> >         git checkout 6c034c08f8d0addb6fecba38c9c428b1c4df7c29
> >         # save the config file
> >         mkdir build_dir && cp config build_dir/.config
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash
>                                                     ^^^^^
>
> > If you fix the issue, kindly add following tag where applicable
> > Reported-by: kernel test robot <lkp@intel.com>
> >
> > All errors (new ones prefixed by >>):
> >
> >>> ld.lld: error: ./arch/powerpc/kernel/vmlinux.lds:46: { expected, but got SPECIAL
> >    >>>  .got : AT(ADDR(.got) - (0xc0000000 -0x00000000)) SPECIAL {
> >    >>>                                                   ^
>
> I guess SPECIAL is a binutils ld ism?
>
> I can't find it documented anywhere.
>
> Presumably we can just not use it, given we never did before?

Yeah that's what it is, oops I just took it from the linker script.

I think we can drop it, I think it selects either old or new plt
sections that are created with --secure-plt, I guess depending on
some link options and copmatibility concerns. Doesn't look like
ppc32 uses --secure-plt.

Thanks,
Nick


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/7] powerpc: build / linker improvements
  2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
                   ` (6 preceding siblings ...)
  2022-09-16  4:07 ` [PATCH v2 7/7] powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE Nicholas Piggin
@ 2022-10-04 13:24 ` Michael Ellerman
  7 siblings, 0 replies; 14+ messages in thread
From: Michael Ellerman @ 2022-10-04 13:24 UTC (permalink / raw)
  To: Nicholas Piggin, Christophe Leroy, linuxppc-dev, Michael Ellerman

On Fri, 16 Sep 2022 14:07:48 +1000, Nicholas Piggin wrote:
> This series is mainly about moving more things out of writable and
> executable memory, and slightly moving the linker script in the
> direction of the binutils ld internal linker script as we do.
> 
> Thanks,
> Nick
> 
> [...]

Applied to powerpc/next.

[1/7] powerpc: move __end_rodata to cover arch read-only sections
      https://git.kernel.org/powerpc/c/7082f8e7d2276575a8806370007cbb4a7b9abdce
[2/7] powerpc/32/build: move got1/got2 sections out of text
      https://git.kernel.org/powerpc/c/1faa1235c1a00614bc4849a8dbd0790363c9a22f
[3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only
      https://git.kernel.org/powerpc/c/f21ba4499a15b76ad6013ca0a60873dbcf164c7b
[4/7] powerpc/build: move .data.rel.ro, .sdata2 to read-only
      https://git.kernel.org/powerpc/c/b6adc6d6d327229d75607a948cde2349d317f366
[5/7] powerpc/64/build: only include .opd with ELFv1
      https://git.kernel.org/powerpc/c/c787fed11890babda1e4882cd3b6efaf412e1bde
[6/7] powerpc/64/build: merge .got and .toc input sections
      https://git.kernel.org/powerpc/c/1e9eca485a840985a663080eb049c420272d4bdd
[7/7] powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE
      https://git.kernel.org/powerpc/c/fdfdcfd504933ed06eb6b4c9df21eede0e213c3e

cheers

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-10-04 13:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16  4:07 [PATCH v2 0/7] powerpc: build / linker improvements Nicholas Piggin
2022-09-16  4:07 ` [PATCH v2 1/7] powerpc: move __end_rodata to cover arch read-only sections Nicholas Piggin
2022-09-16  4:07 ` [PATCH v2 2/7] powerpc/32/build: move got1/got2 sections out of text Nicholas Piggin
2022-09-16  4:07 ` [PATCH v2 3/7] powerpc/build: move got, toc, plt, branch_lt sections to read-only Nicholas Piggin
2022-09-17 20:15   ` kernel test robot
2022-09-19  5:39     ` Michael Ellerman
2022-09-20 10:50       ` Nicholas Piggin
2022-09-16  4:07 ` [PATCH v2 4/7] powerpc/build: move .data.rel.ro, .sdata2 " Nicholas Piggin
2022-09-16  4:07 ` [PATCH v2 5/7] powerpc/64/build: only include .opd with ELFv1 Nicholas Piggin
2022-09-16  4:07 ` [PATCH v2 6/7] powerpc/64/build: merge .got and .toc input sections Nicholas Piggin
2022-09-16 18:45   ` Christophe Leroy
2022-09-17  6:36     ` Michael Ellerman
2022-09-16  4:07 ` [PATCH v2 7/7] powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE Nicholas Piggin
2022-10-04 13:24 ` [PATCH v2 0/7] powerpc: build / linker improvements Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).