Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ZachBacon/5816ea8e273bd9d31a3a5afe8868944c to your computer and use it in GitHub Desktop.

Select an option

Save ZachBacon/5816ea8e273bd9d31a3a5afe8868944c to your computer and use it in GitHub Desktop.
binutils
From: Zach Bacon <thezachbacon@gmail.com.com>
Subject: [PATCH] ld/PE: place .debug_gnu_pubnames and .debug_gnu_pubtypes
The default PE/PE+ linker scripts have orphan-placement rules for the
standard DWARF .debug_pubnames / .debug_pubtypes sections, but not for
the GNU-extension .debug_gnu_pubnames / .debug_gnu_pubtypes sections
emitted by GCC's -ggnu-pubnames (which is implied by -gsplit-dwarf).
Without an explicit rule, the linker treats those sections as orphans
and assigns them an arbitrary high VMA, placing them at the front of
the PE section table. PE requires sections to be sorted by RVA, so
Windows refuses to load the resulting image with "exec format error".
Fix by adding parallel placement rules next to the existing
.debug_pubnames / .debug_pubtypes blocks in pe.sc and pep.sc.
ld/ChangeLog:
* scripttempl/pe.sc: Add orphan placement for .debug_gnu_pubnames
and .debug_gnu_pubtypes sections.
* scripttempl/pep.sc: Likewise.
---
ld/scripttempl/pe.sc | 10 ++++++++++
ld/scripttempl/pep.sc | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc
--- a/ld/scripttempl/pe.sc
+++ b/ld/scripttempl/pe.sc
@@ -238,6 +238,11 @@ SECTIONS
{
*(.debug_pubnames)
}
+ .debug_gnu_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_gnu_pubnames)
+ }
+
.zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
{
*(.zdebug_pubnames)
@@ -337,6 +342,11 @@ SECTIONS
{
*(.debug_pubtypes)
}
+ .debug_gnu_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_gnu_pubtypes)
+ }
+
.zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
{
*(.zdebug_pubtypes)
diff --git a/ld/scripttempl/pep.sc b/ld/scripttempl/pep.sc
--- a/ld/scripttempl/pep.sc
+++ b/ld/scripttempl/pep.sc
@@ -238,6 +238,11 @@ SECTIONS
{
*(.debug_pubnames)
}
+ .debug_gnu_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_gnu_pubnames)
+ }
+
.zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
{
*(.zdebug_pubnames)
@@ -337,6 +342,11 @@ SECTIONS
{
*(.debug_pubtypes)
}
+ .debug_gnu_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_gnu_pubtypes)
+ }
+
.zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
{
*(.zdebug_pubtypes)
--
2.46.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment