aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/CopyConfig.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-05-20[llvm-objcopy] Refactor CopyConfig structure.Alexey Lapshin1-1191/+0
This patch prepares llvm-objcopy to move its implementation into a separate library. To make it possible it is necessary to minimize internal dependencies. Differential Revision: https://reviews.llvm.org/D99055
2021-05-19[llvm-objcopy] Add support for '--' for delimiting options from input/output ↵Sergey Dmitriev1-2/+11
files This will allow to use llvm-objcopy with file names that begin with dashes. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D102665
2021-05-04[llvm-objcopy] --dump-section: error if '=' is missing or filename is emptyFangrui Song1-2/+8
Fix PR45416: the diagnostic when '=' is missing is misleading. `FileOutputBuffer::create` returns successfully when the filename is empty (the temporary file is `.tmp%%%%%%%`), but `FileOutputBuffer::commit` will error when renaming `.tmp%%%%%%%` to the empty name). Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D101697
2021-04-16[llvm-objcopy] clang-format a lineNico Weber1-3/+4
2021-03-08[llvm-objcopy][MachO] Add support for --keep-undefinedAlexander Shaposhnikov1-0/+2
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-02-15[llvm-objcopy] Delete --build-id-link-{dir,input,output}Fangrui Song1-7/+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-10-28[llvm-install-name-tool] Quote passed rpath args in error messagesKeith Smiley1-11/+11
This diff refactors error reporting to make it more clear what arguments were passed to llvm-install-name-tool. Test plan: make check-all Differential revision: https://reviews.llvm.org/D90080
2020-10-23[llvm-install-name-tool] Add -prepend_rpath optionKeith Smiley1-0/+15
This diff adds the option -prepend_rpath which inserts an rpath as the first rpath in the binary. Test plan: make check-all Differential revision: https://reviews.llvm.org/D89605
2020-10-13[llvm-install-name-tool] Add -delete_all_rpaths optionTobias Hieta1-0/+3
This diff adds an option to remove all rpaths from a Mach-O binary. Test plan: make check-all Differential revision: https://reviews.llvm.org/D88674
2020-09-18[llvm-objcopy][MachO] Add llvm-bitcode-strip driverAlexander Shaposhnikov1-1/+86
This diff adds llvm-bitcode-strip driver to llvm-objcopy. In the future this will enable us to build a replacement for the tool bitcode_strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D87212
2020-09-18[llvm-install-name-tool] Validate -id value earlyAlexander Shaposhnikov1-3/+6
The code which validates the value of -id is moved into the function parseInstallNameToolOptions. Test plan: make check-all Differential revision: https://reviews.llvm.org/D87855
2020-07-06[llvm-install-name-tool] Merge install-name optionsSameer Arora1-20/+17
This diff merges all options for llvm-install-name-tool under a single function processLoadCommands. Also adds another test case for -add_rpath option. Test plan: make check-all Reviewed by: jhenderson, alexshap, smeenai, Ktwu Differential Revision: https://reviews.llvm.org/D82812
2020-07-06Temporarily Revert "[llvm-install-name-tool] Merge install-name options" as ↵Eric Christopher1-17/+20
it breaks the objcopy build. This reverts commit c143900a0851b2c7b7d52e4825c7f073b3474cf6.
2020-07-06[llvm-install-name-tool] Merge install-name optionsSameer Arora1-20/+17
This diff merges all options for llvm-install-name-tool under a single function processLoadCommands. Also adds another test case for -add_rpath option. Test plan: make check-all Reviewed by: jhenderson, alexshap, smeenai, Ktwu Differential Revision: https://reviews.llvm.org/D82812
2020-06-30[llvm-install-name-tool] Add -change optionSameer Arora1-0/+5
Implement `-change` option for install-name-tool. The behavior exactly matches that of cctools. Depends on D82410. Reviewed By: jhenderson, smeenai Differential Revision: https://reviews.llvm.org/D82613
2020-06-30[llvm-install-name-tool] Add -id optionSameer Arora1-0/+3
Implement `-id` option for install-name-tool. Differences from cctool's behavior: - Does **NOT** throw an error if multiple -id options are specified. Instead, picks the last one. - Throws an error in case empty id is specified. Reviewed By: jhenderson, smeenai Differential Revision: https://reviews.llvm.org/D82410
2020-06-26[llvm-install-name-tool] Add support for -rpath optionAlexander Shaposhnikov1-0/+44
This diff implements -rpath option for llvm-install-name-tool which replaces the rpath value in the specified Mach-O binary. Patch by Sameer Arora! Test plan: make check-all Differential revision: https://reviews.llvm.org/D82051
2020-06-24[llvm-objcopy] Update help messagesAlexander Shaposhnikov1-8/+29
This diff updates the help messages for llvm-objcopy, llvm-strip and llvm-install-name-tool. Patch by Sameer Arora! Test plan: make check-all Differential revision: https://reviews.llvm.org/D81907
2020-06-22[llvm-install-name-tool] Implement delete_rpath optionAlexander Shaposhnikov1-0/+13
This diff adds support for deleting an rpath from a Mach-O binary. Patch by Sameer Arora! Test plan: make check-all Differential revision: https://reviews.llvm.org/D81527
2020-05-26[llvm-objcopy][MachO] Add support for removing Swift symbolsAlexander Shaposhnikov1-0/+1
cctools strip has the option "-T" which removes Swift symbols. This diff implements this option in llvm-strip for MachO. Test plan: make check-all Differential revision: https://reviews.llvm.org/D80099
2020-05-17Revert rGca18ce1a00cd8b7cb7ce0e130440f5ae1ffe86ee "GlobPattern.h - remove ↵Simon Pilgrim1-1/+1
unnecessary BitVector.h/StringRef.h includes. NFC" Causes lld build errors
2020-05-17GlobPattern.h - remove unnecessary BitVector.h/StringRef.h includes. NFCSimon Pilgrim1-1/+1
Use forward declarations (BitVector already had one) and an headers to source file that were implicitly using them.
2020-04-20Reland D76675 [llvm-objcopy] Match GNU behaviour regarding file symbolsFangrui Song1-2/+6
Don't error on Config.KeepFileSymbols for COFF and Mach-O. Original description: GNU objcopy removes STT_FILE symbols for strip-debug operations, and keeps them for --discard-all operation. Match their behaviour for llvm-objcopy. Bug: https://github.com/android/ndk/issues/1212 Differential Revision: https://reviews.llvm.org/D76675
2020-04-21Revert "[llvm-objcopy] Match GNU behaviour regarding file symbols"Yi Kong1-6/+2
This reverts commit 7c65e88d0bc85ff2732a4e23c397ff842b97b828. Broke non ELF targets.
2020-04-21[llvm-objcopy] Match GNU behaviour regarding file symbolsYi Kong1-2/+6
GNU objcopy removes STT_FILE symbols for strip-debug operations, and keeps them for --discard-all operation. Match their behaviour for llvm-objcopy. Bug: https://github.com/android/ndk/issues/1212 Differential Revision: https://reviews.llvm.org/D76675
2020-04-06Support bfdname "elf32-hexagon".Sid Manning1-0/+1
Add support and update testcases. Differential Revision: https://reviews.llvm.org/D77579
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-27/+27
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-27/+27
2020-01-20[llvm-objcopy][ELF] Allow setting SHF_EXCLUDE flag for ELF sectionsSergey Dmitriev1-2/+3
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-11-19Introduce llvm-install-name-toolAlexander Shaposhnikov1-0/+89
This diff adds a new "driver" for llvm-objcopy which is supposed to emulate the behavior of install-name-tool. This is a recommit of b5913e6 with ubsan, test dependencies issues fixed. Differential revision: https://reviews.llvm.org/D69146 Test plan: make check-all
2019-11-19Revert "Introduce llvm-install-name-tool"Alexander Shaposhnikov1-89/+0
This temporarily reverts the commit 88f00aef684ff84a6494e1f17d5466c5678f703d. The change broke the buildbot http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/36836
2019-11-19Introduce llvm-install-name-toolAlexander Shaposhnikov1-0/+89
This diff adds a new "driver" for llvm-objcopy which is supposed to emulate the behavior of install-name-tool. This is a recommit of b5913e6d2 with ubsan issues fixed. Differential revision: https://reviews.llvm.org/D69146 Test plan: make check-all
2019-11-06Revert "Introduce llvm-install-name-tool"Alexander Shaposhnikov1-89/+0
This reverts commit b5913e6d2f6d13fb753df701619731ca11936316.
2019-11-06Introduce llvm-install-name-toolAlexander Shaposhnikov1-0/+89
This diff adds a new "driver" for llvm-objcopy which is supposed to emulate the behavior of install-name-tool. Differential revision: https://reviews.llvm.org/D69146 Test plan: make check-all
2019-10-18Fix MSVC "not all control paths return a value" warning. NFCI.Simon Pilgrim1-0/+1
llvm-svn: 375214
2019-10-17[llvm-objcopy] Add support for shell wildcardsJordan Rupprecht1-37/+123
Summary: GNU objcopy accepts the --wildcard flag to allow wildcard matching on symbol-related flags. (Note: it's implicitly true for section flags). The basic syntax is to allow *, ?, \, and [] which work similarly to how they work in a shell. Additionally, starting a wildcard with ! causes that wildcard to prevent it from matching a flag. Use an updated GlobPattern in libSupport to handle these patterns. It does not fully match the `fnmatch` used by GNU objcopy since named character classes (e.g. `[[:digit:]]`) are not supported, but this should support most existing use cases (mostly just `*` is what's used anyway). Reviewers: jhenderson, MaskRay, evgeny777, espindola, alexshap Reviewed By: MaskRay Subscribers: nickdesaulniers, emaste, arichardson, hiraditya, jakehehrlich, abrachet, seiya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66613 llvm-svn: 375169
2019-10-09Unify the two CRC implementationsHans Wennborg1-7/+3
David added the JamCRC implementation in r246590. More recently, Eugene added a CRC-32 implementation in r357901, which falls back to zlib's crc32 function if present. These checksums are essentially the same, so having multiple implementations seems unnecessary. This replaces the CRC-32 implementation with the simpler one from JamCRC, and implements the JamCRC interface in terms of CRC-32 since this means it can use zlib's implementation when available, saving a few bytes and potentially making it faster. JamCRC took an ArrayRef<char> argument, and CRC-32 took a StringRef. This patch changes it to ArrayRef<uint8_t> which I think is the best choice, and simplifies a few of the callers nicely. Differential revision: https://reviews.llvm.org/D68570 llvm-svn: 374148
2019-10-02[llvm-objcopy] Add --set-section-alignmentFangrui Song1-0/+26
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-24[llvm-objcopy] Fix a warningon unused variable. NFC.Michael Liao1-1/+1
llvm-svn: 372745
2019-09-24 [llvm-objcopy] Refactor ELF-specific config out to ELFCopyConfig. NFC.Seiya Nuta1-103/+5
Summary: This patch splits the command-line parsing into two phases: First, parse cross-platform options and leave ELF-specific options unparsed. Second, in the ELF implementation, parse ELF-specific options and construct ELFCopyConfig. Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich, MaskRay Reviewed By: alexshap, jhenderson, jakehehrlich, MaskRay Subscribers: mgorny, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67139 llvm-svn: 372712
2019-09-14[llvm-objcopy] Ignore -B --binary-architecture=Fangrui Song1-32/+0
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-09-14[llvm-objcopy] Default --output-target to --input-target when unspecifiedFangrui Song1-14/+17
Fixes PR42171. In GNU objcopy, if -O (--output-target) is not specified, the value is copied from -I (--input-target). ``` objcopy -I binary -B i386:x86-64 a.txt b # b is copied from a.txt llvm-objcopy -I binary -B i386:x86-64 a.txt b # b is an x86-64 object file ``` This patch changes our behavior to match GNU. With this change, we can delete code related to -B handling (D67215). Reviewed By: jakehehrlich Differential Revision: https://reviews.llvm.org/D67144 llvm-svn: 371913
2019-09-14[llvm-objcopy] Add support for response files in llvm-strip and llvm-objcopyMichael Pozulp1-4/+14
Summary: Addresses https://bugs.llvm.org/show_bug.cgi?id=42671 Reviewers: jhenderson, espindola, alexshap, rupprecht Reviewed By: jhenderson Subscribers: seiya, emaste, arichardson, jakehehrlich, MaskRay, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65372 llvm-svn: 371911
2019-09-04Fix "enumeral and non-enumeral type in conditional expression" warnings. NFCI.Simon Pilgrim1-1/+1
llvm-svn: 370892
2019-08-30[llvm-objcopy] Allow the visibility of symbols created by --binary andChris Jackson1-2/+22
--add-symbol to be specified with --new-symbol-visibility llvm-svn: 370458
2019-08-22[llvm-objcopy][NFC] Refactor symbol/section matchingJordan Rupprecht1-18/+17
Summary: The matchers for section/symbol related flags (e.g. `--keep-symbol=Name` or `--regex --keep-symbol=foo.*`) are currently just vectors that are matched linearlly. However, adding wildcard support would require negative matching too, e.g. a symbol should be removed if it matches a wildcard *but* doesn't match some other wildcard. To make the next patch simpler, consolidate matching logic to a class defined in CopyConfig that takes care of matching. Reviewers: jhenderson, seiya, MaskRay, espindola, alexshap Reviewed By: jhenderson, MaskRay Subscribers: emaste, arichardson, jakehehrlich, abrachet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66432 llvm-svn: 369689
2019-08-15[llvm-objcopy] Allow 'protected' visibility to be set when usingChris Jackson1-0/+1
add-symbol Reviewers: Maskray, rupprecht Differential Revision: https://reviews.llvm.org/D65891 llvm-svn: 368982
2019-08-08[llvm-strip] Support --strip-sectionsWolfgang Pieb1-0/+1
llvm-objcopy already supports --strip-sections. It is a good fit for its alias llvm-strip to support it as well. Reviewers: rupprecht, jhenderson Differential Revision: https://reviews.llvm.org/D65787 llvm-svn: 368241
2019-07-29[llvm-objcopy] Improve --add-section argument string parsingSergey Dmitriev1-2/+11
Differential Revision: https://reviews.llvm.org/D65346 llvm-svn: 367236
2019-07-05[llvm-objcopy][NFC] Refactor output target parsing v2Seiya Nuta1-19/+50
Summary: Use an enum instead of string to hold the output file format in Config.InputFormat and Config.OutputFormat. It's essential to support other output file formats other than ELF. This patch originally has been submitted as D63239. However, there was an use-of-uninitialized-value bug and reverted in r364379 (git commit 4ee933c). This patch includes the fix for the bug by setting Config.InputFormat/Config.OutputFormat in parseStripOptions. Reviewers: espindola, alexshap, rupprecht, jhenderson Reviewed By: jhenderson Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64170 llvm-svn: 365173