21 Commits

Author SHA1 Message Date
Peter Collingbourne
57bdd1c058 llvm-objcopy: Remove unused field. NFCI.
Differential Revision: https://reviews.llvm.org/D59126

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355892 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-12 02:17:01 +00:00
George Rimar
ee1b824708 [llvm-objcopy] - Fix --compress-debug-sections when there are relocations.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355821 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-11 11:01:24 +00:00
George Rimar
34045966ba [llvm-objcopy] - Remove dead code. NFCI.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355505 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-06 14:12:18 +00:00
George Rimar
1054a222d5 [llvm-objcopy] - Remove an excessive zlib::isAvailable() check and dead code.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355503 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-06 14:08:27 +00:00
George Rimar
c80500fed5 [llvm-objcopy] - Fix incorrect CompressedSection creation.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355501 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-06 14:01:54 +00:00
George Rimar
32f6332ef1 [llvm-objdump] - Improve the error message for "removing a section that is used by relocation" case.
This refines/improves the error message introduced in D58625

Differential revision: https://reviews.llvm.org/D58709

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355074 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-28 08:21:50 +00:00
George Rimar
ea5f709d73 [llvm-objcopy] - Check for invalidated relocations when removing a section.
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354962 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-27 11:18:27 +00:00
Jordan Rupprecht
1ef2f4ce53 [llvm-objcopy] Make removeSectionReferences batched
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354597 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 16:45:42 +00:00
Jordan Rupprecht
11549f9b9d [llvm-objcopy][NFC] Propagate errors in removeSymbols/removeSectionReferences
Reviewers: jhenderson, alexshap, jakehehrlich, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D57543

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352877 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 15:20:36 +00:00
Jordan Rupprecht
8cf7aa39d7 [llvm-objcopy] Return Error from Buffer::allocate(), [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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351896 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-22 23:49:16 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Jordan Rupprecht
aff9f2f0b9 [llvm-objcopy] Fix buildbots on older compilers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350343 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 19:09:00 +00:00
Jordan Rupprecht
22cd3d31e8 Fix typos in comments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350337 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 17:51:32 +00:00
Jordan Rupprecht
8dbe072cd5 [llvm-objcopy][ELF] Implement a mutable section visitor that updates size-related fields (Size, EntrySize, Align) before layout.
Summary:
Fix EntrySize, Size, and Align before doing layout calculation.

As a side cleanup, this removes a dependence on sizeof(Elf_Sym) within BinaryReader, so we can untemplatize that.

This unblocks a cleaner implementation of handling the -O<format> flag. See D53667 for a previous attempt. Actual implementation of the -O<format> flag will come in an upcoming commit, this is largely a NFC (although not _totally_ one, because alignment on binary input was actually wrong before).

Reviewers: jakehehrlich, jhenderson, alexshap, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D56211

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350336 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-03 17:45:30 +00:00
George Rimar
2033f0377d [llvm-objcopy] Use ELFOSABI_NONE instead of 0. NFC.
This was requested during the review of D55886.
(sorry, forgot to address this)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349741 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-20 10:59:52 +00:00
George Rimar
1224b482b4 [llvm-objcopy] - Do not drop the OS/ABI and ABIVersion fields of ELF header
This is https://bugs.llvm.org/show_bug.cgi?id=40005,

Patch teaches llvm-objcopy to preserve OS/ABI and ABIVersion fields of ELF header.
(Currently, it drops them to zero).

Differential revision: https://reviews.llvm.org/D55886

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349738 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-20 10:51:42 +00:00
Fangrui Song
53a62241d3 Use llvm::copy. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347126 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-17 01:44:25 +00:00
Fangrui Song
d2f818dc6a [llvm-objcopy] Use llvm::all_of and rename the variables "Segment" to avoid confusion with the type of the same name
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347123 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-17 01:15:55 +00:00
Jordan Rupprecht
1033d5958c [llvm-objcopy] Don't apply --localize flags to common symbols
Summary:
--localize-symbol and --localize-hidden will currently localize common symbols. GNU objcopy will not localize these symbols even when explicitly requested, which seems reasonable; common symbols should always be global so they can be merged during linking.

See PR39461

Reviewers: jakehehrlich, jhenderson, alexshap, MaskRay, espindola

Reviewed By: jakehehrlich, jhenderson, alexshap, MaskRay

Subscribers: emaste, arichardson, alexshap, MaskRay, llvm-commits

Differential Revision: https://reviews.llvm.org/D53782

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345856 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 17:26:36 +00:00
Fangrui Song
b530051d91 [llvm-objcopy] Use proper cases
Reviewers: jhenderson, alexshap, jakehehrlich, espindola, rupprecht

Reviewed By: jhenderson, rupprecht

Subscribers: emaste, arichardson, rupprecht, llvm-commits

Differential Revision: https://reviews.llvm.org/D53971

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345845 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 16:02:12 +00:00
Alexander Shaposhnikov
245f8d7f3f [llvm-objcopy] Move elf-specific code into subfolder
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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345544 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-29 21:22:58 +00:00