xref: /llvm-project/llvm/docs/CommandGuide/llvm-ifs.rst (revision a74d9e74e5f97640ed0727fcd363c165209dfbf1)
18ada9b57SHaowei Wullvm-ifs - shared object stubbing tool
28ada9b57SHaowei Wu======================================
38ada9b57SHaowei Wu
48ada9b57SHaowei Wu.. program:: llvm-ifs
58ada9b57SHaowei Wu
68ada9b57SHaowei WuSYNOPSIS
78ada9b57SHaowei Wu--------
88ada9b57SHaowei Wu
98ada9b57SHaowei Wu:program:`llvm-ifs` [*options*] *inputs*
108ada9b57SHaowei Wu
118ada9b57SHaowei WuDESCRIPTION
128ada9b57SHaowei Wu-----------
138ada9b57SHaowei Wu
148ada9b57SHaowei Wu:program:`llvm-ifs` is a tool that jointly produces human readable text-based
158ada9b57SHaowei Wustubs (.ifs files) for shared objects and linkable shared object stubs
168ada9b57SHaowei Wu(.so files) from either ELF shared objects or text-based stubs. The text-based
178ada9b57SHaowei Wustubs is useful for monitoring ABI changes of the shared object. The linkable
188ada9b57SHaowei Wushared object stubs can be used to avoid unnecessary relinks when the ABI of
198ada9b57SHaowei Wushared libraries does not change.
208ada9b57SHaowei Wu
218ada9b57SHaowei Wu
228ada9b57SHaowei WuIFS FORMATS
238ada9b57SHaowei Wu-----------
248ada9b57SHaowei Wu
258ada9b57SHaowei WuHere is an example of the text representation (IFS) of a shared object produced
268ada9b57SHaowei Wuby the :program:`llvm-ifs`:
278ada9b57SHaowei Wu
288ada9b57SHaowei Wu::
298ada9b57SHaowei Wu
308ada9b57SHaowei Wu  --- !ifs-v1
318ada9b57SHaowei Wu  IFSVersion: 3.0
328ada9b57SHaowei Wu  SoName: libtest.so /* Optional */
338ada9b57SHaowei Wu  Target: x86_64-unknown-linux-gnu   /* Optional, format 1, same format as llvm target triple */
348ada9b57SHaowei Wu  Target: { Arch: x86_64, Endianness: little, Bitwidth: 64 } /* Optional, format 2 */
358ada9b57SHaowei Wu  NeededLibs:
368ada9b57SHaowei Wu    - libc.so.6
378ada9b57SHaowei Wu  Symbols:
388ada9b57SHaowei Wu    - { Name: sym0, Type: Notype }
398ada9b57SHaowei Wu    - { Name: sym1, Type: Object, Size: 0 }
408ada9b57SHaowei Wu    - { Name: sym2, Type: Func, Weak: false }
418ada9b57SHaowei Wu    - { Name: sym3, Type: TLS }
428ada9b57SHaowei Wu    - { Name: sym4, Type: Unknown, Warning: foo }
438ada9b57SHaowei Wu  ...
448ada9b57SHaowei Wu
458ada9b57SHaowei Wu* ``IFSVersion``: Version of the IFS file for reader compatibility.
468ada9b57SHaowei Wu
478ada9b57SHaowei Wu* ``SoName`` (optional): Name of the shared object file that is being stubbed.
488ada9b57SHaowei Wu
498ada9b57SHaowei Wu* ``Target`` (optional): The architecture, endianness and bitwise information of
508ada9b57SHaowei Wu  this shared object. It can be either in explicit format or in implicit LLVM
518ada9b57SHaowei Wu  triple format. It can be optional and can be overridden from command line
528ada9b57SHaowei Wu  options.
538ada9b57SHaowei Wu
548ada9b57SHaowei Wu* ``NeededLibs``: The list of the external shared objects that this library depends on.
558ada9b57SHaowei Wu
568ada9b57SHaowei Wu* ``Symbols``: A collection of all data needed to link objects for each symbol, sorted by name in ascending order.
578ada9b57SHaowei Wu
588ada9b57SHaowei Wu  + ``Name``: Symbol name.
598ada9b57SHaowei Wu
608ada9b57SHaowei Wu  + ``Type``: Whether the symbol is an object, function, no-type, thread local storage, or unknown. Symbol types not explicitly supported are mapped as unknown to improve signal-to-noise ratio.
618ada9b57SHaowei Wu
6254d7fde4SSylvestre Ledru  + ``Size``: The size of the symbol in question, doesn't apply to functions, and is optional for NoType symbols.
638ada9b57SHaowei Wu
648ada9b57SHaowei Wu  + ``Undefined``: Whether or not the symbol is defined in this shared object file.
658ada9b57SHaowei Wu
668ada9b57SHaowei Wu  + ``Weak``: Whether or not the symbol should be treated as weak.
678ada9b57SHaowei Wu
688ada9b57SHaowei Wu  + ``Warning`` (optional): Warning text to output when this symbol is linked against.
698ada9b57SHaowei Wu
708ada9b57SHaowei WuThis YAML based text format contains everything that is needed to generate a
718ada9b57SHaowei Wulinkable ELF shared object as well as an Apple TAPI format file. The ordering
728ada9b57SHaowei Wuof symbols is sorted, so these files can be easily compared using diff tools.
738ada9b57SHaowei WuIf the content of the file changes, it indicates a potentially ABI breaking
748ada9b57SHaowei Wuchange.
758ada9b57SHaowei Wu
768ada9b57SHaowei Wu
778ada9b57SHaowei WuELF STUB FORMAT
788ada9b57SHaowei Wu---------------
798ada9b57SHaowei Wu
808ada9b57SHaowei WuA minimum ELF file that can be used by linker should have following sections properly populated:
818ada9b57SHaowei Wu
828ada9b57SHaowei Wu* ELF header.
838ada9b57SHaowei Wu
848ada9b57SHaowei Wu* Section headers.
858ada9b57SHaowei Wu
868ada9b57SHaowei Wu* Dynamic symbol table (``.dynsym`` section).
878ada9b57SHaowei Wu
888ada9b57SHaowei Wu* Dynamic string table (``.dynstr`` section).
898ada9b57SHaowei Wu
908ada9b57SHaowei Wu* Dynamic table (``.dynamic`` section).
918ada9b57SHaowei Wu
928ada9b57SHaowei Wu  + ``DT_SYMTAB`` entry.
938ada9b57SHaowei Wu
948ada9b57SHaowei Wu  + ``DT_STRTAB`` entry.
958ada9b57SHaowei Wu
968ada9b57SHaowei Wu  + ``DT_STRSZ`` entry.
978ada9b57SHaowei Wu
988ada9b57SHaowei Wu  + ``DT_NEEDED`` entries. (optional)
998ada9b57SHaowei Wu
1008ada9b57SHaowei Wu  + ``DT_SONAME`` entry. (optional)
1018ada9b57SHaowei Wu
1028ada9b57SHaowei Wu* Section header string table (``.shstrtab`` section)
1038ada9b57SHaowei Wu
1048ada9b57SHaowei WuThis ELF file may have compatibility issues with ELF analysis tools that rely on the program headers.
1058ada9b57SHaowei WuLinkers like LLD work fine with such a minimum ELF file without errors.
1068ada9b57SHaowei Wu
1078ada9b57SHaowei WuOPTIONS
1088ada9b57SHaowei Wu-------
1098ada9b57SHaowei Wu
1108ada9b57SHaowei Wu.. option:: --input-format=[IFS|ELF|OtherObjectFileFormats]
1118ada9b57SHaowei Wu
1128ada9b57SHaowei Wu Specify input file format. Currently, only text IFS files and ELF shared
1138ada9b57SHaowei Wu object files are supported. This flag is optional as the input format can be
1148ada9b57SHaowei Wu inferred.
1158ada9b57SHaowei Wu
1168ada9b57SHaowei Wu.. option:: --output-elf=<output-filename>
1178ada9b57SHaowei Wu
1188ada9b57SHaowei Wu Specify the output file for ELF shared object stub.
1198ada9b57SHaowei Wu
1208ada9b57SHaowei Wu.. option:: --output-ifs=<output-filename>
1218ada9b57SHaowei Wu
1228ada9b57SHaowei Wu Specify the output file for text IFS.
1238ada9b57SHaowei Wu
1248ada9b57SHaowei Wu.. option:: --output-tbd=<output-filename>
1258ada9b57SHaowei Wu
1268ada9b57SHaowei Wu Specify the output file for Apple TAPI tbd.
1278ada9b57SHaowei Wu
1288ada9b57SHaowei Wu.. option:: --arch=[x86_64|AArch64|...]
1298ada9b57SHaowei Wu
1308ada9b57SHaowei Wu This flag is optional and it should only be used when reading an IFS file
1318ada9b57SHaowei Wu which does not define the ``Arch`` (architecture). This flag defines the
1328ada9b57SHaowei Wu architecture of the output file, and can be any string supported by ELF
1338ada9b57SHaowei Wu 'e_machine' field. If the value is conflicting with the IFS file, an error
1348ada9b57SHaowei Wu will be reported and the program will stop.
1358ada9b57SHaowei Wu
1368ada9b57SHaowei Wu.. option:: --endianness=[little|big]
1378ada9b57SHaowei Wu
1388ada9b57SHaowei Wu This flag is optional and it should only be used when reading an IFS file
1398ada9b57SHaowei Wu which does not define the ``Endianness``. This flag defines the endianness of
1408ada9b57SHaowei Wu the output file. If the value is conflicting with the IFS file, an error
1418ada9b57SHaowei Wu will be reported and the program will stop.
1428ada9b57SHaowei Wu
1438ada9b57SHaowei Wu.. option:: --bitwidth=[32|64]
1448ada9b57SHaowei Wu
1458ada9b57SHaowei Wu This flag is optional and it should only be used when reading an IFS file
1468ada9b57SHaowei Wu which does not define the ``BitWidth``. This flag defines the bit width of the
1478ada9b57SHaowei Wu output file. If the value is conflicting with the input IFS file, an error
1488ada9b57SHaowei Wu will be reported and the program will stop.
1498ada9b57SHaowei Wu
1508ada9b57SHaowei Wu.. option:: --target=<target triple>
1518ada9b57SHaowei Wu
1528ada9b57SHaowei Wu This flag is optional and should only be used when reading an IFS file
1538ada9b57SHaowei Wu which does not define any target information. This flag defines architecture,
1548ada9b57SHaowei Wu endianness and bit width of the output file using llvm target triple.
1558ada9b57SHaowei Wu This flag cannot be used simultaneously with other target related flags.
1568ada9b57SHaowei Wu
1578ada9b57SHaowei Wu.. option:: --hint-ifs-target=<target triple>
1588ada9b57SHaowei Wu
1598ada9b57SHaowei Wu This flag is optional and should only be used when reading an ELF shared
1608ada9b57SHaowei Wu object and generating an IFS file. by default, llvm-ifs will use '``Arch``,
1618ada9b57SHaowei Wu ``Endianness`` and ``BitWidth``' fields to reflect the target information from the
1628ada9b57SHaowei Wu input object file. Using this flag will tell llvm-ifs the expected target
1638ada9b57SHaowei Wu triple in the output IFS file. If the value matches the target information
1648ada9b57SHaowei Wu from the object file, this value will be used in the 'Target:' filed in the
1658ada9b57SHaowei Wu generated IFS. If it conflicts with the input object file, an error will be
1668ada9b57SHaowei Wu reported and the program will stop.
1678ada9b57SHaowei Wu
1688ada9b57SHaowei Wu.. option:: --hint-ifs-target
1698ada9b57SHaowei Wu
1708ada9b57SHaowei Wu This flag is optional and should only be used when outputting an IFS file.
1718ada9b57SHaowei Wu This flag strips the ``Arch`` field from the IFS file so it can be overridden
1728ada9b57SHaowei Wu later.
1738ada9b57SHaowei Wu
1748ada9b57SHaowei Wu.. option:: --strip-ifs-endianness
1758ada9b57SHaowei Wu
1768ada9b57SHaowei Wu This flag is optional and should only be used when outputting an IFS file.
1778ada9b57SHaowei Wu This flag strips the ``Endianness`` field from the IFS file so it can be
1788ada9b57SHaowei Wu overridden later.
1798ada9b57SHaowei Wu
1808ada9b57SHaowei Wu.. option:: --strip-ifs-bitwidth
1818ada9b57SHaowei Wu
1828ada9b57SHaowei Wu This flag is optional and should only be used when outputting an IFS file.
1838ada9b57SHaowei Wu This flag strips the ``BitWidth`` field from the IFS file so it can be overridden
1848ada9b57SHaowei Wu later.
1858ada9b57SHaowei Wu
1868ada9b57SHaowei Wu.. option:: --strip-ifs-target
1878ada9b57SHaowei Wu
1888ada9b57SHaowei Wu This flag is optional and should only be used when outputting an IFS file.
1898ada9b57SHaowei Wu This flag strips the ``Target`` field from the IFS file so it can be overridden
1908ada9b57SHaowei Wu later.
1918ada9b57SHaowei Wu
1928ada9b57SHaowei Wu.. option:: --write-if-changed
1938ada9b57SHaowei Wu
1948ada9b57SHaowei Wu When this flag is set, llvm-ifs will only write the output file if it does not
1958ada9b57SHaowei Wu already exist or the content will be different from the existing file.
1968ada9b57SHaowei Wu
197*a74d9e74SAlex Brachet.. option:: --strip-size
198*a74d9e74SAlex Brachet
199*a74d9e74SAlex Brachet When this flag is set, llvm-ifs will remove the size field from the output ifs
200*a74d9e74SAlex Brachet file. This is useful for shared objects that only intend to be linked against
201*a74d9e74SAlex Brachet position independent code which doesn't need copy relocations, or where the size
202*a74d9e74SAlex Brachet of an object is not a useful part of the abi to track.
203*a74d9e74SAlex Brachet
2048ada9b57SHaowei WuEXIT STATUS
2058ada9b57SHaowei Wu-----------
2068ada9b57SHaowei Wu
2078ada9b57SHaowei WuIf :program:`llvm-ifs` succeeds, it will exit with 0. Otherwise, if an
2088ada9b57SHaowei Wuerror occurs, it will exit with a non-zero value.
209