[PATCH] APX: Add R_X86_64_CODE_(5|6)_(GOTPCRELX|GOTTPOFF|GOTPC32_TLSDESC)

6 views
Skip to first unread message

H.J. Lu

unread,
Feb 6, 2024, 9:11:48 AMFeb 6
to x86-6...@googlegroups.com
Add 6 new relocations:

#define R_X86_64_CODE_5_GOTPCRELX 46
#define R_X86_64_CODE_5_GOTTPOFF 47
#define R_X86_64_CODE_5_GOTPC32_TLSDESC 48
#define R_X86_64_CODE_6_GOTPCRELX 49
#define R_X86_64_CODE_6_GOTTPOFF 50
#define R_X86_64_CODE_6_GOTPC32_TLSDESC 51

R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF,
R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX and
R_X86_64_CODE_6_GOTPC32_TLSDESC are added only for completeness.

R_X86_64_CODE_6_GOTTPOFF must be used to encode APX NDD add instructions:

add %reg1, foo@gottpoff(%rip), %reg2

and

add foo@gottpoff(%rip), %reg1, %reg2

It is similar to R_X86_64_GOTTPOFF and linker can optimize them to:

add $foo@tpoff, %reg1, %reg2
---
x86-64-ABI/object-files.tex | 71 ++++++++++++++++++++++++++-----------
1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/x86-64-ABI/object-files.tex b/x86-64-ABI/object-files.tex
index e26264a..3eb0dce 100644
--- a/x86-64-ABI/object-files.tex
+++ b/x86-64-ABI/object-files.tex
@@ -489,6 +489,12 @@ or \texttt{Elf32_Rel} relocation entries.
\texttt{R_X86_64_CODE_4_GOTPCRELX} & 43 & \textit{word32} & \texttt{G + GOT + A - P} \\
\texttt{R_X86_64_CODE_4_GOTTPOFF} & 44 & \textit{word32} & \\
\texttt{R_X86_64_CODE_4_GOTPC32_TLSDESC} & 45 & \textit{word32} & \\
+ \texttt{R_X86_64_CODE_5_GOTPCRELX} & 46 & \textit{word32} & \texttt{G + GOT + A - P} \\
+ \texttt{R_X86_64_CODE_5_GOTTPOFF} & 47 & \textit{word32} & \\
+ \texttt{R_X86_64_CODE_5_GOTPC32_TLSDESC} & 48 & \textit{word32} & \\
+ \texttt{R_X86_64_CODE_6_GOTPCRELX} & 49 & \textit{word32} & \texttt{G + GOT + A - P} \\
+ \texttt{R_X86_64_CODE_6_GOTTPOFF} & 50 & \textit{word32} & \\
+ \texttt{R_X86_64_CODE_6_GOTPC32_TLSDESC} & 51 & \textit{word32} & \\
\cline{1-4}
\multicolumn{4}{l}{\small $^\dagger$ This relocation is used only for LP64.}\\
\multicolumn{4}{l}{\small $^{\dagger\dagger}$ This relocation only
@@ -537,16 +543,22 @@ instructions:
\end{footnotesize}

\noindent
-\begin{sloppypar}
where \code{binop} is one of \code{adc}, \code{add}, \code{and},
\code{cmp}, \code{or}, \code{sbb}, \code{sub}, \code{xor}
-instructions, the \texttt{R_X86_64_GOTPCRELX} relocation,
-the \texttt{R_X86_64_REX_GOTPCRELX} relocation if the
-\code{REX} prefix is present, or the \texttt{R_X86_64_CODE_4_GOTPCRELX}
-relocation if the instruction starts at 4 bytes before the relocation
-offset, should be generated, instead of the \texttt{R_X86_64_GOTPCREL}
-relocation. See also section~\ref{opt_gotpcrelx}.
-\end{sloppypar}
+instructions, the following \texttt{GOTPCRELX} relocations should be
+generated (see also section~\ref{opt_gotpcrelx}):
+\begin{description}
+\item \texttt{R_X86_64_GOTPCRELX} The instruction starts at 2 bytes
+ before the relocation offset.
+\item \texttt{R_X86_64_REX_GOTPCRELX} The instruction starts at 3 bytes
+ before the relocation offset with the \code{REX} prefix.
+\item \texttt{R_X86_64_CODE_4_GOTPCRELX} The instruction starts at 4
+ bytes before the relocation offset.
+\item \texttt{R_X86_64_CODE_5_GOTPCRELX} The instruction starts at 5
+ bytes before the relocation offset.
+\item \texttt{R_X86_64_CODE_6_GOTPCRELX} The instruction starts at 6
+ bytes before the relocation offset.
+\end{description}

\begin{sloppypar}
The \texttt{R_X86_64_32} and \texttt{R_X86_64_32S} relocations truncate
@@ -564,7 +576,6 @@ added for documentation purposes. The \texttt{R_X86_64_16}, and
resp. 8-bits.
\end{sloppypar}

-\begin{sloppypar}
The relocations \texttt{R_X86_64_DTPMOD64},
\texttt{R_X86_64_DTPOFF64}, \texttt{R_X86_64_TPOFF64},
\texttt{R_X86_64_TLSGD}, \texttt{R_X86_64_TLSLD},
@@ -574,24 +585,42 @@ of the Thread-Local Storage ABI extensions and are documented in the
document called ``ELF Handling for Thread-Local
Storage''\footnote{This document is currently available via
\raggedright\url{http://www.akkadia.org/drepper/tls.pdf}}\index{Thread-Local
- Storage}. \texttt{R_X86_64_GOTTPOFF} should be generated only if
-the instruction starts at 3 bytes before the relocation offset where
-linker expects a \code{REX} byte. \texttt{R_X86_64_CODE_4_GOTTPOFF}
-should be generated, instead of \texttt{R_X86_64_GOTTPOFF}, if the
-instruction starts at 4 bytes before the relocation offset and linker
-optimization must take the different instruction encoding into account.
+ Storage}. The following \texttt{GOTTPOFF} relocations should be
+generated:
+\begin{description}
+\item \texttt{R_X86_64_GOTTPOFF} The instruction starts at 3 bytes
+ before the relocation offset with the \code{REX} byte.
+\item \texttt{R_X86_64_CODE_4_GOTTPOFF} The instruction starts at 4 bytes
+ before the relocation offset.
+\item \texttt{R_X86_64_CODE_5_GOTTPOFF} The instruction starts at 5 bytes
+ before the relocation offset.
+\item \texttt{R_X86_64_CODE_6_GOTTPOFF} The instruction starts at 6 bytes
+ before
+ the relocation offset.
+\end{description}
+Linker optimization must take the different instruction encoding into
+account.
+
The relocations \texttt{R_X86_64_GOTPC32_TLSDESC},
\texttt{R_X86_64_TLSDESC_CALL} and \texttt{R_X86_64_TLSDESC} are also
used for Thread-Local Storage, but are not documented there as of this
writing. A description can be found in the document ``Thread-Local
Storage Descriptors for IA32 and AMD64/EM64T''\footnote{This document
is currently available via
- \raggedright\url{http://www.fsfla.org/~lxoliva/writeups/TLS/RFC-TLSDESC-x86.txt}}.
-\texttt{R_X86_64_CODE_4_GOTPC32_TLSDESC} should be generated, instead of
-\texttt{R_X86_64_GOTPC32_TLSDESC}, if the instruction starts at 4 bytes
-before the relocation offset and linker optimization must take the
-different instruction encoding into account.
-\end{sloppypar}
+ \raggedright\url{http://www.fsfla.org/~lxoliva/writeups/TLS/RFC-TLSDESC-x86.txt}}. The following \texttt{GOTPC32_TLSDESC} relocations should be
+generated:
+\begin{description}
+\item \texttt{R_X86_64_GOTPC32_TLSDESC} The instruction starts at 3 bytes
+ before the relocation offset.
+\item \texttt{R_X86_64_CODE_4_GOTPC32_TLSDESC} The instruction starts at
+ 4 bytes before the relocation offset.
+\item \texttt{R_X86_64_CODE_5_GOTPC32_TLSDESC} The instruction starts at
+ 5 bytes before the relocation offset.
+\item \texttt{R_X86_64_CODE_6_GOTPC32_TLSDESC} The instruction starts at
+ 6 bytes before the relocation offset.
+\end{description}
+Linker optimization must take the different instruction encoding into
+account.

In order to make this document self-contained, a description of the
TLS relocations follows.
--
2.43.0

Michael Matz

unread,
Feb 6, 2024, 9:45:45 AMFeb 6
to H.J. Lu, x86-6...@googlegroups.com
Hello,

On Tue, 6 Feb 2024, H.J. Lu wrote:

> Add 6 new relocations:
>
> #define R_X86_64_CODE_5_GOTPCRELX 46
> #define R_X86_64_CODE_5_GOTTPOFF 47
> #define R_X86_64_CODE_5_GOTPC32_TLSDESC 48
> #define R_X86_64_CODE_6_GOTPCRELX 49
> #define R_X86_64_CODE_6_GOTTPOFF 50
> #define R_X86_64_CODE_6_GOTPC32_TLSDESC 51
>
> R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF,
> R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX and
> R_X86_64_CODE_6_GOTPC32_TLSDESC are added only for completeness.

Fine with me.


Ciao,
Michael.
Reply all
Reply to author
Forward
0 new messages