1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
Commit Graph

235 Commits

Author SHA1 Message Date
Alexander Shaposhnikov
ebcba7c93c [tools] Introduce llvm-strip
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-07 19:32:09 +00:00
Paul Semel
de5f098777 [llvm-objcopy] Add --discard-all (-x) option
llvm-svn: 331400
2018-05-02 20:19:22 +00:00
Paul Semel
9070f9fa91 [llvm-objcopy] Add --weaken option
llvm-svn: 331397
2018-05-02 20:14:49 +00:00
Paul Semel
9f7c96bb7c [llvm-objcopy] Add --weaken-symbol (-W) option
llvm-svn: 331070
2018-04-27 19:16:27 +00:00
Paul Semel
4f7c52eb8c [llvm-objcopy] Add --globalize-symbol option
llvm-svn: 331068
2018-04-27 19:09:44 +00:00
Alexander Shaposhnikov
9280736736 [llvm-objcopy] Implement --redefine-sym option
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 18:28:17 +00:00
Paul Semel
a9fcbb5878 [llvm-objcopy] Add --localize-symbol option
llvm-svn: 330963
2018-04-26 17:44:43 +00:00
Alexander Shaposhnikov
c9587757a5 Recommit "[llvm-objcopy] Switch over to using TableGen for parsing arguments"
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-24 05:43:32 +00:00
Alexander Shaposhnikov
ce08a9fffe [llvm-objcopy] Fix sh_link
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
2018-04-20 20:46:04 +00:00
Jake Ehrlich
8aef1bb4cd Revert "[llvm-objcopy] Switch over to using TableGen for parsing arguments"
TableGen seems to work differently on windows. I'll need to revert this

This reverts commit 7a153ddea067b24da59f6a66c733d79205969501.

llvm-svn: 329867
2018-04-12 00:40:50 +00:00
Jake Ehrlich
e9823fde1e [llvm-objcopy] Switch over to using TableGen for parsing arguments
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-04-11 23:37:03 +00:00
Alexander Shaposhnikov
7e2d822599 [llvm-objcopy] Implement support for section groups
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
2018-03-21 19:53:44 +00:00
Alexander Shaposhnikov
fdd845e8b4 [llvm-objcopy] Revert the tests from r328012
Temporarily revert the tests from r328012 as well.

llvm-svn: 328026
2018-03-20 19:50:14 +00:00
Alexander Shaposhnikov
e7f6fbc46e [llvm-objcopy] Implement support for section groups
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
2018-03-20 18:20:42 +00:00
Jake Ehrlich
cf89f75d39 Revert "[llvm-objcopy] Add support for large indexes"
Not all build bots have unzip which I used in a test.

This reverts commit 0b1f26d39ea42dd3716b525fbc8c78d8c7bb4479.

llvm-svn: 326941
2018-03-07 20:33:02 +00:00
Jake Ehrlich
9c26f5f5ea [llvm-objcopy] Add support for large indexes
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
2018-03-07 19:59:15 +00:00
Alexander Richardson
a80b0b4cfd [llvm-objcopy] Use the full filename in --add-gnu-debuglink
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
2018-02-19 19:53:44 +00:00
Jake Ehrlich
f69705a3db [llvm-objcopy] Fix handling of zero-size segments in llvm-objcopy
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
2018-02-14 23:31:33 +00:00
Alexander Shaposhnikov
ec7f07b81d [llvm-objcopy] Make modifications in-place if output is not specified
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-02-09 23:33:31 +00:00
Jake Ehrlich
07922aa56a [llvm-objcopy] Refactor llvm-objcopy to use reader and writer objects
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 22:46:17 +00:00
Jake Ehrlich
a86044965a [llvm-objcopy] Add --add-gnu-debuglink
This change adds support for --add-gnu-debuglink to llvm-objcopy

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

