llvm-objcopy.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. llvm-objcopy - object copying and editing tool
  2. ==============================================
  3. .. program:: llvm-objcopy
  4. SYNOPSIS
  5. --------
  6. :program:`llvm-objcopy` [*options*] *input* [*output*]
  7. DESCRIPTION
  8. -----------
  9. :program:`llvm-objcopy` is a tool to copy and manipulate objects. In basic
  10. usage, it makes a semantic copy of the input to the output. If any options are
  11. specified, the output may be modified along the way, e.g. by removing sections.
  12. If no output file is specified, the input file is modified in-place. If "-" is
  13. specified for the input file, the input is read from the program's standard
  14. input stream. If "-" is specified for the output file, the output is written to
  15. the standard output stream of the program.
  16. If the input is an archive, any requested operations will be applied to each
  17. archive member individually.
  18. The tool is still in active development, but in most scenarios it works as a
  19. drop-in replacement for GNU's :program:`objcopy`.
  20. GENERIC AND CROSS-PLATFORM OPTIONS
  21. ----------------------------------
  22. The following options are either agnostic of the file format, or apply to
  23. multiple file formats.
  24. .. option:: --add-gnu-debuglink <debug-file>
  25. Add a .gnu_debuglink section for ``<debug-file>`` to the output.
  26. .. option:: --disable-deterministic-archives, -U
  27. Use real values for UIDs, GIDs and timestamps when updating archive member
  28. headers.
  29. .. option:: --discard-all, -x
  30. Remove most local symbols from the output. Different file formats may limit
  31. this to a subset of the local symbols. For example, file and section symbols in
  32. ELF objects will not be discarded.
  33. .. option:: --enable-deterministic-archives, -D
  34. Enable deterministic mode when copying archives, i.e. use 0 for archive member
  35. header UIDs, GIDs and timestamp fields. On by default.
  36. .. option:: --help, -h
  37. Print a summary of command line options.
  38. .. option:: --only-section <section>, -j
  39. Remove all sections from the output, except for sections named ``<section>``.
  40. Can be specified multiple times to keep multiple sections.
  41. .. option:: --regex
  42. If specified, symbol and section names specified by other switches are treated
  43. as extended POSIX regular expression patterns.
  44. .. option:: --remove-section <section>, -R
  45. Remove the specified section from the output. Can be specified multiple times
  46. to remove multiple sections simultaneously.
  47. .. option:: --strip-all-gnu
  48. Remove all symbols, debug sections and relocations from the output. This option
  49. is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
  50. .. option:: --strip-all, -S
  51. For ELF objects, remove from the output all symbols and non-alloc sections not
  52. within segments, except for .gnu.warning sections and the section name table.
  53. For COFF objects, remove all symbols, debug sections, and relocations from the
  54. output.
  55. .. option:: --strip-debug, -g
  56. Remove all debug sections from the output.
  57. .. option:: --strip-symbol <symbol>, -N
  58. Remove all symbols named ``<symbol>`` from the output. Can be specified
  59. multiple times to remove multiple symbols.
  60. .. option:: --strip-symbols <filename>
  61. Remove all symbols whose names appear in the file ``<filename>``, from the
  62. output. In the file, each line represents a single symbol name, with leading
  63. and trailing whitespace ignored, as is anything following a '#'. Can be
  64. specified multiple times to read names from multiple files.
  65. .. option:: --strip-unneeded-symbol <symbol>
  66. Remove from the output all symbols named ``<symbol>`` that are local or
  67. undefined and are not required by any relocation.
  68. .. option:: --strip-unneeded-symbols <filename>
  69. Remove all symbols whose names appear in the file ``<filename>``, from the
  70. output, if they are local or undefined and are not required by any relocation.
  71. In the file, each line represents a single symbol name, with leading and
  72. trailing whitespace ignored, as is anything following a '#'. Can be specified
  73. multiple times to read names from multiple files.
  74. .. option:: --strip-unneeded
  75. Remove from the output all local or undefined symbols that are not required by
  76. relocations.
  77. .. option:: --version, -V
  78. Display the version of this program.
  79. COFF-SPECIFIC OPTIONS
  80. ---------------------
  81. The following options are implemented only for COFF objects. If used with other
  82. objects, :program:`llvm-objcopy` will either emit an error or silently ignore
  83. them.
  84. .. option:: --only-keep-debug
  85. Remove the contents of non-debug sections from the output, but keep the section
  86. headers.
  87. ELF-SPECIFIC OPTIONS
  88. --------------------
  89. The following options are implemented only for ELF objects. If used with other
  90. objects, :program:`llvm-objcopy` will either emit an error or silently ignore
  91. them.
  92. .. option:: --add-section <section=file>
  93. Add a section named ``<section>`` with the contents of ``<file>`` to the
  94. output. The section will be of type `SHT_NOTE`, if the name starts with
  95. ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be specified multiple
  96. times to add multiple sections.
  97. .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
  98. Add a new symbol called ``<name>`` to the output symbol table, in the section
  99. named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
  100. the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
  101. properties. Accepted values are:
  102. - `global` = the symbol will have global binding.
  103. - `local` = the symbol will have local binding.
  104. - `weak` = the symbol will have weak binding.
  105. - `default` = the symbol will have default visibility.
  106. - `hidden` = the symbol will have hidden visibility.
  107. - `file` = the symbol will be an `STT_FILE` symbol.
  108. - `section` = the symbol will be an `STT_SECTION` symbol.
  109. - `object` = the symbol will be an `STT_OBJECT` symbol.
  110. - `function` = the symbol will be an `STT_FUNC` symbol.
  111. - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
  112. Additionally, the following flags are accepted but ignored: `debug`,
  113. `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
  114. Can be specified multiple times to add multiple symbols.
  115. .. option:: --allow-broken-links
  116. Allow llvm-objcopy to remove sections even if it would leave invalid section
  117. references. Any invalid sh_link fields will be set to zero.
  118. .. option:: --binary-architecture <arch>, -B
  119. Specify the architecture to use, when transforming an architecture-less format
  120. (e.g. binary) to another format. Valid options are:
  121. - `aarch64`
  122. - `arm`
  123. - `i386`
  124. - `i386:x86-64`
  125. - `mips`
  126. - `powerpc:common64`
  127. - `riscv:rv32`
  128. - `riscv:rv64`
  129. - `sparc`
  130. - `sparcel`
  131. - `x86-64`
  132. .. option:: --build-id-link-dir <dir>
  133. Set the directory used by :option:`--build-id-link-input` and
  134. :option:`--build-id-link-output`.
  135. .. option:: --build-id-link-input <suffix>
  136. Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
  137. specified by :option:`--build-id-link-dir`. The path used is derived from the
  138. hex build ID.
  139. .. option:: --build-id-link-output <suffix>
  140. Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
  141. specified by :option:`--build-id-link-dir`. The path used is derived from the
  142. hex build ID.
  143. .. option:: --change-start <incr>, --adjust-start
  144. Add ``<incr>`` to the program's start address. Can be specified multiple
  145. times, in which case the values will be applied cumulatively.
  146. .. option:: --compress-debug-sections [<style>]
  147. Compress DWARF debug sections in the output, using the specified style.
  148. Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
  149. specified.
  150. .. option:: --decompress-debug-sections
  151. Decompress any compressed DWARF debug sections in the output.
  152. .. option:: --discard-locals, -X
  153. Remove local symbols starting with ".L" from the output.
  154. .. option:: --dump-section <section>=<file>
  155. Dump the contents of section ``<section>`` into the file ``<file>``. Can be
  156. specified multiple times to dump multiple sections to different files.
  157. ``<file>`` is unrelated to the input and output files provided to
  158. :program:`llvm-objcopy` and as such the normal copying and editing
  159. operations will still be performed. No operations are performed on the sections
  160. prior to dumping them.
  161. .. option:: --extract-dwo
  162. Remove all sections that are not DWARF .dwo sections from the output.
  163. .. option:: --extract-main-partition
  164. Extract the main partition from the output.
  165. .. option:: --extract-partition <name>
  166. Extract the named partition from the output.
  167. .. option:: --globalize-symbol <symbol>
  168. Mark any defined symbols named ``<symbol>`` as global symbols in the output.
  169. Can be specified multiple times to mark multiple symbols.
  170. .. option:: --globalize-symbols <filename>
  171. Read a list of names from the file ``<filename>`` and mark defined symbols with
  172. those names as global in the output. In the file, each line represents a single
  173. symbol, with leading and trailing whitespace ignored, as is anything following
  174. a '#'. Can be specified multiple times to read names from multiple files.
  175. .. option:: --input-target <format>, -I
  176. Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
  177. valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
  178. to determine the format automatically.
  179. .. option:: --keep-file-symbols
  180. Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
  181. .. option:: --keep-global-symbol <symbol>
  182. Make all symbols local in the output, except for symbols with the name
  183. ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
  184. .. option:: --keep-global-symbols <filename>
  185. Make all symbols local in the output, except for symbols named in the file
  186. ``<filename>``. In the file, each line represents a single symbol, with leading
  187. and trailing whitespace ignored, as is anything following a '#'. Can be
  188. specified multiple times to read names from multiple files.
  189. .. option:: --keep-section <section>
  190. When removing sections from the output, do not remove sections named
  191. ``<section>``. Can be specified multiple times to keep multiple sections.
  192. .. option:: --keep-symbol <symbol>, -K
  193. When removing symbols from the output, do not remove symbols named
  194. ``<symbol>``. Can be specified multiple times to keep multiple symbols.
  195. .. option:: --keep-symbols <filename>
  196. When removing symbols from the output do not remove symbols named in the file
  197. ``<filename>``. In the file, each line represents a single symbol, with leading
  198. and trailing whitespace ignored, as is anything following a '#'. Can be
  199. specified multiple times to read names from multiple files.
  200. .. option:: --localize-hidden
  201. Make all symbols with hidden or internal visibility local in the output.
  202. .. option:: --localize-symbol <symbol>, -L
  203. Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
  204. output. Can be specified multiple times to mark multiple symbols as local.
  205. .. option:: --localize-symbols <filename>
  206. Read a list of names from the file ``<filename>`` and mark defined non-common
  207. symbols with those names as local in the output. In the file, each line
  208. represents a single symbol, with leading and trailing whitespace ignored, as is
  209. anything following a '#'. Can be specified multiple times to read names from
  210. multiple files.
  211. .. option:: --output-target <format>, -O
  212. Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
  213. of valid ``<format>`` values. If unspecified, the output format is assumed to
  214. be the same as the input file's format.
  215. .. option:: --prefix-alloc-sections <prefix>
  216. Add ``<prefix>`` to the front of the names of all allocatable sections in the
  217. output.
  218. .. option:: --prefix-symbols <prefix>
  219. Add ``<prefix>`` to the front of every symbol name in the output.
  220. .. option:: --preserve-dates, -p
  221. Preserve access and modification timestamps in the output.
  222. .. option:: --redefine-sym <old>=<new>
  223. Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
  224. multiple times to rename multiple symbols.
  225. .. option:: --redefine-syms <filename>
  226. Rename symbols in the output as described in the file ``<filename>``. In the
  227. file, each line represents a single symbol to rename, with the old name and new
  228. name separated by an equals sign. Leading and trailing whitespace is ignored,
  229. as is anything following a '#'. Can be specified multiple times to read names
  230. from multiple files.
  231. .. option:: --rename-section <old>=<new>[,<flag>,...]
  232. Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
  233. specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
  234. supported flags. Can be specified multiple times to rename multiple sections.
  235. .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
  236. Set section properties in the output of section ``<section>`` based on the
  237. specified ``<flag>`` values. Can be specified multiple times to update multiple
  238. sections.
  239. Following is a list of supported flags and their effects:
  240. - `alloc` = add the `SHF_ALLOC` flag.
  241. - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
  242. section.
  243. - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
  244. - `code` = add the `SHF_EXECINSTR` flag.
  245. - `merge` = add the `SHF_MERGE` flag.
  246. - `strings` = add the `SHF_STRINGS` flag.
  247. - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
  248. section.
  249. The following flags are also accepted, but are ignored for GNU compatibility:
  250. `noload`, `debug`, `data`, `rom`, `share`.
  251. .. option:: --set-start-addr <addr>
  252. Set the start address of the output to ``<addr>``. Overrides any previously
  253. specified :option:`--change-start` or :option:`--adjust-start` options.
  254. .. option:: --split-dwo <dwo-file>
  255. Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
  256. ``<dwo-file>`` as the output file and no other options, and then with
  257. :option:`--strip-dwo` on the input file.
  258. .. option:: --strip-dwo
  259. Remove all DWARF .dwo sections from the output.
  260. .. option:: --strip-non-alloc
  261. Remove from the output all non-allocatable sections that are not within
  262. segments.
  263. .. option:: --strip-sections
  264. Remove from the output all section headers and all section data not within
  265. segments. Note that many tools will not be able to use an object without
  266. section headers.
  267. .. option:: --target <format>, -F
  268. Equivalent to :option:`--input-target` and :option:`--output-target` for the
  269. specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
  270. values.
  271. .. option:: --weaken-symbol <symbol>, -W
  272. Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
  273. be specified multiple times to mark multiple symbols as weak.
  274. .. option:: --weaken-symbols <filename>
  275. Read a list of names from the file ``<filename>`` and mark global symbols with
  276. those names as weak in the output. In the file, each line represents a single
  277. symbol, with leading and trailing whitespace ignored, as is anything following
  278. a '#'. Can be specified multiple times to read names from multiple files.
  279. .. option:: --weaken
  280. Mark all defined global symbols as weak in the output.
  281. SUPPORTED FORMATS
  282. -----------------
  283. The following values are currently supported by :program:`llvm-objcopy` for the
  284. :option:`--input-target`, :option:`--output-target`, and :option:`--target`
  285. options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
  286. - `binary`
  287. - `ihex`
  288. - `elf32-i386`
  289. - `elf32-x86-64`
  290. - `elf64-x86-64`
  291. - `elf32-iamcu`
  292. - `elf32-littlearm`
  293. - `elf64-aarch64`
  294. - `elf64-littleaarch64`
  295. - `elf32-littleriscv`
  296. - `elf64-littleriscv`
  297. - `elf32-powerpc`
  298. - `elf32-powerpcle`
  299. - `elf64-powerpc`
  300. - `elf64-powerpcle`
  301. - `elf32-bigmips`
  302. - `elf32-ntradbigmips`
  303. - `elf32-ntradlittlemips`
  304. - `elf32-tradbigmips`
  305. - `elf32-tradlittlemips`
  306. - `elf64-tradbigmips`
  307. - `elf64-tradlittlemips`
  308. - `elf32-sparc`
  309. - `elf32-sparcel`
  310. Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
  311. suffix.
  312. BINARY INPUT AND OUTPUT
  313. -----------------------
  314. If `binary` is used as the value for :option:`--input-target`, the input file
  315. will be embedded as a data section in an ELF relocatable object, with symbols
  316. ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
  317. ``_binary_<file_name>_size`` representing the start, end and size of the data,
  318. where ``<file_name>`` is the path of the input file as specified on the command
  319. line with non-alphanumeric characters converted to ``_``.
  320. If `binary` is used as the value for :option:`--output-target`, the output file
  321. will be a raw binary file, containing the memory image of the input file.
  322. Symbols and relocation information will be discarded. The image will start at
  323. the address of the first loadable section in the output.
  324. EXIT STATUS
  325. -----------
  326. :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
  327. Otherwise, it exits with code 0.
  328. BUGS
  329. ----
  330. To report bugs, please visit <http://llvm.org/bugs/>.
  331. There is a known issue with :option:`--input-target` and :option:`--target`
  332. causing only ``binary`` and ``ihex`` formats to have any effect. Other values
  333. will be ignored and :program:`llvm-objcopy` will attempt to guess the input
  334. format.
  335. SEE ALSO
  336. --------
  337. :manpage:`llvm-strip(1)`