summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/Object.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [NFC][llvm-objcopy] Cleanup namespace usage in llvm-objcopy.Puyan Lotfi2018-07-181-0/+3
| | | | | | | | | | 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-161-5/+5
| | | | | | | | 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-161-17/+171
| | | | | | | | | | | | | | | | | | | 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-46/+58
| | | | | | | | | | | 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-1/+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-objcopy] Fix null symbol handlingPaul Semel2018-06-011-3/+3
| | | | | | | | | 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: 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
* [llvm-objcopy] Add --strip-unneeded optionPaul Semel2018-05-251-0/+16
| | | | | | Differential Revision: https://reviews.llvm.org/D46896 llvm-svn: 333267
* Revert "[llvm-objcopy] Add --strip-unneeded option"Paul Semel2018-05-221-15/+1
| | | | | | | | 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-1/+15
| | | | | | | | 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/+28
| | | | llvm-svn: 331924
* [llvm-objcopy] Add --discard-all (-x) optionPaul Semel2018-05-021-6/+10
| | | | llvm-svn: 331400
* [llvm-objcopy] Implement --redefine-sym optionAlexander Shaposhnikov2018-04-261-9/+3
| | | | | | | | | | | 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-16/+11
| | | | | | | | | | | | 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-24/+85
| | | | | | | | | | | | | | | | | | | 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-75/+23
| | | | | | | 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-23/+75
| | | | | | | | | | | | | | | | | 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-173/+24
| | | | | | | | 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-24/+173
| | | | | | | | | | | | | 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] Use the full filename in --add-gnu-debuglinkAlexander Richardson2018-02-191-2/+2
| | | | | | | | | | | | | | | | | Summary: The current implementation was writing the file name without the extension whereas GNU objcopy writes the full filename. With this change GDB will now load the .debug file instead of silently ignoring it. Reviewers: jakehehrlich, jhenderson Reviewed By: jakehehrlich Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D43474 llvm-svn: 325528
* [llvm-objcopy] Fix handling of zero-size segments in llvm-objcopyJake Ehrlich2018-02-141-28/+57
| | | | | | | | | | | | | | | | | 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-10/+10
| | | | | | | 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
* Reland "[llvm-objcopy] Refactor llvm-objcopy to use reader and writer objects"Jake Ehrlich2018-01-261-4/+4
| | | | | | I had more unused varibles. This change removes those to get rid of warnings. llvm-svn: 323493
* Reland "[llvm-objcopy] Refactor llvm-objcopy to use reader and writer objects"Jake Ehrlich2018-01-261-0/+2
| | | | | | Added line to output the proper files in the output to binary case. llvm-svn: 323489
* Revert "Reland "[llvm-objcopy] Refactor llvm-objcopy to use reader and ↵Jake Ehrlich2018-01-261-10/+10
| | | | | | | | | | | | 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-10/+10
| | | | | | 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-270/+332
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+49
| | | | | | | | 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-49/+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-332/+270
| | | | | | | | | | 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-270/+332
| | | | llvm-svn: 323463
* [llvm-objcopy] Use physical instead of virtual address when aligning and ↵Jake Ehrlich2018-01-221-16/+39
| | | | | | | | | | | | | | | | | | | | | placing sections in binary For sections with different virtual and physical addresses, alignment and placement in the output binary should be based on the physical address. Ran into this problem with a bare metal ARM project where llvm-objcopy added a lot of zero-padding before the .data section that had differing addresses. GNU objcopy did not add the padding, and after this fix, neither does llvm-objcopy. Update a test case so a section has different physical and virtual addresses. Fixes B35708 Authored By: Owen Shaw (owenpshaw) Differential Revision: https://reviews.llvm.org/D41619 llvm-svn: 323144
* tempJake Ehrlich2018-01-091-0/+49
| | | | llvm-svn: 322132
* [llvm-objcopy] Add --localize-hidden optionJake Ehrlich2018-01-051-0/+19
| | | | | | | 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/+5
| | | | | | | 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/+12
| | | | | | | | 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] Reformat everything using clang-format -iJake Ehrlich2017-12-151-16/+14
| | | | | | | | | 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
* [llvm-objcopy] Change -O binary to respect section removal and behave like ↵Jake Ehrlich2017-11-151-63/+129
| | | | | | | | | | | | | | | | GNU objcopy The original -O binary implementation just copied segment data from the object and dumped it into a file. This doesn't take into account any operations performed on objects such as section removal. GNU objcopy has some specific behavior that we'd also like to respect. For instance using -O binary and -j <some_section> will dump <some_section> to a file. This change implements GNU objcopy style -O binary to as close of an approximation as I can determine. Differential Revision: https://reviews.llvm.org/D39713 llvm-svn: 318324
* [llvm-objcopy] Fix bug in how segment alignment was being handledJake Ehrlich2017-11-021-3/+17
| | | | | | | | | | | | | | | Just aligning segment offsets to segment alignment is incorrect and also wastes more space than is needed. The requirement is that p_offset == p_addr modulo p_align *not* that p_offset == 0 modulo p_align. Generally speaking we've been using p_addr == 0 modulo p_align. In fact yaml2obj can't even produce a valid situation which causes llvm-objcopy to produce incorrect results because alignment and offset were both inherited from the sections the program header covers. This change fixes this bad behavior in llvm-objcopy. Differential Revision: https://reviews.llvm.org/D39132 llvm-svn: 317284
* [dsymutil, llvm-objcopy] Fix some Clang-tidy modernize and Include What You ↵Eugene Zelenko2017-11-011-31/+48
| | | | | | Use warnings; other minor fixes (NFC). llvm-svn: 317123
* Revert "[ADT] Make Twine's copy constructor private."Zachary Turner2017-10-111-3/+3
| | | | | | | | | | This reverts commit 4e4ee1c507e2707bb3c208e1e1b6551c3015cbf5. This is failing due to some code that isn't built on MSVC so I didn't catch. Not immediately obvious how to fix this at first glance, so I'm reverting for now. llvm-svn: 315536
* [ADT] Make Twine's copy constructor private.Zachary Turner2017-10-111-3/+3
| | | | | | | | | | | | | | | | | There's a lot of misuse of Twine scattered around LLVM. This ranges in severity from benign (returning a Twine from a function by value that is just a string literal) to pretty sketchy (storing a Twine by value in a class). While there are some uses for copying Twines, most of the very compelling ones are confined to the Twine class implementation itself, and other uses are either dubious or easily worked around. This patch makes Twine's copy constructor private, and fixes up all callsites. Differential Revision: https://reviews.llvm.org/D38767 llvm-svn: 315530
* Reland "[llvm-objcopy] Add support for --strip-sections to remove all ↵Jake Ehrlich2017-10-111-19/+32
| | | | | | | | | | | | | | | | | | | | | section headers leaving only program headers and loadable segment data" ubsan caught an issue I made where I was converting a null pointer to a reference. elf utils implements a particularly extreme form of stripping that I'd like to support. eu-strip has an option called "strip-sections" that removes all section headers and leaves only program headers and the segment data. I have implemented this option partly as a test but mainly because in Fuchsia we would like to use this option to minimize the size of our executables. The other strip options that are on my list include --strip-all and --strip-debug. This is a preliminary implementation that I'd like to start using in Fuchsia builds if possible. This change implements such a stripping option for llvm-objcopy Differential Revision: https://reviews.llvm.org/D38335 llvm-svn: 315484
* Revert "[llvm-objcopy] Add support for --strip-sections to remove all ↵Jake Ehrlich2017-10-111-28/+17
| | | | | | | | section headers leaving only program headers and loadable segment data" This reverts commit rL315412 llvm-svn: 315417
* [llvm-objcopy] Add support for --strip-sections to remove all section ↵Jake Ehrlich2017-10-111-17/+28
| | | | | | | | | | | | | | | | | | headers leaving only program headers and loadable segment data elf utils implements a particularly extreme form of stripping that I'd like to support. eu-strip has an option called "strip-sections" that removes all section headers and leaves only program headers and the segment data. I have implemented this option partly as a test but mainly because in Fuchsia we would like to use this option to minimize the size of our executables. The other strip options that are on my list include --strip-all and --strip-debug. This is a preliminary implementation that I'd like to start using in Fuchsia builds if possible. This change implements such a stripping option for llvm-objcopy Differential Revision: https://reviews.llvm.org/D38335 llvm-svn: 315412
* [llvm-objcopy] Fix latent bug that allowed some Sections to be improperly ↵Jake Ehrlich2017-10-101-15/+9
| | | | | | | | | | | | | | | | cast to StringTableSections If a Section had Type SHT_STRTAB (which could happen if you had a .dynstr section) it was possible to cast Section to StringTableSection and get away with any operation that was supported by SectionBase without it being noticed. This change makes this bug easier to notice and fixes it where it occurred. It also made me realize that there was some duplication of efforts in the loop that calls ::initialize. These issues are all fixed by this change. Differential Revision: https://reviews.llvm.org/D38329 llvm-svn: 315372
* [llvm-objcopy] Add support for removing sectionsJake Ehrlich2017-10-101-3/+74
| | | | | | | | | | | This change adds support for removing sections using the -R field (as GNU objcopy does as well). This change should let us add many helpful tests and is a proper stepping stone for adding more general kinds of stripping. Differential Revision: https://reviews.llvm.org/D38260 llvm-svn: 315346
* Revert "temporary"Jake Ehrlich2017-10-101-74/+3
| | | | | | | | | I forgot to add a proper commit message. I'm reverting this to fix that. This reverts commit r315344. llvm-svn: 315345
* temporaryJake Ehrlich2017-10-101-3/+74
| | | | llvm-svn: 315344
* [llvm-objcopy] Fix major layout bugs in llvm-objcopyJake Ehrlich2017-10-041-19/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Somehow a few massive errors slipped though the cracks of testing. 1. The code in Segment::finalize was left over from the old layout algorithm. In certain situations this would cause very strange issues with segment layout. For instance in the shift-segments.test case it would cause the second segment to have the same offset as the first. 2. In debugging this I discovered another issue. Namely section alignment was not being computed based on Section->Align but instead Section->Offset which is bizarre and makes no sense. I have no clue how it worked in the first place. This issue is also fixed 3. Fixing #2 exposed a bug where things were not being written past the end of the file that technically should have been. This was because in certain cases (like overlapping-segments) the end of the file wouldn't always be bumped if the offset could be chosen relative to an existing segment that already had it's offset chosen. For fully nested segments this is fine but for overlapping segments this leaves the end of the file short. So I changed how the offset is bumped when looping though segments. Differential Revision: https://reviews.llvm.org/D38436 llvm-svn: 314918
OpenPOWER on IntegriCloud