llvm-svn: 323477
2018-01-25 22:15:14 +00:00
Aaron Ballman
d75397b53e Revert r322132; it appears to be an accidental commit, based on the commit 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-25 21:08:23 +00:00
Aaron Ballman
9f0f6d25f7 Reverting r323463 as it appears to be an accidental commit. Regardless, it 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-25 21:03:38 +00:00
Jake Ehrlich
9e42d579d2 tmp
llvm-svn: 323463
2018-01-25 20:24:17 +00:00
Jake Ehrlich
da574d3bff [llvm-objcopy] Use physical instead of virtual address when aligning and 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
2018-01-22 19:27:30 +00:00
Jake Ehrlich
548d9f0152 temp
llvm-svn: 322132
2018-01-09 23:00:25 +00:00
Jake Ehrlich
374396ccbc [llvm-objcopy] Add --localize-hidden option
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
2018-01-05 19:19:09 +00:00
Jake Ehrlich
8a24bd315b [llvm-objcopy] Add support for visibility
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
2018-01-02 23:01:24 +00:00
Jake Ehrlich
9f580d4e7a [llvm-objcopy] Add option to add a progbits section from a file
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-19 00:47:30 +00:00
Rafael Espindola
12cba944e4 Simplify test.
It can use attrib instead of icacls.

llvm-svn: 319809
2017-12-05 18:26:23 +00:00
Rafael Espindola
d8d1aa83ad Delete temp file if rename fails.
Without this when lld failed to replace the output file it would leave
the temporary behind. The problem is that the existing logic is

- cancel the delete flag
- rename

We have to cancel first to avoid renaming and then crashing and
deleting the old version. What is missing then is deleting the
temporary file if the rename fails.

This can be an issue on both unix and windows, but I am not sure how
to cause the rename to fail reliably on unix. I think it can be done
on ZFS since it has an ACL system similar to what windows uses, but
adding support for checking that in llvm-lit is probably not worth it.

llvm-svn: 319786
2017-12-05 16:40:56 +00:00
Jake Ehrlich
ba962c5889 [llvm-objcopy] Add support for --only-keep/-j and --keep
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
2017-11-30 20:14:53 +00:00
Jake Ehrlich
952158c13d [llvm-objcopy] Add --strip-all-gnu and change --strip-all
GNU's --strip-all doesn't strip as aggressively as it could in general.
Currently llvm-objcopy copies the exact behavoir of GNU's --strip-all.
eu-strip is used as a drop in replacement for GNU strip/objcopy in many many
places without issue. eu-strip removes non-allocated sections and keeps
.gnu.warning* sections. Because --strip-all will likely be the most widely
used stripping option we should make --strip-all as aggressive as it can safely
be. Since we have evidence from eu-strip that this is a safe option we should
allow it. For those that might still have an issue afterwards I've added
--strip-all-gnu as an exact drop in replacement for GNU's --strip-all as well.

llvm-svn: 319071
2017-11-27 18:56:01 +00:00
Jake Ehrlich
20e541caa9 [llvm-objcopy] Change -O binary to respect section removal and behave like 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
2017-11-15 19:13:31 +00:00
Jake Ehrlich
3273135094 [llvm-objcopy] Add -strip-non-alloc option to remove all non-allocated sections
This change adds a new flag not present in GNU objcopy that we call
--strip-non-alloc.

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

llvm-svn: 318168
2017-11-14 18:50:24 +00:00
Jake Ehrlich
0c7906a7ed [llvm-objcopy] Support the rest of the ELF formats
We haven't been supporting anything but ELF64LE since the start. Luckily
this was always accounted for and the change is pretty trivial. B35281
requests this change for ELF32LE. This change adds support for ELF32LE,
ELF64BE, and ELF32BE with all supported features that already existed
for ELF64LE.

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

