aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-11-16 06:37:53 -0800
committerAndreas K. Hüttel <dilfridge@gentoo.org>2021-01-23 20:18:36 +0200
commitbadd76e2d57da479efddf8b76b0910778cf84d5a (patch)
tree26f777008e61fec654cf3bb5a425be149b2f5899
parentaarch64: Add support for Neoverse N2 CPU (diff)
downloadbinutils-gdb-badd76e2d57da479efddf8b76b0910778cf84d5a.tar.gz
binutils-gdb-badd76e2d57da479efddf8b76b0910778cf84d5a.tar.bz2
binutils-gdb-badd76e2d57da479efddf8b76b0910778cf84d5a.zip
elf: Set rel_from_abs to 1 for __ehdr_start
bfdlink.h has /* Symbol will be converted from absolute to section-relative. Set for symbols defined by a script from "dot" (also SEGMENT_START or ORIGIN) outside of an output section statement. */ unsigned int rel_from_abs : 1; 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) . Set rel_from_abs 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 rel_from_abs 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. (cherry picked from commit cbd5b99cce073273f668b154d4514e8e7e7ccc51) (cherry picked from commit 1767e3f3bd6d460491f8c8d032a7fea88d5ec8ff)
-rw-r--r--ld/ChangeLog9
-rw-r--r--ld/ldelf.c2
-rw-r--r--ld/testsuite/ld-i386/i386.exp1
-rw-r--r--ld/testsuite/ld-i386/pr26869.d14
-rw-r--r--ld/testsuite/ld-i386/pr26869.s3
5 files changed, 29 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 2742ad11e6..46c02f6f78 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2020-11-16 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/26869
+ * ldelf.c (ldelf_before_allocation): Set rel_from_abs 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.
+
2020-10-07 H.J. Lu <hongjiu.lu@intel.com>
* testsuite/ld-i386/property-3.r: Updated for Fedora binary
diff --git a/ld/ldelf.c b/ld/ldelf.c
index bada3ade2d..831d032fe5 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1589,6 +1589,8 @@ 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;
+ /* It will be converted to section-relative later. */
+ ehdr_start->rel_from_abs = 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 3089a66337..f031b01ffe 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -473,6 +473,7 @@ run_dump_test "pr26263"
run_dump_test "pr26711-1"
run_dump_test "pr26711-2"
run_dump_test "pr26711-3"
+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)