[PATCH] elf: Set ldscript_def to 1 for __ehdr_start

H.J. Lu hjl.tools@gmail.com
Thu Nov 12 12:56:41 GMT 2020


linker.c has

.{* Return TRUE if the symbol described by a linker hash entry H
.   is going to be absolute.  Linker-script defined symbols can be
.   converted from absolute to section-relative ones late in the
.   link.  Use this macro to correctly determine whether the symbol
.   will actually end up absolute in output.  *}
.#define bfd_is_abs_symbol(H) \
.  (((H)->type == bfd_link_hash_defined \
.    || (H)->type == bfd_link_hash_defweak) \
.   && bfd_is_abs_section ((H)->u.def.section) \
.   && !(H)->rel_from_abs)
.

elfxx-x86.h has

/* Return TRUE if the symbol described by a linker hash entry H is
   going to be absolute.  Similar to bfd_is_abs_symbol, but excluding
   all linker-script defined symbols.  */
 #define ABS_SYMBOL_P(H) \
  (bfd_is_abs_symbol (&(H)->root) && !(H)->root.ldscript_def)

Set ldscript_def to 1 for __ehdr_start which will be converted from
absolute to section-relative in assign_file_positions_for_load_sections.

	PR ld/26869
	* ldelf.c (ldelf_before_allocation): Set ldscript_def to 1 for
	__ehdr_start.
	* testsuite/ld-i386/i386.exp: Run pr26869.
	* testsuite/ld-i386/pr26869.d: New file.
	* testsuite/ld-i386/pr26869.s: Likewise.
---
 ld/ldelf.c                     |  1 +
 ld/testsuite/ld-i386/i386.exp  |  1 +
 ld/testsuite/ld-i386/pr26869.d | 14 ++++++++++++++
 ld/testsuite/ld-i386/pr26869.s |  3 +++
 4 files changed, 19 insertions(+)
 create mode 100644 ld/testsuite/ld-i386/pr26869.d
 create mode 100644 ld/testsuite/ld-i386/pr26869.s

diff --git a/ld/ldelf.c b/ld/ldelf.c
index c37358f05e..0a5b066bda 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1590,6 +1590,7 @@ ldelf_before_allocation (char *audit, char *depaudit,
 		      (char *) &ehdr_start->u + sizeof ehdr_start->u.def.next,
 		      sizeof ehdr_start_save_u);
 	      ehdr_start->type = bfd_link_hash_defined;
+	      ehdr_start->ldscript_def = 1;
 	      ehdr_start->u.def.section = bfd_abs_section_ptr;
 	      ehdr_start->u.def.value = 0;
 	    }
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 9c06f7006b..0620721559 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -480,6 +480,7 @@ run_dump_test "property-x86-isa1"
 run_dump_test "property-x86-isa2"
 run_dump_test "property-x86-isa3"
 run_dump_test "property-x86-isa4"
+run_dump_test "pr26869"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr26869.d b/ld/testsuite/ld-i386/pr26869.d
new file mode 100644
index 0000000000..bfd00a70e9
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr26869.d
@@ -0,0 +1,14 @@
+#as: --32
+#ld: -shared -melf_i386
+#readelf: -r -s --wide
+
+Relocation section '.rel.dyn' at offset 0x[a-f0-9]+ contains 1 entry:
+ Offset     Info    Type                Sym. Value  Symbol's Name
+0+[a-f0-9]+  00000008 R_386_RELATIVE        
+
+#...
+Symbol table '.symtab' contains [0-9]+ entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+#...
+ +[a-f0-9]+: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 __ehdr_start
+#pass
diff --git a/ld/testsuite/ld-i386/pr26869.s b/ld/testsuite/ld-i386/pr26869.s
new file mode 100644
index 0000000000..e492b98e86
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr26869.s
@@ -0,0 +1,3 @@
+	.text
+foo:
+	pushl	__ehdr_start@GOT(%ebx)
-- 
2.28.0



More information about the Binutils mailing list