Blame SOURCES/0009-gnuefi-preserve-.gnu.hash-sections-unbreaks-elilo-on.patch

67650e
From 2cc0b085fb82e80d43cc08c8376dff9f9532a72d Mon Sep 17 00:00:00 2001
67650e
From: Sergei Trofimovich <slyfox@gentoo.org>
67650e
Date: Sat, 27 Jan 2018 20:29:05 +0000
67650e
Subject: [PATCH 09/25] gnuefi: preserve .gnu.hash sections (unbreaks elilo on
67650e
 IA-64)
67650e
67650e
Gentoo has slightly modified linker defaults: --hash-style=gnu
67650e
This means all ELF files in system have '.gnu.hash' section
67650e
but no '.hash' section.
67650e
67650e
gnuefi's ldscript did not account for it and as a result
67650e
one symbol 'ImageBase' did not resolve locally for elilo.so
67650e
and caused 'elilo' to fail to load by ia64 EFI:
67650e
  Loading.: Gentoo (try new elilo)
67650e
  ImageAddress: pointer is outside of image
67650e
  ImageAddress: pointer is outside of image
67650e
67650e
Those two relocations come from crt0-efi-ia64.S PE32 entry point
67650e
fdescr:
67650e
67650e
```
67650e
    #define IMAGE_REL_BASED_DIR64<->10
67650e
    .section .reloc, "a"
67650e
    data4   _start_plabel // Page RVA
67650e
    data4   12            // Block Size (2*4+2*2)
67650e
    data2   (IMAGE_REL_BASED_DIR64<<12) +  0 // reloc for plabel's entry point
67650e
    data2   (IMAGE_REL_BASED_DIR64<<12) +  8 // reloc for plabel's global pointer
67650e
```
67650e
67650e
These refer ImageBase.
67650e
67650e
The change adds '.gnu.hash' collection (follows existing '.hash'
67650e
collection).
67650e
67650e
Tested on IA-64 by successfully booting elilo-3.16.
67650e
67650e
Bug: https://bugs.gentoo.org/575300
67650e
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
67650e
---
67650e
 README.gnuefi                  | 8 +++++++-
67650e
 gnuefi/elf_ia32_efi.lds        | 4 +++-
67650e
 gnuefi/elf_ia32_fbsd_efi.lds   | 4 +++-
67650e
 gnuefi/elf_ia64_efi.lds        | 4 +++-
67650e
 gnuefi/elf_x86_64_efi.lds      | 4 +++-
67650e
 gnuefi/elf_x86_64_fbsd_efi.lds | 4 +++-
67650e
 6 files changed, 22 insertions(+), 6 deletions(-)
67650e
67650e
diff --git a/README.gnuefi b/README.gnuefi
67650e
index a7feec0ba28..512698c28b4 100644
67650e
--- a/README.gnuefi
67650e
+++ b/README.gnuefi
67650e
@@ -231,11 +231,17 @@ and page sized.These eight sections are used to group together the much
67650e
 greater number of sections that are typically present in ELF object files.
67650e
 Specifically:
67650e
 
67650e
- .hash
67650e
+ .hash (and/or .gnu.hash)
67650e
 	Collects the ELF .hash info (this section _must_ be the first
67650e
 	section in order to build a shared object file; the section is
67650e
 	not actually loaded or used at runtime).
67650e
 
67650e
+	GNU binutils provides a mechanism to generate different hash info
67650e
+	via --hash-style=<sysv|gnu|both> option. In this case output
67650e
+	shared object will contain .hash section, .gnu.hash section or
67650e
+	both. In order to generate correct output linker script preserves
67650e
+	both types of hash sections.
67650e
+
67650e
  .text
67650e
 	Collects all sections containing executable code.
67650e
 
