summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/Object.h
Commit message (Collapse)AuthorAgeFilesLines
* [llvm-objcopy] Move elf-specific code into subfolderAlexander Shaposhnikov2018-10-291-774/+0
| | | | | | | | | | | 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
* [llvm-objcopy] Introduce dispatch mechanism based on the inputAlexander Shaposhnikov2018-10-241-0/+3
| | | | | | | | | | | | | 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
* [llvm-objcopy] Factor out BufferAlexander Shaposhnikov2018-10-161-43/+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
* [llvm-objcopy] Factor out CopyConfigAlexander Shaposhnikov2018-10-111-9/+1
| | | | | | | | | | | | 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
* [llvm-objcopy] Adding support for decompressing zlib compressed dwarf sections.Puyan Lotfi2018-10-011-0/+32
| | | | | | | | | | | | | | | 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] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi2018-09-071-2/+25
| | | | | | | | | | | | | | | | | | | | | | | 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-071-25/+2
| | | | | | Various bots still fail for unknown reason. llvm-svn: 341613
* [llvm-objcopy] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi2018-09-061-2/+25
| | | | | | | | | | | | | | | | | | | | 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
* Revert r341342: Dwarf .debug section compression support (zlib, zlib-gnu).Chandler Carruth2018-09-041-25/+2
| | | | | | | | | | | | 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
* [llvm-objcopy] Dwarf .debug section compression support (zlib, zlib-gnu).Puyan Lotfi2018-09-031-2/+25
| | | | | | | | | | | | | | | | | | | 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-objcopy] Add support for -I binary -B <arch>.Jordan Rupprecht2018-08-171-6/+48
| | | | | | | | | | | | | | | | | 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-objcopy] NFC: Fix minor formatting issuesJordan Rupprecht2018-08-131-1/+1
| | | | llvm-svn: 339616
* [llvm-objcopy] NFC: consistently use typename ELFT::<X> definitions in headersJordan Rupprecht2018-08-101-0/+2
| | | | llvm-svn: 339448
* [llvm-objcopy] Add --prefix-symbols optionPaul Semel2018-08-091-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D50381 llvm-svn: 339362
* [llvm-objcopy] Add --dump-sectionPaul Semel2018-08-091-0/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D49979 llvm-svn: 339358
* [NFC][llvm-objcopy] Cleanup namespace usage in llvm-objcopy.Puyan Lotfi2018-07-181-0/+2
| | | | | | | | | | 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
* [llvm-objcopy] Add support for large indexesJake Ehrlich2018-07-161-4/+44
| | | | | | | | | | | | | | | | | | | 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
* [llvm-objcopy] Add support for static librariesAlexander Shaposhnikov2018-07-061-17/+54
| | | | | | | | | | | 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-071-5/+0
| | | | | | | | | | | | | | 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-objcopy] Fix null symbol handlingPaul Semel2018-06-011-1/+2
| | | | | | | | | 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-objcopy] Add --strip-unneeded optionPaul Semel2018-05-251-3/+8
| | | | | | Differential Revision: https://reviews.llvm.org/D46896 llvm-svn: 333267
* [llvm-objcopy] Fix the behavior of --strip-* and --keep-symbolAlexander Shaposhnikov2018-05-221-0/+1
| | | | | | | | | | | | 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
* Revert "[llvm-objcopy] Add --strip-unneeded option"Paul Semel2018-05-221-13/+3
| | | | | | | | There is a use after free I didn't see. Need to investigate. This reverts commit f7624abeb1f0d012309baf2e78cf2499fbfe5e5f. llvm-svn: 332925
* [llvm-objcopy] Add --strip-unneeded optionPaul Semel2018-05-211-3/+13
| | | | | | | | This option removes symbols that are not needed by relocations. Differential Revision: https://reviews.llvm.org/D46896 llvm-svn: 332915
* [llvm-objcopy] Add --strip-symbol (-N) optionPaul Semel2018-05-091-1/+6
| | | | llvm-svn: 331924
* [llvm-objcopy] Add --discard-all (-x) optionPaul Semel2018-05-021-0/+1
| | | | llvm-svn: 331400
* [llvm-objcopy] Implement --redefine-sym optionAlexander Shaposhnikov2018-04-261-1/+2
| | | | | | | | | | | 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
* [llvm-objcopy] Fix sh_linkAlexander Shaposhnikov2018-04-201-18/+9
| | | | | | | | | | | | This diff fixes sh_link for various types of sections (i.e. for SHT_ARM_EXIDX, SHT_HASH). In particular, this change enables us to use llvm-objcopy with clang -gsplit-dwarf for the target android-arm. Test plan: make check-all Differential revision: https://reviews.llvm.org/D45851 llvm-svn: 330478
* [llvm-objcopy] Implement support for section groupsAlexander Shaposhnikov2018-03-211-21/+52
| | | | | | | | | | | | | | | | | | | This diff adds support for SHT_GROUP sections to llvm-objcopy. Some sections are interrelated and comprise a group. For example, a definition of an inline function might require, in addition to the section containing its instructions, a read-only data section containing literals referenced inside the function. A section of the type SHT_GROUP contains the indices of the group members, therefore, it needs to be updated whenever the indices change. Similarly, the fields sh_link, sh_info should be recalculated as well. [Resubmit r328012 with the proper handling of endianness] Test plan: make check-all Differential revision: https://reviews.llvm.org/D43996 llvm-svn: 328143
* [llvm-objcopy] Revert r328012Alexander Shaposhnikov2018-03-201-45/+20
| | | | | | | Temporarily revert r328012 (since it broke down the big-endian bots), will resubmit an updated version later. llvm-svn: 328024
* [llvm-objcopy] Implement support for section groupsAlexander Shaposhnikov2018-03-201-20/+45
| | | | | | | | | | | | | | | | | This diff adds support for SHT_GROUP sections to llvm-objcopy. Some sections are interrelated and comprise a group. For example, a definition of an inline function might require, in addition to the section containing its instructions, a read-only data section containing literals referenced inside the function. A section of the type SHT_GROUP contains the indices of the group members, therefore, it needs to be updated whenever the indices change. Similarly, the fields sh_link, sh_info should be recalculated as well. Test plan: make check-all Differential revision: https://reviews.llvm.org/D43996 llvm-svn: 328012
* Revert "[llvm-objcopy] Add support for large indexes"Jake Ehrlich2018-03-071-42/+3
| | | | | | | | Not all build bots have unzip which I used in a test. This reverts commit 0b1f26d39ea42dd3716b525fbc8c78d8c7bb4479. llvm-svn: 326941
* [llvm-objcopy] Add support for large indexesJake Ehrlich2018-03-071-3/+42
| | | | | | | | | | | | | Because of -ffunction-sections (and maybe other use cases I'm not aware of?) it can occur that we need more than 0xfeff sections but ELF dosn't support that many sections. To solve this problem SHN_XINDEX exists and with it come a whole host of changes for section indexes everywhere. This change adds support for those cases which should allow llvm-objcopy to copy binaries that have an arbitrary number of sections. Differential Revision: https://reviews.llvm.org/D42516 llvm-svn: 326940
* [llvm-objcopy] Fix typo in setSymTabAlexander Shaposhnikov2018-02-241-2/+3
| | | | | | | | | | | | This diff fixes the name of the argument of setSymTab and makes setSymTab/setStrTab private (to make the public interface a bit cleaner). Test plan: make check-all Differential revision: https://reviews.llvm.org/D43661 llvm-svn: 326005
* [llvm-objcopy] Fix handling of zero-size segments in llvm-objcopyJake Ehrlich2018-02-141-0/+13
| | | | | | | | | | | | | | | | | Some ELF files produced by lld may have zero-size segment placeholders as shown below. Since GNU_STACK Offset is 0, the current code makes it the lowest used offset, and relocates all the segments over the ELF header. The resulting binary is total garbage. This change fixes how llvm-objcopy handles PT_PHDR properlly by treating ELF headers and the program header table as segments to allow the layout algorithm decide where those should go. Author: vit9696 Differential Revision: https://reviews.llvm.org/D42872 llvm-svn: 325189
* Reland "[llvm-objcopy] Refactor llvm-objcopy to use reader and writer objects"Jake Ehrlich2018-01-261-1/+1
| | | | | | | Somehow I reverted changes I made in a previous Reland. This change re-relands unconfusing a varible name with a type name. llvm-svn: 323494
* Revert "Reland "[llvm-objcopy] Refactor llvm-objcopy to use reader and ↵Jake Ehrlich2018-01-261-1/+1
| | | | | | | | | | | | writer objects"" Tests were working on my system because the old correct files were left over and the new bug was that the output files were not being output at all. Consequently the test work on my system but fail on any other system. This reverts commit r323484. llvm-svn: 323486
* Reland "[llvm-objcopy] Refactor llvm-objcopy to use reader and writer objects"Jake Ehrlich2018-01-261-1/+1
| | | | | | I named a varible the same as a type which caused a warning. I also had unamed varibles. llvm-svn: 323484
* [llvm-objcopy] Refactor llvm-objcopy to use reader and writer objectsJake Ehrlich2018-01-251-91/+234
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [llvm-objcopy] Add --add-gnu-debuglinkJake Ehrlich2018-01-251-0/+20
| | | | | | | | This change adds support for --add-gnu-debuglink to llvm-objcopy Differential Revision: https://reviews.llvm.org/D41731 llvm-svn: 323477
* Revert r322132; it appears to be an accidental commit, based on the commit ↵Aaron Ballman2018-01-251-20/+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
* Reverting r323463 as it appears to be an accidental commit. Regardless, it ↵Aaron Ballman2018-01-251-234/+91
| | | | | | | | | | 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
* tmpJake Ehrlich2018-01-251-91/+234
| | | | llvm-svn: 323463
* tempJake Ehrlich2018-01-091-0/+20
| | | | llvm-svn: 322132
* [llvm-objcopy] Add --localize-hidden optionJake Ehrlich2018-01-051-1/+2
| | | | | | | 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
* [llvm-objcopy] Add support for visibilityJake Ehrlich2018-01-021-2/+3
| | | | | | | I have no clue how this was missed when symbol table support was added. This change ensures that the visibility of symbols is preserved by default. llvm-svn: 321681
* [llvm-objcopy] Add option to add a progbits section from a fileJake Ehrlich2017-12-191-0/+15
| | | | | | | | This change adds support for adding progbits sections with contents from a file Differential Revision: https://reviews.llvm.org/D41212 llvm-svn: 321047
* [llvm-objcopy] Add support for --only-keep/-j and --keepJake Ehrlich2017-11-301-0/+2
| | | | | | | | | | | | | This change adds support for the --only-keep option and the -j alias as well. A common use case for these being used together is to dump a specific section's data. Additionally the --keep option is added (GNU objcopy doesn't have this) to avoid removing a bunch of things. This allows people to err on the side of stripping aggressively and then to keep the specific bits that they need for their application. Differential Revision: https://reviews.llvm.org/D39021 llvm-svn: 319467
* [llvm-objcopy] Add support for dwarf fissionJake Ehrlich2017-11-031-0/+1
| | | | | | | | This change adds support for dwarf fission. Differential Revision: https://reviews.llvm.org/D39207 llvm-svn: 317350
* [dsymutil, llvm-objcopy] Fix some Clang-tidy modernize and Include What You ↵Eugene Zelenko2017-11-011-90/+112
| | | | | | Use warnings; other minor fixes (NFC). llvm-svn: 317123
OpenPOWER on IntegriCloud