]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gccint/target-macros/position-independent-code.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / target-macros / position-independent-code.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: position independent code, PIC
7
8 .. _pic:
9
10 Position Independent Code
11 *************************
12
13 This section describes macros that help implement generation of position
14 independent code. Simply defining these macros is not enough to
15 generate valid PIC; you must also add support to the hook
16 ``TARGET_LEGITIMATE_ADDRESS_P`` and to the macro
17 ``PRINT_OPERAND_ADDRESS``, as well as ``LEGITIMIZE_ADDRESS``. You
18 must modify the definition of :samp:`movsi` to do something appropriate
19 when the source operand contains a symbolic address. You may also
20 need to alter the handling of switch statements so that they use
21 relative addresses.
22
23 .. i rearranged the order of the macros above to try to force one of
24
25 .. them to the next line, to eliminate an overfull hbox. -mew 10feb93
26
27 .. c:macro:: PIC_OFFSET_TABLE_REGNUM
28
29 The register number of the register used to address a table of static
30 data addresses in memory. In some cases this register is defined by a
31 processor's 'application binary interface' (ABI). When this macro
32 is defined, RTL is generated for this register once, as with the stack
33 pointer and frame pointer registers. If this macro is not defined, it
34 is up to the machine-dependent files to allocate such a register (if
35 necessary). Note that this register must be fixed when in use (e.g.
36 when ``flag_pic`` is true).
37
38 .. c:macro:: PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
39
40 A C expression that is nonzero if the register defined by
41 ``PIC_OFFSET_TABLE_REGNUM`` is clobbered by calls. If not defined,
42 the default is zero. Do not define
43 this macro if ``PIC_OFFSET_TABLE_REGNUM`` is not defined.
44
45 .. c:macro:: LEGITIMATE_PIC_OPERAND_P (x)
46
47 A C expression that is nonzero if :samp:`{x}` is a legitimate immediate
48 operand on the target machine when generating position independent code.
49 You can assume that :samp:`{x}` satisfies ``CONSTANT_P``, so you need not
50 check this. You can also assume :samp:`{flag_pic}` is true, so you need not
51 check it either. You need not define this macro if all constants
52 (including ``SYMBOL_REF``) can be immediate operands when generating
53 position independent code.