[PATCH v2] x86: Restore PC16 relocation overflow check
Jan Beulich
jbeulich@suse.com
Fri May 28 12:41:17 GMT 2021
On 28.05.2021 14:22, H.J. Lu wrote:
> The x86-64 psABI has
>
> ---
> A program or object file using R_X86_64_8, R_X86_64_16, R_X86_64_PC16
> or R_X86_64_PC8 relocations is not conformant to this ABI, these
> relocations are only added for documentation purposes.
> ---
>
> Since x86 PC16 relocations were intended for 16-bit programs in an ELF32
> or ELF64 container, PC16 relocation should wrap-around in 16-bit address
> space.
At the risk of stating the obvious - this wrapping around is not
expressed correctly by complain_overflow_bitfield. I simply can't
see how, in a 32- or 64-bit container, 16-bit code could ever be
linked correctly, suitably detecting overflow where it would
cause a problem at runtime. This is only possible when the linker
knows 16-bit segment boundaries.
Therefore I see only two reasonable modes of operation for the
linker:
1) Treat PC16 analogously to PC8/PC32/PC64.
2) Don't check PC16 (and then also PC8, 8, and 16) for overflow
at all.
The default ought to be 1, while 2 ought to be enabled explicitly
(and at the programmer's own risk) for code caring to link sizable
amounts of 16-bit code (i.e. when the overflow checking gets in
the way).
This said, with the psABI saying what it says, I could see one
taking the position of taking "don't check overflows at all" as
a legitimate mode to always operate in. But then again this
ought to apply to all four non-conformant reloc types at the
same time.
Jan
More information about the Binutils
mailing list