Re: [PATCH] x86: Disallow ".long foo@PLT - .L4" for PLT32 relocation

"Maciej W. Rozycki" <[email protected]> Mon, 3 Aug 2026 18:46:27 +0100 (BST)
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
On Mon, 3 Aug 2026, H.J. Lu wrote:

> > >>>>>  Jan, please correct me if I'm wrong since commit d182319b0955 has no
> > >>>>> change description and there's no documentation for `.slong' in the GAS
> > >>>>> manual either.  What are the x86 psABI ELF relocation types corresponding
> > >>>>> to `.long' and `.slong' respectively in this context?
> > >>>>
> > >>>> For .long there simply is no correct relocation type to use for PLT (and,
> > >>>> fwiw, simple PC-relative) expressions. The correct type to use is
> > >>>> R_X86_64_PLT32 (and R_X86_64_PC32 for the simple PC-rel case).

 Would you please provide me with the calculation R_X86_64_PLT32 stands 
for and what the calculation required would be for `.long' should we have 
an actual relocation representing this operation?  Also what is the linker 
expected by the psABI to do on an overflow condition?

> > >>>> For the simple PC-rel case we simply cannot require use of .slong, as we've
> > >>>> been accepting .long (then guessing that .slong was meant). Else we'd very
> > >>>> likely break existing code. Since @PLT was rejected so far when used with
> > >>>> .long and .slong, doing better here is imo very desirable (if not
> > >>>> imperative).

 Ack, understood, although would perhaps an assembly warning be in order?  
Does this case typically come from handwritten assembly or one of compiled 
origin?

> > How can it be correct if it would break if a suitable relocation was introduced?
> > Just because it has been this way from the start of x86-64 doesn't mean it was
> > right. There are many things which needed correction later one One of them being
> > the original lack of .slong.
> 
> That is purely your opinion.   I don't think correction is needed on this.

 I don't find it a matter of anyone's opinion.  Relocations are deferred 
calculation operators for expressions that cannot be resolved at assembly 
time and these operators need to match the calculation requested at the 
assembly level.

 I gather the difference between `.long' and `.slong' here is analogous to 
MOVZX vs MOVSX (speaking in terms of machine operations) combined with a 
further calculation (to be hopefully clarified by Jan) implied by the use 
of a PLT reference as per the psABI.  It seems to me that expressing both 
calculations with just one relocation operation is self-contradictory.

 Am I missing something here?

  Maciej