Skip to contentSkip to conversation

PATCH: Fix gnu-efi-3.0b-041222 for ia32

PATCH H. J. Lu 5 participants 11 messages Mar 17, 2006

lore
Share & tools
lore

H. J. Lu

author
#0 lore raw

I don't know where I should report gnu-efi bug. The ia32 support in gnu-efi-3.0b-041222 doesn't work with newer gcc and binutils. The problem is in the linker script. The new gcc may put functions in .text* sections. The newer linker handles orphaned sections differently. I tested this patch on both ia32 and ia64 with different versions of gcc and binutils by building elilo 3.6. Elilo 3.6 loads and run kernel correctly on ia64. It seems to work find on ia32.

Thanks.

H.J.

gnuefi/elf_ia32_efi.lds renamed from gnuefi/elf_ia32_efi.lds.ia32 +6 -5
@@ -9,7 +9,11 @@ SECTIONS
   . = ALIGN(4096);
   .text :
   {
-   *(.text)
+   *(.text*)
+  }
+  .reloc :
+  {
+   *(.reloc)
   }
   . = ALIGN(4096);
   .data :
@@ -48,12 +52,9 @@ SECTIONS
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
   . = ALIGN(4096);
-  .ignored.reloc :
+  /DISCARD/ :
   {
     *(.rel.reloc)
-  }
-  .ignored :
-  {
     *(.eh_frame)
   }
 }
gnuefi/elf_ia64_efi.lds renamed from gnuefi/elf_ia64_efi.lds.ia32 +1 -4
@@ -59,13 +59,10 @@ SECTIONS
   .dynsym   : { *(.dynsym) }
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
-  .ignored_reloc :
+  /DISCARD/ :
   {
     *(.rela.plabel)
     *(.rela.reloc)
-  }
-  /DISCARD/ :
-  {
     *(.IA_64.unwind*)
     *(.IA64.unwind*)
   }
#1 lore raw

gnuefi/elf_ia32_efi.lds SECTIONS · line 12

Quoted 2 lines · H. J. Lu
gnuefi/elf_ia32_efi.lds renamed from gnuefi/elf_ia32_efi.lds.ia32 +1 -1
-   *(.text)
+   *(.text*)

That should be .text.*, not .text*. The distinction here is important. Admittedly, it will probably never matter for gnu-efi, but get this wrong in binutils and you will break some end user code.

#2 lore raw
In reply to H. J. Lu
Quoted 1 line · James E Wilson

That should be .text.*, not .text*.

And because .text.* doesn't match .text, this actually needs to be

    *(.text .text.*)

Try looking at ld --verbose output, and grepping for .text.

Signature · 1 line
Jim Wilson, GNU Tools Support, http://www.specifix.com
author
#3 lore raw
In reply to H. J. Lu
Quoted 5 lines · James E Wilson
Quoted 1 line · James E Wilson

That should be .text.*, not .text*.

And because .text.* doesn't match .text, this actually needs to be

    *(.text .text.*)

I don't think so. linker calls fnmatch to match section names by patterns. According to my man page:

NAME
fnmatch - match filename or pathname

SYNOPSIS

       #include <fnmatch.h>

       int fnmatch(const char *pattern, const char *string, int flags);

DESCRIPTION
The fnmatch() function checks whether the string argument
matches the
pattern argument, which is a shell wildcard pattern.

".text*" should work as a shell wildcard pattern.

Quoted 1 line

Try looking at ld --verbose output, and grepping for .text.

This is the updated patch to include *(.gnu.linkonce.t.*) sections.

H.J.
---

gnuefi/elf_ia32_efi.lds renamed from gnuefi/elf_ia32_efi.lds.ia32 +7 -5
@@ -9,7 +9,12 @@ SECTIONS
   . = ALIGN(4096);
   .text :
   {
-   *(.text)
+   *(.text*)
+   *(.gnu.linkonce.t.*)
+  }
+  .reloc :
+  {
+   *(.reloc)
   }
   . = ALIGN(4096);
   .data :
@@ -48,12 +53,9 @@ SECTIONS
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
   . = ALIGN(4096);
-  .ignored.reloc :
+  /DISCARD/ :
   {
     *(.rel.reloc)
-  }
-  .ignored :
-  {
     *(.eh_frame)
   }
 }
gnuefi/elf_ia64_efi.lds renamed from gnuefi/elf_ia64_efi.lds.ia32 +2 -5
@@ -9,7 +9,7 @@ SECTIONS
   . = ALIGN(4096);
   .text :
   {
-   *(.text)
+   *(.text*)
    *(.gnu.linkonce.t*)
   }
   . = ALIGN(4096);
