Skip to contentSkip to conversation

powerpc/vmlinux.lds: Explicitly retain .gnu.hash

PATCH Applied Michael Ellerman 3 participants 7 messages Feb 27, 2020 – Apr 1, 2020 PowerPC

lore
Share & tools
lore

Michael Ellerman

author reviewer
#0 lore raw

PATCH 1/2 powerpc/vmlinux.lds: Explicitly retain .gnu.hash

Relocatable kernel builds produce a warning about .gnu.hash being an orphan section:

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

If we try to discard it the build fails:

  ld -EL -m elf64lppc -pie --orphan-handling=warn --build-id -o
    .tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive
    arch/powerpc/kernel/head_64.o arch/powerpc/kernel/entry_64.o
    ...
    sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive
    --start-group lib/lib.a --end-group
  ld: could not find section .gnu.hash

So add an entry to explicitly retain it, as we do for .hash.

---
 arch/powerpc/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kernel/vmlinux.lds.S +1 -0
index b4c89a1acebb..31a0f201fb6f 100644
@@ -256,6 +256,7 @@ SECTIONS
 		*(.dynamic)
 	}
 	.hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
+	.gnu.hash : AT(ADDR(.gnu.hash) - LOAD_OFFSET) { *(.gnu.hash) }
 	.interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
 	.rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
 	{
Signature · 1 line
2.21.1
author reviewer
#1 lore raw

PATCH 2/2 powerpc/vmlinux.lds: Discard .interp section

The .interp section specifies which "interpreter", ie. dynamic loader, the kernel requests. But that doesn't make any sense, the kernel is not a regular binary that is run with an interpreter.

The content seems to be some default value, this file doesn't even exist on my system:
00000000 2f 75 73 72 2f 6c 69 62 2f 6c 64 2e 73 6f 2e 31 |/usr/lib/ld.so.1|

So the section serves no useful purpose and consumes a small amount of space.

Also Alan Modra says we "likely could discard" it, so do so.

---
 arch/powerpc/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/vmlinux.lds.S +1 -1
index 31a0f201fb6f..619ffbaf72ad 100644
@@ -257,7 +257,6 @@ SECTIONS
 	}
 	.hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
 	.gnu.hash : AT(ADDR(.gnu.hash) - LOAD_OFFSET) { *(.gnu.hash) }
-	.interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
 	.rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
 	{
 		__rela_dyn_start = .;
@@ -370,5 +369,6 @@ SECTIONS
 		*(.gnu.version*)
 		*(.gnu.attributes)
 		*(.eh_frame)
+		*(.interp)
 	}
 }
Signature · 1 line
2.21.1
#2 lore raw

Re: [PATCH 2/2] powerpc/vmlinux.lds: Discard .interp section

Quoted 4 lines · Michael Ellerman

The .interp section specifies which "interpreter", ie. dynamic loader, the kernel requests. But that doesn't make any sense, the kernel is not a regular binary that is run with an interpreter.

Quoted 8 lines

The content seems to be some default value, this file doesn't even exist on my system:
00000000 2f 75 73 72 2f 6c 69 62 2f 6c 64 2e 73 6f 2e 31 |/usr/lib/ld.so.1|

So the section serves no useful purpose and consumes a small amount of space.

Also Alan Modra says we "likely could discard" it, so do so.

Yes, but you ought to check with the mimimum required binutils. It is quite possible that an older linker will blow up.

If the minimum required binutils is at least binutils-2.26 then passing --no-dynamic-linker to ld is a more elegant solution.

Quoted 27 lines
---
 arch/powerpc/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/vmlinux.lds.S +1 -1
index 31a0f201fb6f..619ffbaf72ad 100644
@@ -257,7 +257,6 @@ SECTIONS
 	}
 	.hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
 	.gnu.hash : AT(ADDR(.gnu.hash) - LOAD_OFFSET) { *(.gnu.hash) }
-	.interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
 	.rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
 	{
 		__rela_dyn_start = .;
@@ -370,5 +369,6 @@ SECTIONS
 		*(.gnu.version*)
 		*(.gnu.attributes)
 		*(.eh_frame)
+		*(.interp)
 	}
 }
