[PATCH] i386: Issue an error for baseless @GOT relocation with relaxation
Jan Beulich
jbeulich@suse.com
Thu Nov 6 07:41:32 GMT 2025
On 05.11.2025 23:59, H.J. Lu wrote:
> On Wed, Nov 5, 2025 at 11:31 PM Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>>
>> Hi Jan,
>>
>>> On 27.10.2025 11:09, H.J. Lu wrote:
>>>> On Mon, Oct 27, 2025 at 5:52 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>>
>>>>> On 27.10.2025 10:31, H.J. Lu wrote:
>>>>>> On Mon, Oct 27, 2025 at 4:41 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>>>>
>>>>>>> On 26.10.2025 00:28, H.J. Lu wrote:
>>>>>>>> When -mrelax-relocations=no is used, don't generate baseless R_386_GOT32X
>>>>>>>> relocation. Issue an error instead.
>>>>>>>>
>>>>>>>> PR gas/33552
>>>>>>>> * config/tc-i386.c (output_disp): Issue an error for baseless @GOT
>>>>>>>> relocation without relaxation in 32-bit.
>>>>>>>> * testsuite/gas/i386/got-no-relax-error.l: New file.
>>>>>>>> * testsuite/gas/i386/got-no-relax-error.s: Likewise.
>>>>>>>> * testsuite/gas/i386/got-no-relax.d: Don't use got.s. Remove
>>>>>>>> R_386_GOT32X entries.
>>>>>>>> * testsuite/gas/i386/i386.exp: Run got-no-relax-error.
>>>>>>>>
>>>>>>>
>>>>>>> Please can you add a reference to the part of the spec that puts in place
>>>>>>> this restriction?
>>>>>>
>>>>>> It is more of an ISA restriction. In i386 psABI, there are 2 kinds of PLTs,
>>>>>> one with EBX for PIC and the other without EBX for non-PIC. The baseless
>>>>>> @GOT reloc can only be used with non-PIC PLT.
>>>>>
>>>>> But the two PLT kinds must be specified somewhere. As must be the relocation
>>>>
>>>> It is in i386 psABI. They are implemented in elf32-i386.c.
>>>>
>>>>> types. Furthermore, how does the PLT come into play here when we're talking
>>>>> of a GOT reloc? R_386-GOT32X is G + A - GOT / G + A, i.e. nothing PLT-ish in
>>>>
>>>> jmp *foo@GOT
>>>>
>>>> was added for -fno-plt. For the same reason as non-PIC PLT, it only works
>>>> without PIC.
>>>>
>>>>> there. The description in the psABI also clearly mentions forms with and
>>>>> without base register.
>>>>
>>>> It is covered in:
>>>>
>>>> https://gitlab.com/x86-psABIs/i386-ABI
>>>
>>> Hmm, yes, I see the text there was extended at some point. Having a single
>>> reloc with two different calculations is, however, a no-go. Even more so with
>>> an arch like x86, where you can't reliably move backwards in the instruction
>>> byte stream.
>>
>> apparently this patch has never been tested either natively on Solaris
>> or with --enable-x86-relax-relocations=no, the only configurations where
>> it makes a noticeable difference. When doing one finds that it causes
>> quite a number of testsuite regressions:
>
> I withdrew my patch. Please see
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=33552
>
> for why R_386_GOT32X was generated for
>
> jmp *_start@GOT
What does this mean for Rainer's patch, though? I think it is correct to avoid
emitting this reloc when --enable-x86-relax-relocations=no. This is the only
way to ensure objects generated by gas can be processed by GOT32X unaware
linkers, for example. Besides addressing the Solaris issues Rainer points out.
Jan
More information about the Binutils
mailing list