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

Jan Beulich jbeulich@suse.com
Thu Mar 4 08:52:06 GMT 2021


On 04.03.2021 05:46, Alan Modra wrote:
> On Tue, Mar 02, 2021 at 10:47:03AM +0100, 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.
> 
> OK.

Just to confirm - subsequently I did send a test case to be added
here, for which I have these additional entries:

	* testsuite/ld-pe/reloc.s, testsuite/ld-pe/reloc.d: New.
	* testsuite/ld-pe/pe.exp: Run new test.

Is that okay to commit as a whole, or should I re-submit (or
submit the test case addition as a separate change)?

>> +		  /* Nor for absolute symbols.  */
>> +		  else if (blhe && ldexp_is_final_sym_absolute (blhe)
>> +			   && (!blhe->linker_def
>> +			       || (strcmp(sym->name, "__image_base__")
>> +				   && strcmp(sym->name, U ("__ImageBase")))))
> 
> Space after strcmp.

Oh, yes, sorry.

Jan


More information about the Binutils mailing list