summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy
Commit message (Collapse)AuthorAgeFilesLines
...
* Revert r356129 due to greendragon bot failuresJames Henderson2019-03-143-17/+15
| | | | llvm-svn: 356133
* [llvm-objcopy]Don't implicitly strip sections in segmentsJames Henderson2019-03-143-15/+17
| | | | | | | | | | | | | | | | | | | | | 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
* [llvm-objcopy][NFC] Remove unnecessary llvm-objcopy.h #includesJordan Rupprecht2019-03-135-5/+0
| | | | llvm-svn: 356109
* [llvm-objcopy] Cleanup errors from CopyConfig and remove llvm-objcopy.h ↵Jordan Rupprecht2019-03-131-14/+24
| | | | | | | | | | dependency error() was previously cleaned up from CopyConfig, but new uses were introduced. This also tweaks the error message for --add-symbol to report all invalid flags. llvm-svn: 356105
* [llvm-objcopy] Remove unneeded checks. NFCEugene Leviant2019-03-121-27/+23
| | | | | | Differential revision: https://reviews.llvm.org/D59081 llvm-svn: 355914
* llvm-objcopy: Remove unused field. NFCI.Peter Collingbourne2019-03-122-9/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D59126 llvm-svn: 355892
* [llvm-objcopy] - Fix --compress-debug-sections when there are relocations.George Rimar2019-03-113-16/+32
| | | | | | | | | | | | | | | When --compress-debug-sections is given, llvm-objcopy removes the uncompressed sections and adds compressed to the section list. This makes all the pointers to old sections to be outdated. Currently, code already has logic for replacing the target sections of the relocation sections. But we also have to update the relocations by themselves. This fixes https://bugs.llvm.org/show_bug.cgi?id=40885. Differential revision: https://reviews.llvm.org/D58960 llvm-svn: 355821
* [llvm-objcopy] - Remove dead code. NFCI.George Rimar2019-03-061-7/+1
| | | | | | | | | | | | | | DecompressedSection can only be created if --decompress-debug-sections is specified. https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/ELFObjcopy.cpp#L492 If it is specified when !zlib::isAvailable(), we error out early when parsing the options: https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/CopyConfig.cpp#L657 What means the code I am removing in this patch is dead. Differential revision: https://reviews.llvm.org/D59017 llvm-svn: 355505
* [llvm-objcopy] - Remove an excessive zlib::isAvailable() check and dead code.George Rimar2019-03-061-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are 2 places where llvm-objcopy creates CompressedSection: For --compress-debug-sections. It might create the compressed section from regular here: https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/ELFObjcopy.cpp#L486 All initially compressed sections are created as CompressedSection during reading the sections from an object: https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/Object.cpp#L1118 Those have DebugCompressionType::None type and a different constructor. Case 1 has the following code in its constructor: if (!zlib::isAvailable()) { CompressionType = DebugCompressionType::None; return; } (https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/Object.cpp#L267) We can never reach that code with because would report an error much earlier: https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/CopyConfig.cpp#L480 So the code I am removing is dead. Landing this will address the issue mentioned in https://bugs.llvm.org/show_bug.cgi?id=40886. Differential revision: https://reviews.llvm.org/D59019 llvm-svn: 355503
* [llvm-objcopy] - Fix incorrect CompressedSection creation.George Rimar2019-03-061-1/+2
| | | | | | | | | | We should create CompressedSection only if the section has SHF_COMPRESSED flag or it's name starts from '.zdebug'. Currently, we create it if section's data starts from ZLIB signature. Differential revision: https://reviews.llvm.org/D59018 llvm-svn: 355501
* [llvm-objcopy] - Simplify `isCompressable` and fix the issue relative.George Rimar2019-03-051-11/+2
| | | | | | | | | | | | When --compress-debug-sections is given, llvm-objcopy do not compress sections that have "ZLIB" header in data. Normally this signature is used in zlib-gnu compression format. But if zlib-gnu used then the name of the compressed section should start from .z* (e.g .zdebug_info). If it does not, then it is not a zlib-gnu format and section should be treated as a normal uncompressed section. Differential revision: https://reviews.llvm.org/D58908 llvm-svn: 355399
* [llvm-objcopy] - Report "no zlib available" error properly when ↵George Rimar2019-03-051-4/+4
| | | | | | | | | | | | | | | | --compress-debug-sections is used. If zlib is not available, and --compress-debug-sections is passed, we want to report an error. Currently, it is only reported for --compress_debug_sections= form of the option. Fixes the https://bugs.llvm.org/show_bug.cgi?id=40886. I do not think there is a way to write a test for this. Differential revision: https://reviews.llvm.org/D58909 llvm-svn: 355391
* [llvm-objdump] - Improve the error message for "removing a section that is ↵George Rimar2019-02-281-6/+6
| | | | | | | | | | used by relocation" case. This refines/improves the error message introduced in D58625 Differential revision: https://reviews.llvm.org/D58709 llvm-svn: 355074
* [llvm-objcopy] - Check for invalidated relocations when removing a section.George Rimar2019-02-272-6/+26
| | | | | | | | | | | This is https://bugs.llvm.org/show_bug.cgi?id=40818 Removing a section that is used by relocation is an error we did not report. The patch fixes that. Differential revision: https://reviews.llvm.org/D58625 llvm-svn: 354962
* Fix Wenum-compare gcc7 warning. NFCI.Simon Pilgrim2019-02-271-3/+3
| | | | llvm-svn: 354958
* [llvm-objcopy] Add --set-start, --change-start and --adjust-startEugene Leviant2019-02-265-1/+48
| | | | | | Differential revision: https://reviews.llvm.org/D58173 llvm-svn: 354854
* [llvm-objcopy] Add --add-symbolEugene Leviant2019-02-256-2/+106
| | | | | | Differential revision: https://reviews.llvm.org/D58234 llvm-svn: 354787
* [llvm-objcopy][NFC] Add std::move() to fix older BBJordan Rupprecht2019-02-211-2/+2
| | | | llvm-svn: 354603
* [llvm-objcopy][NFC] More error cleanupJordan Rupprecht2019-02-213-89/+177
| | | | | | | | | | | | | | | | | | | 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
* [llvm-objcopy] Make removeSectionReferences batchedJordan Rupprecht2019-02-212-17/+31
| | | | | | | | | | | | | | | | | | | | | | Summary: Removing a large number of sections from a file with a lot of symbols can have abysmal (i.e. O(n^2)) performance, e.g. when running `--only-section` to extract one section out of a large file. This comes from iterating over all symbols in the symbol table each time we remove a section, to remove references to the section we just removed. Instead, do just one pass of symbol removal by passing a hash set of all the sections we'd like to remove references to. This fixes a regression when running llvm-objcopy -j <one section> on an object file with many sections and symbols -- on my machine, running `objcopy -j .keep_me huge-input.o /tmp/foo.o` takes .3s with GNU objcopy, 1.3s with an updated llvm-objcopy, and 7+ minutes with llvm-objcopy prior to this patch. Reviewers: MaskRay, jhenderson, jakehehrlich, alexshap, espindola Reviewed By: MaskRay, jhenderson Subscribers: echristo, emaste, arichardson, mgrang, jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D58296 llvm-svn: 354597
* [llvm-objcopy] Add --strip-unneeded-symbol(s)Eugene Leviant2019-02-135-8/+32
| | | | | | Differential revision: https://reviews.llvm.org/D58027 llvm-svn: 353919
* Small refactoring of FileError. NFC.Eugene Leviant2019-02-113-9/+3
| | | | | | Differential revision: https://reviews.llvm.org/D57945 llvm-svn: 353679
* Update new files added to llvm-objcopy to use the new file header.Chandler Carruth2019-02-117-28/+21
| | | | llvm-svn: 353666
* [llvm-objcopy] Add few file processing directivesEugene Leviant2019-02-082-5/+38
| | | | | | Differential revision: https://reviews.llvm.org/D57877 llvm-svn: 353521
* [llvm-objcopy] Add --redefine-symsEugene Leviant2019-02-084-4/+50
| | | | | | Differential revision: https://reviews.llvm.org/D57738 llvm-svn: 353509
* [llvm-objcopy] Allow regular expressions in name comparisonEugene Leviant2019-02-064-26/+59
| | | | | | Differential revision: https://reviews.llvm.org/D57517 llvm-svn: 353289
* [ADT] Add a fallible_iterator wrapper.Lang Hames2019-02-051-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
* [llvm-objcopy][NFC] simplify an error returnJordan Rupprecht2019-02-041-3/+1
| | | | llvm-svn: 353074
* [llvm-objcopy][NFC] Use StringSaver for --keep-global-symbolsJordan Rupprecht2019-02-042-7/+11
| | | | | | | | | | | | | | Summary: Use StringSaver/BumpPtrAlloc when parsing lines from --keep-global-symbols files. This allows us to consistently use StringRef for driver options, which avoids copying the full strings for each object copied, as well as simplifies part of D57517. Reviewers: jhenderson, evgeny777, alexshap Subscribers: jakehehrlich Tags: #llvm Differential Revision: https://reviews.llvm.org/D57617 llvm-svn: 353068
* [llvm-objcopy][NFC] Fix trailing semicolon warning.Clement Courbet2019-02-041-2/+2
| | | | llvm-svn: 353035
* [llvm-objcopy] Add ability to copy MachO object filesAlexander Shaposhnikov2019-02-029-0/+962
| | | | | | | | | | 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
* [llvm-objcopy][NFC] More error propagation (executeObjcopyOnArchive)Jordan Rupprecht2019-02-011-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
* [llvm-strip] Implement --keep-file-symbolsEugene Leviant2019-02-012-0/+4
| | | | | | Differential revision: https://reviews.llvm.org/D57582 llvm-svn: 352878
* [llvm-objcopy][NFC] Propagate errors in removeSymbols/removeSectionReferencesJordan Rupprecht2019-02-013-61/+84
| | | | | | | | | | | | | | Reviewers: jhenderson, alexshap, jakehehrlich, espindola Reviewed By: jhenderson Subscribers: emaste, arichardson, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D57543 llvm-svn: 352877
* [llvm-objcopy] Skip --localize-symbol for undefined symbolsJordan Rupprecht2019-01-311-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Include the symbol being defined in the list of requirements for using --localize-symbol. This is used, for example, when someone is depending on two different projects that have the same (or close enough) method defined in each library, and using "-L sym" for a conflicting symbol in one of the libraries so that the definition from the other one is used. However, the library may have internal references to the symbol, which cause program crashes when those are used, i.e.: ``` $ cat foo.c int foo() { return 5; } $ cat bar.c int foo(); int bar() { return 2 * foo(); } $ cat foo2.c int foo() { /* Safer implementation */ return 42; } $ cat main.c int bar(); int main() { __builtin_printf("bar = %d\n", bar()); return 0; } $ ar rcs libfoo.a foo.o bar.o $ ar rcs libfoo2.a foo2.o # Picks the wrong foo() impl $ clang main.o -lfoo -lfoo2 -L. -o main # Picks the right foo() impl $ objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main # Links somehow, but crashes at runtime $ llvm-objcopy -L foo libfoo.a && clang main.o -lfoo -lfoo2 -L. -o main ``` Reviewers: jhenderson, alexshap, jakehehrlich, espindola Subscribers: emaste, arichardson Differential Revision: https://reviews.llvm.org/D57417 llvm-svn: 352767
* [llvm-strip] Add --strip-symbolEugene Leviant2019-01-312-4/+11
| | | | | | Differential revision: https://reviews.llvm.org/D57440 llvm-svn: 352746
* [llvm-objcopy][NFC] More error propagation (linkToBuildIdDir)Jordan Rupprecht2019-01-301-13/+21
| | | | llvm-svn: 352640
* [llvm-objcopy] Support -X|--discard-locals.Jordan Rupprecht2019-01-306-12/+41
| | | | | | | | | | | | | | | | | | | 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
* [llvm-objcopy][NFC] More error propagationJordan Rupprecht2019-01-305-47/+64
| | | | | | | | | | | | 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
* [llvm-objcopy] Implement --set-section-flags.Jordan Rupprecht2019-01-295-38/+104
| | | | | | | | | | | | | | | | | 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
* [llvm-objcopy] Fix crash when writing empty binary outputJordan Rupprecht2019-01-282-0/+25
| | | | | | | | | | | | | | Summary: When using llvm-objcopy -O binary and the resulting file will be empty (e.g. removing the only section that would be written, or using --only-keep with a section that doesn't exist/isn't SHF_ALLOC), we crash because FileOutputBuffer expects Size > 0. Add a regression test, and change Buffer to open/truncate the output file in this case. Reviewers: alexshap, jhenderson, jakehehrlich, espindola Reviewed By: alexshap, jhenderson Subscribers: jfb, llvm-commits, emaste, arichardson Differential Revision: https://reviews.llvm.org/D56806 llvm-svn: 352371
* [llvm-objcopy] Add support for -g as an alias for --strip-debugDouglas Yung2019-01-251-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
* [llvm-objcopy] [COFF] Error out on use of unhandled optionsMartin Storsjo2019-01-231-0/+15
| | | | | | | | Prefer erroring out than silently not doing what was requested. Differential Revision: https://reviews.llvm.org/D57045 llvm-svn: 351948
* [llvm-objcopy] [COFF] Fix handling of aux symbols for big objectsMartin Storsjo2019-01-236-26/+76
| | | | | | | | | | | | | | | | | | | | | | | | | The aux symbols were stored in an opaque std::vector<uint8_t>, with contents interpreted according to the rest of the symbol. All aux symbol types but one fit in 18 bytes (sizeof(coff_symbol16)), and if written to a bigobj, two extra padding bytes are written (as sizeof(coff_symbol32) is 20). In the storage agnostic intermediate representation, store the aux symbols as a series of coff_symbol16 sized opaque blobs. (In practice, all such aux symbols only consist of one aux symbol, so this is more flexible than what reality needs.) The special case is the file aux symbols, which are written in potentially more than one aux symbol slot, without any padding, as one single long string. This can't be stored in the same opaque vector of fixed sized aux symbol entries. The file aux symbols will occupy a different number of aux symbol slots depending on the type of output object file. As nothing in the intermediate process needs to have accurate raw symbol indices, updating that is moved into the writer class. Differential Revision: https://reviews.llvm.org/D57009 llvm-svn: 351947
* [llvm-objcopy] [COFF] Clear the unwritten tail of coff_section::Header::NameMartin Storsjo2019-01-231-0/+1
| | | | | | This should fix the add-gnu-debuglink test on all buildbots. llvm-svn: 351934
* Reapply: [llvm-objcopy] [COFF] Implement --add-gnu-debuglinkMartin Storsjo2019-01-235-7/+95
| | | | | | | | | | | This was reverted since it broke a couple buildbots. The reason for the breakage is not yet known, but this time, the test has got more diagnostics added, to hopefully allow figuring out what goes wrong. Differential Revision: https://reviews.llvm.org/D57007 llvm-svn: 351931
* [llvm-objcopy] Return Error from Buffer::allocate(), ↵Jordan Rupprecht2019-01-228-34/+63
| | | | | | | | | | | | | | | | | | | | | | | [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
* Revert "[llvm-objcopy] [COFF] Implement --add-gnu-debuglink"Martin Storsjo2019-01-225-95/+7
| | | | | | | This reverts commit r351801, as it caused errors on (so far) ppc64be and aarch64 buildbots - the reason is yet unknown. llvm-svn: 351811
* [llvm-objcopy] [COFF] Implement --add-gnu-debuglinkMartin Storsjo2019-01-225-7/+95
| | | | | | Differential Revision: https://reviews.llvm.org/D57007 llvm-svn: 351801
* [llvm-objcopy] [COFF] Update symbol indices in weak externalsMartin Storsjo2019-01-225-6/+40
| | | | | | Differential Revision: https://reviews.llvm.org/D57006 llvm-svn: 351800
OpenPOWER on IntegriCloud