llvm-svn: 318166
2017-11-14 18:41:47 +00:00
Jake Ehrlich
adbdf83687 [llvm-objcopy] Add --strip-debug
Many projects use this option. There are two ways to use it. You can
either a) Just use --strip-debug and keep the old file with debug
content or b) you can use --strip-debug, --only-keep-debug, and
--add-gnu-debuglink all in conjunction to create two separate files, the
stripped file and the debug file. --only-keep-debug is more complicated
than --strip-debug because it keeps the section headers without keeping
section contents. That's not really supported by llvm-objcopy at the
moment but I plan on adding it. So this change just supports a) and
options to support b) will come soon.

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

llvm-svn: 318094
2017-11-13 22:13:08 +00:00
Jake Ehrlich
917785f184 [llvm-objcopy] Add --strip-all option to llvm-objcopy
This change adds a slightly less extreme form of stripping. It should
remove any section that starts with ".debug" and should remove any
symbol table or relocations. In general this strips out most of the
stuff you don't need to execute but leaves a number of things around.
This behavior has been designed to be compatible with GNU strip/objcopy
--strip-all so that anywhere you currently use --strip-all you should be
able to use llvm-objcopy as a drop in replacement.

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

llvm-svn: 318092
2017-11-13 22:02:07 +00:00
Rafael Espindola
0b65b26f04 Make sure an error is always handled.
llvm-svn: 317724
2017-11-08 21:15:21 +00:00
Jake Ehrlich
69d508d9f8 [llvm-objcopy] Add support for dwarf fission
This change adds support for dwarf fission.

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

llvm-svn: 317350
2017-11-03 18:58:41 +00:00
Jake Ehrlich
5033237287 [llvm-objcopy] Fix bug in how segment alignment was being handled
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
2017-11-02 23:24:04 +00:00
Jake Ehrlich
888c5073d1 Reland "[llvm-objcopy] Add support for --strip-sections to remove all 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
2017-10-11 18:09:18 +00:00
Jake Ehrlich
ef3e8ca734 Revert "[llvm-objcopy] Add support for --strip-sections to remove all section headers leaving only program headers and loadable segment data"
This reverts commit rL315412

llvm-svn: 315417
2017-10-11 02:42:29 +00:00
Jake Ehrlich
319aa8e7b0 [llvm-objcopy] Add support for --strip-sections to remove all section 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
2017-10-11 01:59:06 +00:00
Jake Ehrlich
0d141d6a28 [llvm-objcopy] Add ability to remove multiple sections by name
This change adds the ability to use the "-R"/"-remove-section" option
multiple times.

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

llvm-svn: 315385
2017-10-10 23:02:43 +00:00
Jake Ehrlich
c58d77a269 [llvm-objcopy] Add support for removing sections
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
2017-10-10 18:47:09 +00:00
Jake Ehrlich
518ecb8d6d Revert "temporary"
I forgot to add a proper commit message. I'm reverting this
to fix that.

This reverts commit r315344.

llvm-svn: 315345
2017-10-10 18:32:22 +00:00
Jake Ehrlich
875bd340c8 temporary
llvm-svn: 315344
2017-10-10 18:28:15 +00:00
Jake Ehrlich
dd2311d56c [llvm-objcopy] Fix major layout bugs in llvm-objcopy
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
2017-10-04 17:44:42 +00:00
Jake Ehrlich
f096324571 [llvm-objcopy] Add support for dynamic relocations
This change adds support for dynamic relocations (allocated
SHT_REL/SHT_RELA sections with a dynamic symbol table as their link).

The binary I added for the test is here:
https://drive.google.com/file/d/0B3gtIAmiMwZXSjJUZE9pUjd4M0k/view?usp=sharing

Unless support for dynamic symbol tables in yaml2obj is added this is
needed.

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

llvm-svn: 314227
2017-09-26 18:02:25 +00:00
Jake Ehrlich
f68b3a1b5f Reland "[llvm-objcopy] Add support for .dynamic, .dynsym, and .dynstr"
I did not upload two binaries that I reference in tests.

This change adds support for sections involved in dynamic loading such
as SHT_DYNAMIC, SHT_DYNSYM, and allocated string tables.