67650e
diff --git a/gnuefi/elf_ia32_efi.lds b/gnuefi/elf_ia32_efi.lds
67650e
index 6cc4ce1b8c7..f27fe5fc6e6 100644
67650e
--- a/gnuefi/elf_ia32_efi.lds
67650e
+++ b/gnuefi/elf_ia32_efi.lds
67650e
@@ -5,7 +5,9 @@ SECTIONS
67650e
 {
67650e
   . = 0;
67650e
   ImageBase = .;
67650e
-  .hash : { *(.hash) }	/* this MUST come first! */
67650e
+  /* .hash and/or .gnu.hash MUST come first! */
67650e
+  .hash : { *(.hash) }
67650e
+  .gnu.hash : { *(.gnu.hash) }
67650e
   . = ALIGN(4096);
67650e
   .text :
67650e
   {
67650e
diff --git a/gnuefi/elf_ia32_fbsd_efi.lds b/gnuefi/elf_ia32_fbsd_efi.lds
67650e
index 77d6fade1a5..cd309e24f7f 100644
67650e
--- a/gnuefi/elf_ia32_fbsd_efi.lds
67650e
+++ b/gnuefi/elf_ia32_fbsd_efi.lds
67650e
@@ -5,7 +5,9 @@ SECTIONS
67650e
 {
67650e
   . = 0;
67650e
   ImageBase = .;
67650e
-  .hash : { *(.hash) }	/* this MUST come first! */
67650e
+  /* .hash and/or .gnu.hash MUST come first! */
67650e
+  .hash : { *(.hash) }
67650e
+  .gnu.hash : { *(.gnu.hash) }
67650e
   . = ALIGN(4096);
67650e
   .text :
67650e
   {
67650e
diff --git a/gnuefi/elf_ia64_efi.lds b/gnuefi/elf_ia64_efi.lds
67650e
index baca9623b57..190792a0c94 100644
67650e
--- a/gnuefi/elf_ia64_efi.lds
67650e
+++ b/gnuefi/elf_ia64_efi.lds
67650e
@@ -5,7 +5,9 @@ SECTIONS
67650e
 {
67650e
   . = 0;
67650e
   ImageBase = .;
67650e
-  .hash : { *(.hash) }	/* this MUST come first! */
67650e
+  /* .hash and/or .gnu.hash MUST come first! */
67650e
+  .hash : { *(.hash) }
67650e
+  .gnu.hash : { *(.gnu.hash) }
67650e
   . = ALIGN(4096);
67650e
   .text :
67650e
   {
67650e
diff --git a/gnuefi/elf_x86_64_efi.lds b/gnuefi/elf_x86_64_efi.lds
67650e
index 942d1f3eff7..7be59023510 100644
67650e
--- a/gnuefi/elf_x86_64_efi.lds
67650e
+++ b/gnuefi/elf_x86_64_efi.lds
67650e
@@ -6,7 +6,9 @@ SECTIONS
67650e
 {
67650e
   . = 0;
67650e
   ImageBase = .;
67650e
-  .hash : { *(.hash) }	/* this MUST come first! */
67650e
+  /* .hash and/or .gnu.hash MUST come first! */
67650e
+  .hash : { *(.hash) }
67650e
+  .gnu.hash : { *(.gnu.hash) }
67650e
   . = ALIGN(4096);
67650e
   .eh_frame : 
67650e
   { 
67650e
diff --git a/gnuefi/elf_x86_64_fbsd_efi.lds b/gnuefi/elf_x86_64_fbsd_efi.lds
67650e
index 6fd2031c13b..fe1f3342cae 100644
67650e
--- a/gnuefi/elf_x86_64_fbsd_efi.lds
67650e
+++ b/gnuefi/elf_x86_64_fbsd_efi.lds
67650e
@@ -6,7 +6,9 @@ SECTIONS
67650e
 {
67650e
   . = 0;
67650e
   ImageBase = .;
67650e
-  .hash : { *(.hash) }	/* this MUST come first! */
67650e
+  /* .hash and/or .gnu.hash MUST come first! */
67650e
+  .hash : { *(.hash) }
67650e
+  .gnu.hash : { *(.gnu.hash) }
67650e
   . = ALIGN(4096);
67650e
   .eh_frame : 
67650e
   { 
67650e
-- 
67650e
2.15.0
67650e