aboutsummaryrefslogtreecommitdiff
path: root/llvm/docs/CommandGuide/llvm-objcopy.rst
AgeCommit message (Collapse)AuthorFilesLines
2025-05-22[llvm] Fix typos in documentation (#141078)Kazu Hirata1-1/+1
2025-03-11[llvm-objcopy,ELF] --discard-locals/--discard-all: allow and keep symbols ↵Fangrui Song1-4/+5
referenced by relocations In GNU objcopy, symbols referenced by relocations are retained. Our COFF (https://reviews.llvm.org/D56480) and Mach-O (https://reviews.llvm.org/D75104) ports port the behavior, but the ELF port doesn't. This PR implements the behavior for ELF. Close #47468 (tcl has a use case that requires `strip -x tclStubLib.o` to strip local symbols not referenced by relocations.) Pull Request: https://github.com/llvm/llvm-project/pull/130704
2025-01-23Reapply "[llvm-objcopy][ELF] Add an option to remove notes (#118739)"Igor Kudrin1-0/+5
This fixes "unused-local-typedef" warnings in 9324e6a7a5. This adds an option `--remove-note=[name/]type` to selectively delete notes in ELF files, where `type` is the numeric value of the note type and `name` is the name of the originator. The name can be omitted, in which case all notes of the specified type will be removed. For now, only `SHT_NOTE` sections that are not associated with segments are handled. The implementation can be extended later as needed. RFC: https://discourse.llvm.org/t/rfc-llvm-objcopy-feature-for-editing-notes/83491
2025-01-23Revert "[llvm-objcopy][ELF] Add an option to remove notes (#118739)"Igor Kudrin1-5/+0
This reverts commit 9324e6a7a5c5adc5b5c38c3e3cbecd7e1e98876a.
2025-01-23[llvm-objcopy][ELF] Add an option to remove notes (#118739)Igor Kudrin1-0/+5
This adds an option `--remove-note=[name/]type` to selectively delete notes in ELF files, where `type` is the numeric value of the note type and `name` is the name of the originator. The name can be omitted, in which case all notes of the specified type will be removed. For now, only `SHT_NOTE` sections that are not associated with segments are handled. The implementation can be extended later as needed. RFC: https://discourse.llvm.org/t/rfc-llvm-objcopy-feature-for-editing-notes/83491
2024-12-24[llvm-objcopy] Add support of symbol modification flags for MachO (#120895)Richard Dzenis1-50/+50
This patch adds support of the following llvm-objcopy flags for MachO: - `--globalize-symbol`, `--globalize-symbols`, - `--keep-global-symbol`, `-G`, `--keep-global-symbols`, - `--localize-symbol`, `-L`, `--localize-symbols`, - `--skip-symbol`, `--skip-symbols`. Code in `updateAndRemoveSymbols` for MachO is kept similar to its version for ELF. Fixes #120894
2024-10-04[doc] Fix rendering for objcopy's --remove-symbol-prefix option text (#111131)bd1976bris1-2/+2
2024-07-30[llvm-objcopy] Add --change-section-address (#98664)Eleanor Bonnici1-0/+9
--change-section address and its alias --adjust-section-vma allows modification of section addresses in a relocatable file. This used to be used, for example, in Fiasco microkernel. On a relocatable file this option behaves the same as GNU objcopy, apart from the fact that it does not issue any warnings, for example, when an argument is not used. GNU objcopy does not produce an error when passed an executable file but the usecase for this is not clear, and the behaviour is inconsistent. The idea of GNU objcopy --change-section-address is that the option should change both LMA and VMA in an executable file. Since this patch does not implement executable file support, only VMA is changed.
2024-07-11[llvm-objcopy] Add verification of added .note section formatserge-sans-paille1-0/+9
Also add a --no-verify-note-sections flag to make it possible to add invalid sections if needs be. Pull Request: https://github.com/llvm/llvm-project/pull/90458
2024-07-08[llvm-objcopy] Add change-section-lma *+/-offset (#95431)Eleanor Bonnici1-0/+4
llvm-objcopy did not support change-section-lma argument. This patch adds support for a use case of change-section-lma, that is shifting load address of all sections by the same offset. This seems to be the only practical use case of change-section-lma, found in other software such as Zephyr RTOS's build system. This is an option that could possibly be supported in some other than ELF formats, however this change only implements it for ELF. When used with other formats an error message is raised. In comparison, the behavior of GNU objcopy is inconsistent. For some ELF files it behaves the same as described above. For others, it copies the file without modifying the p_paddr fields when it would be expected. In some experiments it modifies arbitrary fields in section or program headers. It is unclear what exactly determines this. The executable file generated by yaml2obj in this test is not parsable by GNU objcopy. With Machine set to EM_AARCH64, the file can be parsed and the first test in the test file completes with 0 exit code. However, the result is rather arbitrary. AArch64 GNU objcopy subtracts 0x1000 from p_filesz and p_memsz of the first LOAD section and 0x1000 from p_offset of the second LOAD section. It does not look meaningful.
2024-04-26[llvm-objcopy][docs] Use "Mark" rather than "Make" in the objcopy docs for ↵bd1976bris1-3/+3
consistency (#90080) llvm-objcopy --help uses the term "Mark" rather than "Make". e.g. "Mark all symbols local" Change llvm/docs to align.
2024-04-15[llvm-objcopy] Add --compress-sectionsFangrui Song1-0/+8
--compress-sections is similar to --compress-debug-sections but applies to arbitrary sections. * `--compress-sections <section>=none`: decompress sections * `--compress-sections <section>=[zlib|zstd]`: compress sections with zlib/zstd Like `--remove-section`, the pattern is by default a glob, but a regex when --regex is specified. For `--remove-section` like options, `!` prevents matches and is not dependent on ordering (see `ELF/wildcard-syntax.test`). Since `--compress-sections a=zlib --compress-sections a=none` naturally allows overriding, having an order-independent `!` would be confusing. Therefore, `!` is disallowed. Sections within a segment are effectively immutable. Report an error for an attempt to (de)compress them. `SHF_ALLOC` sections in a relocatable file can be compressed, but linkers usually reject them. Note: Before this patch, a compressed relocation section is recognized as a `RelocationSectionBase` as well and `removeSections` `!ToRemove(*ToRelSec)` may incorrectly interpret a `CompressedSections` as `RelocationSectionBase`, leading to ubsan failure for the new test. Fix this by setting `OriginalFlags` in CompressedSection::CompressedSection. Link: https://discourse.llvm.org/t/rfc-compress-arbitrary-sections-with-ld-lld-compress-sections/71674 Pull Request: https://github.com/llvm/llvm-project/pull/85036
2024-04-05Revert "[llvm-objcopy] Add --compress-sections"Mitch Phillips1-8/+0
This reverts commit 9e3b64b9f95aadf57568576712902a272fe66503. Reason: Broke the UBSan buildbot. See the comments in the pull request (https://github.com/llvm/llvm-project/pull/85036) for more information.
2024-04-04[llvm-objcopy] Add --compress-sectionsFangrui Song1-0/+8
--compress-sections is similar to --compress-debug-sections but applies to arbitrary sections. * `--compress-sections <section>=none`: decompress sections * `--compress-sections <section>=[zlib|zstd]`: compress sections with zlib/zstd Like `--remove-section`, the pattern is by default a glob, but a regex when --regex is specified. For `--remove-section` like options, `!` prevents matches and is not dependent on ordering (see `ELF/wildcard-syntax.test`). Since `--compress-sections a=zlib --compress-sections a=none` naturally allows overriding, having an order-independent `!` would be confusing. Therefore, `!` is disallowed. Sections within a segment are effectively immutable. Report an error for an attempt to (de)compress them. `SHF_ALLOC` sections in a relocatable file can be compressed, but linkers usually reject them. Link: https://discourse.llvm.org/t/rfc-compress-arbitrary-sections-with-ld-lld-compress-sections/71674 Pull Request: https://github.com/llvm/llvm-project/pull/85036
2024-03-21[llvm-objcopy] Add --skip-symbol and --skip-symbols options (#80873)Ilia Kuklin1-0/+13
Add --skip-symbol and --skip-symbols options that allow to skip symbols when executing other options that can change the symbol's name, binding or visibility, similar to an existing option --keep-symbol that keeps a symbol from being removed by other options.
2024-02-28[llvm-objcopy] Add --set-symbol-visibility and --set-symbols-visibility ↵Ilia Kuklin1-0/+9
options (#80872) Add options --set-symbol-visibility and --set-symbols-visibility to manually change the visibility of symbols. There is already an option to set the visibility of newly added symbols via --add-symbol and --new-symbol-visibility. This option will allow to change the visibility of already existing symbols.
2024-02-27[llvm-objcopy] Improve help messages (#82830)Fangrui Song1-2/+2
https://reviews.llvm.org/D63820 added llvm/docs/CommandGuide/llvm-objcopy.rst with clearer semantics, e.g. ``` Read a list of names from the file <filename> and mark defined symbols with those names as global in the output instead of the help message Read a list of symbols from <filename> and marks them global" (omits "defined") Rename sections called <old> to <new> in the output instead of the help message Rename a section from old to new (multiple sections may be named <old> ``` Sync the help messages to incorporate the CommandGuide improvement. While here, switch to the conventional imperative sentences for a few options. Additionally, mark some options as grp_coff or grp_macho.
2024-02-16[docs][llvm-objcopy] Add missing formats (#81981)Ulrich Weigand1-0/+4
Bring list of supported formats in docs back in sync with the code.
2024-02-09[llvm-objcopy] Support SREC output format (#75874)quic-areg1-2/+7
Adds a new output target "srec" to write SREC files from ELF inputs. https://en.wikipedia.org/wiki/SREC_(file_format)
2024-02-07[llvm-objcopy] Add --remove-symbol-prefix (#79415)Yi Kong1-0/+5
2023-12-14[llvm-objcopy] Add --gap-fill and --pad-to options (#65815)quic-akaryaki1-0/+10
`--gap-fill <value>` fills the gaps between sections with a specified 8-bit value, instead of zero. `--pad-to <address>` pads the output binary up to the specified load address, using the 8-bit value from `--gap-fill` or zero. These options are only supported for ELF input and binary output.
2023-07-25[llvm-objcopy] --set-section-flags: allow "large" to add SHF_X86_64_LARGEThomas Köppe1-2/+5
Currently, objcopy cannot set the new flag SHF_X86_64_LARGE. This change introduces the named flag "large" which translates to that section flag. An "invalid argument" error is produced if a user attempts to set the flag on an architecture other than X86_64. Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D153262
2022-09-08[llvm-objcopy] Support --{,de}compress-debug-sections for zstdFangrui Song1-1/+1
Also, add ELFCOMPRESS_ZSTD (2) from the approved generic-abi proposal: https://groups.google.com/g/generic-abi/c/satyPkuMisk ("Add new ch_type value: ELFCOMPRESS_ZSTD") Link: https://discourse.llvm.org/t/rfc-zstandard-as-a-second-compression-method-to-llvm/63399 ("[RFC] Zstandard as a second compression method to LLVM") Reviewed By: jhenderson, dblaikie Differential Revision: https://reviews.llvm.org/D130458
2022-09-08Revert "[Support] Add ↵Nikita Popov1-1/+1
llvm::compression::{getReasonIfUnsupported,compress,decompress}" This reverts commit 19dc3cff0f771bb8933136ef68e782553e920d04. This reverts commit 5b19a1f8e88da9ec92b995bfee90043795c2c252. This reverts commit 9397648ac8ad192f7e6e6a8e6894c27bf7e024e9. This reverts commit 10842b44759f987777b08e7714ef77da2526473a. Breaks the GCC build, as reported here: https://reviews.llvm.org/D130506#3776415
2022-09-07[llvm-objcopy] Support --{,de}compress-debug-sections for zstdFangrui Song1-1/+1
Also, add ELFCOMPRESS_ZSTD (2) from the approved generic-abi proposal: https://groups.google.com/g/generic-abi/c/satyPkuMisk ("Add new ch_type value: ELFCOMPRESS_ZSTD") Link: https://discourse.llvm.org/t/rfc-zstandard-as-a-second-compression-method-to-llvm/63399 ("[RFC] Zstandard as a second compression method to LLVM") Reviewed By: jhenderson, dblaikie Differential Revision: https://reviews.llvm.org/D130458
2022-07-29Revert D130458 "[llvm-objcopy] Support --{,de}compress-debug-sections for zstd"Fangrui Song1-1/+1
This reverts commit c26dc2904b95b3685d883e760e84046ea6c33d7f. The new Zstd dispatch has an ongoing design discussion related to https://reviews.llvm.org/D130516#3688123 . Revert for now before it is resolved.
2022-07-28[llvm-objcopy] Support --{,de}compress-debug-sections for zstdFangrui Song1-1/+1
Also, add ELFCOMPRESS_ZSTD (2) from the approved generic-abi proposal: https://groups.google.com/g/generic-abi/c/satyPkuMisk ("Add new ch_type value: ELFCOMPRESS_ZSTD") Link: https://discourse.llvm.org/t/rfc-zstandard-as-a-second-compression-method-to-llvm/63399 ("[RFC] Zstandard as a second compression method to LLVM") Differential Revision: https://reviews.llvm.org/D130458
2022-07-25[llvm-objcopy] Simplify --compress-debug-sections handling with AliasArgs. NFCFangrui Song1-4/+3
2022-07-13[docs][llvm-objcopy] Fix unpaired `<align>``Fangrui Song1-1/+1
2022-07-13[llvm-objcopy][ELF] Add --set-section-typeFangrui Song1-0/+5
The request is mentioned on D129053. I feel that having this functionality is mildly useful (not strong). * Rename .ctors to .init_array and change sh_type to SHT_INIT_ARRAY (GNU objcopy detects the special name but we don't). * Craft tests for a new SHT_LLVM_* extension Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D129337
2022-04-04[llvm-objcopy][docs] Update --update-section descriptiongbreynoo1-0/+6
I noticed that when --update-section was added to llvm-objcopy it was not added to the command guide, see 25bcd94234530955c58c6530a9271c813827637c. This change adds it to the docs and updates the help text. Differential Revision: https://reviews.llvm.org/D122907
2022-01-10[llvm-objcopy] Implement the PE-COFF specific --subsystem optionMartin Storsjö1-0/+7
This implements the parsing of the highly PE-COFF specific option in ConfigManager.cpp, setting Optional<> values in COFFConfig, which then are used in COFFObjcopy. This should fix https://github.com/mstorsjo/llvm-mingw/issues/239. Differential Revision: https://reviews.llvm.org/D116556
2022-01-06Update Bug report URL to Github IssuesChuanqi Xu1-1/+1
Although we moved to Github Issues. The bug report message refers to Bugzilla still. This patch tries to update these URLs. Reviewed By: MaskRay, Quuxplusone, jhenderson, libunwind, libc++ Differential Revision: https://reviews.llvm.org/D116351
2021-11-15[NFC] Trim trailing whitespace in *.rstShao-Ce SUN1-1/+1
2021-09-24[llvm-objcopy][docs] Add missing options to the help output and the command ↵gbreynoo1-1/+1
guide This change is to keep the help text and command guide of objcopy in tandem. - In the help output the options --rename-section and --set-section-flags were missing the flag exclude, which is found in the command guide. - In the command guide the alias -G for --keep-global-symbol was missing, which is found in the help output. Differential Revision: https://reviews.llvm.org/D110340
2021-03-08[docs] Fix llvm-objcopy.rstAlexander Shaposhnikov1-1/+1
Adjust the title underline, NFC.
2021-03-08[llvm-objcopy][MachO] Add support for --keep-undefinedAlexander Shaposhnikov1-0/+7
This diff introduces --keep-undefined in llvm-objcopy/llvm-strip for Mach-O which makes the tools preserve undefined symbols. Test plan: make check-all Differential revision: https://reviews.llvm.org/D97040
2021-03-04[llvm-objcopy][llvm-strip] Improve --discard-all documentation and helpJames Henderson1-1/+1
The help text and documentation for the --discard-all option failed to mention that the option also causes the removal of debug sections. This change fixes both for both llvm-objcopy and llvm-strip. Reviewed by: MaskRay Differential Revision: https://reviews.llvm.org/D97662
2021-02-15[llvm-objcopy] Delete --build-id-link-{dir,input,output}Fangrui Song1-17/+0
The few options are niche. They solved a problem which was traditionally solved with more shell commands (`llvm-readelf -n` fetches the Build ID. Then `ln` is used to hard link the file to a directory derived from the Build ID.) Due to limitation, they are no longer used by Fuchsia and they don't appear to be used elsewhere (checked with Google Search and Debian Code Search). So delete them without a transition period. Announcement: https://lists.llvm.org/pipermail/llvm-dev/2021-February/148446.html Differential Revision: https://reviews.llvm.org/D96310
2020-05-05[docs][llvm-objcopy] Update --output-target text with right defaultsJames Henderson1-1/+2
The --output-target documentation has slightly rotted, as the default is no longer purely based on the input file format, but also the value of --input-target. This patch updates the documentation to make this explicit. Reviewed by: MaskRay, alexshap Differential Revision: https://reviews.llvm.org/D79318
2020-03-22doc: use the right url to bugzillaSylvestre Ledru1-1/+1
2020-03-22Doc: Links should use httpsSylvestre Ledru1-1/+1
2020-02-26[docs][llvm-objcopy][llvm-strip] Move --wildcard description earlierJames Henderson1-4/+4
This moves it above the response file description, which should be at the end.
2020-01-24[llvm-objcopy][COFF] Add support for --set-section-flagsSergey Dmitriev1-22/+39
Reviewers: jhenderson, MaskRay, alexshap, rupprecht, mstorsjo Reviewed By: jhenderson Subscribers: abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73107
2020-01-24[doc][llvm-objcopy] Remove redundant COFF-specific sub-headingJames Henderson1-7/+0
The sub-heading used to contain the --only-keep-debug switch as that switch wasn't implemented for ELF at one point. Since the switch is now in the generic options section, and there are no other options in this sub-heading, it is pointless and can be deleted.
2020-01-20[llvm-objcopy][ELF] Allow setting SHF_EXCLUDE flag for ELF sectionsSergey Dmitriev1-0/+1
Summary: This patch adds support for setting SHF_EXCLUDE flag for ELF sections. Reviewers: jhenderson, grimar, MaskRay, mstorsjo, espindola, alexshap, rupprecht Reviewed By: jhenderson, MaskRay Subscribers: emaste, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D72128
2019-12-16[llvm-objcopy][MachO] Implement --add-sectionSeiya Nuta1-0/+3
Reviewers: alexshap, rupprecht, jhenderson Reviewed By: alexshap, jhenderson Subscribers: mgorny, jakehehrlich, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66283
2019-11-25[llvm-objcopy][MachO] Implement --dump-sectionSeiya Nuta1-9/+12
Reviewers: alexshap, rupprecht, jhenderson Reviewed By: alexshap, rupprecht, jhenderson Subscribers: MaskRay, jakehehrlich, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66408
2019-11-15[llvm-objcopy][MachO] Implement --remove-sectionSeiya Nuta1-0/+3
Reviewers: alexshap, rupprecht, jhenderson Reviewed By: rupprecht, jhenderson Subscribers: jakehehrlich, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66282
2019-11-12[llvm-objcopy][COFF] Implement --redefine-sym and --redefine-symsFangrui Song1-13/+13
The parsing error tests in ELF/redefine-symbols.test are not specific to ELF. Move them to redefine-symbols.test. Add COFF/redefine-symbols.test for COFF specific tests. Also fix the documentation regarding --redefine-syms: the old and new names are separated by whitespace, not an equals sign. Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D70036