[PATCH 1/6] ld: don't generate base relocations in PE output for absolute symbols

Jan Beulich jbeulich@suse.com
Tue Mar 2 13:30:45 GMT 2021


On 02.03.2021 10:47, Jan Beulich via Binutils wrote:
> It is the very nature of absolute symbols that they don't change even
> if the loader decides to put the image at other than its link-time base
> address. Of the linker-defined (and PE-specific) symbols __image_base__
> (and its alias) needs special casing, as it'll still appear to be
> absolute at this point.
> 
> A new inquiry function in ldexp.c is needed because PE base relocations
> get generated before ldexp_finalize_syms() runs, yet whether a
> relocation is needed depends on the ultimate property of a symbol.
> 
> ld/
> 2021-02-XX  Jan Beulich  <jbeulich@suse.com>
> 
> 	* ldexp.c (ldexp_is_final_sym_absolute): New.
> 	* ldexp.h (ldexp_is_final_sym_absolute): Declare.
> 	* pe-dll.c (generate_reloc): Skip absolute symbols.

Below the testcase I'm going to add to this change.

Jan

--- a/ld/testsuite/ld-pe/pe.exp
+++ b/ld/testsuite/ld-pe/pe.exp
@@ -76,6 +76,8 @@ run_dump_test "longsecn-5"
 run_dump_test "orphan"
 run_dump_test "orphan_nu"
 
+run_dump_test "reloc"
+
 run_dump_test "weakdef-1"
 
 run_dump_test "pr19803"
--- /dev/null
+++ b/ld/testsuite/ld-pe/reloc.d
@@ -0,0 +1,14 @@
+#name: PE base relocations
+#ld: --enable-reloc-section
+#objdump: -p
+
+.*:     file format .*
+
+#...
+PE File Base Relocations.*
+Virtual Address: .* Number of fixups 4
+[ 	]*reloc    0 offset    0 .* (LOW|HIGHLOW|DIR64)
+[ 	]*reloc    1 offset    [248] .* (LOW|HIGHLOW|DIR64)
+[ 	]*reloc    2 offset   [124]0 .* (LOW|HIGHLOW|DIR64)
+[ 	]*reloc    3 offset    0 .* ABSOLUTE
+#pass
--- /dev/null
+++ b/ld/testsuite/ld-pe/reloc.s
@@ -0,0 +1,13 @@
+	.data
+	.p2align 4
+start:
+	.dc.a	__image_base__
+	.dc.a	start
+	.dc.a	__section_alignment__
+	.dc.a	__file_alignment__
+	.dc.a	__major_os_version__
+	.dc.a	__minor_os_version__
+	.dc.a	__major_subsystem_version__
+	.dc.a	__minor_subsystem_version__
+	.dc.a	end
+end:



More information about the Binutils mailing list