elf: Set rel_from_abs to 1 for __ehdr_start
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 13 Nov 2020 23:44:35 +0000 (15:44 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 13 Nov 2020 23:44:47 +0000 (15:44 -0800)
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.

ld/ChangeLog
ld/ldelf.c
ld/testsuite/ld-i386/i386.exp
ld/testsuite/ld-i386/pr26869.d [new file with mode: 0644]
ld/testsuite/ld-i386/pr26869.s [new file with mode: 0644]

index d5d37b1da32a50d52403c747896bdbbc379825af..70ea14b41915e67e90d957c3961cc24e9363c74f 100644 (file)
@@ -1,3 +1,12 @@
+2020-11-13  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-11-09  Andreas Schwab  <schwab@linux-m68k.org>
 
        * Makefile.am (development.exp): Fix regexp.
index c37358f05e58e19a810110e0a8440ad218caa665..5cfddef39b3d22aff90fac9e9c0acbbad4930024 100644 (file)
@@ -1590,6 +1590,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;
            }
index 9c06f7006b79c3fbbf21e94fe7c27d1a87c9ef5c..0620721559eba3d6cd0366277441d96667d9f6ed 100644 (file)
@@ -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 (file)
index 0000000..bfd00a7
--- /dev/null
@@ -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 (file)
index 0000000..e492b98
--- /dev/null
@@ -0,0 +1,3 @@
+       .text
+foo:
+       pushl   __ehdr_start@GOT(%ebx)