aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-03-11Remove unused Endian.h includes, NFCReid Kleckner1-0/+1
Mainly avoids including Host.h everywhere: $ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 3141 - /usr/local/google/home/rnk/llvm-project/llvm/include/llvm/Support/Host.h
2020-01-29[llvm-objcopy] Initial support for wasm in llvm-objcopyDerek Schuff1-1/+5
Currently only supports simple copying, other operations to follow. Reviewers: sbc100, alexshap, jhenderson Differential Revision: https://reviews.llvm.org/D70930 This is a reland of a928d127a with a one-line fix to ensure that the wasm version number is written as little-endian (it's the only field in all of the binary format that's not a single byte or an LEB, but we may have to watch out more when we start handling the linking section).
2020-01-29Revert "[llvm-objcopy] Initial support for wasm in llvm-objcopy"Derek Schuff1-5/+1
This reverts commit a928d127a52a061733d2e42c4c9159a267f7dbd4. It seems to cause issues with big-endian architectures.
2020-01-28[llvm-objcopy] Initial support for wasm in llvm-objcopyDerek Schuff1-1/+5
Currently only supports simple copying, other operations to follow. Reviewers: sbc100, alexshap, jhenderson Differential Revision: https://reviews.llvm.org/D70930
2019-11-19Introduce llvm-install-name-toolAlexander Shaposhnikov1-5/+15
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-15/+5
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-5/+15
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-15/+5
This reverts commit b5913e6d2f6d13fb753df701619731ca11936316.
2019-11-06Introduce llvm-install-name-toolAlexander Shaposhnikov1-5/+15
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-17[llvm-objcopy] Add support for shell wildcardsJordan Rupprecht1-1/+1
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-09-24 [llvm-objcopy] Refactor ELF-specific config out to ELFCopyConfig. NFC.Seiya Nuta1-12/+17
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] Add support for response files in llvm-strip and llvm-objcopyMichael Pozulp1-2/+20
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-08-20[llvm-objcopy] Append '\n' to warning messagesFangrui Song1-1/+1
Currently the warning message of `llvm-strip %t.o %t.o` does not include the trailing newline. Fix this by appending a '\n'. This is the only warning llvm-objcopy and llvm-strip can issue. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D66475 llvm-svn: 369391
2019-07-11[llvm-objcopy] Don't change permissions of non-regular output filesFangrui Song1-2/+13
There is currently an EPERM error when a regular user executes `llvm-objcopy a.o /dev/null`. Worse, root can even change the mode bits of /dev/null. Fix it by checking if the output file is special. A new overload of llvm::sys::fs::setPermissions with FD as the parameter is added. Users should provide `perm & ~umask` as the parameter if they intend to respect umask. The existing overload of llvm::sys::fs::setPermissions may be deleted if we can find an implementation of fchmod() on Windows. fchmod() is usually better than chmod() because it saves syscalls and can avoid race condition. Reviewed By: jakehehrlich, jhenderson Differential Revision: https://reviews.llvm.org/D64236 llvm-svn: 365753
2019-07-05[llvm-objcopy][NFC] Refactor output target parsing v2Seiya Nuta1-9/+23
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
2019-07-05Fix patch not passing test casesAlex Brachet1-1/+2
llvm-svn: 365170
2019-07-04[llvm-objcopy] Change handling of output file permissionsAlex Brachet1-10/+26
Summary: Address bug [[ https://bugs.llvm.org/show_bug.cgi?id=42082 | 42082 ]] where files were always outputted with 0775 permissions. Now, the output file is given either 0666 or 0777 if the object is executable. Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich, MaskRay Reviewed By: rupprecht, jhenderson, jakehehrlich, MaskRay Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62718 llvm-svn: 365162
2019-06-26Revert [llvm-objcopy][NFC] Refactor output target parsingRumeet Dhindsa1-21/+9
This reverts r364254 (git commit 545f001d1b9a7b58a68d75e70bfc36c841de8999) This change causes some llvm-obcopy tests to fail with valgrind. Following is the output for basic-keep.test Command Output (stderr): -- ==107406== Conditional jump or move depends on uninitialised value(s) ==107406== at 0x1A30DD: executeObjcopy(llvm::objcopy::CopyConfig const&) (llvm-objcopy.cpp:235) ==107406== by 0x1A3935: main (llvm-objcopy.cpp:294) llvm-svn: 364379
2019-06-26Revert [llvm-objcopy][NFCI] Fix build failure with GCCRumeet Dhindsa1-2/+0
This reverts r364263 (git commit 81eb82840524818ec0ec14285c866c09b9634df0) This commit is related to r364254 which is causing some llvm-objcopy tests to fail with valgrind. Error: Conditional jump or move depends on uninitialised value(s) llvm-svn: 364378
2019-06-25[llvm-objcopy][NFCI] Fix build failure with GCCSeiya Nuta1-0/+2
Here is unreachable since the switch statement above is exhaustive. llvm-svn: 364263
2019-06-25[llvm-objcopy][NFC] Refactor output target parsingSeiya Nuta1-9/+21
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. Reviewers: espindola, alexshap, rupprecht, jhenderson Reviewed By: rupprecht, jhenderson Subscribers: jyknight, compnerd, emaste, arichardson, fedor.sergeev, jakehehrlich, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63239 llvm-svn: 364254
2019-06-18[llvm-strip] Error when using stdin twiceAlex Brachet1-1/+7
Summary: Implements bug [[ https://bugs.llvm.org/show_bug.cgi?id=42204 | 42204 ]]. llvm-strip now warns when the same input file is used more than once, and errors when stdin is used more than once. Reviewers: jhenderson, rupprecht, espindola, alexshap Reviewed By: jhenderson, rupprecht Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63122 llvm-svn: 363638
2019-06-14[llvm-objcopy] Remove no-op flush of errsAlex Brachet1-1/+0
Reviewers: alexshap, rupprecht, jhenderson Subscribers: jakehehrlich, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63313 llvm-svn: 363354
2019-06-14[llvm-objcopy] Changed command line parsing errorsAlex Brachet1-2/+2
Summary: Tidied up errors during command line parsing to be more consistent with the rest of llvm-objcopy errors. Reviewers: jhenderson, rupprecht, espindola, alexshap Reviewed By: jhenderson, rupprecht Subscribers: emaste, arichardson, MaskRay, llvm-commits, jakehehrlich Tags: #llvm Differential Revision: https://reviews.llvm.org/D62973 llvm-svn: 363350
2019-06-13[llvm-objcopy] Implement IHEX readerEugene Leviant1-3/+17
This is the final part of IHEX format support in llvm-objcopy Differential revision: https://reviews.llvm.org/D62583 llvm-svn: 363243
2019-06-01[llvm-objcopy] test commitAlex Brachet1-1/+1
llvm-svn: 362289
2019-05-08[llvm-objcopy] Improve error message for unrecognised archive memberJames Henderson1-6/+6
Prior to this patch, llvm-objcopy's error messages for archives with unsupported members only mentioned the archive name, not the member name, making them unhelpful. This change improves it by approximately following GNU objcopy's error message syntax of "<archive name>(<member name>): <problem>". Reviewed by: grimar Differential Revision: https://reviews.llvm.org/D61674 llvm-svn: 360251
2019-02-21[llvm-objcopy][NFC] More error cleanupJordan Rupprecht1-21/+37
Summary: This removes calls to `error()`/`reportError()` in the main driver (llvm-objcopy.cpp) as well as the associated argv-parsing (CopyConfig.cpp). `logAllUnhandledErrors()` is now the main way to print errors. There are still a few uses from within the per-arch drivers, so we can't delete them yet... but almost! Reviewers: jhenderson, alexshap, espindola Reviewed By: jhenderson Subscribers: emaste, arichardson, jakehehrlich, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58316 llvm-svn: 354600
2019-02-11Small refactoring of FileError. NFC.Eugene Leviant1-6/+2
Differential revision: https://reviews.llvm.org/D57945 llvm-svn: 353679
2019-02-08[llvm-objcopy] Add --redefine-symsEugene Leviant1-4/+6
Differential revision: https://reviews.llvm.org/D57738 llvm-svn: 353509
2019-02-05[ADT] Add a fallible_iterator wrapper.Lang Hames1-3/+0
A fallible iterator is one whose increment or decrement operations may fail. This would usually be supported by replacing the ++ and -- operators with methods that return error: class MyFallibleIterator { public: // ... Error inc(); Errro dec(); // ... }; The downside of this style is that it no longer conforms to the C++ iterator concept, and can not make use of standard algorithms and features such as range-based for loops. The fallible_iterator wrapper takes an iterator written in the style above and adapts it to (mostly) conform with the C++ iterator concept. It does this by providing standard ++ and -- operator implementations, returning any errors generated via a side channel (an Error reference passed into the wrapper at construction time), and immediately jumping the iterator to a known 'end' value upon error. It also marks the Error as checked any time an iterator is compared with a known end value and found to be inequal, allowing early exit from loops without redundant error checking*. Usage looks like: MyFallibleIterator I = ..., E = ...; Error Err = Error::success(); for (auto &Elem : make_fallible_range(I, E, Err)) { // Loop body is only entered when safe. // Early exits from loop body permitted without checking Err. if (SomeCondition) return; } if (Err) // Handle error. * Since failure causes a fallible iterator to jump to end, testing that a fallible iterator is not an end value implicitly verifies that the error is a success value, and so is equivalent to an error check. Reviewers: dblaikie, rupprecht Subscribers: mgorny, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57618 llvm-svn: 353237
2019-02-02[llvm-objcopy] Add ability to copy MachO object filesAlexander Shaposhnikov1-0/+4
This diff implements first bits for copying (without modification) MachO object files. Test plan: make check-all Differential revision: https://reviews.llvm.org/D54674 llvm-svn: 352944
2019-02-01[llvm-objcopy][NFC] More error propagation (executeObjcopyOnArchive)Jordan Rupprecht1-14/+18
Summary: Replace some reportError() calls with error propagation that was missed from rL352625. Note this also adds an error check during Archive iteration that was being hidden by a different error check before: ``` for (const Archive::Child &Child : Ar.children(Err)) { Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary(); if (!ChildOrErr) // This aborts, so Err is never checked reportError(Ar.getFileName(), ChildOrErr.takeError()); ``` Err is being checked after the loop, so during happy runs, everything is fine. But when reportError is changed to return the error instead of aborting, the fact that Err is never checked is now noticed in tests that trigger an error during the loop. Reviewers: jhenderson, dblaikie, alexshap Reviewed By: dblaikie Subscribers: llvm-commits, lhames, jakehehrlich Tags: #llvm Differential Revision: https://reviews.llvm.org/D57462 llvm-svn: 352888
2019-01-30[llvm-objcopy][NFC] More error propagationJordan Rupprecht1-11/+18
Summary: Do some more error cleanup, removing some dependencies from llvm-objcopy's error/reportError in [ELF/COFF]Objcopy methods. Reviewers: jhenderson, alexshap, jakehehrlich, mstorsjo, espindola Subscribers: emaste, arichardson Differential Revision: https://reviews.llvm.org/D57423 llvm-svn: 352625
2019-01-22[llvm-objcopy] Return Error from Buffer::allocate(), ↵Jordan Rupprecht1-2/+13
[ELF]Writer::finalize(), and [ELF]Writer::commit() Summary: This patch changes a few methods to return Error instead of manually calling error/reportError to abort. This will make it easier to extract into a library. Note that error() takes just a string (this patch also adds an overload that takes an Error), while reportError() takes string + [error/code]. To help unify things, use FileError to associate a given filename with an error. Note that this takes some special care (for now), e.g. calling reportError(FileName, <something that could be FileError>) will duplicate the filename. The goal is to eventually remove reportError() and have every error associated with a file to be a FileError, and just one error handling block at the tool level. This change was suggested in D56806. I took it a little further than suggested, but completely fixing llvm-objcopy will take a couple more patches. If this approach looks good, I'll commit this and apply similar patche(s) for the rest. This change is NFC in terms of non-error related code, although the error message changes in one context. Reviewers: alexshap, jhenderson, jakehehrlich, mstorsjo, espindola Reviewed By: alexshap, jhenderson Subscribers: llvm-commits, emaste, arichardson Differential Revision: https://reviews.llvm.org/D56930 llvm-svn: 351896
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-19[llvm-objcopy] Initial COFF supportMartin Storsjo1-0/+4
This is an initial implementation of no-op passthrough copying of COFF with objcopy. Differential Revision: https://reviews.llvm.org/D54939 llvm-svn: 349605
2018-11-11[Support] Make error banner optional in logAllUnhandledErrorsJonas Devlieghere1-1/+1
In a lot of places an empty string was passed as the ErrorBanner to logAllUnhandledErrors. This patch makes that argument optional to simplify the call sites. llvm-svn: 346604
2018-11-07[llvm-strip] Check "strip" with StringRef::contains instead of ends_withFangrui Song1-1/+1
Summary: If argv[0] is version suffixed, e.g. llvm-strip-7, this will still work. Reviewers: rupprecht, jhenderson, alexshap, jakehehrlich Reviewed By: rupprecht Subscribers: alexshap, jakehehrlich, llvm-commits Differential Revision: https://reviews.llvm.org/D54193 llvm-svn: 346292
2018-11-01[llvm-objcopy] Support --{enable,disable}-deterministic-archivesJordan Rupprecht1-4/+4
Summary: ar and objcopy/strip all support configuring whether archives are written deterministically (timestamps/UIDs/GIDs/etc zero'd). This has been ported to llvm-ar (the U/D modifiers) but not yet to llvm-objcopy/strip. Reviewers: jakehehrlich, jhenderson, alexshap Reviewed By: jhenderson Subscribers: ruiu, mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D53913 llvm-svn: 345859
2018-10-29[llvm-objcopy] Move elf-specific code into subfolderAlexander Shaposhnikov1-471/+1
In this diff the elf-specific code is moved into the subfolder ELF (and factored out from llvm-objcopy.cpp). Test plan: make check-all Differential revision: https://reviews.llvm.org/D53790 llvm-svn: 345544
2018-10-24[llvm-objcopy] Introduce dispatch mechanism based on the inputAlexander Shaposhnikov1-23/+65
In this diff we introduce dispatch mechanism based on the type of the input (archive, object file, raw binary) and the format (coff, elf, macho). We also move the ELF-specific code into the namespace llvm::objcopy::elf. Test plan: make check-all Differential revision: https://reviews.llvm.org/D53311 llvm-svn: 345217
2018-10-16[llvm-objcopy] Factor out BufferAlexander Shaposhnikov1-0/+1
In this diff we move out the hierarchy of buffers from Object.h/Object.cpp into separate files since it is not ELF-specific and will be reused later. After this change Object.h/Object.cpp are almost exclusively ELF-specific. Test plan: make check-all Differential revision: https://reviews.llvm.org/D53298 llvm-svn: 344585
2018-10-11[llvm-objcopy] Factor out CopyConfigAlexander Shaposhnikov1-462/+2
In this diff we move out CopyConfig from llvm-oobjcopy.cpp into a separate header CopyConfig.h to enable us (in the future) reuse this class in the other implementations of objcopy (for coff, mach-o). Additionally this enables us to unload the complexity from llvm-objcopy.cpp a little bit. Test plan: make check-all Differential revision: https://reviews.llvm.org/D53006 llvm-svn: 344307
2018-10-10Test commit: fix typo in commentArmando Montanez1-1/+1
llvm-svn: 344185
2018-10-10[opt] Change the parameter of OptTable::PrintHelp from Name to Usage and ↵Fangrui Song1-4/+5
don't append "[options] <inputs>" Summary: Before, "[options] <inputs>" is unconditionally appended to the `Name` parameter. It is more flexible to change its semantic to `Usage` and let user customize the usage line. % llvm-objcopy ... USAGE: llvm-objcopy <input> [ <output> ] [options] <inputs> With this patch: % llvm-objcopy ... USAGE: llvm-objcopy input [output] Reviewers: rupprecht, alexshap, jhenderson Reviewed By: rupprecht Subscribers: jakehehrlich, mehdi_amini, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D51009 llvm-svn: 344097
2018-10-01[llvm-objcopy] Adding support for decompressing zlib compressed dwarf sections.Puyan Lotfi1-13/+38
Summary: I had added support for compressing dwarf sections in a prior commit, this one adds support for decompressing. Usage is: llvm-objcopy --decompress-debug-sections input.o output.o Reviewers: jakehehrlich, jhenderson, alexshap Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D51841 llvm-svn: 343451
2018-09-21[llvm-objcopy/llvm-strip]: handle --versionJordan Rupprecht1-0/+10
Summary: Implement --version for objcopy and strip. I think there are LLVM utilities that automatically handle this, but that doesn't seem to work with custom parsing since this binary handles both objcopy and strip, so it uses custom parsing. This fixes PR38298 Reviewers: jhenderson, alexshap, jakehehrlich Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52328 llvm-svn: 342702
2018-09-07[llvm-objcopy] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi1-4/+73
Third Attempt: - Alignment issues resolved. - zlib::isAvailable() detected. - ArrayRef misuse fixed. Usage: llvm-objcopy --compress-debug-sections=zlib foo.o llvm-objcopy --compress-debug-sections=zlib-gnu foo.o In both cases the debug section contents is compressed with zlib. In the GNU style case the header is the "ZLIB" magic string followed by the uint64 big- endian decompressed size. In the non-GNU mode the header is the Elf(32|64)_Chdr. Decompression support is coming soon. Differential Revision: https://reviews.llvm.org/D49678 llvm-svn: 341635
2018-09-07Revert: [llvm-objcopy] Dwarf .debug section compression (Second Attempt).Puyan Lotfi1-72/+4
Various bots still fail for unknown reason. llvm-svn: 341613