2013-04-11 07:28:17 +08:00
|
|
|
===============
|
|
|
|
LLVM Extensions
|
|
|
|
===============
|
|
|
|
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:hidden:
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
|
|
|
|
This document describes extensions to tools and formats LLVM seeks compatibility
|
|
|
|
with.
|
|
|
|
|
2013-08-14 23:27:20 +08:00
|
|
|
General Assembly Syntax
|
|
|
|
===========================
|
|
|
|
|
|
|
|
C99-style Hexadecimal Floating-point Constants
|
|
|
|
----------------------------------------------
|
|
|
|
|
|
|
|
LLVM's assemblers allow floating-point constants to be written in C99's
|
|
|
|
hexadecimal format instead of decimal if desired.
|
|
|
|
|
|
|
|
.. code-block:: gas
|
2013-08-15 00:18:47 +08:00
|
|
|
|
2013-08-14 23:27:20 +08:00
|
|
|
.section .data
|
|
|
|
.float 0x1c2.2ap3
|
|
|
|
|
2013-04-11 07:28:17 +08:00
|
|
|
Machine-specific Assembly Syntax
|
|
|
|
================================
|
|
|
|
|
|
|
|
X86/COFF-Dependent
|
|
|
|
------------------
|
|
|
|
|
2013-07-06 20:13:10 +08:00
|
|
|
Relocations
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
2013-12-21 02:15:00 +08:00
|
|
|
The following additional relocation types are supported:
|
2013-04-11 07:28:17 +08:00
|
|
|
|
|
|
|
**@IMGREL** (AT&T syntax only) generates an image-relative relocation that
|
|
|
|
corresponds to the COFF relocation types ``IMAGE_REL_I386_DIR32NB`` (32-bit) or
|
|
|
|
``IMAGE_REL_AMD64_ADDR32NB`` (64-bit).
|
|
|
|
|
[docs] Fixing Sphinx warnings to unclog the buildbot
Lots of blocks had "llvm" or "nasm" syntax types but either weren't following
the syntax, or the syntax has changed (and sphinx hasn't keep up) or the type
doesn't even exist (nasm?).
Other documents had :options: what were invalid. I only removed those that had
warnings, and left the ones that didn't, in order to follow the principle of
least surprise.
This is like this for ages, but the buildbot is now failing on errors. It may
take a while to upgrade the buildbot's sphinx, if that's even possible, but
that shouldn't stop us from getting docs updates (which seem down for quite
a while).
Also, we're not losing any syntax highlight, since when it doesn't parse, it
doesn't colour. Ie. those blocks are not being highlighted anyway.
I'm trying to get all docs in one go, so that it's easy to revert later if we
do fix, or at least easy to know what's to fix.
llvm-svn: 276109
2016-07-20 20:16:38 +08:00
|
|
|
.. code-block:: text
|
2013-04-11 07:28:17 +08:00
|
|
|
|
|
|
|
.text
|
|
|
|
fun:
|
|
|
|
mov foo@IMGREL(%ebx, %ecx, 4), %eax
|
|
|
|
|
|
|
|
.section .pdata
|
|
|
|
.long fun@IMGREL
|
|
|
|
.long (fun@imgrel + 0x3F)
|
|
|
|
.long $unwind$fun@imgrel
|
2013-07-06 20:13:10 +08:00
|
|
|
|
2013-12-21 02:15:00 +08:00
|
|
|
**.secrel32** generates a relocation that corresponds to the COFF relocation
|
|
|
|
types ``IMAGE_REL_I386_SECREL`` (32-bit) or ``IMAGE_REL_AMD64_SECREL`` (64-bit).
|
|
|
|
|
|
|
|
**.secidx** relocation generates an index of the section that contains
|
|
|
|
the target. It corresponds to the COFF relocation types
|
|
|
|
``IMAGE_REL_I386_SECTION`` (32-bit) or ``IMAGE_REL_AMD64_SECTION`` (64-bit).
|
|
|
|
|
2017-01-18 05:48:31 +08:00
|
|
|
.. code-block:: none
|
2013-12-21 02:15:00 +08:00
|
|
|
|
|
|
|
.section .debug$S,"rn"
|
|
|
|
.long 4
|
|
|
|
.long 242
|
|
|
|
.long 40
|
2017-01-02 11:00:19 +08:00
|
|
|
.secrel32 _function_name + 0
|
2013-12-21 02:15:00 +08:00
|
|
|
.secidx _function_name
|
|
|
|
...
|
2013-07-06 20:13:10 +08:00
|
|
|
|
|
|
|
``.linkonce`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
|
2014-06-07 03:26:12 +08:00
|
|
|
``.linkonce [ comdat type ]``
|
2013-07-06 20:13:10 +08:00
|
|
|
|
|
|
|
Supported COMDAT types:
|
|
|
|
|
|
|
|
``discard``
|
|
|
|
Discards duplicate sections with the same COMDAT symbol. This is the default
|
|
|
|
if no type is specified.
|
|
|
|
|
|
|
|
``one_only``
|
|
|
|
If the symbol is defined multiple times, the linker issues an error.
|
|
|
|
|
|
|
|
``same_size``
|
|
|
|
Duplicates are discarded, but the linker issues an error if any have
|
|
|
|
different sizes.
|
|
|
|
|
|
|
|
``same_contents``
|
|
|
|
Duplicates are discarded, but the linker issues an error if any duplicates
|
|
|
|
do not have exactly the same content.
|
|
|
|
|
|
|
|
``largest``
|
|
|
|
Links the largest section from among the duplicates.
|
|
|
|
|
|
|
|
``newest``
|
|
|
|
Links the newest section from among the duplicates.
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section .text$foo
|
|
|
|
.linkonce
|
|
|
|
...
|
|
|
|
|
2013-11-20 03:52:52 +08:00
|
|
|
``.section`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
MC supports passing the information in ``.linkonce`` at the end of
|
|
|
|
``.section``. For example, these two codes are equivalent
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section secName, "dr", discard, "Symbol1"
|
|
|
|
.globl Symbol1
|
|
|
|
Symbol1:
|
|
|
|
.long 1
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section secName, "dr"
|
|
|
|
.linkonce discard
|
|
|
|
.globl Symbol1
|
|
|
|
Symbol1:
|
|
|
|
.long 1
|
|
|
|
|
2013-12-20 18:32:12 +08:00
|
|
|
Note that in the combined form the COMDAT symbol is explicit. This
|
2014-02-15 14:02:36 +08:00
|
|
|
extension exists to support multiple sections with the same name in
|
|
|
|
different COMDATs:
|
2013-11-20 03:52:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section secName, "dr", discard, "Symbol1"
|
|
|
|
.globl Symbol1
|
|
|
|
Symbol1:
|
|
|
|
.long 1
|
|
|
|
|
|
|
|
.section secName, "dr", discard, "Symbol2"
|
|
|
|
.globl Symbol2
|
|
|
|
Symbol2:
|
|
|
|
.long 1
|
2014-04-30 15:05:07 +08:00
|
|
|
|
2014-06-07 03:26:12 +08:00
|
|
|
In addition to the types allowed with ``.linkonce``, ``.section`` also accepts
|
|
|
|
``associative``. The meaning is that the section is linked if a certain other
|
|
|
|
COMDAT section is linked. This other section is indicated by the comdat symbol
|
|
|
|
in this directive. It can be any symbol defined in the associated section, but
|
|
|
|
is usually the associated section's comdat.
|
|
|
|
|
|
|
|
The following restrictions apply to the associated section:
|
|
|
|
|
|
|
|
1. It must be a COMDAT section.
|
|
|
|
2. It cannot be another associative COMDAT section.
|
|
|
|
|
|
|
|
In the following example the symobl ``sym`` is the comdat symbol of ``.foo``
|
|
|
|
and ``.bar`` is associated to ``.foo``.
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section .foo,"bw",discard, "sym"
|
|
|
|
.section .bar,"rd",associative, "sym"
|
|
|
|
|
2016-09-15 23:11:49 +08:00
|
|
|
MC supports these flags in the COFF ``.section`` directive:
|
|
|
|
|
|
|
|
- ``b``: BSS section (``IMAGE_SCN_CNT_INITIALIZED_DATA``)
|
|
|
|
- ``d``: Data section (``IMAGE_SCN_CNT_UNINITIALIZED_DATA``)
|
|
|
|
- ``n``: Section is not loaded (``IMAGE_SCN_LNK_REMOVE``)
|
|
|
|
- ``r``: Read-only
|
|
|
|
- ``s``: Shared section
|
|
|
|
- ``w``: Writable
|
|
|
|
- ``x``: Executable section
|
|
|
|
- ``y``: Not readable
|
|
|
|
- ``D``: Discardable (``IMAGE_SCN_MEM_DISCARDABLE``)
|
|
|
|
|
|
|
|
These flags are all compatible with gas, with the exception of the ``D`` flag,
|
|
|
|
which gnu as does not support. For gas compatibility, sections with a name
|
|
|
|
starting with ".debug" are implicitly discardable.
|
|
|
|
|
2015-04-05 02:02:01 +08:00
|
|
|
|
2018-03-02 04:42:28 +08:00
|
|
|
ARM64/COFF-Dependent
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
Relocations
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
|
|
|
The following additional symbol variants are supported:
|
|
|
|
|
|
|
|
**:secrel_lo12:** generates a relocation that corresponds to the COFF relocation
|
|
|
|
types ``IMAGE_REL_ARM64_SECREL_LOW12A`` or ``IMAGE_REL_ARM64_SECREL_LOW12L``.
|
|
|
|
|
|
|
|
**:secrel_hi12:** generates a relocation that corresponds to the COFF relocation
|
|
|
|
type ``IMAGE_REL_ARM64_SECREL_HIGH12A``.
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
add x0, x0, :secrel_hi12:symbol
|
|
|
|
ldr x0, [x0, :secrel_lo12:symbol]
|
|
|
|
|
|
|
|
add x1, x1, :secrel_hi12:symbol
|
|
|
|
add x1, x1, :secrel_lo12:symbol
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2015-04-05 02:02:01 +08:00
|
|
|
ELF-Dependent
|
|
|
|
-------------
|
|
|
|
|
|
|
|
``.section`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
In order to support creating multiple sections with the same name and comdat,
|
|
|
|
it is possible to add an unique number at the end of the ``.seciton`` directive.
|
|
|
|
For example, the following code creates two sections named ``.text``.
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
2015-04-07 00:34:41 +08:00
|
|
|
.section .text,"ax",@progbits,unique,1
|
2015-04-05 02:02:01 +08:00
|
|
|
nop
|
|
|
|
|
2015-04-07 00:34:41 +08:00
|
|
|
.section .text,"ax",@progbits,unique,2
|
2015-04-05 02:02:01 +08:00
|
|
|
nop
|
|
|
|
|
|
|
|
|
|
|
|
The unique number is not present in the resulting object at all. It is just used
|
|
|
|
in the assembler to differentiate the sections.
|
|
|
|
|
2017-04-05 06:35:08 +08:00
|
|
|
The 'o' flag is mapped to SHF_LINK_ORDER. If it is present, a symbol
|
2017-02-09 22:59:20 +08:00
|
|
|
must be given that identifies the section to be placed is the
|
|
|
|
.sh_link.
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section .foo,"a",@progbits
|
|
|
|
.Ltmp:
|
2017-04-05 06:35:08 +08:00
|
|
|
.section .bar,"ao",@progbits,.Ltmp
|
2017-02-09 22:59:20 +08:00
|
|
|
|
|
|
|
which is equivalent to just
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section .foo,"a",@progbits
|
2017-04-05 06:35:08 +08:00
|
|
|
.section .bar,"ao",@progbits,.foo
|
2017-02-09 22:59:20 +08:00
|
|
|
|
2018-01-31 00:29:29 +08:00
|
|
|
``.linker-options`` Section (linker options)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
In order to support passing linker options from the frontend to the linker, a
|
|
|
|
special section of type ``SHT_LLVM_LINKER_OPTIONS`` (usually named
|
|
|
|
``.linker-options`` though the name is not significant as it is identified by
|
|
|
|
the type). The contents of this section is a simple pair-wise encoding of
|
2018-01-31 08:16:23 +08:00
|
|
|
directives for consideration by the linker. The strings are encoded as standard
|
2018-01-31 00:29:29 +08:00
|
|
|
null-terminated UTF-8 strings. They are emitted inline to avoid having the
|
2018-01-31 08:16:23 +08:00
|
|
|
linker traverse the object file for retrieving the value. The linker is
|
2018-01-31 00:29:29 +08:00
|
|
|
permitted to not honour the option and instead provide a warning/error to the
|
|
|
|
user that the requested option was not honoured.
|
|
|
|
|
2018-01-31 08:16:23 +08:00
|
|
|
The section has type ``SHT_LLVM_LINKER_OPTIONS`` and has the ``SHF_EXCLUDE``
|
2018-01-31 00:29:29 +08:00
|
|
|
flag to ensure that the section is treated as opaque by linkers which do not
|
|
|
|
support the feature and will not be emitted into the final linked binary.
|
|
|
|
|
|
|
|
This would be equivalent to the follow raw assembly:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section ".linker-options","e",@llvm_linker_options
|
|
|
|
.asciz "option 1"
|
|
|
|
.asciz "value 1"
|
|
|
|
.asciz "option 2"
|
|
|
|
.asciz "value 2"
|
|
|
|
|
2018-01-31 08:16:23 +08:00
|
|
|
The following directives are specified:
|
|
|
|
|
2018-01-31 00:29:29 +08:00
|
|
|
- lib
|
|
|
|
|
|
|
|
The parameter identifies a library to be linked against. The library will
|
|
|
|
be looked up in the default and any specified library search paths
|
|
|
|
(specified to this point).
|
|
|
|
|
2018-01-31 07:49:27 +08:00
|
|
|
- libpath
|
2018-01-31 00:29:29 +08:00
|
|
|
|
|
|
|
The paramter identifies an additional library search path to be considered
|
|
|
|
when looking up libraries after the inclusion of this option.
|
2017-02-09 22:59:20 +08:00
|
|
|
|
[ELF] Implement Dependent Libraries Feature
This patch implements a limited form of autolinking primarily designed to allow
either the --dependent-library compiler option, or "comment lib" pragmas (
https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in
C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically
add the specified library to the link when processing the input file generated
by the compiler.
Currently this extension is unique to LLVM and LLD. However, care has been taken
to design this feature so that it could be supported by other ELF linkers.
The design goals were to provide:
- A simple linking model for developers to reason about.
- The ability to to override autolinking from the linker command line.
- Source code compatibility, where possible, with "comment lib" pragmas in other
environments (MSVC in particular).
Dependent library support is implemented differently for ELF platforms than on
the other platforms. Primarily this difference is that on ELF we pass the
dependent library specifiers directly to the linker without manipulating them.
This is in contrast to other platforms where they are mapped to a specific
linker option by the compiler. This difference is a result of the greater
variety of ELF linkers and the fact that ELF linkers tend to handle libraries in
a more complicated fashion than on other platforms. This forces us to defer
handling the specifiers to the linker.
In order to achieve a level of source code compatibility with other platforms
we have restricted this feature to work with libraries that meet the following
"reasonable" requirements:
1. There are no competing defined symbols in a given set of libraries, or
if they exist, the program owner doesn't care which is linked to their
program.
2. There may be circular dependencies between libraries.
The binary representation is a mergeable string section (SHF_MERGE,
SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES
(0x6fff4c04). The compiler forms this section by concatenating the arguments of
the "comment lib" pragmas and --dependent-library options in the order they are
encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs
sections with the normal mergeable string section rules. As an example, #pragma
comment(lib, "foo") would result in:
.section ".deplibs","MS",@llvm_dependent_libraries,1
.asciz "foo"
For LTO, equivalent information to the contents of a the .deplibs section can be
retrieved by the LLD for bitcode input files.
LLD processes the dependent library specifiers in the following way:
1. Dependent libraries which are found from the specifiers in .deplibs sections
of relocatable object files are added when the linker decides to include that
file (which could itself be in a library) in the link. Dependent libraries
behave as if they were appended to the command line after all other options. As
a consequence the set of dependent libraries are searched last to resolve
symbols.
2. It is an error if a file cannot be found for a given specifier.
3. Any command line options in effect at the end of the command line parsing apply
to the dependent libraries, e.g. --whole-archive.
4. The linker tries to add a library or relocatable object file from each of the
strings in a .deplibs section by; first, handling the string as if it was
specified on the command line; second, by looking for the string in each of the
library search paths in turn; third, by looking for a lib<string>.a or
lib<string>.so (depending on the current mode of the linker) in each of the
library search paths.
5. A new command line option --no-dependent-libraries tells LLD to ignore the
dependent libraries.
Rationale for the above points:
1. Adding the dependent libraries last makes the process simple to understand
from a developers perspective. All linkers are able to implement this scheme.
2. Error-ing for libraries that are not found seems like better behavior than
failing the link during symbol resolution.
3. It seems useful for the user to be able to apply command line options which
will affect all of the dependent libraries. There is a potential problem of
surprise for developers, who might not realize that these options would apply
to these "invisible" input files; however, despite the potential for surprise,
this is easy for developers to reason about and gives developers the control
that they may require.
4. This algorithm takes into account all of the different ways that ELF linkers
find input files. The different search methods are tried by the linker in most
obvious to least obvious order.
5. I considered adding finer grained control over which dependent libraries were
ignored (e.g. MSVC has /nodefaultlib:<library>); however, I concluded that this
is not necessary: if finer control is required developers can fall back to using
the command line directly.
RFC thread: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131004.html.
Differential Revision: https://reviews.llvm.org/D60274
llvm-svn: 360984
2019-05-17 11:44:15 +08:00
|
|
|
``SHT_LLVM_DEPENDENT_LIBRARIES`` Section (Dependent Libraries)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This section contains strings specifying libraries to be added to the link by
|
|
|
|
the linker.
|
|
|
|
|
|
|
|
The section should be consumed by the linker and not written to the output.
|
|
|
|
|
|
|
|
The strings are encoded as standard null-terminated UTF-8 strings.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section ".deplibs","MS",@llvm_dependent_libraries,1
|
|
|
|
.asciz "library specifier 1"
|
|
|
|
.asciz "library specifier 2"
|
|
|
|
|
|
|
|
The interpretation of the library specifiers is defined by the consuming linker.
|
|
|
|
|
[MC] Add assembler support for .cg_profile.
Object FIle Representation
At codegen time this is emitted into the ELF file a pair of symbol indices and a weight. In assembly it looks like:
.cg_profile a, b, 32
.cg_profile freq, a, 11
.cg_profile freq, b, 20
When writing an ELF file these are put into a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight).
Differential Revision: https://reviews.llvm.org/D44965
llvm-svn: 333823
2018-06-03 00:33:01 +08:00
|
|
|
``SHT_LLVM_CALL_GRAPH_PROFILE`` Section (Call Graph Profile)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This section is used to pass a call graph profile to the linker which can be
|
|
|
|
used to optimize the placement of sections. It contains a sequence of
|
|
|
|
(from symbol, to symbol, weight) tuples.
|
|
|
|
|
|
|
|
It shall have a type of ``SHT_LLVM_CALL_GRAPH_PROFILE`` (0x6fff4c02), shall
|
|
|
|
have the ``SHF_EXCLUDE`` flag set, the ``sh_link`` member shall hold the section
|
|
|
|
header index of the associated symbol table, and shall have a ``sh_entsize`` of
|
|
|
|
16. It should be named ``.llvm.call-graph-profile``.
|
|
|
|
|
|
|
|
The contents of the section shall be a sequence of ``Elf_CGProfile`` entries.
|
|
|
|
|
|
|
|
.. code-block:: c
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf_Word cgp_from;
|
|
|
|
Elf_Word cgp_to;
|
|
|
|
Elf_Xword cgp_weight;
|
|
|
|
} Elf_CGProfile;
|
|
|
|
|
|
|
|
cgp_from
|
|
|
|
The symbol index of the source of the edge.
|
|
|
|
|
|
|
|
cgp_to
|
|
|
|
The symbol index of the destination of the edge.
|
|
|
|
|
|
|
|
cgp_weight
|
|
|
|
The weight of the edge.
|
|
|
|
|
|
|
|
This is represented in assembly as:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.cg_profile from, to, 42
|
|
|
|
|
|
|
|
``.cg_profile`` directives are processed at the end of the file. It is an error
|
|
|
|
if either ``from`` or ``to`` are undefined temporary symbols. If either symbol
|
|
|
|
is a temporary symbol, then the section symbol is used instead. If either
|
|
|
|
symbol is undefined, then that symbol is defined as if ``.weak symbol`` has been
|
|
|
|
written at the end of the file. This forces the symbol to show up in the symbol
|
|
|
|
table.
|
|
|
|
|
2018-07-18 06:17:18 +08:00
|
|
|
``SHT_LLVM_ADDRSIG`` Section (address-significance table)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This section is used to mark symbols as address-significant, i.e. the address
|
|
|
|
of the symbol is used in a comparison or leaks outside the translation unit. It
|
|
|
|
has the same meaning as the absence of the LLVM attributes ``unnamed_addr``
|
|
|
|
and ``local_unnamed_addr``.
|
|
|
|
|
|
|
|
Any sections referred to by symbols that are not marked as address-significant
|
|
|
|
in any object file may be safely merged by a linker without breaking the
|
|
|
|
address uniqueness guarantee provided by the C and C++ language standards.
|
|
|
|
|
|
|
|
The contents of the section are a sequence of ULEB128-encoded integers
|
|
|
|
referring to the symbol table indexes of the address-significant symbols.
|
|
|
|
|
|
|
|
There are two associated assembly directives:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.addrsig
|
|
|
|
|
|
|
|
This instructs the assembler to emit an address-significance table. Without
|
|
|
|
this directive, all symbols are considered address-significant.
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.addrsig_sym sym
|
|
|
|
|
|
|
|
This marks ``sym`` as address-significant.
|
|
|
|
|
2019-05-29 11:29:01 +08:00
|
|
|
``SHT_LLVM_SYMPART`` Section (symbol partition specification)
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This section is used to mark symbols with the `partition`_ that they
|
|
|
|
belong to. An ``.llvm_sympart`` section consists of a null-terminated string
|
|
|
|
specifying the name of the partition followed by a relocation referring to
|
|
|
|
the symbol that belongs to the partition. It may be constructed as follows:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
.section ".llvm_sympart","",@llvm_sympart
|
|
|
|
.asciz "libpartition.so"
|
|
|
|
.word symbol_in_partition
|
|
|
|
|
|
|
|
.. _partition: https://lld.llvm.org/Partitions.html
|
|
|
|
|
2018-06-20 00:47:31 +08:00
|
|
|
CodeView-Dependent
|
|
|
|
------------------
|
|
|
|
|
|
|
|
``.cv_file`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Syntax:
|
|
|
|
``.cv_file`` *FileNumber FileName* [ *checksum* ] [ *checksumkind* ]
|
|
|
|
|
|
|
|
``.cv_func_id`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Introduces a function ID that can be used with ``.cv_loc``.
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
``.cv_func_id`` *FunctionId*
|
|
|
|
|
|
|
|
``.cv_inline_site_id`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Introduces a function ID that can be used with ``.cv_loc``. Includes
|
|
|
|
``inlined at`` source location information for use in the line table of the
|
|
|
|
caller, whether the caller is a real function or another inlined call site.
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
``.cv_inline_site_id`` *FunctionId* ``within`` *Function* ``inlined_at`` *FileNumber Line* [ *Colomn* ]
|
|
|
|
|
|
|
|
``.cv_loc`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
The first number is a file number, must have been previously assigned with a
|
|
|
|
``.file`` directive, the second number is the line number and optionally the
|
|
|
|
third number is a column position (zero if not specified). The remaining
|
|
|
|
optional items are ``.loc`` sub-directives.
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
``.cv_loc`` *FunctionId FileNumber* [ *Line* ] [ *Column* ] [ *prologue_end* ] [ ``is_stmt`` *value* ]
|
|
|
|
|
|
|
|
``.cv_linetable`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Syntax:
|
|
|
|
``.cv_linetable`` *FunctionId* ``,`` *FunctionStart* ``,`` *FunctionEnd*
|
|
|
|
|
|
|
|
``.cv_inline_linetable`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Syntax:
|
|
|
|
``.cv_inline_linetable`` *PrimaryFunctionId* ``,`` *FileNumber Line FunctionStart FunctionEnd*
|
|
|
|
|
|
|
|
``.cv_def_range`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
The *GapStart* and *GapEnd* options may be repeated as needed.
|
|
|
|
|
|
|
|
Syntax:
|
|
|
|
``.cv_def_range`` *RangeStart RangeEnd* [ *GapStart GapEnd* ] ``,`` *bytes*
|
|
|
|
|
|
|
|
``.cv_stringtable`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
``.cv_filechecksums`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
``.cv_filechecksumoffset`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Syntax:
|
|
|
|
``.cv_filechecksumoffset`` *FileNumber*
|
|
|
|
|
|
|
|
``.cv_fpo_data`` Directive
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Syntax:
|
|
|
|
``.cv_fpo_data`` *procsym*
|
|
|
|
|
2014-04-30 15:05:07 +08:00
|
|
|
Target Specific Behaviour
|
|
|
|
=========================
|
|
|
|
|
2017-02-01 02:28:44 +08:00
|
|
|
X86
|
|
|
|
---
|
|
|
|
|
|
|
|
Relocations
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
|
|
|
``@ABS8`` can be applied to symbols which appear as immediate operands to
|
|
|
|
instructions that have an 8-bit immediate form for that operand. It causes
|
|
|
|
the assembler to use the 8-bit form and an 8-bit relocation (e.g. ``R_386_8``
|
|
|
|
or ``R_X86_64_8``) for the symbol.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
cmpq $foo@ABS8, %rdi
|
|
|
|
|
|
|
|
This causes the assembler to select the form of the 64-bit ``cmpq`` instruction
|
|
|
|
that takes an 8-bit immediate operand that is sign extended to 64 bits, as
|
|
|
|
opposed to ``cmpq $foo, %rdi`` which takes a 32-bit immediate operand. This
|
|
|
|
is also not the same as ``cmpb $foo, %dil``, which is an 8-bit comparison.
|
|
|
|
|
2014-04-30 15:05:07 +08:00
|
|
|
Windows on ARM
|
|
|
|
--------------
|
|
|
|
|
|
|
|
Stack Probe Emission
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The reference implementation (Microsoft Visual Studio 2012) emits stack probes
|
|
|
|
in the following fashion:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
movw r4, #constant
|
|
|
|
bl __chkstk
|
|
|
|
sub.w sp, sp, r4
|
|
|
|
|
2014-05-15 09:52:21 +08:00
|
|
|
However, this has the limitation of 32 MiB (±16MiB). In order to accommodate
|
2014-04-30 15:05:07 +08:00
|
|
|
larger binaries, LLVM supports the use of ``-mcode-model=large`` to allow a 4GiB
|
|
|
|
range via a slight deviation. It will generate an indirect jump as follows:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
movw r4, #constant
|
|
|
|
movw r12, :lower16:__chkstk
|
|
|
|
movt r12, :upper16:__chkstk
|
|
|
|
blx r12
|
|
|
|
sub.w sp, sp, r4
|
|
|
|
|
2014-06-10 04:18:42 +08:00
|
|
|
Variable Length Arrays
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The reference implementation (Microsoft Visual Studio 2012) does not permit the
|
|
|
|
emission of Variable Length Arrays (VLAs).
|
|
|
|
|
|
|
|
The Windows ARM Itanium ABI extends the base ABI by adding support for emitting
|
|
|
|
a dynamic stack allocation. When emitting a variable stack allocation, a call
|
|
|
|
to ``__chkstk`` is emitted unconditionally to ensure that guard pages are setup
|
|
|
|
properly. The emission of this stack probe emission is handled similar to the
|
|
|
|
standard stack probe emission.
|
|
|
|
|
|
|
|
The MSVC environment does not emit code for VLAs currently.
|
|
|
|
|
2017-12-20 14:51:45 +08:00
|
|
|
Windows on ARM64
|
|
|
|
----------------
|
|
|
|
|
|
|
|
Stack Probe Emission
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
The reference implementation (Microsoft Visual Studio 2017) emits stack probes
|
|
|
|
in the following fashion:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
mov x15, #constant
|
|
|
|
bl __chkstk
|
|
|
|
sub sp, sp, x15, lsl #4
|
|
|
|
|
|
|
|
However, this has the limitation of 256 MiB (±128MiB). In order to accommodate
|
|
|
|
larger binaries, LLVM supports the use of ``-mcode-model=large`` to allow a 8GiB
|
|
|
|
(±4GiB) range via a slight deviation. It will generate an indirect jump as
|
|
|
|
follows:
|
|
|
|
|
|
|
|
.. code-block:: gas
|
|
|
|
|
|
|
|
mov x15, #constant
|
|
|
|
adrp x16, __chkstk
|
|
|
|
add x16, x16, :lo12:__chkstk
|
|
|
|
blr x16
|
|
|
|
sub sp, sp, x15, lsl #4
|
|
|
|
|