Changes for third draft (1.5c) of PC-relative addressing changes.

Signed-off-by: Bill Schmidt <wschmidt@linux.ibm.com>
pull/92/head
Bill Schmidt 6 years ago
parent 3df4806fd8
commit 2fa2511313

@ -57,7 +57,7 @@
<holder>Freescale Semiconductor, Inc</holder>
</copyright>
<!-- TODO: Set the correct document releaseinfo -->
<releaseinfo>Revision 1.5b draft</releaseinfo>
<releaseinfo>Revision 1.5c draft</releaseinfo>
<productname>OpenPOWER</productname>
<pubdate/>

@ -93,6 +93,17 @@

<revhistory>
<!-- TODO: Set the initial version information and clear any old information out -->
<revision>
<date>2018-04-28</date>
<revdescription>
<itemizedlist spacing="compact">
<listitem>
<para>Revision 1.5c: PC-relative addressing third
draft.</para>
</listitem>
</itemizedlist>
</revdescription>
</revision>
<revision>
<date>2018-04-13</date>
<revdescription>

@ -4064,6 +4064,426 @@ xml:id="dbdoclet.50655240_pgfId-1156194">
requirements. Some tools may not work with alternate calling sequences
and conventions.</para>
</note>
<section xml:id="dbdoclet.50655241_FnLinkage" revisionflag="added">
<title>Function Call Linkage Protocols</title>
<para>
The compiler (or assembly programmer) and linker cooperate to make
function calls as efficient as possible. Different protocols are
required depending on whether a call is local, whether the caller
and/or callee use a TOC pointer in r2 for code or data accesses
(see <xref linkend="dbdoclet.50655241_66700" />), and whether the
caller and/or callee guarantee to preserve r2. A local
function call is one where the callee is known and visible within
the unit of code being compiled or assembled. A function that
uses a TOC pointer always has a separate local entry point (see
<xref linkend="dbdoclet.50655240___RefHeading___Toc377640597" />),
and preserves r2 when called via its local entry point. See <xref
linkend="dbdoclet.50655241_95185" /> for information about encoding
this information in the symbol table entries of functions.
</para>
<para>
<xref linkend="dbdoclet.50655241_ExternalProtocols" /> summarizes the
protocol requirements for external function calls, and
<xref linkend="dbdoclet.50655241_LocalProtocols" /> summarizes the
protocol requirements for local function calls. Each entry in these
tables is further described in the referenced section.
<note><para>Note that
this ABI does not define protocols where the caller does not use
a TOC pointer, but does preserve r2. It is most efficient when
such functions are always leaf procedures. It is not forbidden for
such a function to call another function, but in this case it is
up to the caller to save and restore r2 around each call.
</para></note>
</para>
<table frame="all" pgwide="1"
xml:id="dbdoclet.50655241_ExternalProtocols">
<title>Protocols for External Function Calls</title>
<tgroup cols="6">
<colspec colname="c1" colwidth="8*" align="center" />
<colspec colname="c2" colwidth="8*" align="center" />
<colspec colname="c3" colwidth="8*" align="center" />
<colspec colname="c4" colwidth="8*" align="center" />
<colspec colname="c5" colwidth="13*" align="center" />
<colspec colname="c6" colwidth="15*" align="center" />
<thead valign="middle">
<row>
<entry align="center" rowsep="1">
<para>
Caller
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Callee
</para>
</entry>
<entry align="center" rowsep="1">
<para>
PLT stub
</para>
</entry>
<entry align="center" rowsep="1">
<para>
nop needed?
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Relocation
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Section link
</para>
</entry>
</row>
</thead>
<tbody valign="middle">
<row>
<entry>
<para>
Uses TOC
</para>
</entry>
<entry>
<para>
Any
</para>
</entry>
<entry>
<para>
r2 save
</para>
</entry>
<entry>
<para>
Yes
</para>
</entry>
<entry>
<para>
R_PPC64_REL24
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Ext2"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
Does not use TOC, does not preserve r2
</para>
</entry>
<entry>
<para>
Any
</para>
</entry>
<entry>
<para>
No r2 save
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Ext1"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
<table frame="all" pgwide="1"
xml:id="dbdoclet.50655241_LocalProtocols">
<title>Protocols for Local Function Calls</title>
<tgroup cols="6">
<colspec colname="c1" colwidth="8*" align="center" />
<colspec colname="c2" colwidth="8*" align="center" />
<colspec colname="c3" colwidth="8*" align="center" />
<colspec colname="c4" colwidth="8*" align="center" />
<colspec colname="c5" colwidth="13*" align="center" />
<colspec colname="c6" colwidth="15*" align="center" />
<thead valign="middle">
<row>
<entry align="center" rowsep="1">
<para>
Caller
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Callee
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Call method
</para>
</entry>
<entry align="center" rowsep="1">
<para>
nop needed?
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Relocation
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Section link
</para>
</entry>
</row>
</thead>
<tbody valign="middle">
<row>
<entry morerows="2">
<para>
Uses TOC
</para>
</entry>
<entry>
<para>
Uses TOC
</para>
</entry>
<entry>
<para>
Local
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local20"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
Does not use TOC, preserves r2
</para>
</entry>
<entry>
<para>
Local
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local20"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
Does not use TOC, does not preserve r2
</para>
</entry>
<entry>
<para>
r2 save stub
</para>
</entry>
<entry>
<para>
Yes
</para>
</entry>
<entry>
<para>
R_PPC64_REL24
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local21"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry morerows="1">
<para>
Does not use TOC, does not preserve r2
</para>
</entry>
<entry>
<para>
Uses TOC
</para>
</entry>
<entry>
<para>
r12 setup stub
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local12"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
Does not use TOC
</para>
</entry>
<entry>
<para>
Local
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local10"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
<section xml:id="dbdoclet.50655241_Ext2">
<title>External Call, Caller Uses TOC</title>
<para>
When a function that uses a TOC pointer makes any call to an
external function, the compiler generates a nop instruction after the
bl instruction for the call. The linker generates a procedure
linkage table (PLT) stub that saves r2 and replaces the nop
instruction with a restore of r2. (The save of r2 may be omitted
from the PLT stub if the R_PPC64_TOCSAVE relocation is used; see
<xref linkend="dbdoclet.50655241_90220" />.) If the callee requires
a TOC, the PLT stub also includes code to place the callee's global
entry point into r12. See <xref linkend="dbdoclet.50655242_82622"
/> for a full description of PLT stubs.
</para>
</section>
<section xml:id="dbdoclet.50655241_Ext1">
<title>External Call, Caller Does Not Use TOC, Caller Does Not Preserve
r2</title>
<para>
When a function that does not use a TOC pointer and does not preserve
r2 makes any call to an
external function, the compiler does not generate a nop instruction
after the bl instruction for the call. Instead, the compiler
annotates the bl instruction with an R_PPC64_REL24_NOTOC
relocation. The linker generates a PLT stub that does not include
a save of r2. If the callee requires a TOC, the PLT stub also
includes code to place the callee's global entry point into r12.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local20">
<title>Local Call, Caller Uses TOC, Callee Preserves r2</title>
<para>
When a function that uses a TOC pointer makes a local call to a
function that also preserves r2, the compiler generates a direct call
to the function's local entry point, and does not generate a nop
instruction after the call.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local21">
<title>Local Call, Caller Uses TOC, Callee Does Not Preserve r2</title>
<para>
When a function that uses a TOC pointer makes a local call to a
function
that does not preserve r2, the compiler generates a nop instruction
after the call. The linker generates a PLT stub that saves r2, but
does not include code to place the callee's global entry point into
r12, and replaces the nop instruction with a restore of r2. (The
save of r2 may be omitted from the PLT stub if the R_PPC64_TOCSAVE
relocation is used; see <xref linkend="dbdoclet.50655241_90220" />.)
</para>
</section>
<section xml:id="dbdoclet.50655241_Local12">
<title>Local Call, Caller Does Not Preserve r2, Callee Uses TOC</title>
<para>
When a function that does not use a TOC and does not preserve r2
makes a local call to
a function that requires a TOC pointer, the compiler does not
generate a nop instruction after the bl instruction for the call.
The linker generates a PLT stub that does not include a save of r2,
but does include code to place the callee's global entry point into
r12. The compiler annotates the bl instruction with an
R_PPC64_REL24_NOTOC relocation.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local10">
<title>Local Call, Caller Does Not Preserve r2, Callee Does Not Use
TOC</title>
<para>
When a function that does not use a TOC and does not preserve r2
makes a local call to
a function that does not require a TOC pointer, the compiler
generates a direct call to the function's local entry point, and
does not generate a nop instruction after the call. The compiler
annotates the bl instruction with an R_PPC64_REL24_NOTOC relocation.
</para>
</section>
</section>
<section xml:id="dbdoclet.50655240___RefHeading___Toc377640579">
<title>Registers</title>
<para>Programs and compilers may freely use all registers except those
@ -4210,9 +4630,9 @@ xml:id="dbdoclet.50655240_pgfId-1156194">
<entry>
<para>Nonvolatile<footnote>
<para>Register r2 is nonvolatile with respect to calls
between functions in the same compilation unit <phrase
revisionflag="added">when the caller requires a TOC
pointer</phrase>. It is saved and restored by code inserted
between <phrase revisionflag="added">most</phrase> functions
in the same compilation unit. It is saved and restored by
code inserted
by the linker resolving a call to an external function. For
more information, see <xref linkend="dbdoclet.50655240_51083"
/> <phrase revisionflag="added"> and <xref
@ -4220,9 +4640,8 @@ xml:id="dbdoclet.50655240_pgfId-1156194">
</footnote><phrase revisionflag="added"> or
Volatile<footnote>
<para>Register r2 is volatile and available for use in a
function whose symbol table entry contains an st_other
field wherein the three most-significant bits have a value
of 001. See
function that does not use a TOC pointer and that does
not preserve r2. See
<xref linkend="dbdoclet.50655241_FnLinkage" />.</para>
</footnote></phrase></para>
</entry>
@ -4416,8 +4835,9 @@ xml:id="dbdoclet.50655240_pgfId-1156194">
appropriate TOC save and restore code. If the function is called from
the same module as the callee, the callee must <phrase
revisionflag="added">normally</phrase> preserve the value of r2.
<phrase revisionflag="added">However, if the callee's symbol table
entry is flagged to indicate the callee does not preserve r2, the
<phrase revisionflag="added">If the callee function is called from
a function in the same compilation unit as the callee, and the
callee does not preserve r2, the
caller is responsible for saving and restoring the TOC pointer if it
needs it.</phrase> (See <phrase revisionflag="changed"><xref
linkend="dbdoclet.50655241_FnLinkage" />
@ -6380,7 +6800,7 @@ plxv v1, symbol@pcrel</programlisting>
<itemizedlist>
<listitem>
<para revisionflag="added">By using PC-relative GOT-indirect
addressing (for shared data or very large span from code to data):
addressing (for shared data):
</para>
</listitem>
</itemizedlist>
@ -6418,9 +6838,7 @@ lvx v1, 0, r12</programlisting>
<title>Code Models</title>
<para>Compilers may provide different code models depending on the
expected size of the TOC and the size of the entire executable or
shared library. <phrase revisionflag="added">Assuming that the
TOC pointer is used to address data and/or text, the following
considerations apply:</phrase></para>
shared library.</para>
<itemizedlist>
<listitem>
<para>Small code model: The TOC is accessed using 16-bit offsets
@ -6464,25 +6882,11 @@ lvx v1, 0, r12</programlisting>
sections is provided in
<xref linkend="dbdoclet.50655241_66700" />.</para>
<para revisionflag="added">
PC-relative addressing may be used in either the small or the
medium code model, and is identical for both. Accesses to
PC-relative addressing may be used with the medium code model.
Accesses to
module-local code and data objects use PC-relative addressing with
up to 34-bit offsets. Position-independent code uses PC-relative
GOT-indirect addressing to access other objects in the binary.
If PC-relative addressing span is insufficient to reach any data
item, that access must either be made relative to the TOC
pointer, or a PC-relative indexed form instruction must be used
for the access. PC-relative indexed form instructions provide
up to 64 bits of offset from the current instruction address.
[To discuss: I'm deliberately leaving this flexible for now.
Any concerns? It appears we will probably not see a
load-high-immediate-32 sort of instruction in P10, so we won't
be able to define those kinds of relocs yet.]
</para>
<para revisionflag="added">
When linking objects that contain PC-relative relocations, the
linker should attempt to place the .got section near the text
sections.
GOT-indirect addressing to access shared objects.
</para>
</section>
</section>
@ -6513,11 +6917,16 @@ lvx v1, 0, r12</programlisting>
value. Function pointers shared between modules shall always use the
global entry point to specify the address of a function.</para>
<para>When a linker causes control to transfer to a global entry point
<phrase revisionflag="added">of a function that requires a TOC
pointer</phrase>,
<phrase revisionflag="added">of a function that also has a local entry
point</phrase>,
it must insert a glue code sequence that loads r12 with the global
entry-point address. Code at the global entry point can assume that
register r12 points to the GEP.</para>
entry-point address. Code at the global entry point <phrase
revisionflag="added">of a function that also has a local entry
point</phrase> can assume that
register r12 points to the GEP. <phrase revisionflag="added">
However, code at the global entry point of a function that does not
have a separate local entry point cannot make any assumptions about
the values of either r2 or 12.</phrase></para>
<para>Addresses between the global and local entry points must not be
branch targets, either for function entry or referenced by program
logic of the function, because a linker may rewrite the code sequence
@ -7479,10 +7888,6 @@ nop</programlisting>
<xref linkend="dbdoclet.50655242_20388" />.</para>
</listitem>
</orderedlist>
<para revisionflag="added">
For a function call in a function that does not preserve r2, the nop in
<xref linkend="dbdoclet.50655240_85319" /> need not be generated.
</para>
<para>For indirect function calls, the address of the function to be
called is placed in r12 and the CTR register. A bctrl instruction is used
to perform the indirect branch as shown in
@ -7717,8 +8122,9 @@ bctrl</programlisting>
<listitem><para>When the callee is in the same compilation unit and
is guaranteed to preserve r2.</para></listitem>
</itemizedlist>
In both cases, the bl instruction must be marked with an
R_PPC64_REL24_NOTOC relocation.
In the first case, the bl instruction must be marked with an
R_PPC64_REL24_NOTOC relocation. See <xref
linkend="dbdoclet.50655241_90220" />.
</para>
<para>For calls to functions resolved at runtime, the linker must
generate stub code to load the function address from the PLT.</para>
@ -8651,8 +9057,11 @@ addi r3,r1,p ; R3 = new data area following parameter save area.</pro
about how to locate this material, see
<xref linkend="dbdoclet.50655239___RefHeading___Toc377640569" />.</para>
<para revisionflag="added">
[Ignorant question to discuss: Are there any impacts to unwinding from
new r2 preservation rules?]
When unwinding, care must be taken to restore the TOC pointer r2 if and
only if it has been saved. It is recommended that the unwinder reads the
instruction at the return address in the link register and restores r2
if and only if that instruction is an explicit restore of r2, i.e.,
ld r2,24(r1).
</para>

</section>

@ -270,11 +270,6 @@ e_ident[EI_DATA] ELFDATA2LSB For all little-endian implementations.</progra
.plt
.bss1
.bss</programlisting>
<para revisionflag="added">
[To discuss: Alan, is it appropriate to make any adjustments here
in the presence of PC-relative addressing, to get any sections closer
to .text, or are we as ideal as we can get already?]
</para>
<para>The medium code model is expected to provide a sufficiently large TOC
to provide all data addressing needs of a module with a single TOC.</para>
<para>Compilers may generate two-instruction medium code model references
@ -491,427 +486,6 @@ my_func:
optimize the prologue sequence. Nor does the absence of this relocation
forbid the linker from optimizing the prologue sequence.</para>
</section>
<section xml:id="dbdoclet.50655241_FnLinkage" revisionflag="added">
<title>Function Call Linkage Protocols</title>
<para>
The compiler (or assembly programmer) and linker cooperate to make
function calls as efficient as possible. Different protocols are
required depending on whether a call is local (caller and callee in
the same compilation unit), whether the caller requires r2 to be
preserved, and whether the callee promises to preserve r2. The
"st_other bits" in the caller's and callee's symbol table entries,
described in <xref linkend="dbdoclet.50655241_95185" />, are used to
determine information about r2 preservation requirements.
</para>
<para>
A function that does not require a TOC pointer may have its
st_other bits set to 0 or 1, and its local and global entry points
are the same. If its st_other bits are 0, it preserves r2; if
its st_other bits are 1, it does not promise to do so. It is best
that a function with st_other bits set to 0 does not contain any
function calls; see the Note for st_other 0 in
<xref linkend="dbdoclet.50655241_95185" />.
</para>
<para>
<xref linkend="dbdoclet.50655241_ExternalProtocols" /> summarizes the
protocol requirements for external function calls, and
<xref linkend="dbdoclet.50655241_LocalProtocols" /> summarizes the
protocol requirements for local function calls. Each entry in these
tables is further described in the referenced section.
</para>
<table frame="all" pgwide="1"
xml:id="dbdoclet.50655241_ExternalProtocols">
<title>Protocols for External Function Calls</title>
<tgroup cols="6">
<colspec colname="c1" colwidth="8*" align="center" />
<colspec colname="c2" colwidth="8*" align="center" />
<colspec colname="c3" colwidth="8*" align="center" />
<colspec colname="c4" colwidth="8*" align="center" />
<colspec colname="c5" colwidth="13*" align="center" />
<colspec colname="c6" colwidth="15*" align="center" />
<thead valign="middle">
<row>
<entry align="center" nameend="c2" namest="c1" rowsep="1">
<para>
st_other bits
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
PLT stub
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
nop needed?
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
Relocation
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
Section link
</para>
</entry>
</row>
<row>
<entry align="center" rowsep="1">
<para>
Caller
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Callee
</para>
</entry>
</row>
</thead>
<tbody valign="middle">
<row>
<entry>
<para>
1
</para>
</entry>
<entry>
<para>
0&#8211;6
</para>
</entry>
<entry>
<para>
No r2 save
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Ext1"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
2&#8211;6
</para>
</entry>
<entry>
<para>
0&#8211;6
</para>
</entry>
<entry>
<para>
r2 save
</para>
</entry>
<entry>
<para>
Yes
</para>
</entry>
<entry>
<para>
N/A
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Ext2"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
<table frame="all" pgwide="1"
xml:id="dbdoclet.50655241_LocalProtocols">
<title>Protocols for Local Function Calls</title>
<tgroup cols="6">
<colspec colname="c1" colwidth="8*" align="center" />
<colspec colname="c2" colwidth="8*" align="center" />
<colspec colname="c3" colwidth="8*" align="center" />
<colspec colname="c4" colwidth="8*" align="center" />
<colspec colname="c5" colwidth="13*" align="center" />
<colspec colname="c6" colwidth="15*" align="center" />
<thead valign="middle">
<row>
<entry align="center" nameend="c2" namest="c1" rowsep="1">
<para>
st_other bits
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
Call method
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
nop needed?
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
Relocation
</para>
</entry>
<entry align="center" morerows="1" rowsep="1">
<para>
Section link
</para>
</entry>
</row>
<row>
<entry align="center" rowsep="1">
<para>
Caller
</para>
</entry>
<entry align="center" rowsep="1">
<para>
Callee
</para>
</entry>
</row>
</thead>
<tbody valign="middle">
<row>
<entry morerows="1">
<para>
1
</para>
</entry>
<entry>
<para>
0&#8211;1
</para>
</entry>
<entry>
<para>
Local
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local10"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
2&#8211;6
</para>
</entry>
<entry>
<para>
r12 setup stub
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local12"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry morerows="2">
<para>
2&#8211;6
</para>
</entry>
<entry>
<para>
0
</para>
</entry>
<entry>
<para>
Local
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local20"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
1
</para>
</entry>
<entry>
<para>
r2 save stub
</para>
</entry>
<entry>
<para>
Yes
</para>
</entry>
<entry>
<para>
N/A
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local21"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
<row>
<entry>
<para>
2&#8211;6
</para>
</entry>
<entry>
<para>
Local
</para>
</entry>
<entry>
<para>
No
</para>
</entry>
<entry>
<para>
R_PPC64_REL24_NOTOC
</para>
</entry>
<entry>
<para>
<xref linkend="dbdoclet.50655241_Local20"
xrefstyle="select: nopage" />
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
<section xml:id="dbdoclet.50655241_Ext2">
<title>External Call, Preserving Caller</title>
<para>
When a function that preserves r2 makes any call to an external
function, the compiler generates a nop instruction after the bl
instruction for the call. The linker generates a procedure linkage
table (PLT) stub that saves r2, and replaces the nop instruction with
a restore of r2. If the callee requires a TOC, the PLT stub also
includes code to place the callee's global entry point into r12.
See <xref linkend="dbdoclet.50655242_82622" /> for a full
description of PLT stubs.
</para>
</section>
<section xml:id="dbdoclet.50655241_Ext1">
<title>External Call, Nonpreserving Caller</title>
<para>
When a function that does not preserve r2 makes any call to an
external function, the compiler does not generate a nop instruction
after the bl instruction for the call. Instead, the compiler
annotates the bl instruction with an R_PPC64_REL24_NOTOC
relocation. The linker generates a PLT stub that does not include
a save of r2. If the callee requires a TOC, the PLT stub also
includes code to place the callee's global entry point into r12.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local10">
<title>Local Call, Nonpreserving Caller, Callee Needs No TOC</title>
<para>
When a function that does not preserve r2 makes a local call to
a function that does not require a TOC pointer, the compiler
generates a direct call to the function's local entry point, and
does not generate a nop instruction after the call. The compiler
annotates the bl instruction with an R_PPC64_REL24_NOTOC relocation.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local12">
<title>Local Call, Nonpreserving Caller, Callee Requires TOC</title>
<para>
When a function that does not preserve r2 makes a local call to
a function that requires a TOC pointer, the compiler does not
generate a nop instruction after the bl instruction for the call.
The linker generates a PLT stub that does not include a save of r2,
but does include code to place the callee's global entry point into
r12.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local20">
<title>Local Call, Preserving Caller, Preserving Callee</title>
<para>
When a function that preserves r2 makes a local call to a function
that also preserves r2, the compiler generates a direct call to the
function's local entry point, and does not generate a nop
instruction after the call. The compiler annotates the bl
instruction with an R_PPC64_REL24_NOTOC relocation.
</para>
</section>
<section xml:id="dbdoclet.50655241_Local21">
<title>Local Call, Preserving Caller, Nonpreserving Callee</title>
<para>
When a function that preserves r2 makes a local call to a function
that does not preserve r2, the compiler generates a nop instruction
after the call. The linker generates a PLT stub that saves r2, but
does not include code to place the callee's global entry point into
r12, and replaces the nop instruction with a restore of r2.
</para>
</section>
</section>
<section xml:id="dbdoclet.50655241_81959">
<title>Use of the Small Data Area</title>
<para>For a data item in the .sdata or .sbss sections, a compiler may
@ -5374,7 +4948,8 @@ my_func:
specifies a symbol to be resolved. <phrase revisionflag="added">If the
symbol resolves to a function that requires a TOC pointer (as
determined by st_other bits) then a link editor must arrange for the
call to be via the entry point of the called function. Any</phrase>
call to be via the global entry point of the called function.
Any</phrase>
<phrase revisionflag="deleted">However, if the symbol is resolved by
inserting a call to a PLT stub code, the PLT</phrase> stub code must
not rely on <phrase revisionflag="deleted">the presence of</phrase>
@ -5388,10 +4963,12 @@ my_func:
use.</para>
<para revisionflag="added">R_PPC64_PCREL_OPT</para>
<para revisionflag="added">
This relocation type requests that the annotated load or store
This relocation type requests that the annotated
instruction and its immediately following instruction be optimized by
the linker when the referenced symbol can be statically resolved.
See <xref linkend="dbdoclet.50655241_OptPCRel" /> for details.
the linker when the referenced symbol can be statically resolved,
or when a more efficient PC-relative sequence can be chosen.
See <xref linkend="dbdoclet.50655241_OptPCRel" /> and
<xref linkend="dbdoclet.50655241_OptMask" /> for details.
</para>
</section>
<section>
@ -5455,16 +5032,15 @@ addi 2,2,.TOC.-func@l</programlisting>
requirements as indicated in this section.</para>
<section xml:id="dbdoclet.50655241_69294">
<title>Function Call</title>
<para><phrase revisionflag="added">When present,</phrase>
<para><phrase revisionflag="added">Unless the bl instruction is
annotated with an R_PPC64_REL24_NOTOC relocation,</phrase>
<phrase revisionflag="changed">the</phrase>
static linker must modify a nop instruction after a bl function
call to restore the TOC pointer in r2 from 24(r1) when an external symbol
that may use the TOC may be called, as in
<xref linkend="dbdoclet.50655240_88555" />.
<phrase revisionflag="changed">A function</phrase> must contain a
nop slot after a bl instruction to an external symbol
<phrase revisionflag="added">unless the bl instruction is annotated with
an R_PPC64_REL24_NOTOC relocation</phrase>.</para>
<phrase revisionflag="deleted">A function must contain a
nop slot after a bl instruction to an external symbol.</phrase></para>
</section>
<section>
<title>Reference Optimization</title>
@ -5559,11 +5135,34 @@ nop</programlisting>
in the sequence. The compiler or programmer must further ensure that
the two instructions are not separated by intervening instructions.
</para>
</section>
<section xml:id="dbdoclet.50655241_OptMask" revisionflag="added">
<title>Optimization of Masked Load/Store Sequences</title>
<para>
PC-relative forms of the pmlxv and pmstxv instructions have a
28-bit offset, which is too small to guarantee that the offset
will not overflow when relocated within a medium code model
binary. Compilers should not directly generate PC-relative forms
of these instructions, but may instead generate a short sequence
that can be optimized by a linker. For example:
</para>
<programlisting>paddi r12,symbol@pcrel
pmlxvx v1,r10,r12,VRM,MC,P,0</programlisting>
<para>The previous sequence may be replaced by:</para>
<programlisting>dnop
pmlxv v1,symbol@pcrel(r10),VRM,MC,P,1</programlisting>
<para>
when the linker determines that the offset from the current
instruction address to symbol's address will fit in 28 bits.
</para>
<para>
[To discuss: A possible alternative, due to Alan, is to allow the
code to separate but emit "pld".."lvx;nop" and optimize to
"dnop".."plxv". In this case the PCREL_OPT should be placed on
both groups of insns. Should we pursue?]
Again, this optimization is not universally safe, since it changes
the value of r12 following the data reference. The compiler or
programmer must ensure that the value of r12 is not subsequently
used, and communicate a request for this optimization by placing
an R_PPC64_PCREL_OPT relocation on the first instruction in the
sequence. The compiler or programmer must further ensure that the
two instructions are not separated by intervening instructions.
</para>
</section>
</section>

Loading…
Cancel
Save