292 Commits

Author SHA1 Message Date
Eugene Leviant
ae2e11429b [llvm-objcopy] Fill .symtab_shndx section correctly
Differential revision: https://reviews.llvm.org/D60555


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358278 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-12 11:59:30 +00:00
James Henderson
4e6b00fa2c [llvm-objcopy] Make section rename/set flags case-insensitive
This fixes https://bugs.llvm.org/show_bug.cgi?id=41305. GNU objcopy
--set-section-flags/--rename-section flags are case-insensitive, so this
patch updates llvm-objcopy to match.

Reviewed by: grimar

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357590 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 14:40:27 +00:00
Jordan Rupprecht
b9af20dec1 [llvm-objcopy] Change SHT_NOBITS to SHT_PROBITS for some --set-section-flags
Summary:
Some flags accepted by --set-section-flags and --rename-section can change a SHT_NOBITS section to a SHT_PROGBITS section. Note that none of them can change a SHT_PROGBITS to SHT_NOBITS.

The full list (found via experimentation of individually setting each flag) that does this is: contents, load, noload, code, data, rom, and debug.

This was found by testing llvm-objcopy with the gnu binutils test suite, specifically this test case: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/testsuite/binutils-all/copy-1.d;h=f2b0d9e90df738c2891b4d5c7b62f62894b556ca;hb=HEAD

Reviewers: jhenderson, grimar, jakehehrlich, alexshap, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, MaskRay, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357492 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-02 16:49:56 +00:00
James Henderson
925602b588 [llvm-objcopy]Allow llvm-objcopy to be used on an ELF file with no section headers
This patch fixes https://bugs.llvm.org/show_bug.cgi?id=41293 and
https://bugs.llvm.org/show_bug.cgi?id=41045. llvm-objcopy assumed that
it could always read a section header string table. This isn't the case
when the sections were previously all stripped, and the e_shstrndx field
was set to 0. This patch fixes this. It also fixes a double space in an
error message relating to this issue, and prevents llvm-objcopy from
adding extra space for non-existent section headers, meaning that
--strip-sections on the output of a previous --strip-sections run
produces identical output, simplifying the test.

Reviewed by: rupprecht, grimar

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357475 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-02 14:11:13 +00:00
Yi Kong
7177f4e661 [llvm-objcopy] Add --keep-symbols option
Differential Revision: https://reviews.llvm.org/D60054

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357418 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-01 18:12:43 +00:00
Fangrui Song
4fd25f1573 [llvm-objcopy] Replace the size() helper with SectionTableRef::size
Summary:
BTW, STLExtras.h provides llvm::size() which is similar to std::size()
for random access iterators. However, if we prefer qualified
llvm::size(), the member function .size() will be more convenient.

Reviewers: jhenderson, jakehehrlich, rupprecht, grimar, alexshap, espindola

Reviewed By: grimar

Subscribers: emaste, arichardson, jdoerfert, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357347 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-30 14:08:59 +00:00
Fangrui Song
4086f0cda4 [llvm-objcopy] Fix case style of LayoutSegments. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357265 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-29 15:27:58 +00:00
Fangrui Song
b149dcc9a0 [llvm-objcopy] Delete two redundant reinterpret_cast. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357238 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-29 08:08:20 +00:00
Jordan Rupprecht
d7f746ca03 [llvm-objcopy][NFC] Move ELF-specific logic into /ELF/ directory
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357199 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-28 18:27:00 +00:00
George Rimar
dca7346ad9 [llvm-objcopy] - Strip sections before symbols.
This is a fix for https://bugs.llvm.org/show_bug.cgi?id=40007.

Idea is to swap the order of stripping. So that we strip sections before
symbols what allows us to strip relocation sections without emitting
the error about relative symbols.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357017 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-26 18:42:15 +00:00
James Henderson
ea6301340f [llvm-objcopy]Preserve data in segments not covered by sections
llvm-objcopy previously knew nothing about data in segments that wasn't
covered by section headers, meaning that it wrote zeroes instead of what
was there. As it is possible for this data to be useful to the loader,
this patch causes llvm-objcopy to start preserving this data. Data in
sections that are explicitly removed continues to be written as zeroes.

This fixes https://bugs.llvm.org/show_bug.cgi?id=41005.

Reviewed by: jakehehrlich, rupprecht

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356919 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-25 16:36:26 +00:00
George Rimar
b05515fb57 [llvm-objcopy] - Refactor the code. NFC.
The idea of the patch is about to move out the code to a new
helper static functions (to reduce the size of 'handleArgs' and to
isolate the parts of it's logic).

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356889 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-25 12:34:25 +00:00
George Rimar
d33d5ac7aa Recommit r356738 "[llvm-objcopy] - Implement replaceSectionReferences for GroupSection class."
Fix: r356853 + set AddressAlign to 4 in 
Inputs/compress-debug-sections.yaml for the new group section introduced.

Original commit message:

Currently, llvm-objcopy incorrectly handles compression and decompression of the
sections from COMDAT groups, because we do not implement the
replaceSectionReferences for this type of the sections.

The patch does that.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356856 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-24 14:41:45 +00:00
George Rimar
8b8a0a7835 [llvm-objcopy] - Report SHT_GROUP sections with invalid alignment.
This patch fixes the reason of ubsan failure (UB detected) 
happened after landing the D59638 (I had to revert it).
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/11760/steps/check-llvm%20ubsan/logs/stdio)

