aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
AgeCommit message (Collapse)AuthorFilesLines
2018-08-09[llvm-objcopy] Add --dump-sectionPaul Semel1-0/+37
Differential Revision: https://reviews.llvm.org/D49979 llvm-svn: 339358
2018-08-02[NFC] clang-format cleanup of a couple files in llvm-objcopy.Puyan Lotfi1-1/+2
llvm-svn: 338752
2018-08-01[llvm-objcopy] Add support for --rename-section flags from gnu objcopyJordan Rupprecht1-8/+103
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
2018-07-31[llvm-objcopy] Make --strip-debug strip .gdb_indexFangrui Song1-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
2018-07-27[llvm-objcopy] Make --strip-debug strip .zdebug* (zlib-gnu) sectionsFangrui Song1-8/+9
This behavior matches GNU objcopy. llvm-svn: 338173
2018-07-26Handle the lack of a symbol table correctly.Stephen Hines1-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
2018-07-20[llvm-objcopy] Add basic support for --rename-sectionJordan Rupprecht1-0/+17
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
2018-07-18[NFC][llvm-objcopy] Cleanup namespace usage in llvm-objcopy.Puyan Lotfi1-29/+32
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
2018-07-16[NFC][llvm-objcopy] Make helper functions staticPuyan Lotfi1-19/+23
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
2018-07-12Add --strip-all option back to llvm-strip.Stephen Hines1-0/+1
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
2018-07-06[llvm-objcopy] Add support for static librariesAlexander Shaposhnikov1-23/+91
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
2018-06-07[llvm-strip] Expose --strip-unneeded optionPaul Semel1-3/+3
Differential Revision: https://reviews.llvm.org/D47818 llvm-svn: 334182
2018-06-06[llvm-strip] Expose --discard-all optionAlexander Shaposhnikov1-1/+4
Expose objcopy's --discard-all option in llvm-strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47750 llvm-svn: 334131
2018-06-01[llvm-objcopy] Fix null symbol handlingPaul Semel1-3/+1
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
2018-05-31[llvm-strip] Add -o option to llvm-stripAlexander Shaposhnikov1-1/+2
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
2018-05-26[llvm-objcopy] Add --keep-file-symbols optionPaul Semel1-3/+7
This option prevent from removing file symbols while removing symbols. Differential Revision: https://reviews.llvm.org/D46830 llvm-svn: 333339
2018-05-25[llvm-objcopy] Add --strip-unneeded optionPaul Semel1-0/+17
Differential Revision: https://reviews.llvm.org/D46896 llvm-svn: 333267
2018-05-23[llvm-strip] Minor fix of the usage of TableGenAlexander Shaposhnikov1-13/+26
This is a small follow-up to the revisions r333117 and r331663. 1. Avoid the name conflicts of the generated variables for prefixes. 2. Apply clang-format -i -style=llvm to llvm-objcopy.cpp once again. 3. Add a test for the flag with double dash. Test plan: make check-all llvm-svn: 333120
2018-05-23[llvm-strip] Expose --keep-symbol optionAlexander Shaposhnikov1-0/+3
Expose --keep-symbol option in llvm-strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47222 llvm-svn: 333117
2018-05-22[llvm-objcopy] Fix the behavior of --strip-* and --keep-symbolAlexander Shaposhnikov1-45/+62
If one runs llvm-objcopy --strip-all --keep-symbol foo and the symbol table indeed contains the symbol "foo" then it should not be removed. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47052 llvm-svn: 333008
2018-05-22Revert "[llvm-objcopy] Add --strip-unneeded option"Paul Semel1-9/+0
There is a use after free I didn't see. Need to investigate. This reverts commit f7624abeb1f0d012309baf2e78cf2499fbfe5e5f. llvm-svn: 332925
2018-05-21[llvm-objcopy] Add --strip-unneeded optionPaul Semel1-0/+9
This option removes symbols that are not needed by relocations. Differential Revision: https://reviews.llvm.org/D46896 llvm-svn: 332915
2018-05-18[llvm-objcopy] Fix formattingAlexander Shaposhnikov1-8/+8
Apply clang-format -i -style=llvm to llvm-objcopy.cpp NFC. Test plan: make check-all llvm-svn: 332693
2018-05-15[llvm-objcopy] Add --only-keep-debug as a noopJake Ehrlich1-0/+2
This option just keeps being a problem and really needs to be implemented in some fashion. Implementing it properly requires some kind of "replaceSectionReference" method because all the existing links need to be maintained. The desired behavior is just for allocated sections to become NOBITS but actually implementing that is rather tricky due to the current design of llvm-objcopy. However converting allocated sections to NOBITS is just an optimization and not something debuggers need. Debuggers can debug a stripped executable and take an unstripped executable for that stripped executable as input. Additionally allocated sections account for a very small part of debug binaries so this optimization is quite small. I propose that for the time being we implement this as a NOP so that people can use llvm-objcopy where they need to, just in a sub-optimal way. This option has already blocked a lot of people and its currently blocking me. llvm-svn: 332396
2018-05-15[llvm-objcopy] Add --keep-symbol (-K) optionPaul Semel1-0/+7
This option permits to explicitly keep the specified symbol so that it doesn't get removed. Differential Revision: https://reviews.llvm.org/D46819 llvm-svn: 332356
2018-05-11[llvm-strip] Add support for -remove-sectionAlexander Shaposhnikov1-0/+4
This diff adds support for -remove-section to llvm-strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D46567 llvm-svn: 332081
2018-05-09[llvm-objcopy] Add --strip-symbol (-N) optionPaul Semel1-1/+10
llvm-svn: 331924
2018-05-08[llvm-objcopy] Fix exit codeAlexander Shaposhnikov1-3/+13
Set the exit code to 1 if no arguments are specified. Test plan: make check-all Differential revision: https://reviews.llvm.org/D46547 llvm-svn: 331776
2018-05-07[tools] Introduce llvm-stripAlexander Shaposhnikov1-16/+82
llvm-strip is supposed to be a drop-in replacement for binutils strip. To start the ball rolling this diff adds the initial bits for llvm-strip, more features will be added incrementally over time. Test plan: make check-all Differential revision: https://reviews.llvm.org/D46407 llvm-svn: 331663
2018-05-02[llvm-objcopy] Add --discard-all (-x) optionPaul Semel1-0/+10
llvm-svn: 331400
2018-05-02[llvm-objcopy] Add --weaken optionPaul Semel1-0/+6
llvm-svn: 331397
2018-04-27[llvm-objcopy] Add --weaken-symbol (-W) optionPaul Semel1-0/+8
llvm-svn: 331070
2018-04-27[llvm-objcopy] Add --globalize-symbol optionPaul Semel1-3/+8
llvm-svn: 331068
2018-04-26[llvm-objcopy] Implement --redefine-sym optionAlexander Shaposhnikov1-27/+28
This diff implements --redefine-sym option for changing the name of a symbol. Test plan: make check-all Differential revision: https://reviews.llvm.org/D46029 llvm-svn: 330973
2018-04-26[llvm-objcopy] Add --localize-symbol optionPaul Semel1-2/+19
llvm-svn: 330963
2018-04-24[llvm-objcopy] Adjust the code for the old versions of msvcAlexander Shaposhnikov1-1/+1
Follow-up for r330685. llvm-svn: 330686
2018-04-24Recommit "[llvm-objcopy] Switch over to using TableGen for parsing arguments"Alexander Shaposhnikov1-108/+175
Add explicit dependency on ObjcopyTableGen and rerun the tests on Windows. I will double-check the build bots and revert this commit if necessary. llvm-svn: 330685
2018-04-13Define InitLLVM to do common initialization all at once.Rui Ueyama1-7/+2
We have a few functions that virtually all command wants to run on process startup/shutdown. This patch adds InitLLVM class to do that all at once, so that we don't need to copy-n-paste boilerplate code to each llvm command's main() function. Differential Revision: https://reviews.llvm.org/D45602 llvm-svn: 330046
2018-04-12Revert "[llvm-objcopy] Switch over to using TableGen for parsing arguments"Jake Ehrlich1-175/+108
TableGen seems to work differently on windows. I'll need to revert this This reverts commit 7a153ddea067b24da59f6a66c733d79205969501. llvm-svn: 329867
2018-04-11[llvm-objcopy] Switch over to using TableGen for parsing argumentsJake Ehrlich1-108/+175
Swithces from using the command line library to using TableGen. This will allow llvm-strip to exist and allow refinements of the command line syntax. Differential Revision: https://reviews.llvm.org/D44236 llvm-svn: 329863
2018-02-09[llvm-objcopy] Make modifications in-place if output is not specifiedAlexander Shaposhnikov1-3/+5
If the output file is not specified make the modifications in-place (like binutils objcopy does). In particular, this fixes the behavior of Clang -gsplit-dwarf (if Clang is configured to use llvm-objcopy), previously it was creating .dwo files, but still leaving *dwo* sections in the original binary. Test plan: make check-all Differential revision: https://reviews.llvm.org/D42873 llvm-svn: 324783
2018-01-25[llvm-objcopy] Refactor llvm-objcopy to use reader and writer objectsJake Ehrlich1-76/+58
While writing code for input and output formats in llvm-objcopy it became apparent that there was a code health problem. This change attempts to solve that problem by refactoring the code to use Reader and Writer objects that can read in different objects in different formats, convert them to a single shared internal representation, and then write them to any other representation. New classes: Reader: the base class used to construct instances of the internal representation Writer: the base class used to write out instances of the internal representation ELFBuilder: a helper class for ELFWriter that takes an ELFFile and converts it to a Object SectionVisitor: it became necessary to remove writeSection from SectionBase because, under the new Reader/Writer scheme, it's possible to convert between ELF Types such as ELF32LE and ELF32BE. This isn't possible with writeSection because it (dynamically) depends on the underlying section type *and* (statically) depends on the ELF type. Bad things would happen if the underlying sections for ELF32LE were used for writing to ELF64BE. To avoid this code smell (which would have compiled, run, and output some nonsesnse) I decoupled writing of sections from a class. SectionWriter: This is just the ELFT templated implementation of SectionVisitor. Many classes now have this class as a friend so that the writing methods in this class can write out private data. ELFWriter: This is the Writer that outputs to ELF BinaryWriter: This is the Writer that outputs to Binary ElfType: Because the ELF Type is not a part of the Object anymore we need a way to construct the correct default Writer based on properties of the Reader. This enum just keeps track of the ELF type of the input so it can be used as the default output type as well. Object has correspondingly undergone some serious changes as well. It now has more generic methods for building and manipulating ELF binaries. This interface makes ELFBuilder easy enough to use and will make the BinaryReader/Builder easy to create as well. Most changes in this diff are cosmetic and deal with the fact that a method has been moved from one class to another or a change from a pointer to a reference. Almost no changes should result in a functional difference (this is after all a refactor). One minor functional change was made and the result can be seen in remove-shstrtab-error.test. The fact that it fails hasn't changed but the error message has changed because that failure is detected at a later point in the code now (because WriteSectionHeaders is a property of the ElfWriter *not* a property of the Object). I'd say roughly 80-90% of this code is cosmetically different, 10-19% is different but functionally the same, and 1-5% is functionally different despite not causing a change in tests. Differential Revision: https://reviews.llvm.org/D42222 llvm-svn: 323480
2018-01-25[llvm-objcopy] Add --add-gnu-debuglinkJake Ehrlich1-0/+8
This change adds support for --add-gnu-debuglink to llvm-objcopy Differential Revision: https://reviews.llvm.org/D41731 llvm-svn: 323477
2018-01-25Revert r322132; it appears to be an accidental commit, based on the commit ↵Aaron Ballman1-8/+0
message. The original author of the commit has not commented on whether this was accidental or purposeful, so if this revert is in error, the author can re-commit with an actual commit message. llvm-svn: 323466
2018-01-25Reverting r323463 as it appears to be an accidental commit. Regardless, it ↵Aaron Ballman1-58/+76
broke a lot of build bots, so reverting back to green. http://lab.llvm.org:8011/builders/lldb-amd64-ninja-netbsd8/builds/9294 http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/24084 http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/9567 llvm-svn: 323465
2018-01-25tmpJake Ehrlich1-76/+58
llvm-svn: 323463
2018-01-09tempJake Ehrlich1-0/+8
llvm-svn: 322132
2018-01-05[llvm-objcopy] Add --localize-hidden optionJake Ehrlich1-0/+12
This change adds support in llvm-objcopy for GNU objcopy's --localize-hidden option. This option changes every hidden or internal symbol into a local symbol. llvm-svn: 321884
2017-12-19[llvm-objcopy] Add option to add a progbits section from a fileJake Ehrlich1-1/+21
This change adds support for adding progbits sections with contents from a file Differential Revision: https://reviews.llvm.org/D41212 llvm-svn: 321047
2017-12-15[llvm-objcopy] Reformat everything using clang-format -iJake Ehrlich1-10/+8
Overtime some non-clang formatted code has creeped into llvm-objcopy. This patch fixes all of that. Differential Revision: https://reviews.llvm.org/D41262 llvm-svn: 320856