annotate llvm/docs/Extensions.rst @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 ===============
anatofuz
parents:
diff changeset
2 LLVM Extensions
anatofuz
parents:
diff changeset
3 ===============
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 .. contents::
anatofuz
parents:
diff changeset
6 :local:
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 .. toctree::
anatofuz
parents:
diff changeset
9 :hidden:
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 Introduction
anatofuz
parents:
diff changeset
12 ============
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 This document describes extensions to tools and formats LLVM seeks compatibility
anatofuz
parents:
diff changeset
15 with.
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 General Assembly Syntax
anatofuz
parents:
diff changeset
18 ===========================
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 C99-style Hexadecimal Floating-point Constants
anatofuz
parents:
diff changeset
21 ----------------------------------------------
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 LLVM's assemblers allow floating-point constants to be written in C99's
anatofuz
parents:
diff changeset
24 hexadecimal format instead of decimal if desired.
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 .. code-block:: gas
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 .section .data
anatofuz
parents:
diff changeset
29 .float 0x1c2.2ap3
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 Machine-specific Assembly Syntax
anatofuz
parents:
diff changeset
32 ================================
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 X86/COFF-Dependent
anatofuz
parents:
diff changeset
35 ------------------
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 Relocations
anatofuz
parents:
diff changeset
38 ^^^^^^^^^^^
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 The following additional relocation types are supported:
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 **@IMGREL** (AT&T syntax only) generates an image-relative relocation that
anatofuz
parents:
diff changeset
43 corresponds to the COFF relocation types ``IMAGE_REL_I386_DIR32NB`` (32-bit) or
anatofuz
parents:
diff changeset
44 ``IMAGE_REL_AMD64_ADDR32NB`` (64-bit).
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 .. code-block:: text
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 .text
anatofuz
parents:
diff changeset
49 fun:
anatofuz
parents:
diff changeset
50 mov foo@IMGREL(%ebx, %ecx, 4), %eax
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 .section .pdata
anatofuz
parents:
diff changeset
53 .long fun@IMGREL
anatofuz
parents:
diff changeset
54 .long (fun@imgrel + 0x3F)
anatofuz
parents:
diff changeset
55 .long $unwind$fun@imgrel
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 **.secrel32** generates a relocation that corresponds to the COFF relocation
anatofuz
parents:
diff changeset
58 types ``IMAGE_REL_I386_SECREL`` (32-bit) or ``IMAGE_REL_AMD64_SECREL`` (64-bit).
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 **.secidx** relocation generates an index of the section that contains
anatofuz
parents:
diff changeset
61 the target. It corresponds to the COFF relocation types
anatofuz
parents:
diff changeset
62 ``IMAGE_REL_I386_SECTION`` (32-bit) or ``IMAGE_REL_AMD64_SECTION`` (64-bit).
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 .. code-block:: none
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 .section .debug$S,"rn"
anatofuz
parents:
diff changeset
67 .long 4
anatofuz
parents:
diff changeset
68 .long 242
anatofuz
parents:
diff changeset
69 .long 40
anatofuz
parents:
diff changeset
70 .secrel32 _function_name + 0
anatofuz
parents:
diff changeset
71 .secidx _function_name
anatofuz
parents:
diff changeset
72 ...
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 ``.linkonce`` Directive
anatofuz
parents:
diff changeset
75 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 Syntax:
anatofuz
parents:
diff changeset
78
anatofuz
parents:
diff changeset
79 ``.linkonce [ comdat type ]``
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 Supported COMDAT types:
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 ``discard``
anatofuz
parents:
diff changeset
84 Discards duplicate sections with the same COMDAT symbol. This is the default
anatofuz
parents:
diff changeset
85 if no type is specified.
anatofuz
parents:
diff changeset
86
anatofuz
parents:
diff changeset
87 ``one_only``
anatofuz
parents:
diff changeset
88 If the symbol is defined multiple times, the linker issues an error.
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 ``same_size``
anatofuz
parents:
diff changeset
91 Duplicates are discarded, but the linker issues an error if any have
anatofuz
parents:
diff changeset
92 different sizes.
anatofuz
parents:
diff changeset
93
anatofuz
parents:
diff changeset
94 ``same_contents``
anatofuz
parents:
diff changeset
95 Duplicates are discarded, but the linker issues an error if any duplicates
anatofuz
parents:
diff changeset
96 do not have exactly the same content.
anatofuz
parents:
diff changeset
97
anatofuz
parents:
diff changeset
98 ``largest``
anatofuz
parents:
diff changeset
99 Links the largest section from among the duplicates.
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 ``newest``
anatofuz
parents:
diff changeset
102 Links the newest section from among the duplicates.
anatofuz
parents:
diff changeset
103
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 .. code-block:: gas
anatofuz
parents:
diff changeset
106
anatofuz
parents:
diff changeset
107 .section .text$foo
anatofuz
parents:
diff changeset
108 .linkonce
anatofuz
parents:
diff changeset
109 ...
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 ``.section`` Directive
anatofuz
parents:
diff changeset
112 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 MC supports passing the information in ``.linkonce`` at the end of
anatofuz
parents:
diff changeset
115 ``.section``. For example, these two codes are equivalent
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 .. code-block:: gas
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 .section secName, "dr", discard, "Symbol1"
anatofuz
parents:
diff changeset
120 .globl Symbol1
anatofuz
parents:
diff changeset
121 Symbol1:
anatofuz
parents:
diff changeset
122 .long 1
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124 .. code-block:: gas
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 .section secName, "dr"
anatofuz
parents:
diff changeset
127 .linkonce discard
anatofuz
parents:
diff changeset
128 .globl Symbol1
anatofuz
parents:
diff changeset
129 Symbol1:
anatofuz
parents:
diff changeset
130 .long 1
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 Note that in the combined form the COMDAT symbol is explicit. This
anatofuz
parents:
diff changeset
133 extension exists to support multiple sections with the same name in
anatofuz
parents:
diff changeset
134 different COMDATs:
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136
anatofuz
parents:
diff changeset
137 .. code-block:: gas
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 .section secName, "dr", discard, "Symbol1"
anatofuz
parents:
diff changeset
140 .globl Symbol1
anatofuz
parents:
diff changeset
141 Symbol1:
anatofuz
parents:
diff changeset
142 .long 1
anatofuz
parents:
diff changeset
143
anatofuz
parents:
diff changeset
144 .section secName, "dr", discard, "Symbol2"
anatofuz
parents:
diff changeset
145 .globl Symbol2
anatofuz
parents:
diff changeset
146 Symbol2:
anatofuz
parents:
diff changeset
147 .long 1
anatofuz
parents:
diff changeset
148
anatofuz
parents:
diff changeset
149 In addition to the types allowed with ``.linkonce``, ``.section`` also accepts
anatofuz
parents:
diff changeset
150 ``associative``. The meaning is that the section is linked if a certain other
anatofuz
parents:
diff changeset
151 COMDAT section is linked. This other section is indicated by the comdat symbol
anatofuz
parents:
diff changeset
152 in this directive. It can be any symbol defined in the associated section, but
anatofuz
parents:
diff changeset
153 is usually the associated section's comdat.
anatofuz
parents:
diff changeset
154
anatofuz
parents:
diff changeset
155 The following restrictions apply to the associated section:
anatofuz
parents:
diff changeset
156
anatofuz
parents:
diff changeset
157 1. It must be a COMDAT section.
anatofuz
parents:
diff changeset
158 2. It cannot be another associative COMDAT section.
anatofuz
parents:
diff changeset
159
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
160 In the following example the symbol ``sym`` is the comdat symbol of ``.foo``
150
anatofuz
parents:
diff changeset
161 and ``.bar`` is associated to ``.foo``.
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163 .. code-block:: gas
anatofuz
parents:
diff changeset
164
anatofuz
parents:
diff changeset
165 .section .foo,"bw",discard, "sym"
anatofuz
parents:
diff changeset
166 .section .bar,"rd",associative, "sym"
anatofuz
parents:
diff changeset
167
anatofuz
parents:
diff changeset
168 MC supports these flags in the COFF ``.section`` directive:
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 - ``b``: BSS section (``IMAGE_SCN_CNT_INITIALIZED_DATA``)
anatofuz
parents:
diff changeset
171 - ``d``: Data section (``IMAGE_SCN_CNT_UNINITIALIZED_DATA``)
anatofuz
parents:
diff changeset
172 - ``n``: Section is not loaded (``IMAGE_SCN_LNK_REMOVE``)
anatofuz
parents:
diff changeset
173 - ``r``: Read-only
anatofuz
parents:
diff changeset
174 - ``s``: Shared section
anatofuz
parents:
diff changeset
175 - ``w``: Writable
anatofuz
parents:
diff changeset
176 - ``x``: Executable section
anatofuz
parents:
diff changeset
177 - ``y``: Not readable
anatofuz
parents:
diff changeset
178 - ``D``: Discardable (``IMAGE_SCN_MEM_DISCARDABLE``)
anatofuz
parents:
diff changeset
179
anatofuz
parents:
diff changeset
180 These flags are all compatible with gas, with the exception of the ``D`` flag,
anatofuz
parents:
diff changeset
181 which gnu as does not support. For gas compatibility, sections with a name
anatofuz
parents:
diff changeset
182 starting with ".debug" are implicitly discardable.
anatofuz
parents:
diff changeset
183
anatofuz
parents:
diff changeset
184
anatofuz
parents:
diff changeset
185 ARM64/COFF-Dependent
anatofuz
parents:
diff changeset
186 --------------------
anatofuz
parents:
diff changeset
187
anatofuz
parents:
diff changeset
188 Relocations
anatofuz
parents:
diff changeset
189 ^^^^^^^^^^^
anatofuz
parents:
diff changeset
190
anatofuz
parents:
diff changeset
191 The following additional symbol variants are supported:
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 **:secrel_lo12:** generates a relocation that corresponds to the COFF relocation
anatofuz
parents:
diff changeset
194 types ``IMAGE_REL_ARM64_SECREL_LOW12A`` or ``IMAGE_REL_ARM64_SECREL_LOW12L``.
anatofuz
parents:
diff changeset
195
anatofuz
parents:
diff changeset
196 **:secrel_hi12:** generates a relocation that corresponds to the COFF relocation
anatofuz
parents:
diff changeset
197 type ``IMAGE_REL_ARM64_SECREL_HIGH12A``.
anatofuz
parents:
diff changeset
198
anatofuz
parents:
diff changeset
199 .. code-block:: gas
anatofuz
parents:
diff changeset
200
anatofuz
parents:
diff changeset
201 add x0, x0, :secrel_hi12:symbol
anatofuz
parents:
diff changeset
202 ldr x0, [x0, :secrel_lo12:symbol]
anatofuz
parents:
diff changeset
203
anatofuz
parents:
diff changeset
204 add x1, x1, :secrel_hi12:symbol
anatofuz
parents:
diff changeset
205 add x1, x1, :secrel_lo12:symbol
anatofuz
parents:
diff changeset
206 ...
anatofuz
parents:
diff changeset
207
anatofuz
parents:
diff changeset
208
anatofuz
parents:
diff changeset
209 ELF-Dependent
anatofuz
parents:
diff changeset
210 -------------
anatofuz
parents:
diff changeset
211
anatofuz
parents:
diff changeset
212 ``.section`` Directive
anatofuz
parents:
diff changeset
213 ^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
214
anatofuz
parents:
diff changeset
215 In order to support creating multiple sections with the same name and comdat,
anatofuz
parents:
diff changeset
216 it is possible to add an unique number at the end of the ``.section`` directive.
anatofuz
parents:
diff changeset
217 For example, the following code creates two sections named ``.text``.
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 .. code-block:: gas
anatofuz
parents:
diff changeset
220
anatofuz
parents:
diff changeset
221 .section .text,"ax",@progbits,unique,1
anatofuz
parents:
diff changeset
222 nop
anatofuz
parents:
diff changeset
223
anatofuz
parents:
diff changeset
224 .section .text,"ax",@progbits,unique,2
anatofuz
parents:
diff changeset
225 nop
anatofuz
parents:
diff changeset
226
anatofuz
parents:
diff changeset
227
anatofuz
parents:
diff changeset
228 The unique number is not present in the resulting object at all. It is just used
anatofuz
parents:
diff changeset
229 in the assembler to differentiate the sections.
anatofuz
parents:
diff changeset
230
anatofuz
parents:
diff changeset
231 The 'o' flag is mapped to SHF_LINK_ORDER. If it is present, a symbol
anatofuz
parents:
diff changeset
232 must be given that identifies the section to be placed is the
anatofuz
parents:
diff changeset
233 .sh_link.
anatofuz
parents:
diff changeset
234
anatofuz
parents:
diff changeset
235 .. code-block:: gas
anatofuz
parents:
diff changeset
236
anatofuz
parents:
diff changeset
237 .section .foo,"a",@progbits
anatofuz
parents:
diff changeset
238 .Ltmp:
anatofuz
parents:
diff changeset
239 .section .bar,"ao",@progbits,.Ltmp
anatofuz
parents:
diff changeset
240
anatofuz
parents:
diff changeset
241 which is equivalent to just
anatofuz
parents:
diff changeset
242
anatofuz
parents:
diff changeset
243 .. code-block:: gas
anatofuz
parents:
diff changeset
244
anatofuz
parents:
diff changeset
245 .section .foo,"a",@progbits
anatofuz
parents:
diff changeset
246 .section .bar,"ao",@progbits,.foo
anatofuz
parents:
diff changeset
247
anatofuz
parents:
diff changeset
248 ``.linker-options`` Section (linker options)
anatofuz
parents:
diff changeset
249 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
250
anatofuz
parents:
diff changeset
251 In order to support passing linker options from the frontend to the linker, a
anatofuz
parents:
diff changeset
252 special section of type ``SHT_LLVM_LINKER_OPTIONS`` (usually named
anatofuz
parents:
diff changeset
253 ``.linker-options`` though the name is not significant as it is identified by
anatofuz
parents:
diff changeset
254 the type). The contents of this section is a simple pair-wise encoding of
anatofuz
parents:
diff changeset
255 directives for consideration by the linker. The strings are encoded as standard
anatofuz
parents:
diff changeset
256 null-terminated UTF-8 strings. They are emitted inline to avoid having the
anatofuz
parents:
diff changeset
257 linker traverse the object file for retrieving the value. The linker is
anatofuz
parents:
diff changeset
258 permitted to not honour the option and instead provide a warning/error to the
anatofuz
parents:
diff changeset
259 user that the requested option was not honoured.
anatofuz
parents:
diff changeset
260
anatofuz
parents:
diff changeset
261 The section has type ``SHT_LLVM_LINKER_OPTIONS`` and has the ``SHF_EXCLUDE``
anatofuz
parents:
diff changeset
262 flag to ensure that the section is treated as opaque by linkers which do not
anatofuz
parents:
diff changeset
263 support the feature and will not be emitted into the final linked binary.
anatofuz
parents:
diff changeset
264
anatofuz
parents:
diff changeset
265 This would be equivalent to the follow raw assembly:
anatofuz
parents:
diff changeset
266
anatofuz
parents:
diff changeset
267 .. code-block:: gas
anatofuz
parents:
diff changeset
268
anatofuz
parents:
diff changeset
269 .section ".linker-options","e",@llvm_linker_options
anatofuz
parents:
diff changeset
270 .asciz "option 1"
anatofuz
parents:
diff changeset
271 .asciz "value 1"
anatofuz
parents:
diff changeset
272 .asciz "option 2"
anatofuz
parents:
diff changeset
273 .asciz "value 2"
anatofuz
parents:
diff changeset
274
anatofuz
parents:
diff changeset
275 The following directives are specified:
anatofuz
parents:
diff changeset
276
anatofuz
parents:
diff changeset
277 - lib
anatofuz
parents:
diff changeset
278
anatofuz
parents:
diff changeset
279 The parameter identifies a library to be linked against. The library will
anatofuz
parents:
diff changeset
280 be looked up in the default and any specified library search paths
anatofuz
parents:
diff changeset
281 (specified to this point).
anatofuz
parents:
diff changeset
282
anatofuz
parents:
diff changeset
283 - libpath
anatofuz
parents:
diff changeset
284
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
285 The parameter identifies an additional library search path to be considered
150
anatofuz
parents:
diff changeset
286 when looking up libraries after the inclusion of this option.
anatofuz
parents:
diff changeset
287
anatofuz
parents:
diff changeset
288 ``SHT_LLVM_DEPENDENT_LIBRARIES`` Section (Dependent Libraries)
anatofuz
parents:
diff changeset
289 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
290
anatofuz
parents:
diff changeset
291 This section contains strings specifying libraries to be added to the link by
anatofuz
parents:
diff changeset
292 the linker.
anatofuz
parents:
diff changeset
293
anatofuz
parents:
diff changeset
294 The section should be consumed by the linker and not written to the output.
anatofuz
parents:
diff changeset
295
anatofuz
parents:
diff changeset
296 The strings are encoded as standard null-terminated UTF-8 strings.
anatofuz
parents:
diff changeset
297
anatofuz
parents:
diff changeset
298 For example:
anatofuz
parents:
diff changeset
299
anatofuz
parents:
diff changeset
300 .. code-block:: gas
anatofuz
parents:
diff changeset
301
anatofuz
parents:
diff changeset
302 .section ".deplibs","MS",@llvm_dependent_libraries,1
anatofuz
parents:
diff changeset
303 .asciz "library specifier 1"
anatofuz
parents:
diff changeset
304 .asciz "library specifier 2"
anatofuz
parents:
diff changeset
305
anatofuz
parents:
diff changeset
306 The interpretation of the library specifiers is defined by the consuming linker.
anatofuz
parents:
diff changeset
307
anatofuz
parents:
diff changeset
308 ``SHT_LLVM_CALL_GRAPH_PROFILE`` Section (Call Graph Profile)
anatofuz
parents:
diff changeset
309 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
310
anatofuz
parents:
diff changeset
311 This section is used to pass a call graph profile to the linker which can be
anatofuz
parents:
diff changeset
312 used to optimize the placement of sections. It contains a sequence of
anatofuz
parents:
diff changeset
313 (from symbol, to symbol, weight) tuples.
anatofuz
parents:
diff changeset
314
anatofuz
parents:
diff changeset
315 It shall have a type of ``SHT_LLVM_CALL_GRAPH_PROFILE`` (0x6fff4c02), shall
anatofuz
parents:
diff changeset
316 have the ``SHF_EXCLUDE`` flag set, the ``sh_link`` member shall hold the section
anatofuz
parents:
diff changeset
317 header index of the associated symbol table, and shall have a ``sh_entsize`` of
anatofuz
parents:
diff changeset
318 16. It should be named ``.llvm.call-graph-profile``.
anatofuz
parents:
diff changeset
319
anatofuz
parents:
diff changeset
320 The contents of the section shall be a sequence of ``Elf_CGProfile`` entries.
anatofuz
parents:
diff changeset
321
anatofuz
parents:
diff changeset
322 .. code-block:: c
anatofuz
parents:
diff changeset
323
anatofuz
parents:
diff changeset
324 typedef struct {
anatofuz
parents:
diff changeset
325 Elf_Word cgp_from;
anatofuz
parents:
diff changeset
326 Elf_Word cgp_to;
anatofuz
parents:
diff changeset
327 Elf_Xword cgp_weight;
anatofuz
parents:
diff changeset
328 } Elf_CGProfile;
anatofuz
parents:
diff changeset
329
anatofuz
parents:
diff changeset
330 cgp_from
anatofuz
parents:
diff changeset
331 The symbol index of the source of the edge.
anatofuz
parents:
diff changeset
332
anatofuz
parents:
diff changeset
333 cgp_to
anatofuz
parents:
diff changeset
334 The symbol index of the destination of the edge.
anatofuz
parents:
diff changeset
335
anatofuz
parents:
diff changeset
336 cgp_weight
anatofuz
parents:
diff changeset
337 The weight of the edge.
anatofuz
parents:
diff changeset
338
anatofuz
parents:
diff changeset
339 This is represented in assembly as:
anatofuz
parents:
diff changeset
340
anatofuz
parents:
diff changeset
341 .. code-block:: gas
anatofuz
parents:
diff changeset
342
anatofuz
parents:
diff changeset
343 .cg_profile from, to, 42
anatofuz
parents:
diff changeset
344
anatofuz
parents:
diff changeset
345 ``.cg_profile`` directives are processed at the end of the file. It is an error
anatofuz
parents:
diff changeset
346 if either ``from`` or ``to`` are undefined temporary symbols. If either symbol
anatofuz
parents:
diff changeset
347 is a temporary symbol, then the section symbol is used instead. If either
anatofuz
parents:
diff changeset
348 symbol is undefined, then that symbol is defined as if ``.weak symbol`` has been
anatofuz
parents:
diff changeset
349 written at the end of the file. This forces the symbol to show up in the symbol
anatofuz
parents:
diff changeset
350 table.
anatofuz
parents:
diff changeset
351
anatofuz
parents:
diff changeset
352 ``SHT_LLVM_ADDRSIG`` Section (address-significance table)
anatofuz
parents:
diff changeset
353 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
354
anatofuz
parents:
diff changeset
355 This section is used to mark symbols as address-significant, i.e. the address
anatofuz
parents:
diff changeset
356 of the symbol is used in a comparison or leaks outside the translation unit. It
anatofuz
parents:
diff changeset
357 has the same meaning as the absence of the LLVM attributes ``unnamed_addr``
anatofuz
parents:
diff changeset
358 and ``local_unnamed_addr``.
anatofuz
parents:
diff changeset
359
anatofuz
parents:
diff changeset
360 Any sections referred to by symbols that are not marked as address-significant
anatofuz
parents:
diff changeset
361 in any object file may be safely merged by a linker without breaking the
anatofuz
parents:
diff changeset
362 address uniqueness guarantee provided by the C and C++ language standards.
anatofuz
parents:
diff changeset
363
anatofuz
parents:
diff changeset
364 The contents of the section are a sequence of ULEB128-encoded integers
anatofuz
parents:
diff changeset
365 referring to the symbol table indexes of the address-significant symbols.
anatofuz
parents:
diff changeset
366
anatofuz
parents:
diff changeset
367 There are two associated assembly directives:
anatofuz
parents:
diff changeset
368
anatofuz
parents:
diff changeset
369 .. code-block:: gas
anatofuz
parents:
diff changeset
370
anatofuz
parents:
diff changeset
371 .addrsig
anatofuz
parents:
diff changeset
372
anatofuz
parents:
diff changeset
373 This instructs the assembler to emit an address-significance table. Without
anatofuz
parents:
diff changeset
374 this directive, all symbols are considered address-significant.
anatofuz
parents:
diff changeset
375
anatofuz
parents:
diff changeset
376 .. code-block:: gas
anatofuz
parents:
diff changeset
377
anatofuz
parents:
diff changeset
378 .addrsig_sym sym
anatofuz
parents:
diff changeset
379
anatofuz
parents:
diff changeset
380 This marks ``sym`` as address-significant.
anatofuz
parents:
diff changeset
381
anatofuz
parents:
diff changeset
382 ``SHT_LLVM_SYMPART`` Section (symbol partition specification)
anatofuz
parents:
diff changeset
383 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
384
anatofuz
parents:
diff changeset
385 This section is used to mark symbols with the `partition`_ that they
anatofuz
parents:
diff changeset
386 belong to. An ``.llvm_sympart`` section consists of a null-terminated string
anatofuz
parents:
diff changeset
387 specifying the name of the partition followed by a relocation referring to
anatofuz
parents:
diff changeset
388 the symbol that belongs to the partition. It may be constructed as follows:
anatofuz
parents:
diff changeset
389
anatofuz
parents:
diff changeset
390 .. code-block:: gas
anatofuz
parents:
diff changeset
391
anatofuz
parents:
diff changeset
392 .section ".llvm_sympart","",@llvm_sympart
anatofuz
parents:
diff changeset
393 .asciz "libpartition.so"
anatofuz
parents:
diff changeset
394 .word symbol_in_partition
anatofuz
parents:
diff changeset
395
anatofuz
parents:
diff changeset
396 .. _partition: https://lld.llvm.org/Partitions.html
anatofuz
parents:
diff changeset
397
anatofuz
parents:
diff changeset
398 CodeView-Dependent
anatofuz
parents:
diff changeset
399 ------------------
anatofuz
parents:
diff changeset
400
anatofuz
parents:
diff changeset
401 ``.cv_file`` Directive
anatofuz
parents:
diff changeset
402 ^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
403 Syntax:
anatofuz
parents:
diff changeset
404 ``.cv_file`` *FileNumber FileName* [ *checksum* ] [ *checksumkind* ]
anatofuz
parents:
diff changeset
405
anatofuz
parents:
diff changeset
406 ``.cv_func_id`` Directive
anatofuz
parents:
diff changeset
407 ^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
408 Introduces a function ID that can be used with ``.cv_loc``.
anatofuz
parents:
diff changeset
409
anatofuz
parents:
diff changeset
410 Syntax:
anatofuz
parents:
diff changeset
411 ``.cv_func_id`` *FunctionId*
anatofuz
parents:
diff changeset
412
anatofuz
parents:
diff changeset
413 ``.cv_inline_site_id`` Directive
anatofuz
parents:
diff changeset
414 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
415 Introduces a function ID that can be used with ``.cv_loc``. Includes
anatofuz
parents:
diff changeset
416 ``inlined at`` source location information for use in the line table of the
anatofuz
parents:
diff changeset
417 caller, whether the caller is a real function or another inlined call site.
anatofuz
parents:
diff changeset
418
anatofuz
parents:
diff changeset
419 Syntax:
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
420 ``.cv_inline_site_id`` *FunctionId* ``within`` *Function* ``inlined_at`` *FileNumber Line* [ *Column* ]
150
anatofuz
parents:
diff changeset
421
anatofuz
parents:
diff changeset
422 ``.cv_loc`` Directive
anatofuz
parents:
diff changeset
423 ^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
424 The first number is a file number, must have been previously assigned with a
anatofuz
parents:
diff changeset
425 ``.file`` directive, the second number is the line number and optionally the
anatofuz
parents:
diff changeset
426 third number is a column position (zero if not specified). The remaining
anatofuz
parents:
diff changeset
427 optional items are ``.loc`` sub-directives.
anatofuz
parents:
diff changeset
428
anatofuz
parents:
diff changeset
429 Syntax:
anatofuz
parents:
diff changeset
430 ``.cv_loc`` *FunctionId FileNumber* [ *Line* ] [ *Column* ] [ *prologue_end* ] [ ``is_stmt`` *value* ]
anatofuz
parents:
diff changeset
431
anatofuz
parents:
diff changeset
432 ``.cv_linetable`` Directive
anatofuz
parents:
diff changeset
433 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
434 Syntax:
anatofuz
parents:
diff changeset
435 ``.cv_linetable`` *FunctionId* ``,`` *FunctionStart* ``,`` *FunctionEnd*
anatofuz
parents:
diff changeset
436
anatofuz
parents:
diff changeset
437 ``.cv_inline_linetable`` Directive
anatofuz
parents:
diff changeset
438 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
439 Syntax:
anatofuz
parents:
diff changeset
440 ``.cv_inline_linetable`` *PrimaryFunctionId* ``,`` *FileNumber Line FunctionStart FunctionEnd*
anatofuz
parents:
diff changeset
441
anatofuz
parents:
diff changeset
442 ``.cv_def_range`` Directive
anatofuz
parents:
diff changeset
443 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
444 The *GapStart* and *GapEnd* options may be repeated as needed.
anatofuz
parents:
diff changeset
445
anatofuz
parents:
diff changeset
446 Syntax:
anatofuz
parents:
diff changeset
447 ``.cv_def_range`` *RangeStart RangeEnd* [ *GapStart GapEnd* ] ``,`` *bytes*
anatofuz
parents:
diff changeset
448
anatofuz
parents:
diff changeset
449 ``.cv_stringtable`` Directive
anatofuz
parents:
diff changeset
450 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
451
anatofuz
parents:
diff changeset
452 ``.cv_filechecksums`` Directive
anatofuz
parents:
diff changeset
453 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
454
anatofuz
parents:
diff changeset
455 ``.cv_filechecksumoffset`` Directive
anatofuz
parents:
diff changeset
456 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
457 Syntax:
anatofuz
parents:
diff changeset
458 ``.cv_filechecksumoffset`` *FileNumber*
anatofuz
parents:
diff changeset
459
anatofuz
parents:
diff changeset
460 ``.cv_fpo_data`` Directive
anatofuz
parents:
diff changeset
461 ^^^^^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
462 Syntax:
anatofuz
parents:
diff changeset
463 ``.cv_fpo_data`` *procsym*
anatofuz
parents:
diff changeset
464
anatofuz
parents:
diff changeset
465 Target Specific Behaviour
anatofuz
parents:
diff changeset
466 =========================
anatofuz
parents:
diff changeset
467
anatofuz
parents:
diff changeset
468 X86
anatofuz
parents:
diff changeset
469 ---
anatofuz
parents:
diff changeset
470
anatofuz
parents:
diff changeset
471 Relocations
anatofuz
parents:
diff changeset
472 ^^^^^^^^^^^
anatofuz
parents:
diff changeset
473
anatofuz
parents:
diff changeset
474 ``@ABS8`` can be applied to symbols which appear as immediate operands to
anatofuz
parents:
diff changeset
475 instructions that have an 8-bit immediate form for that operand. It causes
anatofuz
parents:
diff changeset
476 the assembler to use the 8-bit form and an 8-bit relocation (e.g. ``R_386_8``
anatofuz
parents:
diff changeset
477 or ``R_X86_64_8``) for the symbol.
anatofuz
parents:
diff changeset
478
anatofuz
parents:
diff changeset
479 For example:
anatofuz
parents:
diff changeset
480
anatofuz
parents:
diff changeset
481 .. code-block:: gas
anatofuz
parents:
diff changeset
482
anatofuz
parents:
diff changeset
483 cmpq $foo@ABS8, %rdi
anatofuz
parents:
diff changeset
484
anatofuz
parents:
diff changeset
485 This causes the assembler to select the form of the 64-bit ``cmpq`` instruction
anatofuz
parents:
diff changeset
486 that takes an 8-bit immediate operand that is sign extended to 64 bits, as
anatofuz
parents:
diff changeset
487 opposed to ``cmpq $foo, %rdi`` which takes a 32-bit immediate operand. This
anatofuz
parents:
diff changeset
488 is also not the same as ``cmpb $foo, %dil``, which is an 8-bit comparison.
anatofuz
parents:
diff changeset
489
anatofuz
parents:
diff changeset
490 Windows on ARM
anatofuz
parents:
diff changeset
491 --------------
anatofuz
parents:
diff changeset
492
anatofuz
parents:
diff changeset
493 Stack Probe Emission
anatofuz
parents:
diff changeset
494 ^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
495
anatofuz
parents:
diff changeset
496 The reference implementation (Microsoft Visual Studio 2012) emits stack probes
anatofuz
parents:
diff changeset
497 in the following fashion:
anatofuz
parents:
diff changeset
498
anatofuz
parents:
diff changeset
499 .. code-block:: gas
anatofuz
parents:
diff changeset
500
anatofuz
parents:
diff changeset
501 movw r4, #constant
anatofuz
parents:
diff changeset
502 bl __chkstk
anatofuz
parents:
diff changeset
503 sub.w sp, sp, r4
anatofuz
parents:
diff changeset
504
anatofuz
parents:
diff changeset
505 However, this has the limitation of 32 MiB (±16MiB). In order to accommodate
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
506 larger binaries, LLVM supports the use of ``-mcmodel=large`` to allow a 4GiB
150
anatofuz
parents:
diff changeset
507 range via a slight deviation. It will generate an indirect jump as follows:
anatofuz
parents:
diff changeset
508
anatofuz
parents:
diff changeset
509 .. code-block:: gas
anatofuz
parents:
diff changeset
510
anatofuz
parents:
diff changeset
511 movw r4, #constant
anatofuz
parents:
diff changeset
512 movw r12, :lower16:__chkstk
anatofuz
parents:
diff changeset
513 movt r12, :upper16:__chkstk
anatofuz
parents:
diff changeset
514 blx r12
anatofuz
parents:
diff changeset
515 sub.w sp, sp, r4
anatofuz
parents:
diff changeset
516
anatofuz
parents:
diff changeset
517 Variable Length Arrays
anatofuz
parents:
diff changeset
518 ^^^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
519
anatofuz
parents:
diff changeset
520 The reference implementation (Microsoft Visual Studio 2012) does not permit the
anatofuz
parents:
diff changeset
521 emission of Variable Length Arrays (VLAs).
anatofuz
parents:
diff changeset
522
anatofuz
parents:
diff changeset
523 The Windows ARM Itanium ABI extends the base ABI by adding support for emitting
anatofuz
parents:
diff changeset
524 a dynamic stack allocation. When emitting a variable stack allocation, a call
anatofuz
parents:
diff changeset
525 to ``__chkstk`` is emitted unconditionally to ensure that guard pages are setup
anatofuz
parents:
diff changeset
526 properly. The emission of this stack probe emission is handled similar to the
anatofuz
parents:
diff changeset
527 standard stack probe emission.
anatofuz
parents:
diff changeset
528
anatofuz
parents:
diff changeset
529 The MSVC environment does not emit code for VLAs currently.
anatofuz
parents:
diff changeset
530
anatofuz
parents:
diff changeset
531 Windows on ARM64
anatofuz
parents:
diff changeset
532 ----------------
anatofuz
parents:
diff changeset
533
anatofuz
parents:
diff changeset
534 Stack Probe Emission
anatofuz
parents:
diff changeset
535 ^^^^^^^^^^^^^^^^^^^^
anatofuz
parents:
diff changeset
536
anatofuz
parents:
diff changeset
537 The reference implementation (Microsoft Visual Studio 2017) emits stack probes
anatofuz
parents:
diff changeset
538 in the following fashion:
anatofuz
parents:
diff changeset
539
anatofuz
parents:
diff changeset
540 .. code-block:: gas
anatofuz
parents:
diff changeset
541
anatofuz
parents:
diff changeset
542 mov x15, #constant
anatofuz
parents:
diff changeset
543 bl __chkstk
anatofuz
parents:
diff changeset
544 sub sp, sp, x15, lsl #4
anatofuz
parents:
diff changeset
545
anatofuz
parents:
diff changeset
546 However, this has the limitation of 256 MiB (±128MiB). In order to accommodate
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
547 larger binaries, LLVM supports the use of ``-mcmodel=large`` to allow a 8GiB
150
anatofuz
parents:
diff changeset
548 (±4GiB) range via a slight deviation. It will generate an indirect jump as
anatofuz
parents:
diff changeset
549 follows:
anatofuz
parents:
diff changeset
550
anatofuz
parents:
diff changeset
551 .. code-block:: gas
anatofuz
parents:
diff changeset
552
anatofuz
parents:
diff changeset
553 mov x15, #constant
anatofuz
parents:
diff changeset
554 adrp x16, __chkstk
anatofuz
parents:
diff changeset
555 add x16, x16, :lo12:__chkstk
anatofuz
parents:
diff changeset
556 blr x16
anatofuz
parents:
diff changeset
557 sub sp, sp, x15, lsl #4
anatofuz
parents:
diff changeset
558