Signature · 1 line
2.21.1
Signature · 2 lines
Alan Modra
Australia Development Lab, IBM
author reviewer
#3 lore raw

Re: [PATCH 2/2] powerpc/vmlinux.lds: Discard .interp section

Quoted 9 lines · Alan Modra
Quoted 8 lines · Michael Ellerman

The .interp section specifies which "interpreter", ie. dynamic loader, the kernel requests. But that doesn't make any sense, the kernel is not a regular binary that is run with an interpreter.

The content seems to be some default value, this file doesn't even exist on my system:
00000000 2f 75 73 72 2f 6c 69 62 2f 6c 64 2e 73 6f 2e 31 |/usr/lib/ld.so.1|

Quoted 7 lines
Quoted 4 lines

So the section serves no useful purpose and consumes a small amount of space.

Also Alan Modra says we "likely could discard" it, so do so.

Yes, but you ought to check with the mimimum required binutils. It is quite possible that an older linker will blow up.

OK, I guess I'll have to test.

Quoted 2 lines

If the minimum required binutils is at least binutils-2.26 then passing --no-dynamic-linker to ld is a more elegant solution.

The current minimum is 2.21, though there's talk of increasing it to 2.23.

cheers

#4 lore raw
In reply to Michael Ellerman
Quoted 15 lines · Michael Ellerman

Relocatable kernel builds produce a warning about .gnu.hash being an orphan section:

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

If we try to discard it the build fails:

  ld -EL -m elf64lppc -pie --orphan-handling=warn --build-id -o
    .tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive
    arch/powerpc/kernel/head_64.o arch/powerpc/kernel/entry_64.o
    ...
    sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive
    --start-group lib/lib.a --end-group
  ld: could not find section .gnu.hash
Quoted 1 line

So add an entry to explicitly retain it, as we do for .hash.

Looks fine to me. You can also pass --hash-style=sysv to ld (since binutils-2.18) to disable generation of .gnu.hash.

Quoted 20 lines
---
 arch/powerpc/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kernel/vmlinux.lds.S +1 -0
index b4c89a1acebb..31a0f201fb6f 100644
@@ -256,6 +256,7 @@ SECTIONS
 		*(.dynamic)
 	}
 	.hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
+	.gnu.hash : AT(ADDR(.gnu.hash) - LOAD_OFFSET) { *(.gnu.hash) }
 	.interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
 	.rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
 	{
Signature · 1 line
2.21.1
Signature · 2 lines
Alan Modra
Australia Development Lab, IBM
author reviewer
#5 lore raw
Quoted 16 lines · Alan Modra
Quoted 15 lines · Michael Ellerman

Relocatable kernel builds produce a warning about .gnu.hash being an orphan section:

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

If we try to discard it the build fails:

  ld -EL -m elf64lppc -pie --orphan-handling=warn --build-id -o
    .tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive
    arch/powerpc/kernel/head_64.o arch/powerpc/kernel/entry_64.o
    ...
    sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive
    --start-group lib/lib.a --end-group
  ld: could not find section .gnu.hash
Quoted 4 lines
Quoted 1 line

So add an entry to explicitly retain it, as we do for .hash.

Looks fine to me. You can also pass --hash-style=sysv to ld (since binutils-2.18) to disable generation of .gnu.hash.

Our current minimum is 2.21, so that's probably 5-10 years away :)

cheers

#6 lore raw
In reply to Michael Ellerman
Quoted 15 lines · Michael Ellerman

Relocatable kernel builds produce a warning about .gnu.hash being an orphan section:

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

If we try to discard it the build fails:

  ld -EL -m elf64lppc -pie --orphan-handling=warn --build-id -o
    .tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive
    arch/powerpc/kernel/head_64.o arch/powerpc/kernel/entry_64.o
    ...
    sound/built-in.a net/built-in.a virt/built-in.a --no-whole-archive
    --start-group lib/lib.a --end-group
  ld: could not find section .gnu.hash
Quoted 3 lines

So add an entry to explicitly retain it, as we do for .hash.

Applied to powerpc next.

https://git.kernel.org/powerpc/c/ead983604c5a390f1e3ce085945b60e82f08dbbe

cheers