summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy
Commit message (Collapse)AuthorAgeFilesLines
...
* [llvm-strip] Support -s alias for --strip-all. Make both strip and objcopy ↵Jordan Rupprecht2018-10-232-2/+5
| | | | | | | | | | | | | | | | | | | | | case sensitive to support both -s (--strip-all) and -S (--strip-debug). Summary: GNU strip supports both `-s` and `-S` as aliases for `--strip-all` and `--strip-debug`, respectfully. As part of this, it turns out that strip/objcopy were accepting case insensitive command line args. I'm not sure if there was an explicit reason for this. The only others uses of this are llvm-cvtres/llvm-mt/llvm-lib, which are all tools specific for windows support. Forcing case sensitivity allows both aliases to exist, but seems like a good idea anyway. And as a surprise test case adjustment, the llvm-strip unit test was running with `-keep=unavailable_symbol`, despite `keep` not be a valid flag for strip. This is because there is a flag `-K` which, when case insensitivity is permitted, allows it to be interpreted as `-K` = `eep=unavailable_symbol` (e.g. to allow `-Kfoo` == `--keep-symbol=foo`). Reviewers: jakehehrlich, jhenderson, alexshap Reviewed By: jakehehrlich Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D53163 llvm-svn: 345068
* [llvm-objcopy] Factor out BufferAlexander Shaposhnikov2018-10-166-74/+120
| | | | | | | | | | | | 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
* [llvm-objcopy] Add -F|--target compatibilityJordan Rupprecht2018-10-122-2/+16
| | | | | | | | | | | | | | | | | Summary: This change adds support for the GNU --target flag, which sets both --input-target and --output-target. GNU objcopy doesn't do any checking for whether both --target and --{input,output}-target are used, and so it allows both, e.g. "--target A --output-target B" is equivalent to "--input-target A --output-target B" since the later command line flag would override earlier ones. This may be error prone, so I chose to implement it as an error if both are used. I'm not sure if anyone is actually using both. Reviewers: jakehehrlich, jhenderson, alexshap Reviewed By: jakehehrlich, alexshap Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D53029 llvm-svn: 344321
* [llvm-objcopy] Factor out CopyConfigAlexander Shaposhnikov2018-10-115-471/+541
| | | | | | | | | | | | 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
* Test commit: fix typo in commentArmando Montanez2018-10-101-1/+1
| | | | llvm-svn: 344185
* [opt] Change the parameter of OptTable::PrintHelp from Name to Usage and ↵Fangrui Song2018-10-101-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
* [llvm-objcopy] Make -S an alias for --strip-allJake Ehrlich2018-10-091-2/+2
| | | | | | -S should be an alias for --strip-all not --strip-all-gnu llvm-svn: 344080
* [llvm-objcopy] Adding support for decompressing zlib compressed dwarf sections.Puyan Lotfi2018-10-014-14/+148
| | | | | | | | | | | | | | | 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
* [llvm-objcopy/llvm-strip]: handle --versionJordan Rupprecht2018-09-213-0/+17
| | | | | | | | | | | | | | | | | 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
* [llvm-objcopy] Add missing alias for --strip-all-gnuAlexander Shaposhnikov2018-09-171-0/+2
| | | | | | | | | | | | | This diff adds -S as an alias for --strip-all-gnu (for compatibility with binutils' objcopy). Patch by Dmitry Golovin! Test plan: make check-all Differential revision: https://reviews.llvm.org/D52163 llvm-svn: 342364
* [objcopy] make objcopy follow program header standardsJulie Hockett2018-09-121-7/+6
| | | | | | | | | | | | | | | | | | Submitted on behalf of Armando Montanez (amontanez@google.com). Objects with unused program headers copied by objcopy would always have nonzero values for program header offset and program header entry size. While technically valid, this atypical behavior triggers warnings in some tools. This change sets the two fields to zero when the program header is unused, better fitting the general expectations for unused program header data. Section headers behaved somewhat similarly (though only with the entry size), and are fixed in this revision as well. Differential Revision: https://reviews.llvm.org/D51961 llvm-svn: 342065
* [llvm-objcopy] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi2018-09-074-6/+176
| | | | | | | | | | | | | | | | | | | | | | | 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
* Revert: [llvm-objcopy] Dwarf .debug section compression (Second Attempt).Puyan Lotfi2018-09-074-175/+6
| | | | | | Various bots still fail for unknown reason. llvm-svn: 341613
* [llvm-objcopy] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi2018-09-064-6/+175
| | | | | | | | | | | | | | | | | | | | Second Attempt. Alignment issues resolved. zlib::isAvailable() detected. 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: 341607
* [llvm-strip] Support stripping multiple input filesJordan Rupprecht2018-09-051-14/+35
| | | | | | | | | | | | | | | | | Summary: Allow strip to be called on multiple input files, which is interpreted as stripping N files in place. Using multiple input files is incompatible with -o. To allow this, create a `DriverConfig` struct which just wraps a list of `CopyConfigs`. objcopy will only ever have a single `CopyConfig`, but strip will have N (where N >= 1) CopyConfigs. Reviewers: alexshap, jakehehrlich Reviewed By: alexshap, jakehehrlich Subscribers: MaskRay, jakehehrlich, llvm-commits Differential Revision: https://reviews.llvm.org/D51660 llvm-svn: 341464
* [llvm-strip] Allow copying relocation sections without symbol tables.Jordan Rupprecht2018-09-041-6/+9
| | | | | | | | | | | | | | | | | | | | | Summary: Fixes the error "Link field value 0 in section .rela.plt is invalid" when copying/stripping certain binaries. Minimal repro: ``` $ cat /tmp/a.c int main() { return 0; } $ clang -static /tmp/a.c -o /tmp/a $ llvm-strip /tmp/a -o /tmp/b llvm-strip: error: Link field value 0 in section .rela.plt is invalid. ``` Reviewers: jakehehrlich, alexshap Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D51493 llvm-svn: 341419
* Revert r341342: Dwarf .debug section compression support (zlib, zlib-gnu).Chandler Carruth2018-09-044-161/+6
| | | | | | | | | | | | Also reverts follow-up commits r341343 and r341344. The primary commit continues to break some build bots even after the fixes in r341343 for UBSan issues: http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/5823 It is also failing for me locally (linux, x86-64). llvm-svn: 341360
* [NFC][llvm-objcopy] clang-formating Object.cppPuyan Lotfi2018-09-041-2/+1
| | | | llvm-svn: 341344
* [NFC][llvm-objcopy] Fixing a ubi-san problem with unaligned memory writes.Puyan Lotfi2018-09-041-3/+4
| | | | llvm-svn: 341343
* [llvm-objcopy] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi2018-09-034-6/+161
| | | | | | | | | | | | | | | | | | | 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: 341342
* [llvm-strip] Fix -p|--preserve-dates to not truncate output when used in-place.Jordan Rupprecht2018-08-291-1/+2
| | | | | | | | The restoreDateOnFile() method used to preserve dates uses sys::fs::openFileForWrite(). That method defaults to opening files with CD_CreateAlways, which truncates the output file if it exists. Use CD_OpenExisting instead to open it and *not* truncate it, which also has the side benefit of erroring if the file does not exist (it should always exist, because we just wrote it out). Also, fix the test case to make sure the output is a valid output file, and not empty. The extra test assertions are enough to catch this regression. llvm-svn: 340996
* [llvm-objcopy] Simplify find(X,Y) != X.end() with is_contained()Fangrui Song2018-08-211-3/+3
| | | | llvm-svn: 340241
* [llvm-strip] Allow only one inputFangrui Song2018-08-201-3/+3
| | | | | | | | | | | | | | Summary: Before, llvm-strip accepted a second argument but it would just be ignored. Reviewers: alexshap, jhenderson, paulsemel Reviewed By: alexshap Subscribers: jakehehrlich, rupprecht, llvm-commits Differential Revision: https://reviews.llvm.org/D51004 llvm-svn: 340229
* [llvm-objcopy] Implement -G/--keep-global-symbol(s).Jordan Rupprecht2018-08-172-0/+54
| | | | | | | | | | | | | | | | | Summary: Port GNU Objcopy -G/--keep-global-symbol(s). This is slightly different than the already-implemented --globalize-symbol, which marks a symbol as global when copying. When --keep-global-symbol (alias -G) is used, *only* those symbols marked will stay global, and all other globals are demoted to local. (Also note that it doesn't *promote* a symbol to global). Additionally, there is a pluralized version of the flag --keep-global-symbols, which effectively applies --keep-global-symbol for every non-comment in a file. Reviewers: jakehehrlich, jhenderson, alexshap Reviewed By: jhenderson Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50589 llvm-svn: 340105
* [llvm-objcopy] Add support for -I binary -B <arch>.Jordan Rupprecht2018-08-173-64/+273
| | | | | | | | | | | | | | | | | Summary: The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687. This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start). Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar Reviewed By: jhenderson Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits Differential Revision: https://reviews.llvm.org/D50343 llvm-svn: 340070
* [llvm-strip] Add support for -p/--preserve-datesJordan Rupprecht2018-08-163-4/+48
| | | | | | | | | | | | | | Summary: [llvm-strip] Preserve access/modification timestamps when -p is used. Reviewers: jakehehrlich, jhenderson, alexshap Reviewed By: jhenderson Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50744 llvm-svn: 339921
* [llvm-objcopy] NFC: Fix minor formatting issuesJordan Rupprecht2018-08-132-32/+32
| | | | llvm-svn: 339616
* [llvm-objcopy] NFC: consistently use typename ELFT::<X> definitions in headersJordan Rupprecht2018-08-102-6/+6
| | | | llvm-svn: 339448
* [llvm-objcopy] NFC: Add some color to error()Jordan Rupprecht2018-08-092-4/+7
| | | | llvm-svn: 339404
* [llvm-objcopy] Add --prefix-symbols optionPaul Semel2018-08-093-1/+9
| | | | | | Differential Revision: https://reviews.llvm.org/D50381 llvm-svn: 339362
* [llvm-objcopy] Add --dump-sectionPaul Semel2018-08-094-0/+44
| | | | | | Differential Revision: https://reviews.llvm.org/D49979 llvm-svn: 339358
* [NFC] clang-format cleanup of a couple files in llvm-objcopy.Puyan Lotfi2018-08-022-3/+3
| | | | llvm-svn: 338752
* [llvm-objcopy] Add missing -I command line flag alias for --input-targetJordan Rupprecht2018-08-011-0/+1
| | | | llvm-svn: 338635
* [llvm-objcopy] Add support for --rename-section flags from gnu objcopyJordan Rupprecht2018-08-012-11/+110
| | | | | | | | | | | | | | | | | Summary: Add support for --rename-section flags from gnu objcopy. Not all flags appear to have an effect for ELF objects, but allowing them would allow easier drop-in replacement. Other unrecognized flags are rejected. This was only tested by comparing flags printed by "readelf -e <.o>" against the output of gnu vs llvm objcopy, it hasn't been tested to be valid beyond that. Reviewers: jakehehrlich, alexshap Subscribers: llvm-commits, paulsemel, alexshap Differential Revision: https://reviews.llvm.org/D49870 llvm-svn: 338582
* [llvm-objcopy] Make --strip-debug strip .gdb_indexFangrui Song2018-07-311-1/+2
| | | | | | | | | | | | | | | | | Summary: See binutils-gdb/bfd/elf.c, GNU objcopy also strips .stab* (STABS) .line* (DWARF 1) .gnu.linkonce.wi.* (linkonce section for .debug_info) but I'm not sure we need to be compatible with it. Reviewers: dblaikie, alexshap, jakehehrlich, jhenderson Reviewed By: alexshap, jakehehrlich Subscribers: aprantl, JDevlieghere, jakehehrlich, llvm-commits Differential Revision: https://reviews.llvm.org/D50100 llvm-svn: 338443
* [llvm-objcopy] Make --strip-debug strip .zdebug* (zlib-gnu) sectionsFangrui Song2018-07-271-8/+9
| | | | | | This behavior matches GNU objcopy. llvm-svn: 338173
* Handle the lack of a symbol table correctly.Stephen Hines2018-07-261-2/+3
| | | | | | | | | | | | | | | | | Summary: These two cases will trigger a dereference on a nullptr, since the SymbolTable can be nonexistent for a given library, in addition to just being empty. Reviewers: alexshap Reviewed By: alexshap Subscribers: meikeb, kongyi, chh, jakehehrlich, llvm-commits, pirama Differential Revision: https://reviews.llvm.org/D49534 llvm-svn: 338062
* [llvm-objcopy] Add basic support for --rename-sectionJordan Rupprecht2018-07-202-0/+20
| | | | | | | | | | | | | | | Summary: Add basic support for --rename-section=old=new to llvm-objcopy. A full replacement for GNU objcopy requires also modifying flags (i.e. --rename-section=old=new,flag1,flag2); I'd like to keep that in a separate change to keep this simple. Reviewers: jakehehrlich, alexshap Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49576 llvm-svn: 337604
* [NFC][llvm-objcopy] Cleanup namespace usage in llvm-objcopy.Puyan Lotfi2018-07-184-29/+39
| | | | | | | | | | Nest any classes not used outside of a file into anon. Nest any classes used across files in llvm-objcopy into namespace llvm::objcopy. Differential Revision: https://reviews.llvm.org/D49449 llvm-svn: 337337
* [NFC][llvm-objcopy] Make helper functions staticPuyan Lotfi2018-07-162-24/+28
| | | | | | | | Anywhere in tools/llvm-objcopy where functions or classes are not referenced outside of a given file, we change things to make the function or class static or put inside an anonymous namespace. llvm-svn: 337220
* [llvm-objcopy] Add support for large indexesJake Ehrlich2018-07-162-21/+215
| | | | | | | | | | | | | | | | | | | This patch is an update of an older patch that never landed (see here: https://reviews.llvm.org/D42516) Recently various users have run into this issue and it just 100% has to be solved at this point. The main difference in this patch is that I use gunzip instead of unzip which should hopefully allow tests to pass. Please review this as if it is a new patch however. I found some issues along the way and made some minor modifications. The binary used in this patch for testing (a zip file to make it small) can be found here: https://drive.google.com/file/d/1UjsnTO9edLttZibbr-2T1bJl92KEQFAO/view?usp=sharing Differential Revision: https://reviews.llvm.org/D49206 llvm-svn: 337204
* Add --strip-all option back to llvm-strip.Stephen Hines2018-07-122-0/+4
| | | | | | | | | | | | | | | | | Summary: This option appears to have been dropped as part of the refactoring in r331663. Unfortunately, if we want to use llvm-strip as a drop-in replacement for strip, this option should still be available. Reviewers: alexshap Reviewed By: alexshap Subscribers: meikeb, kongyi, chh, jakehehrlich, llvm-commits, pirama Differential Revision: https://reviews.llvm.org/D49226 llvm-svn: 336921
* [llvm-objcopy] Add support for static librariesAlexander Shaposhnikov2018-07-063-86/+203
| | | | | | | | | | | This diff adds support for handling static libraries to llvm-objcopy and llvm-strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D48413 llvm-svn: 336455
* [llvm-objcopy] Remove unused field from ObjectAlexander Shaposhnikov2018-06-072-6/+1
| | | | | | | | | | | | | | The class Object contains std::shared_ptr<MemoryBuffer> OwnedData which is not used anywhere. Besides avoiding two stage initialization the motivation to remove it comes from the plan to add (currently missing) support for static libraries. NFC. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47855 llvm-svn: 334217
* [llvm-strip] Expose --strip-unneeded optionPaul Semel2018-06-072-3/+6
| | | | | | Differential Revision: https://reviews.llvm.org/D47818 llvm-svn: 334182
* [llvm-strip] Expose --discard-all optionAlexander Shaposhnikov2018-06-062-1/+9
| | | | | | | | | | Expose objcopy's --discard-all option in llvm-strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47750 llvm-svn: 334131
* [llvm-strip] Add missing aliases for --strip-debugAlexander Shaposhnikov2018-06-041-0/+9
| | | | | | | | | | Add missing aliases for --strip-debug: -g, -S, -d. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47674 llvm-svn: 333940
* [llvm-objcopy] Fix null symbol handlingPaul Semel2018-06-013-7/+6
| | | | | | | | | This fixes the bug where strip-all option was leading to a malformed outputted ELF file. Differential Revision: https://reviews.llvm.org/D47414 llvm-svn: 333772
* [llvm-strip] Add -o option to llvm-stripAlexander Shaposhnikov2018-05-312-1/+6
| | | | | | | | | | | This diff implements the option -o for specifying a file to write the output to. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47505 llvm-svn: 333693
* llvm-objcopy: Set sh_link to 0 on unrecognized symtab-linked sections.Peter Collingbourne2018-05-301-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | Per discussion on the generic-abi mailing list: https://groups.google.com/forum/#!topic/generic-abi/MPr8TVtnVn4 An object file manipulation tool must either write out a symbol table with the same number of entries as the original symbol table and in the same order, or if this is impossible, refuse to operate on the object file if it has unrecognized sections that are linked to the symtab section. However, existing tools (namely GNU strip, GNU objcopy and ld.{bfd,gold,lld} -r) do not comply with this at present: they change symbol table indexes and set sh_link to 0 on the unrecognized symtab-linked sections. We intend to use the latter as a (temporary) signal that a tool has operated on a proposed new symtab-linked section and invalidated the symbol table indexes. However, llvm-objcopy currently keeps sh_link pointing to the new symtab section. This patch changes llvm-objcopy to set sh_link to 0 to match the behaviour of the other tools. Differential Revision: https://reviews.llvm.org/D47404 llvm-svn: 333581
OpenPOWER on IntegriCloud