Skip to contentSkip to conversation

powerpc: Add to linker script discards

PATCH Superseded Joel Stanley 2 participants 6 messages Dec 4, 2018 – Dec 10, 2018 PowerPC

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover powerpc: Add to linker script discards

v2 pulls in the branch_lt patch too. No changes to the first two patches.

Joel Stanley (3):
powerpc: Discard more sections in linker script
powerpc: Discard dynsym section for !PPC32
powerpc: Discard .branch_lt section

 arch/powerpc/kernel/vmlinux.lds.S | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH v2 1/3 powerpc: Discard more sections in linker script

Building the ppc64 kernel with a modern binutils results in this warning:

powerpc64le-linux-gnu-ld: warning: orphan section .gnu.hash' from linker stubs' being placed in section `.gnu.hash'

Alan Modra <[email protected]> explains:

Quoted 4 lines

.gnu.hash, like .hash, is used by glibc ld.so for dynamic symbol lookup. I imagine you don't need either section in a kernel, so discarding both sounds reasonable. Likely you could discard .interp and .dynstr too, and .dynsym when !CONFIG_PPC32.

---
See https://lore.kernel.org/lkml/CACPK8Xft3n5KkpTjN3=7_VUCXHFcK7mxvZm2Rrqu7tppcBoyOg@mail.gmail.com/T/#m58532c86cf0c7b4fb01cc1fe724e48d4c7d8e4a7

---
 arch/powerpc/kernel/vmlinux.lds.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/kernel/vmlinux.lds.S +3 -2
index 434581bcd5b4..6570209b0671 100644
@@ -279,8 +279,6 @@ SECTIONS
 		__dynamic_start = .;
 		*(.dynamic)
 	}
-	.hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
-	.interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
 	.rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
 	{
 		__rela_dyn_start = .;
@@ -388,5 +386,8 @@ SECTIONS
 		*(.gnu.version*)
 		*(.gnu.attributes)
 		*(.eh_frame)
+		*(.hash .gnu.hash)
+		*(.interp)
+		*(.dynstr)
 	}
 }
Signature · 1 line
2.19.1
#2 lore raw

PATCH v2 2/3 powerpc: Discard dynsym section for !PPC32

In reply to Joel Stanley

Alan Modra <[email protected]> explains:

Quoted 2 lines

Likely you could discard .interp > and .dynstr too, and .dynsym when !CONFIG_PPC32.

Discarding of interp and dynstr happened in a previous patch. The dynsym cleanup was a bit less straightforward, so it gets it's own patch.

---
See https://lore.kernel.org/lkml/CACPK8Xft3n5KkpTjN3=7_VUCXHFcK7mxvZm2Rrqu7tppcBoyOg@mail.gmail.com/T/#m58532c86cf0c7b4fb01cc1fe724e48d4c7d8e4a7

---
 arch/powerpc/kernel/vmlinux.lds.S | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/kernel/vmlinux.lds.S +5 -3
index 6570209b0671..2c93a420f456 100644
@@ -266,14 +266,13 @@ SECTIONS
 	}
 #ifdef CONFIG_RELOCATABLE
 	. = ALIGN(8);
+#ifdef CONFIG_PPC32
 	.dynsym : AT(ADDR(.dynsym) - LOAD_OFFSET)
 	{
-#ifdef CONFIG_PPC32
 		__dynamic_symtab = .;
-#endif
 		*(.dynsym)
 	}
-	.dynstr : AT(ADDR(.dynstr) - LOAD_OFFSET) { *(.dynstr) }
+#endif
 	.dynamic : AT(ADDR(.dynamic) - LOAD_OFFSET)
 	{
 		__dynamic_start = .;
@@ -389,5 +388,8 @@ SECTIONS
 		*(.hash .gnu.hash)
 		*(.interp)
 		*(.dynstr)
+#ifndef CONFIG_PPC32
+		*(.dynsym)
+#endif
 	}
 }
Signature · 1 line
2.19.1
#3 lore raw

Re: [PATCH v2 2/3] powerpc: Discard dynsym section for !PPC32

Quoted 15 lines · Joel Stanley

Alan Modra <[email protected]> explains:

Quoted 2 lines

Likely you could discard .interp > and .dynstr too, and .dynsym when !CONFIG_PPC32.

Discarding of interp and dynstr happened in a previous patch. The dynsym cleanup was a bit less straightforward, so it gets it's own patch.

arch/powerpc/kernel/vmlinux.lds.S +0 -0
index 6570209b0671..2c93a420f456 100644
@@ -266,14 +266,13 @@ SECTIONS
 	}
 #ifdef CONFIG_RELOCATABLE

arch/powerpc/kernel/vmlinux.lds.S SECTIONS · line 276

Quoted 10 lines
arch/powerpc/kernel/vmlinux.lds.S +1 -3
 	. = ALIGN(8);
+#ifdef CONFIG_PPC32
 	.dynsym : AT(ADDR(.dynsym) - LOAD_OFFSET)
 	{
-#ifdef CONFIG_PPC32
 		__dynamic_symtab = .;
-#endif
 		*(.dynsym)
 	}
-	.dynstr : AT(ADDR(.dynstr) - LOAD_OFFSET) { *(.dynstr) }

So this last line belongs in the previous patch then, right?

Segher

#4 lore raw

Re: [PATCH v2 2/3] powerpc: Discard dynsym section for !PPC32

Quoted 21 lines · Segher Boessenkool
Quoted 19 lines · Joel Stanley

Alan Modra <[email protected]> explains:

Quoted 2 lines

Likely you could discard .interp > and .dynstr too, and .dynsym when !CONFIG_PPC32.

Discarding of interp and dynstr happened in a previous patch. The dynsym cleanup was a bit less straightforward, so it gets it's own patch.

arch/powerpc/kernel/vmlinux.lds.S +1 -0
index 6570209b0671..2c93a420f456 100644
@@ -266,14 +266,13 @@ SECTIONS
      }
 #ifdef CONFIG_RELOCATABLE
      . = ALIGN(8);
+#ifdef CONFIG_PPC32
      .dynsym : AT(ADDR(.dynsym) - LOAD_OFFSET)
      {
Quoted 8 lines

arch/powerpc/kernel/vmlinux.lds.S SECTIONS · line 276

Quoted 6 lines
arch/powerpc/kernel/vmlinux.lds.S +0 -3
-#ifdef CONFIG_PPC32
              __dynamic_symtab = .;
-#endif
              *(.dynsym)
      }
-     .dynstr : AT(ADDR(.dynstr) - LOAD_OFFSET) { *(.dynstr) }

So this last line belongs in the previous patch then, right?

Correct. Good catch.

#5 lore raw

PATCH v2 3/3 powerpc: Discard .branch_lt section

In reply to Joel Stanley

When building a 32 bit powerpc kernel with Binutils 2.31.1 this warning is emitted:

powerpc-linux-gnu-ld: warning: orphan section .branch_lt' from arch/powerpc/kernel/head_44x.o' being placed in section `.branch_lt'

As of binutils commit 2d7ad24e8726 ("Support PLT16 relocs against local symbols")[1], 32 bit targets can produce .branch_lt sections in their output.

These sections should be empty for the kernel build so discard them for both PPC64 and PPC32.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=2d7ad24e8726ba4c45c9e67be08223a146a837ce

---
v2: Discard instead of keep. Alan said "[discarding] can be a recipe for finding linker bugs", so lets go with that.

---
 arch/powerpc/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/vmlinux.lds.S +1 -1
index 2c93a420f456..af0f81df8bb9 100644
@@ -316,7 +316,6 @@ SECTIONS
 		DATA_DATA
 		*(.data.rel*)
 		*(.toc1)
-		*(.branch_lt)
 	}
 
 	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
@@ -388,6 +387,7 @@ SECTIONS
 		*(.hash .gnu.hash)
 		*(.interp)
 		*(.dynstr)
+		*(.branch_lt)
 #ifndef CONFIG_PPC32
 		*(.dynsym)
 #endif
Signature · 1 line
2.19.1