@@ -59,13 +59,10 @@ SECTIONS
   .dynsym   : { *(.dynsym) }
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
-  .ignored_reloc :
+  /DISCARD/ :
   {
     *(.rela.plabel)
     *(.rela.reloc)
-  }
-  /DISCARD/ :
-  {
     *(.IA_64.unwind*)
     *(.IA64.unwind*)
   }
author
#4 lore raw
In reply to H. J. Lu
Quoted 23 lines · H. J. Lu
Quoted 5 lines · James E Wilson
Quoted 1 line · James E Wilson

That should be .text.*, not .text*.

And because .text.* doesn't match .text, this actually needs to be

    *(.text .text.*)

I don't think so. linker calls fnmatch to match section names by patterns. According to my man page:

NAME
fnmatch - match filename or pathname

SYNOPSIS

       #include <fnmatch.h>

       int fnmatch(const char *pattern, const char *string, int flags);

DESCRIPTION
The fnmatch() function checks whether the string argument
matches the
pattern argument, which is a shell wildcard pattern.

Quoted 6 lines

".text*" should work as a shell wildcard pattern.

Quoted 1 line

Try looking at ld --verbose output, and grepping for .text.

This is the updated patch to include *(.gnu.linkonce.t.*) sections.

This new makes linker scripts similar to normal linker. It should generate the same output.

H.J.
---

gnuefi/elf_ia32_efi.lds renamed from gnuefi/elf_ia32_efi.lds.ia32 +7 -4
@@ -10,6 +10,12 @@ SECTIONS
   .text :
   {
    *(.text)
+   *(.text.*)
+   *(.gnu.linkonce.t.*)
+  }
+  .reloc :
+  {
+   *(.reloc)
   }
   . = ALIGN(4096);
   .data :
@@ -48,12 +54,9 @@ SECTIONS
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
   . = ALIGN(4096);
-  .ignored.reloc :
+  /DISCARD/ :
   {
     *(.rel.reloc)
-  }
-  .ignored :
-  {
     *(.eh_frame)
   }
 }
gnuefi/elf_ia64_efi.lds renamed from gnuefi/elf_ia64_efi.lds.ia32 +2 -4
@@ -10,6 +10,7 @@ SECTIONS
   .text :
   {
    *(.text)
+   *(.text.*)
    *(.gnu.linkonce.t*)
   }
   . = ALIGN(4096);
@@ -59,13 +60,10 @@ SECTIONS
   .dynsym   : { *(.dynsym) }
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
-  .ignored_reloc :
+  /DISCARD/ :
   {
     *(.rela.plabel)
     *(.rela.reloc)
-  }
-  /DISCARD/ :
-  {
     *(.IA_64.unwind*)
     *(.IA64.unwind*)
   }
#5 lore raw
In reply to H. J. Lu
Quoted 10 lines · H. J. Lu
Quoted 5 lines · James E Wilson
Quoted 1 line · James E Wilson

That should be .text.*, not .text*.

And because .text.* doesn't match .text, this actually needs to be

    *(.text .text.*)

I don't think so. linker calls fnmatch to match section names by patterns. According to my man page:

Quoted 6 lines

DESCRIPTION
The fnmatch() function checks whether the string argument
matches the
pattern argument, which is a shell wildcard pattern.

".text*" should work as a shell wildcard pattern.

I believe his point is that .text* matches .textual and .texterific and many other sections which shouldn't be matched. So you need to match .text and .text.*, not just .text*

#6 lore raw
In reply to H. J. Lu
Quoted 3 lines · Matthew Wilcox

I believe his point is that .text* matches .textual and .texterific and many other sections which shouldn't be matched. So you need to match .text and .text.*, not just .text*

Exactly.

The best example I can give is that I've fixed broken linker scripts in libgloss that tried to match linkonce small data sections using .gnu.linkonce.s*, without realizing that linkonce small bss sections are .gnu.linkonce.sb.*. This caused some C++ programs to fail in strange and difficult to debug ways. Those dots are important.

Signature · 1 line
Jim Wilson, GNU Tools Support, http://www.specifix.com
#7 lore raw
In reply to H. J. Lu
Quoted 1 line · H. J. Lu
    *(.gnu.linkonce.t*)

This isn't something you added, but should be fixed just the same. This will accidentally cause some thread-local data sections to be merged into the text section. The thread-local sections may not have existed when this code was written, but they do now. .gnu.linkonce.td.* is used for linkonce thread local data, and .gnu.linkonce.tb.* is used for linkonce thread local bss.

Signature · 1 line
Jim Wilson, GNU Tools Support, http://www.specifix.com
#8 lore raw
In reply to H. J. Lu

H.J.,