Problem is the following. Our implementation of GroupSection assumes that
its address is 4 bytes aligned when writes it:

template <class ELFT>
void ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) {
  ELF::Elf32_Word *Buf =
      reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset);
...

But the test case for D59638 did not set AddressAlign in YAML. So address was
not 4 bytes aligned since Sec.Offset was odd. That triggered the issue.

This patch teaches llvm-objcopy to report an error for such sections (which should
not met in reality), what is better than having UB.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356853 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-24 13:31:08 +00:00
George Rimar
acb922e7f8 Revert r356738 "[llvm-objcopy] - Implement replaceSectionReferences for GroupSection class."
Seems this broke ubsan bot:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/11760

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356745 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-22 12:14:04 +00:00
George Rimar
76308dc543 [llvm-objcopy] - Implement replaceSectionReferences for GroupSection class.
Currently, llvm-objcopy incorrectly handles compression and decompression of the
sections from COMDAT groups, because we do not implement the
replaceSectionReferences for this type of the sections.

The patch does that.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356738 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-22 10:24:37 +00:00
James Henderson
3c1091398e [llvm-objcopy]Add support for *-freebsd output formats
GNU objcopy can support output formats like elf32-i386-freebsd and
elf64-x86-64-freebsd. The only difference from their regular non-freebsd
counterparts that I have observed is that the freebsd versions set the
OS/ABI field to ELFOSABI_FREEBSD. This patch sets the OS/ABI field
according based on the format whenever --output-format is specified.

Reviewed by: rupprecht, grimar

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356737 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-22 10:21:09 +00:00
George Rimar
e9fd37a749 [llvm-objcopy] - Use replaceSectionReferences to update the sections for symbols in symbol table.
If the compression was used and we had a symbol not involved in relocation,
we never updated its section and it was silently removed from the output.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356554 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-20 13:57:47 +00:00
Jake Ehrlich
bb22cd1f19 [llvm-objcopy] Make .build-id linking atomic
This change makes linking into .build-id atomic and safe to use.
Some users under particular workflows are reporting that this races
more than half the time under particular conditions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356404 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-18 20:35:18 +00:00
George Rimar
ab0a1d7699 [llvm-objcopy] - Calculate the string table section sizes correctly.
This fixes the https://bugs.llvm.org/show_bug.cgi?id=40980.

Previously if string optimization occurred as a result of
StringTableBuilder's finalize() method, the size wasn't updated.

This hopefully also makes the interaction between sections during finalization
processes a bit more clear.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356371 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-18 14:27:41 +00:00
Fangrui Song
c2226fc117 [llvm-objcopy] Delete unused parameter from replaceDebugSections. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356245 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-15 10:27:28 +00:00
Fangrui Song
85356e1a66 [llvm-objcopy] Don't use {}; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356244 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-15 10:20:51 +00:00
Jordan Rupprecht
30e91d46e1 [llvm-strip] Hook up (unimplemented) --only-keep-debug
For ELF, we accept but ignore --only-keep-debug. Do the same for llvm-strip.

COFF does implement this, so update the test that it is supported.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356207 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-14 21:51:42 +00:00
James Henderson
d5ba5901b9 [llvm-objcopy]Don't implicitly strip sections in segments
This patch changes llvm-objcopy's behaviour to not strip sections that
are in segments, if they otherwise would be due to a stripping operation
(--strip-all, --strip-sections, --strip-non-alloc). This preserves the
segment contents. It does not change the behaviour of --strip-all-gnu
(although we could choose to do so), because GNU objcopy's behaviour in
this case seems to be to strip the section, nor does it prevent removing
of sections in segments with --remove-section (if a user REALLY wants to
remove a section, we should probably let them, although I could be
persuaded that warning might be appropriate). Tests have been added to
show this latter behaviour.

This fixes https://bugs.llvm.org/show_bug.cgi?id=41006.

Reviewed by: grimar, rupprecht, jakehehrlich

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

