[edk2] BaseTools/Scripts: discard .gnu.hash section in GCC builds

Message ID 20170519104740.16044-1-ard.biesheuvel@linaro.org
State Accepted
Commit 00b00cc57bfe0fca54c904d4dd44a263e243c88b
Headers show

Commit Message

Ard Biesheuvel May 19, 2017, 10:47 a.m.
Some builds of GCC/binutils will default to using the GNU flavor of
the symbol hash table, and will emit it into a section called .gnu.hash
rather than .hash. We have no use for its contents, and GenFw ignores
it anyway, so it shouldn't really matter what we do with it.

However, due to a workaround for AARCH64 we have in GenFw to deal with
older GCCs that corrupt section-based relocations when merging sections
during the final link, we need the ELF and PE/COFF views of the binary
to be identical. Since we don't place the .gnu.hash section explicitly,
it may end up at the beginning of the ELF binary, causing other sections
to be shifted in the ELF view but not in the PE/COFF view.

So let's add .gnu.hash to the GCC linker script. We don't care about its
contents so add it to the /DISCARD/ section.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 BaseTools/Scripts/GccBase.lds | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.9.3

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Leif Lindholm May 19, 2017, 10:58 a.m. | #1
On Fri, May 19, 2017 at 11:47:40AM +0100, Ard Biesheuvel wrote:
> Some builds of GCC/binutils will default to using the GNU flavor of

> the symbol hash table, and will emit it into a section called .gnu.hash

> rather than .hash. We have no use for its contents, and GenFw ignores

> it anyway, so it shouldn't really matter what we do with it.

> 

> However, due to a workaround for AARCH64 we have in GenFw to deal with

> older GCCs that corrupt section-based relocations when merging sections

> during the final link, we need the ELF and PE/COFF views of the binary

> to be identical. Since we don't place the .gnu.hash section explicitly,

> it may end up at the beginning of the ELF binary, causing other sections

> to be shifted in the ELF view but not in the PE/COFF view.

> 

> So let's add .gnu.hash to the GCC linker script. We don't care about its

> contents so add it to the /DISCARD/ section.

> 

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Tested-by: Leif Lindholm <leif.lindholm@linaro.org>


> ---

>  BaseTools/Scripts/GccBase.lds | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds

> index 41e5c0b4a769..a43e0072f2b4 100644

> --- a/BaseTools/Scripts/GccBase.lds

> +++ b/BaseTools/Scripts/GccBase.lds

> @@ -78,7 +78,7 @@ SECTIONS {

>      *(.dynsym)

>      *(.dynstr)

>      *(.dynamic)

> -    *(.hash)

> +    *(.hash .gnu.hash)

>      *(.comment)

>      *(COMMON)

>    }

> -- 

> 2.9.3

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Gao, Liming May 22, 2017, 4:05 a.m. | #2
Reviewed-by: Liming Gao <liming.gao@intel.com>


>-----Original Message-----

>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

>Sent: Friday, May 19, 2017 6:48 PM

>To: edk2-devel@lists.01.org

>Cc: leif.lindholm@linaro.org; Zhu, Yonghong <yonghong.zhu@intel.com>; Gao,

>Liming <liming.gao@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>

>Subject: [PATCH] BaseTools/Scripts: discard .gnu.hash section in GCC builds

>

>Some builds of GCC/binutils will default to using the GNU flavor of

>the symbol hash table, and will emit it into a section called .gnu.hash

>rather than .hash. We have no use for its contents, and GenFw ignores

>it anyway, so it shouldn't really matter what we do with it.

>

>However, due to a workaround for AARCH64 we have in GenFw to deal with

>older GCCs that corrupt section-based relocations when merging sections

>during the final link, we need the ELF and PE/COFF views of the binary

>to be identical. Since we don't place the .gnu.hash section explicitly,

>it may end up at the beginning of the ELF binary, causing other sections

>to be shifted in the ELF view but not in the PE/COFF view.

>

>So let's add .gnu.hash to the GCC linker script. We don't care about its

>contents so add it to the /DISCARD/ section.

>

>Contributed-under: TianoCore Contribution Agreement 1.0

>Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>---

> BaseTools/Scripts/GccBase.lds | 2 +-

> 1 file changed, 1 insertion(+), 1 deletion(-)

>

>diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds

>index 41e5c0b4a769..a43e0072f2b4 100644

>--- a/BaseTools/Scripts/GccBase.lds

>+++ b/BaseTools/Scripts/GccBase.lds

>@@ -78,7 +78,7 @@ SECTIONS {

>     *(.dynsym)

>     *(.dynstr)

>     *(.dynamic)

>-    *(.hash)

>+    *(.hash .gnu.hash)

>     *(.comment)

>     *(COMMON)

>   }

>--

>2.9.3