Quoted 8 lines · H. J. Lu

I don't know where I should report gnu-efi bug. The ia32 support in gnu-efi-3.0b-041222 doesn't work with newer gcc and binutils. The problem is in the linker script. The new gcc may put functions in .text* sections. The newer linker handles orphaned sections differently. I tested this patch on both ia32 and ia64 with different versions of gcc and binutils by building elilo 3.6. Elilo 3.6 loads and run kernel correctly on ia64. It seems to work find on ia32.

As far as I know, I am still the maintainer of this package. But I need to check with some of our Linux people at HP.

It is unfortunate that this package as such strong dependency of the GNU compiler and linker. This has caused a lot of troubles when all the recent updates to gcc. Yet I do not see a way around this.

Once you and James ettle on the right update I'll put it in and push a new package.

Thanks for tracking this down.

Quoted 48 lines

H.J.

gnuefi/elf_ia32_efi.lds renamed from gnuefi/elf_ia32_efi.lds.ia32 +6 -5
@@ -9,7 +9,11 @@ SECTIONS
   . = ALIGN(4096);
   .text :
   {
-   *(.text)
+   *(.text*)
+  }
+  .reloc :
+  {
+   *(.reloc)
   }
   . = ALIGN(4096);
   .data :
@@ -48,12 +52,9 @@ SECTIONS
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
   . = ALIGN(4096);
-  .ignored.reloc :
+  /DISCARD/ :
   {
     *(.rel.reloc)
-  }
-  .ignored :
-  {
     *(.eh_frame)
   }
 }
gnuefi/elf_ia64_efi.lds renamed from gnuefi/elf_ia64_efi.lds.ia32 +1 -4
@@ -59,13 +59,10 @@ SECTIONS
   .dynsym   : { *(.dynsym) }
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
-  .ignored_reloc :
+  /DISCARD/ :
   {
     *(.rela.plabel)
     *(.rela.reloc)
-  }
-  /DISCARD/ :
-  {
     *(.IA_64.unwind*)
     *(.IA64.unwind*)
   }
Signature · 1 line
-Stephane
author
#9 lore raw
In reply to H. J. Lu
Quoted 9 lines · James E Wilson
Quoted 1 line · H. J. Lu
    *(.gnu.linkonce.t*)

This isn't something you added, but should be fixed just the same. This will accidentally cause some thread-local data sections to be merged into the text section. The thread-local sections may not have existed when this code was written, but they do now. .gnu.linkonce.td.* is used for linkonce thread local data, and .gnu.linkonce.tb.* is used for linkonce thread local bss.

I guess we never used TLS in EFI applications before. It doesn't really matter since TLS needs more than the linker script change. Here is the new patch.

H.J.
---

gnuefi/elf_ia32_efi.lds renamed from gnuefi/elf_ia32_efi.lds.ia32 +7 -4
@@ -10,6 +10,12 @@ SECTIONS
   .text :
   {
    *(.text)
+   *(.text.*)
+   *(.gnu.linkonce.t.*)
+  }
+  .reloc :
+  {
+   *(.reloc)
   }
   . = ALIGN(4096);
   .data :
@@ -48,12 +54,9 @@ SECTIONS
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
   . = ALIGN(4096);
-  .ignored.reloc :
+  /DISCARD/ :
   {
     *(.rel.reloc)
-  }
-  .ignored :
-  {
     *(.eh_frame)
   }
 }
gnuefi/elf_ia64_efi.lds renamed from gnuefi/elf_ia64_efi.lds.ia32 +3 -5
@@ -10,7 +10,8 @@ SECTIONS
   .text :
   {
    *(.text)
-   *(.gnu.linkonce.t*)
+   *(.text.*)
+   *(.gnu.linkonce.t.*)
   }
   . = ALIGN(4096);
   __gp = ALIGN (8) + 0x200000;
@@ -59,13 +60,10 @@ SECTIONS
   .dynsym   : { *(.dynsym) }
   . = ALIGN(4096);
   .dynstr   : { *(.dynstr) }
-  .ignored_reloc :
+  /DISCARD/ :
   {
     *(.rela.plabel)
     *(.rela.reloc)
-  }
-  /DISCARD/ :
-  {
     *(.IA_64.unwind*)
     *(.IA64.unwind*)
   }
#10 lore raw
In reply to H. J. Lu
Quoted 2 lines · H. J. Lu

I guess we never used TLS in EFI applications before. It doesn't really matter since TLS needs more than the linker script change.

True, but there is always the danger that someone might copy this linker script somewhere else where it does matter. So we may as well get it right.

This version looks good to me.

Signature · 1 line
Jim Wilson, GNU Tools Support, http://www.specifix.com