This is a reland of r356129, attempting to fix greendragon failures
due to a suspected compatibility issue with od on the greendragon bots
versus other versions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356136 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-14 11:47:41 +00:00
James Henderson
2c597b63fe Revert r356129 due to greendragon bot failures
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356133 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-14 11:23:04 +00:00
James Henderson
e83676d510 [llvm-objcopy]Don't implicitly strip sections in segments
This patch changes llvm-objcopy's behaviour to not strip sections that
are in segments, if they otherwise would be due to a stripping operation
(--strip-all, --strip-sections, --strip-non-alloc). This preserves the
segment contents. It does not change the behaviour of --strip-all-gnu
(although we could choose to do so), because GNU objcopy's behaviour in
this case seems to be to strip the section, nor does it prevent removing
of sections in segments with --remove-section (if a user REALLY wants to
remove a section, we should probably let them, although I could be
persuaded that warning might be appropriate). Tests have been added to
show this latter behaviour.

This fixes https://bugs.llvm.org/show_bug.cgi?id=41006.

Reviewed by: grimar, rupprecht, jakehehrlich

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356129 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-14 10:20:27 +00:00
Jordan Rupprecht
0502ddb2a6 [llvm-objcopy][NFC] Remove unnecessary llvm-objcopy.h #includes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356109 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-13 23:40:16 +00:00
Jordan Rupprecht
86c9a48802 [llvm-objcopy] Cleanup errors from CopyConfig and remove llvm-objcopy.h dependency
error() was previously cleaned up from CopyConfig, but new uses were introduced.

This also tweaks the error message for --add-symbol to report all invalid flags.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356105 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-13 22:26:01 +00:00
Eugene Leviant
c3ad5d9485 [llvm-objcopy] Remove unneeded checks. NFC
Differential revision: https://reviews.llvm.org/D59081


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355914 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-12 12:41:06 +00:00
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
a855622c49 [llvm-objcopy] - Simplify isCompressable and fix the issue relative.
When --compress-debug-sections is given, llvm-objcopy do not compress
sections that have "ZLIB" header in data. Normally this signature is used
in zlib-gnu compression format. But if zlib-gnu used then the name of the compressed
section should start from .z* (e.g .zdebug_info). If it does not, then it is not
a zlib-gnu format and section should be treated as a normal uncompressed section.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355399 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-05 13:07:43 +00:00
George Rimar
de9aea9530 [llvm-objcopy] - Report "no zlib available" error properly when --compress-debug-sections is used.
If zlib is not available, and --compress-debug-sections is passed, 
we want to report an error. Currently, it is only reported for
--compress_debug_sections= form of the option.

Fixes the https://bugs.llvm.org/show_bug.cgi?id=40886.

I do not think there is a way to write a test for this.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355391 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-05 11:32:14 +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
Simon Pilgrim
da6598a60c Fix Wenum-compare gcc7 warning. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354958 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-27 10:19:53 +00:00
Eugene Leviant
1f205834bb [llvm-objcopy] Add --set-start, --change-start and --adjust-start
Differential revision: https://reviews.llvm.org/D58173


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354854 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-26 09:24:22 +00:00
Eugene Leviant
b5395dc0fc [llvm-objcopy] Add --add-symbol
Differential revision: https://reviews.llvm.org/D58234


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354787 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-25 14:12:41 +00:00
Jordan Rupprecht
7f352a421a [llvm-objcopy][NFC] Add std::move() to fix older BB
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354603 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 17:24:55 +00:00
Jordan Rupprecht
794244932b [llvm-objcopy][NFC] More error cleanup
Summary:
This removes calls to `error()`/`reportError()` in the main driver (llvm-objcopy.cpp) as well as the associated argv-parsing (CopyConfig.cpp). `logAllUnhandledErrors()` is now the main way to print errors.

There are still a few uses from within the per-arch drivers, so we can't delete them yet... but almost!

Reviewers: jhenderson, alexshap, espindola

Reviewed By: jhenderson

Subscribers: emaste, arichardson, jakehehrlich, jdoerfert, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354600 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 17:05:19 +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
Eugene Leviant
cb9edfda6c [llvm-objcopy] Add --strip-unneeded-symbol(s)
Differential revision: https://reviews.llvm.org/D58027


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353919 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-13 07:34:54 +00:00
Eugene Leviant
aed0779715 Small refactoring of FileError. NFC.
Differential revision: https://reviews.llvm.org/D57945


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353679 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-11 09:49:37 +00:00
Chandler Carruth
68e4016eed Update new files added to llvm-objcopy to use the new file header.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353666 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-11 08:25:19 +00:00
Eugene Leviant
e436b1687a [llvm-objcopy] Add few file processing directives
Differential revision: https://reviews.llvm.org/D57877


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353521 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-08 14:37:54 +00:00
Eugene Leviant
5f86a06337 [llvm-objcopy] Add --redefine-syms
Differential revision: https://reviews.llvm.org/D57738


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353509 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-08 10:33:16 +00:00
Eugene Leviant
e9f465a6a8 [llvm-objcopy] Allow regular expressions in name comparison
Differential revision: https://reviews.llvm.org/D57517


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353289 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-06 11:00:07 +00:00