_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel May 24, 2017, 1:13 p.m. | #3
On 21 May 2017 at 21:05, Gao, Liming <liming.gao@intel.com> wrote:
> Reviewed-by: Liming Gao <liming.gao@intel.com>

>


Thanks. Pushed as 00b00cc57bfe0fca54c904d4dd44a263e243c88b

>>-----Original Message-----

>>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

>>Sent: Friday, May 19, 2017 6:48 PM

>>To: edk2-devel@lists.01.org

>>Cc: leif.lindholm@linaro.org; Zhu, Yonghong <yonghong.zhu@intel.com>; Gao,

>>Liming <liming.gao@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>

>>Subject: [PATCH] BaseTools/Scripts: discard .gnu.hash section in GCC builds

>>

>>Some builds of GCC/binutils will default to using the GNU flavor of

>>the symbol hash table, and will emit it into a section called .gnu.hash

>>rather than .hash. We have no use for its contents, and GenFw ignores

>>it anyway, so it shouldn't really matter what we do with it.

>>

>>However, due to a workaround for AARCH64 we have in GenFw to deal with

>>older GCCs that corrupt section-based relocations when merging sections

>>during the final link, we need the ELF and PE/COFF views of the binary

>>to be identical. Since we don't place the .gnu.hash section explicitly,

>>it may end up at the beginning of the ELF binary, causing other sections

>>to be shifted in the ELF view but not in the PE/COFF view.

>>

>>So let's add .gnu.hash to the GCC linker script. We don't care about its

>>contents so add it to the /DISCARD/ section.

>>

>>Contributed-under: TianoCore Contribution Agreement 1.0

>>Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>>---

>> BaseTools/Scripts/GccBase.lds | 2 +-

>> 1 file changed, 1 insertion(+), 1 deletion(-)

>>

>>diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds

>>index 41e5c0b4a769..a43e0072f2b4 100644

>>--- a/BaseTools/Scripts/GccBase.lds

>>+++ b/BaseTools/Scripts/GccBase.lds

>>@@ -78,7 +78,7 @@ SECTIONS {

>>     *(.dynsym)

>>     *(.dynstr)

>>     *(.dynamic)

>>-    *(.hash)

>>+    *(.hash .gnu.hash)

>>     *(.comment)

>>     *(COMMON)

>>   }

>>--

>>2.9.3

>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Gao, Liming May 27, 2017, 9:05 a.m. | #4
Ard:
  I just run BaseTools\Scripts\PatchCheck.py to check the latest patches. It reports one issue in this patch. Could you fix it?

The commit message format passed all checks.
Code format is not valid:
 * Line ending ('\n') is not CRLF
   File: BaseTools/Scripts/GccBase.lds
   Line:     *(.hash .gnu.hash)

Thanks
Liming
> -----Original Message-----

> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> Sent: Wednesday, May 24, 2017 9:13 PM

> To: Gao, Liming <liming.gao@intel.com>

> Cc: edk2-devel@lists.01.org; leif.lindholm@linaro.org; Zhu, Yonghong <yonghong.zhu@intel.com>

> Subject: Re: [PATCH] BaseTools/Scripts: discard .gnu.hash section in GCC builds

> 

> On 21 May 2017 at 21:05, Gao, Liming <liming.gao@intel.com> wrote:

> > Reviewed-by: Liming Gao <liming.gao@intel.com>

> >

> 

> Thanks. Pushed as 00b00cc57bfe0fca54c904d4dd44a263e243c88b

> 

> >>-----Original Message-----

> >>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

> >>Sent: Friday, May 19, 2017 6:48 PM

> >>To: edk2-devel@lists.01.org

> >>Cc: leif.lindholm@linaro.org; Zhu, Yonghong <yonghong.zhu@intel.com>; Gao,

> >>Liming <liming.gao@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>

> >>Subject: [PATCH] BaseTools/Scripts: discard .gnu.hash section in GCC builds

> >>

> >>Some builds of GCC/binutils will default to using the GNU flavor of

> >>the symbol hash table, and will emit it into a section called .gnu.hash

> >>rather than .hash. We have no use for its contents, and GenFw ignores

> >>it anyway, so it shouldn't really matter what we do with it.

> >>

> >>However, due to a workaround for AARCH64 we have in GenFw to deal with

> >>older GCCs that corrupt section-based relocations when merging sections

> >>during the final link, we need the ELF and PE/COFF views of the binary

> >>to be identical. Since we don't place the .gnu.hash section explicitly,

> >>it may end up at the beginning of the ELF binary, causing other sections

> >>to be shifted in the ELF view but not in the PE/COFF view.

> >>

> >>So let's add .gnu.hash to the GCC linker script. We don't care about its

> >>contents so add it to the /DISCARD/ section.

> >>

> >>Contributed-under: TianoCore Contribution Agreement 1.0

> >>Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> >>---

> >> BaseTools/Scripts/GccBase.lds | 2 +-

> >> 1 file changed, 1 insertion(+), 1 deletion(-)

> >>

> >>diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds

> >>index 41e5c0b4a769..a43e0072f2b4 100644

> >>--- a/BaseTools/Scripts/GccBase.lds

> >>+++ b/BaseTools/Scripts/GccBase.lds

> >>@@ -78,7 +78,7 @@ SECTIONS {

> >>     *(.dynsym)

> >>     *(.dynstr)

> >>     *(.dynamic)

> >>-    *(.hash)

> >>+    *(.hash .gnu.hash)

> >>     *(.comment)

> >>     *(COMMON)

> >>   }

> >>--

> >>2.9.3

> >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel May 28, 2017, 12:08 p.m. | #5
On 27 May 2017 at 09:05, Gao, Liming <liming.gao@intel.com> wrote:
> Ard:

>   I just run BaseTools\Scripts\PatchCheck.py to check the latest patches. It reports one issue in this patch. Could you fix it?

>


Pushed as f4d3ba87bb8f

-- 
Ard.

> The commit message format passed all checks.

> Code format is not valid:

>  * Line ending ('\n') is not CRLF

>    File: BaseTools/Scripts/GccBase.lds

>    Line:     *(.hash .gnu.hash)

>

> Thanks

> Liming

>> -----Original Message-----

>> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

>> Sent: Wednesday, May 24, 2017 9:13 PM

>> To: Gao, Liming <liming.gao@intel.com>

>> Cc: edk2-devel@lists.01.org; leif.lindholm@linaro.org; Zhu, Yonghong <yonghong.zhu@intel.com>

>> Subject: Re: [PATCH] BaseTools/Scripts: discard .gnu.hash section in GCC builds

>>

>> On 21 May 2017 at 21:05, Gao, Liming <liming.gao@intel.com> wrote:

>> > Reviewed-by: Liming Gao <liming.gao@intel.com>

>> >

>>

>> Thanks. Pushed as 00b00cc57bfe0fca54c904d4dd44a263e243c88b

>>

>> >>-----Original Message-----

>> >>From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]

>> >>Sent: Friday, May 19, 2017 6:48 PM

>> >>To: edk2-devel@lists.01.org

>> >>Cc: leif.lindholm@linaro.org; Zhu, Yonghong <yonghong.zhu@intel.com>; Gao,

>> >>Liming <liming.gao@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>

>> >>Subject: [PATCH] BaseTools/Scripts: discard .gnu.hash section in GCC builds

>> >>

>> >>Some builds of GCC/binutils will default to using the GNU flavor of

>> >>the symbol hash table, and will emit it into a section called .gnu.hash

>> >>rather than .hash. We have no use for its contents, and GenFw ignores

>> >>it anyway, so it shouldn't really matter what we do with it.

>> >>

>> >>However, due to a workaround for AARCH64 we have in GenFw to deal with

>> >>older GCCs that corrupt section-based relocations when merging sections

>> >>during the final link, we need the ELF and PE/COFF views of the binary

>> >>to be identical. Since we don't place the .gnu.hash section explicitly,

>> >>it may end up at the beginning of the ELF binary, causing other sections

>> >>to be shifted in the ELF view but not in the PE/COFF view.

>> >>

>> >>So let's add .gnu.hash to the GCC linker script. We don't care about its

>> >>contents so add it to the /DISCARD/ section.

>> >>

>> >>Contributed-under: TianoCore Contribution Agreement 1.0

>> >>Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>> >>---

>> >> BaseTools/Scripts/GccBase.lds | 2 +-

>> >> 1 file changed, 1 insertion(+), 1 deletion(-)

>> >>

>> >>diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds

>> >>index 41e5c0b4a769..a43e0072f2b4 100644

>> >>--- a/BaseTools/Scripts/GccBase.lds

>> >>+++ b/BaseTools/Scripts/GccBase.lds

>> >>@@ -78,7 +78,7 @@ SECTIONS {

>> >>     *(.dynsym)

>> >>     *(.dynstr)

>> >>     *(.dynamic)

>> >>-    *(.hash)

>> >>+    *(.hash .gnu.hash)

>> >>     *(.comment)

>> >>     *(COMMON)

>> >>   }

>> >>--

>> >>2.9.3

>> >

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Patch hide | download patch | download mbox

diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds
index 41e5c0b4a769..a43e0072f2b4 100644
--- a/BaseTools/Scripts/GccBase.lds
+++ b/BaseTools/Scripts/GccBase.lds
@@ -78,7 +78,7 @@  SECTIONS {
     *(.dynsym)
     *(.dynstr)
     *(.dynamic)
-    *(.hash)
+    *(.hash .gnu.hash)
     *(.comment)
     *(COMMON)
   }