The two added binaries used for tests can be downloaded here and here

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

llvm-svn: 313772
2017-09-20 17:22:06 +00:00
Jake Ehrlich
250f0cb393 Reland "[llvm-objcopy] Add support for .dynamic, .dynsym, and .dynstr"
I overzealously landed this before I was sure that another change
wouldn't break the build that this change depends on.

This change adds support for sections involved in dynamic loading such
as SHT_DYNAMIC, SHT_DYNSYM, and allocated string tables.

The two added binaries used for tests can be downloaded here and here

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

llvm-svn: 313767
2017-09-20 17:11:58 +00:00
Jake Ehrlich
fc23a01ea2 Reland "[llvm-objcopy] Add support for nested and overlapping segments"
I didn't initialize a pointer to be nullptr that I needed to.

This change adds support for nested and even overlapping segments. This means
that PT_PHDR, PT_GNU_RELRO, PT_TLS, and PT_DYNAMIC can be supported properly.

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

llvm-svn: 313682
2017-09-19 21:37:35 +00:00
Jake Ehrlich
362ec74236 Revert "[llvm-objcopy] Add support for .dynamic, .dynsym, and .dynstr"
This reverts commit r313663. Broken because overlapping-sections was
reverted.

llvm-svn: 313665
2017-09-19 20:00:04 +00:00
Jake Ehrlich
4b0a637bb0 Revert "[llvm-objcopy] Add support for nested and overlapping segments"
This reverts commit r313656. Appears to be broken on Windows.

llvm-svn: 313664
2017-09-19 19:52:09 +00:00
Jake Ehrlich
8e38021f91 [llvm-objcopy] Add support for .dynamic, .dynsym, and .dynstr
This change adds support for sections involved in dynamic loading such
as SHT_DYNAMIC, SHT_DYNSYM, and allocated string tables.

The two added binaries used for tests can be downloaded [[
https://drive.google.com/file/d/0B3gtIAmiMwZXOXE3T0RobFg4ZTg/view?usp=sharing
| here ]] and [[
https://drive.google.com/file/d/0B3gtIAmiMwZXTFJSQUJZMGxNSXc/view?usp=sharing
| here ]]

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

llvm-svn: 313663
2017-09-19 19:21:09 +00:00
Jake Ehrlich
de99ea8a55 [llvm-objcopy] Add test to check that architecture specific values are not used on wrong architecture.
This change adds a test that checks the an error is produced when a hexagon
specific reserved section index is used but e_machine is not EM_HEXAGON.

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

llvm-svn: 313661
2017-09-19 19:05:15 +00:00
Jake Ehrlich
3916a38a25 [llvm-objcopy] Add support for nested and overlapping segments
This change adds support for nested and even overlapping segments. This means
that PT_PHDR, PT_GNU_RELRO, PT_TLS, and PT_DYNAMIC can be supported properly.

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

llvm-svn: 313656
2017-09-19 18:14:03 +00:00
Petr Hosek
f5534eb2a2 [llvm-objcopy] Add e_machine validity check for reserved section indexes
As discussed on llvm-commits it was decided it would be best to check
e_machine before declaring that a reserved section index is valid. The
only special e_machine value that matters here is EM_HEXAGON. This
change adds a special check for EM_HEXAGON.

Patch by Jake Ehrlich

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

llvm-svn: 313114
2017-09-13 03:04:50 +00:00
Petr Hosek
3ea650006a [llvm-objcopy] Add support for special section indexes in symbol table greater than SHN_LORESERVE
As is indexes above SHN_LORESERVE will not be handled correctly because
they'll be treated as indexes of sections rather than special values
that should just be copied. This change adds support to copy them
though.

Patch by Jake Ehrlich

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

llvm-svn: 312756
2017-09-07 23:02:50 +00:00
Petr Hosek
503bc9e9c6 Reland "[llvm-objcopy] Add support for relocations"
This change adds support for SHT_REL and SHT_RELA sections in
llvm-objcopy.

