Skip to contentSkip to conversation

x86/boot: explicitly place .eh_frame after .rodata

PATCH Superseded Ilie Halip 4 participants 13 messages Nov 4, 2019 – Dec 14, 2019 x86

lore
Share & tools
lore

Ilie Halip

author
#0 lore raw

PATCH 1/1 x86/boot: explicitly place .eh_frame after .rodata

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because ld.lld has different rules for placing orphan sections (i.e. sections not mentioned in a linker script) compared to ld.bfd.

Particularly, in this case, the merged .eh_frame section is placed before __end_init, which triggers an assert in the script.

Explicitly place this section after .rodata, in accordance with ld.bfd's behavior.

---
 arch/x86/boot/setup.ld | 1 +
 1 file changed, 1 insertion(+)
arch/x86/boot/setup.ld +1 -0
index 0149e41d42c2..4e02eab11b59 100644
@@ -25,6 +25,7 @@ SECTIONS
 
 	. = ALIGN(16);
 	.rodata		: { *(.rodata*) }
+	.eh_frame	: { *(.eh_frame*) }
 
 	.videocards	: {
 		video_cards = .;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · Ilie Halip

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because ld.lld has different rules for placing orphan sections (i.e. sections not mentioned in a linker script) compared to ld.bfd.

Quoted 8 lines

Particularly, in this case, the merged .eh_frame section is placed before __end_init, which triggers an assert in the script.

Explicitly place this section after .rodata, in accordance with ld.bfd's behavior.

Thanks for the patch Ilie! Quoting Fangrui:

"This is related to the orphan placement rule. An orphan section is a section that is not described by the linker script. The orphan section placement is not well documented and the rule used by ld.bfd is not very clear. Being more explicit is the way to go."
https://github.com/ClangBuiltLinux/linux/issues/760#issuecomment-549064237

Looks like Clang doesn't even produce a .eh_frame section.

arch/x86/boot/setup.ld SECTIONS · line 28

Quoted 13 lines
---
 arch/x86/boot/setup.ld | 1 +
 1 file changed, 1 insertion(+)
arch/x86/boot/setup.ld +1 -0
index 0149e41d42c2..4e02eab11b59 100644
@@ -25,6 +25,7 @@ SECTIONS
 
        . = ALIGN(16);
        .rodata         : { *(.rodata*) }
+       .eh_frame       : { *(.eh_frame*) }

The wildcard on the end can be left off; we don't need to glob different sections with the prefix .eh_frame. Would you mind sending a V2 with that removed? (I know .rodata and .data in this linker script globs, but they may actually be putting data in separate sections which we want to munge back together; certainly for -fdata-sections).

Quoted 6 lines
arch/x86/boot/setup.ld +0 -1
        .videocards     : {
                video_cards = .;
--

2.17.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#2 lore raw
Quoted 2 lines

The wildcard on the end can be left off; we don't need to glob different sections with the prefix .eh_frame.

Sounds good, it doesn't look like any .eh_frame_hdr sections are being created so it should be fine to remove that wildcard.

I.H.

author
#3 lore raw

PATCH v2 1/1 x86/boot: explicitly place .eh_frame after .rodata

In reply to Nick Desaulniers

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because ld.lld has different rules for placing orphan sections (i.e. sections not mentioned in a linker script) compared to ld.bfd.

Particularly, in this case, the merged .eh_frame section is placed before __end_init, which triggers an assert in the script.

Explicitly place this section after .rodata, in accordance with ld.bfd's behavior.

---

Changes in V2:
* removed wildcard for input sections (.eh_frame* -> .eh_frame)

 arch/x86/boot/setup.ld | 1 +
 1 file changed, 1 insertion(+)
arch/x86/boot/setup.ld +1 -0
index 0149e41d42c2..30ce52635cd0 100644
@@ -25,6 +25,7 @@ SECTIONS
 
 	. = ALIGN(16);
 	.rodata		: { *(.rodata*) }
+	.eh_frame	: { *(.eh_frame) }
 
 	.videocards	: {
 		video_cards = .;
Signature · 1 line
2.17.1
Reviewed-by Tested-by on v2 1/1
#4 lore raw
Quoted 10 lines · Ilie Halip

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because ld.lld has different rules for placing orphan sections (i.e. sections not mentioned in a linker script) compared to ld.bfd.

Quoted 8 lines

Particularly, in this case, the merged .eh_frame section is placed before __end_init, which triggers an assert in the script.

Explicitly place this section after .rodata, in accordance with ld.bfd's behavior.

Thanks for following up with a v2.

Quoted 23 lines

---

Changes in V2:
* removed wildcard for input sections (.eh_frame* -> .eh_frame)

 arch/x86/boot/setup.ld | 1 +
 1 file changed, 1 insertion(+)
arch/x86/boot/setup.ld +1 -1
index 0149e41d42c2..30ce52635cd0 100644
@@ -25,6 +25,7 @@ SECTIONS
 
        . = ALIGN(16);
        .rodata         : { *(.rodata*) }
+       .eh_frame       : { *(.eh_frame) }
 
        .videocards     : {
                video_cards = .;
--

2.17.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#5 lore raw

Has anyone had a chance to look over this patch?

Thanks,
I.H.

maintainer
#6 lore raw
In reply to Ilie Halip
Quoted 30 lines · Ilie Halip

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because ld.lld has different rules for placing orphan sections (i.e. sections not mentioned in a linker script) compared to ld.bfd.

Particularly, in this case, the merged .eh_frame section is placed before __end_init, which triggers an assert in the script.

Explicitly place this section after .rodata, in accordance with ld.bfd's behavior.

---

Changes in V2:
* removed wildcard for input sections (.eh_frame* -> .eh_frame)

 arch/x86/boot/setup.ld | 1 +
 1 file changed, 1 insertion(+)
arch/x86/boot/setup.ld +0 -0
index 0149e41d42c2..30ce52635cd0 100644

arch/x86/boot/setup.ld SECTIONS · line 28

Quoted 4 lines
arch/x86/boot/setup.ld +1 -0
@@ -25,6 +25,7 @@ SECTIONS
 
 	. = ALIGN(16);
 	.rodata		: { *(.rodata*) }
+	.eh_frame	: { *(.eh_frame) }

The kernel proper linker script does

        /DISCARD/ : {
                *(.eh_frame)
        }

with the .eh_frame section.

Wouldn't that solve your issue too, if you add it to the /DISCARD/ section in that linker script too?

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#7 lore raw
Quoted 14 lines · Borislav Petkov

arch/x86/boot/setup.ld SECTIONS · line 28

Quoted 9 lines · Ilie Halip
arch/x86/boot/setup.ld +1 -0
index 0149e41d42c2..30ce52635cd0 100644
@@ -25,6 +25,7 @@ SECTIONS
 
      . = ALIGN(16);
      .rodata         : { *(.rodata*) }
+     .eh_frame       : { *(.eh_frame) }

The kernel proper linker script does

Quoted 8 lines
        /DISCARD/ : {
                *(.eh_frame)
        }

with the .eh_frame section.

Wouldn't that solve your issue too, if you add it to the /DISCARD/ section in that linker script too?

Yep. Looks like:
- arch/x86/kernel/vmlinux.lds.S
- arch/x86/realmode/rm/realmode.lds.S

discard .eh_frame, while
- arch/x86/entry/vdso/vdso-layout.lds.S
- arch/x86/um/vdso/vdso-layout.lds.S

keep it. I assume then that just vdso code that get linked into userspace needs to preserve this. This suggestion would be a functional change, which is why we pursued the conservative change preserving it.
https://github.com/ClangBuiltLinux/linux/issues/760#issuecomment-549192213

Ilie, would you mind sending a v3 with Boris' recommendation?

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#8 lore raw
Quoted 10 lines · Nick Desaulniers

Yep. Looks like:
- arch/x86/kernel/vmlinux.lds.S
- arch/x86/realmode/rm/realmode.lds.S

discard .eh_frame, while
- arch/x86/entry/vdso/vdso-layout.lds.S
- arch/x86/um/vdso/vdso-layout.lds.S

keep it. I assume then that just vdso code that get linked into userspace needs to preserve this.

Yap, that's what I think too. Lemme add Andy to Cc.

Quoted 2 lines

This suggestion would be a functional change, which is why we pursued the conservative change preserving it.

Sure but what would be the purpose of preserving the section, especially in the early boot code? At least I don't see one. And kernel-proper kills it...

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author
#9 lore raw

PATCH v3 1/1 x86/boot: discard .eh_frame sections

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because GCC generates .eh_frame sections for most of the files in that directory, then ld.lld places the merged section before __end_init, triggering an assert in the linker script.

Fix this by discarding the .eh_frame sections, as suggested by Boris. The kernel proper linker script discards them too.

---

Changes in V3:
* discard .eh_frame instead of placing it after .rodata

Changes in V2:
* removed wildcard for input sections (.eh_frame* -> .eh_frame)

 arch/x86/boot/setup.ld | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/boot/setup.ld +4 -1
index 0149e41d42c2..3da1c37c6dd5 100644
@@ -51,7 +51,10 @@ SECTIONS
 	. = ALIGN(16);
 	_end = .;
 
-	/DISCARD/ : { *(.note*) }
+	/DISCARD/	: {
+		*(.eh_frame)
+		*(.note*)
+	}
 
 	/*
 	 * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
Signature · 1 line
2.17.1
Reviewed-by on v3 1/1
#10 lore raw

Re: [PATCH v3] x86/boot: discard .eh_frame sections

Quoted 11 lines · Ilie Halip

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because GCC generates .eh_frame sections for most of the files in that directory, then ld.lld places the merged section before __end_init, triggering an assert in the linker script.

Quoted 7 lines

Fix this by discarding the .eh_frame sections, as suggested by Boris. The kernel proper linker script discards them too.

Ilie, thanks for following up with a v3.

Quoted 30 lines

---

Changes in V3:
* discard .eh_frame instead of placing it after .rodata

Changes in V2:
* removed wildcard for input sections (.eh_frame* -> .eh_frame)

 arch/x86/boot/setup.ld | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/boot/setup.ld +4 -2
index 0149e41d42c2..3da1c37c6dd5 100644
@@ -51,7 +51,10 @@ SECTIONS
        . = ALIGN(16);
        _end = .;
 
-       /DISCARD/ : { *(.note*) }
+       /DISCARD/       : {
+               *(.eh_frame)
+               *(.note*)
+       }
 
        /*
         * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
--

2.17.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
#11 lore raw

Re: [PATCH v3] x86/boot: discard .eh_frame sections

Bumping for review (I couldn't find if this was merged already in tip/tip)

Quoted 59 lines · Nick Desaulniers
Quoted 11 lines · Ilie Halip

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:
LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because GCC generates .eh_frame sections for most of the files in that directory, then ld.lld places the merged section before __end_init, triggering an assert in the linker script.

Quoted 7 lines

Fix this by discarding the .eh_frame sections, as suggested by Boris. The kernel proper linker script discards them too.

Ilie, thanks for following up with a v3.

Quoted 28 lines

---

Changes in V3:
* discard .eh_frame instead of placing it after .rodata

Changes in V2:
* removed wildcard for input sections (.eh_frame* -> .eh_frame)

 arch/x86/boot/setup.ld | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/boot/setup.ld +4 -2
index 0149e41d42c2..3da1c37c6dd5 100644
@@ -51,7 +51,10 @@ SECTIONS
        . = ALIGN(16);
        _end = .;
 
-       /DISCARD/ : { *(.note*) }
+       /DISCARD/       : {
+               *(.eh_frame)
+               *(.note*)
+       }
 
        /*
         * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility:
--
Quoted 2 lines

2.17.1

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
merge bot Applied
#12 lore raw

[tip: x86/boot] x86/boot: Discard .eh_frame sections

In reply to Ilie Halip
The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     163159aad74d3763b350861b879b41e8f64121fc
Gitweb:        https://git.kernel.org/tip/163159aad74d3763b350861b879b41e8f64121fc
Author:        Ilie Halip <[email protected]>
AuthorDate:    Tue, 26 Nov 2019 16:45:44 +02:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Fri, 13 Dec 2019 11:45:59 +01:00

x86/boot: Discard .eh_frame sections

When using GCC as compiler and LLVM's lld as linker, linking setup.elf fails:

LD arch/x86/boot/setup.elf
ld.lld: error: init sections too big!

This happens because GCC generates .eh_frame sections for most of the files in that directory, then ld.lld places the merged section before __end_init, triggering an assert in the linker script.

Fix this by discarding the .eh_frame sections, as suggested by Boris. The kernel proper linker script discards them too.

[ bp: Going back in history, 64-bit kernel proper has been discarding
.eh_frame since 2002:

    commit acca80acefe20420e69561cf55be64f16c34ea97
    Author: Andi Kleen <[email protected]>
    Date:   Tue Oct 29 23:54:35 2002 -0800

      [PATCH] x86-64 updates for 2.5.44

      ...

    - Remove the .eh_frame on linking. This saves several hundred KB in the
      bzImage

]

---
 arch/x86/boot/setup.ld | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/boot/setup.ld +4 -1
index 0149e41..3da1c37 100644
@@ -51,7 +51,10 @@ SECTIONS
 	. = ALIGN(16);
 	_end = .;
 
-	/DISCARD/ : { *(.note*) }
+	/DISCARD/	: {
+		*(.eh_frame)
+		*(.note*)
+	}
 
 	/*
 	 * The ASSERT() sink to . is intentional, for binutils 2.14 compatibility: