aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/ObjcopyOpts.td
AgeCommit message (Collapse)AuthorFilesLines
2024-04-04[llvm-objcopy] Add --compress-sectionsFangrui Song1-0/+6
--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/+14
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/+11
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-38/+37
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-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/+12
`--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/+2
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
2023-07-14[llvm-objcopy] Remove stray periods from usage textThomas Köppe1-18/+18
The convention for TableGen help messages is to omit the period. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D155242
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-5/+6
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-06-29[llvm-objcopy] Remove support for legacy .zdebug sectionsFangrui Song1-2/+2
clang 14 removed -gz=zlib-gnu support and ld.lld removed linker input support for zlib-gnu in D126793. Now let's remove zlib-gnu from llvm-objcopy. * .zdebug* sections are no longer recognized as debug sections. --strip* don't remove them. They are copied like other opaque sections * --decompress-debug-sections does not uncompress .zdebug* sections * --compress-debug-sections=zlib-gnu is not supported It is very rare but in case a user has object files using .zdebug . They can use llvm-objcopy<15 or GNU objcopy for uncompression. --compress-debug-sections=zlib-gnu is unlikely ever used by anyone, so I do not add a custom diagnostic. Differential Revision: https://reviews.llvm.org/D128688
2022-04-04[llvm-objcopy][docs] Update --update-section descriptiongbreynoo1-1/+1
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/+5
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
2021-11-16[llvm-objcopy] Add --update-sectionLeonard Chan1-0/+4
This is another attempt at D59351 which attempted to add --update-section, but with some heuristics for adjusting segment/section offsets/sizes in the event the data copied into the section is larger than the original size of the section. We are opting to not support this case. GNU's objcopy was able to do this because the linker and objcopy are tightly coupled enough that segment reformatting was simpler. This is not the case with llvm-objcopy and lld where they like to be separated. This will attempt to copy data into the section without changing any other properties of the parent segment (if the section is part of one). Differential Revision: https://reviews.llvm.org/D112116
2021-09-24[llvm-objcopy][docs] Add missing options to the help output and the command ↵gbreynoo1-3/+4
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-02-15[llvm-objcopy] Delete --build-id-link-{dir,input,output}Fangrui Song1-13/+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
2019-10-02[llvm-objcopy] Add --set-section-alignmentFangrui Song1-0/+4
Fixes PR43181. This option was recently added to GNU objcopy (binutils PR24942). `llvm-objcopy -I binary -O elf64-x86-64 --set-section-alignment .data=8` can set the alignment of .data. Reviewed By: grimar, jhenderson, rupprecht Differential Revision: https://reviews.llvm.org/D67656 llvm-svn: 373461
2019-09-14[llvm-objcopy] Ignore -B --binary-architecture=Fangrui Song1-2/+1
GNU objcopy documents that -B is only useful with architecture-less input (i.e. "binary" or "ihex"). After D67144, -O defaults to -I, and -B is essentially a NOP. * If -O is binary/ihex, GNU objcopy ignores -B. * If -O is elf*, -B provides the e_machine field in GNU objcopy. So to convert a blob to an ELF, `-I binary -B i386:x86-64 -O elf64-x86-64` has to be specified. `-I binary -B i386:x86-64 -O elf64-x86-64` creates an ELF with its e_machine field set to EM_NONE in GNU objcopy, but a regular x86_64 ELF in elftoolchain elfcopy. Follow the elftoolchain approach (ignoring -B) to simplify code. Users that expect their command line portable should specify -B. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D67215 llvm-svn: 371914
2019-08-30[llvm-objcopy] Allow the visibility of symbols created by --binary andChris Jackson1-0/+5
--add-symbol to be specified with --new-symbol-visibility llvm-svn: 370458
2019-08-15[llvm-objcopy] Allow 'protected' visibility to be set when usingChris Jackson1-1/+1
add-symbol Reviewers: Maskray, rupprecht Differential Revision: https://reviews.llvm.org/D65891 llvm-svn: 368982
2019-08-15[llvm-objcopy] Move duplicate tablegen from objcopy and strip into one fileMichael Pozulp1-97/+30
Summary: This avoids maintaining the same options in two different places. Reviewers: jhenderson, alexshap, rupprecht, MaskRay Reviewed By: jhenderson, rupprecht, MaskRay Subscribers: MaskRay, wolfgangp, jakehehrlich, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65991 llvm-svn: 368961
2019-06-25[llvm-objcopy][llvm-strip] Fix help text typo for --allow-broken-linksJames Henderson1-1/+1
llvm-svn: 364307
2019-06-07llvm-objcopy: Implement --extract-partition and --extract-main-partition.Peter Collingbourne1-0/+7
This implements the functionality described in https://lld.llvm.org/Partitions.html. It works as follows: - Reads the section headers using the ELF header at file offset 0; - If extracting a loadable partition: - Finds the section containing the required partition ELF header by looking it up in the section table; - Reads the ELF and program headers from the section. - If extracting the main partition: - Reads the ELF and program headers from file offset 0. - Filters the section table according to which sections are in the program headers that it read: - If ParentSegment != nullptr or section is not SHF_ALLOC, then it goes in. - Sections containing partition ELF headers or program headers are excluded as there are no headers for these in ordinary ELF files. Differential Revision: https://reviews.llvm.org/D62364 llvm-svn: 362818
2019-05-08[llvm-objcopy] Add --prefix-alloc-sectionsJames Henderson1-0/+4
This patch adds support for --prefix-alloc-sections, which adds a prefix to every allocated section names. It adds a prefix after renaming section names by --rename-section as GNU objcopy does. Fixes PR41266: https://bugs.llvm.org/show_bug.cgi?id=41266 Differential Revision: https://reviews.llvm.org/D60042 Patch by Seiya Nuta. llvm-svn: 360233
2019-04-26[llvm-objcopy] Accept --long-option but not -long-optionFangrui Song1-27/+28
Summary: llvm-{objcopy,strip} (and many other LLVM binary utilities) accept cl::opt style -long-option as well as many short options (e.g. -p -S -x). People who use them as replacement of GNU binutils often use the grouped option syntax (POSIX Utility Conventions), e.g. -Sx => -S -x, -Wd => -W -d, -sj.text => -s -j.text There is ambiguity if a long option starts with the character used by a short option. Drop the support for -long-option to resolve the ambiguity. This divergence from other utilities is accepted (other utilities continue supporting -long-option). https://lists.llvm.org/pipermail/llvm-dev/2019-April/131786.html Reviewers: alexshap, jakehehrlich, jhenderson, rupprecht, espindola Reviewed By: jakehehrlich, jhenderson, rupprecht Subscribers: grimar, emaste, arichardson, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60439 llvm-svn: 359265
2019-04-18[llvm-objcopy][llvm-strip] Add switch to allow removing referenced sectionsJames Henderson1-0/+6
llvm-objcopy currently emits an error if a section to be removed is referenced by another section. This is a reasonable thing to do, but is different to GNU objcopy. We should allow users who know what they are doing to have a way to produce the invalid ELF. This change adds a new switch --allow-broken-links to both llvm-strip and llvm-objcopy to do precisely that. The corresponding sh_link field is then set to 0 instead of an error being emitted. I cannot use llvm-readelf/readobj to test the link fields because they emit an error if any sections, like the .dynsym, cannot be properly loaded. Reviewed by: rupprecht, grimar Differential Revision: https://reviews.llvm.org/D60324 llvm-svn: 358649
2019-04-01[llvm-objcopy] Add --keep-symbols optionYi Kong1-0/+9
Differential Revision: https://reviews.llvm.org/D60054 llvm-svn: 357418
2019-03-14[llvm-strip] Hook up (unimplemented) --only-keep-debugJordan Rupprecht1-1/+4
For ELF, we accept but ignore --only-keep-debug. Do the same for llvm-strip. COFF does implement this, so update the test that it is supported. llvm-svn: 356207
2019-03-14[llvm-objcopy]Don't implicitly strip sections in segmentsJames Henderson1-9/+10
This patch changes llvm-objcopy's behaviour to not strip sections that are in segments, if they otherwise would be due to a stripping operation (--strip-all, --strip-sections, --strip-non-alloc). This preserves the segment contents. It does not change the behaviour of --strip-all-gnu (although we could choose to do so), because GNU objcopy's behaviour in this case seems to be to strip the section, nor does it prevent removing of sections in segments with --remove-section (if a user REALLY wants to remove a section, we should probably let them, although I could be persuaded that warning might be appropriate). Tests have been added to show this latter behaviour. This fixes https://bugs.llvm.org/show_bug.cgi?id=41006. Reviewed by: grimar, rupprecht, jakehehrlich Differential Revision: https://reviews.llvm.org/D59293 This is a reland of r356129, attempting to fix greendragon failures due to a suspected compatibility issue with od on the greendragon bots versus other versions. llvm-svn: 356136
2019-03-14Revert r356129 due to greendragon bot failuresJames Henderson1-10/+9
llvm-svn: 356133
2019-03-14[llvm-objcopy]Don't implicitly strip sections in segmentsJames Henderson1-9/+10
This patch changes llvm-objcopy's behaviour to not strip sections that are in segments, if they otherwise would be due to a stripping operation (--strip-all, --strip-sections, --strip-non-alloc). This preserves the segment contents. It does not change the behaviour of --strip-all-gnu (although we could choose to do so), because GNU objcopy's behaviour in this case seems to be to strip the section, nor does it prevent removing of sections in segments with --remove-section (if a user REALLY wants to remove a section, we should probably let them, although I could be persuaded that warning might be appropriate). Tests have been added to show this latter behaviour. This fixes https://bugs.llvm.org/show_bug.cgi?id=41006. Reviewed by: grimar, rupprecht, jakehehrlich Differential Revision: https://reviews.llvm.org/D59293 llvm-svn: 356129
2019-02-26[llvm-objcopy] Add --set-start, --change-start and --adjust-startEugene Leviant1-0/+10
Differential revision: https://reviews.llvm.org/D58173 llvm-svn: 354854
2019-02-25[llvm-objcopy] Add --add-symbolEugene Leviant1-0/+8
Differential revision: https://reviews.llvm.org/D58234 llvm-svn: 354787
2019-02-13[llvm-objcopy] Add --strip-unneeded-symbol(s)Eugene Leviant1-0/+9
Differential revision: https://reviews.llvm.org/D58027 llvm-svn: 353919
2019-02-08[llvm-objcopy] Add few file processing directivesEugene Leviant1-0/+21
Differential revision: https://reviews.llvm.org/D57877 llvm-svn: 353521
2019-02-08[llvm-objcopy] Add --redefine-symsEugene Leviant1-0/+10
Differential revision: https://reviews.llvm.org/D57738 llvm-svn: 353509
2019-02-06[llvm-objcopy] Allow regular expressions in name comparisonEugene Leviant1-0/+4
Differential revision: https://reviews.llvm.org/D57517 llvm-svn: 353289
2019-01-30[llvm-objcopy] Support -X|--discard-locals.Jordan Rupprecht1-0/+6
Summary: This adds support for the --discard-locals flag, which acts similarly to --discard-all, except it only applies to compiler-generated symbols (i.e. symbols starting with `.L` in ELF). I am not sure about COFF local symbols: those appear to also use `.L` in most cases, but also use just `L` in other cases, so for now I am just leaving it unimplemented there. Fixes PR36160 Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola Reviewed By: jhenderson Subscribers: llvm-commits, emaste, arichardson Differential Revision: https://reviews.llvm.org/D57248 llvm-svn: 352626
2019-01-29[llvm-objcopy] Implement --set-section-flags.Jordan Rupprecht1-0/+7
Summary: --set-section-flags is used to change the section flags (e.g. SHF_ALLOC) for given sections. The flags allowed are the same from the existing --rename-section=.old=.new[,flags] feature. Additionally, make sure that --set-section-flag cannot be used with --rename-section (either the source or destination), since --rename-section accepts flags. This avoids ambiguity for something like "--rename-section=.foo=.bar,alloc --set-section-flag=.bar,code". Reviewers: jhenderson, jakehehrlich, alexshap, espindola Reviewed By: jhenderson, jakehehrlich Subscribers: llvm-commits, emaste, arichardson Differential Revision: https://reviews.llvm.org/D57198 llvm-svn: 352505
2019-01-25[llvm-objcopy] Add support for -g as an alias for --strip-debugDouglas Yung1-0/+2
This change adds an option -g to llvm-objcopy which is an alias for the existing option --strip-debug. This fixes PR40003. Reviewed by: alexshap Differential Revision: https://reviews.llvm.org/D57217 llvm-svn: 352182
2018-12-06[llvm-objcopy] Change --only-keep to --only-sectionJake Ehrlich1-3/+3
I just hard core goofed when I wrote this and created a different name for no good reason. I'm failry aware of most "fresh" users of llvm-objcopy (that is, users which are not using it as a drop in replacement for GNU objcopy) and can say that only "-j" is being used by such people so this patch should strictly increase compatibility and not remove it. Differential Revision: https://reviews.llvm.org/D52180 llvm-svn: 348446
2018-12-03[llvm-objcopy] Add --build-id-link-dir flagJake Ehrlich1-0/+12
This flag does not exist in GNU objcopy but has a major use case. Debugging tools support the .build-id directory structure to find debug binaries. There is no easy way to build this structure up however. One way to do it is by using llvm-readelf and some crazy shell magic. This implements the feature directly. It is most often the case that you'll want to strip a file and send the original to the .build-id directory but if you just want to send a file to the .build-id directory you can copy to /dev/null instead. Differential Revision: https://reviews.llvm.org/D54384 llvm-svn: 348174
2018-11-28[llvm-objcopy] Hook up the -V alias to --version, output "GNU strip"Martin Storsjo1-0/+1
This allows libtool to detect the presence of llvm-strip and use it with the options --strip-debug and --strip-unneeded. Also hook up the -V alias for objcopy. Differential Revision: https://reviews.llvm.org/D54936 llvm-svn: 347731
2018-11-13[llvm-objcopy] Rename --keep to --keep-section.Jordan Rupprecht1-1/+2
Summary: llvm-objcopy/strip support `--keep` (for sections) and `--keep-symbols` (for symbols). For consistency and clarity, rename `--keep` to `--keep-section`. In fact, for GNU compatability, -K is --keep-symbol, so it's weird that the alias `-K` is not the same as the short-ish `--keep`. Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola Reviewed By: jakehehrlich, MaskRay Subscribers: emaste, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D54477 llvm-svn: 346782
2018-11-01[llvm-objcopy/strip] [NFC] Clean up tablegen opts (clang-format + ↵Jordan Rupprecht1-71/+84
reorganizing things). llvm-svn: 345896