Patch by Jake Ehrlich

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

llvm-svn: 312680
2017-09-06 23:41:02 +00:00
Petr Hosek
3a78bfa9ca Revert "[llvm-objcopy] Add support for relocations"
This reverts r312643 because it's failing on llvm-i686-linux-RA.

llvm-svn: 312645
2017-09-06 16:23:15 +00:00
Petr Hosek
ac4f50b8b9 [llvm-objcopy] Add support for relocations
This change adds support for SHT_REL and SHT_RELA sections in
llvm-objcopy.

Patch by Jake Ehrlich

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

llvm-svn: 312643
2017-09-06 16:19:48 +00:00
Petr Hosek
0006f4db52 Reland "[llvm] Add symbol table support to llvm-objcopy"
This change adds support for SHT_SYMTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 311974
2017-08-29 02:12:03 +00:00
Petr Hosek
0dd7e7e8a1 Revert "[llvm] Add symbol table support to llvm-objcopy"
This reverts commit r311826 because it's failing on llvm-i686-linux-RA.

llvm-svn: 311827
2017-08-26 03:22:25 +00:00
Petr Hosek
5132ad7e08 [llvm] Add symbol table support to llvm-objcopy
This change adds support for SHT_SYMTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 311826
2017-08-26 03:18:41 +00:00
Petr Hosek
e4c1238469 [llvm][llvm-objcopy] When outputting to binary don't output segments that cover no sections
Sometimes LLD will produce a PT_LOAD segment that only covers the
headers (and covers no sections). GNU objcopy does not output the
segment contents for these sections. In particular this is an issue in
building magenta because the final link step for the kernel would
produce just such a PT_LOAD segment. This change is to support this case
and to match what GNU objcopy does in this case.

Patch by Jake Ehrlich

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

llvm-svn: 310149
2017-08-04 23:18:18 +00:00
Petr Hosek
f0989c5e0e Reland "[llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy"
This change adds the "-O binary" flag which directs llvm-objcopy to
output the object file to the same format as GNU objcopy does when given
the flag "-O binary". This was done by splitting the Object class into
two subclasses ObjectELF and ObjectBianry which each output a different
format but relay on the same code to read in the Object in Object.

Patch by Jake Ehrlich

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

llvm-svn: 310127
2017-08-04 21:09:26 +00:00
Petr Hosek
6656c50c3a Revert "[llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy"
This breaks the build on clang-s390x-linux.

This reverts commit r310018.

llvm-svn: 310026
2017-08-04 05:33:44 +00:00
Petr Hosek
660b133016 Reland "[llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy"
This change adds the "-O binary" flag which directs llvm-objcopy to
output the object file to the same format as GNU objcopy does when given
the flag "-O binary". This was done by splitting the Object class into
two subclasses ObjectELF and ObjectBianry which each output a different
format but relay on the same code to read in the Object in Object.

Patch by Jake Ehrlich

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

llvm-svn: 310018
2017-08-04 03:17:37 +00:00
Petr Hosek
649751717a Revert "Reland "[llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy""
This is failing to compile on 32-bit ARM bots.

This reverts commit r309768.

llvm-svn: 309771
2017-08-02 00:03:33 +00:00
Petr Hosek
14dc046adc Reland "[llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy"
This change adds the "-O binary" flag which directs llvm-objcopy to
output the object file to the same format as GNU objcopy does when given
the flag "-O binary". This was done by splitting the Object class into
two subclasses ObjectELF and ObjectBianry which each output a different
format but relay on the same code to read in the Object in Object.

Patch by Jake Ehrlich

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

llvm-svn: 309768
2017-08-01 23:46:33 +00:00
Petr Hosek
855ab9f801 Revert "[llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy"
The change seems to be failing on bots which are using gcc and bfd.ld
as a host compiler and linker.

This reverts commit r309658.

llvm-svn: 309660
2017-08-01 05:31:50 +00:00
Petr Hosek
f01a57df58 [llvm][llvm-objcopy] Added support for outputting to binary in llvm-objcopy
This change adds the "-O binary" flag which directs llvm-objcopy to
output the object file to the same format as GNU objcopy does when given
the flag "-O binary". This was done by splitting the Object class into
two subclasses ObjectELF and ObjectBianry which each output a different
format but relay on the same code to read in the Object in Object.

Patch by Jake Ehrlich

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

llvm-svn: 309658
2017-08-01 05:18:30 +00:00
Petr Hosek
dd99727315 Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
As discussed on llvm-dev I've implemented the first basic steps towards
llvm-objcopy/llvm-objtool (name pending).

This change adds the ability to copy (without modification) 64-bit
little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS,
SHT_NULL and SHT_STRTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 309643
2017-08-01 00:33:58 +00:00
Petr Hosek
575ffaa429 Revert "Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started""
This change is failing tests on Windows bots due to permissions.

This reverts commit r309249.

llvm-svn: 309251
2017-07-27 06:02:05 +00:00
Petr Hosek
c95f0f31bb Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
As discussed on llvm-dev I've implemented the first basic steps towards
llvm-objcopy/llvm-objtool (name pending).

This change adds the ability to copy (without modification) 64-bit
little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS,
SHT_NULL and SHT_STRTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 309249
2017-07-27 04:35:30 +00:00
Petr Hosek
69fc8d4b6f Revert "Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started""
This reverts commit 960873b10dd071298c817ba74ef2228f94ead7a1.

llvm-svn: 309037
2017-07-25 21:55:00 +00:00
Petr Hosek
b36103c9e7 Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
As discussed on llvm-dev I've implemented the first basic steps towards
llvm-objcopy/llvm-objtool (name pending).

This change adds the ability to copy (without modification) 64-bit
little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS,
SHT_NULL and SHT_STRTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 309032
2017-07-25 21:16:33 +00:00
Petr Hosek
af39c73f25 Revert "Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started""
This reverts commit 2b52298eb28ba4d3eca113353a348c02a6ef1f93.

llvm-svn: 308822
2017-07-22 02:43:50 +00:00
Petr Hosek
60040cd12f Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
As discussed on llvm-dev I've implemented the first basic steps towards
llvm-objcopy/llvm-objtool (name pending).

This change adds the ability to copy (without modification) 64-bit
little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS,
SHT_NULL and SHT_STRTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 308821
2017-07-22 02:33:45 +00:00
Petr Hosek
fbf0bf1d12 Revert "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
This reverts commit 2f423248e140b94b8377660d4d2fe9364f30febe.

llvm-svn: 308806
2017-07-21 23:39:39 +00:00
Petr Hosek
d2c2d1bf03 Reland "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
As discussed on llvm-dev I've implemented the first basic steps towards
llvm-objcopy/llvm-objtool (name pending).

This change adds the ability to copy (without modification) 64-bit
little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS,
SHT_NULL and SHT_STRTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 308803
2017-07-21 23:27:40 +00:00
Petr Hosek
b5cbb2278d Revert "[LLVM][llvm-objcopy] Added basic plumbing to get things started"
This reverts commit 98f9792e7ca5bbd9eb43bda72bf497957cfb6eb8.

llvm-svn: 308569
2017-07-20 00:13:32 +00:00
Petr Hosek
1dd6a4a02a [LLVM][llvm-objcopy] Added basic plumbing to get things started
As discussed on llvm-dev I've implemented the first basic steps towards
llvm-objcopy/llvm-objtool (name pending).

This change adds the ability to copy (without modification) 64-bit
little endian ELF executables that have SHT_PROGBITS, SHT_NOBITS,
SHT_NULL and SHT_STRTAB sections.

Patch by Jake Ehrlich

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

llvm-svn: 308559
2017-07-19 23:51:13 +00:00