Commit Graph

8741 Commits

Author SHA1 Message Date
Rafael Espindola a4c15c1339 Remove dummy cast.
llvm-svn: 307220
2017-07-05 23:16:38 +00:00
Rafael Espindola 4cc0cd6556 Use Entry::SecSize in a couple of cases.
This avoids having to compute relocation section sizes early, removing
the last use of assignOffsets.

llvm-svn: 307219
2017-07-05 23:06:59 +00:00
Rafael Espindola 9f9e99be20 Simplify. NFC.
llvm-svn: 307217
2017-07-05 22:30:04 +00:00
Rafael Espindola cf7347379f Remove a function that is now trivial.
llvm-svn: 307214
2017-07-05 22:25:38 +00:00
Rafael Espindola 7016a14702 Using existing variable. NFC.
llvm-svn: 307211
2017-07-05 22:15:58 +00:00
Rafael Espindola cfeb9ae073 Remove two dummy casts. NFC.
llvm-svn: 307209
2017-07-05 22:07:20 +00:00
Eric Beckmann 1d50926e71 Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file.""
This reverts commit 8c8dce3b8f15d6ebaefc35ce88f15a85c8cdbd6e.

llvm-svn: 307191
2017-07-05 19:04:48 +00:00
Eric Beckmann 0eafa581a3 Revert "Revert "Switch external cvtres.exe for llvm's own resource library.""
This reverts commit 165e578e47f1cd38191120aad23a9020fb5476dd.

Forgot to run tests on this.

llvm-svn: 307190
2017-07-05 19:04:33 +00:00
Eric Beckmann 36793a0ecf Revert "Switch external cvtres.exe for llvm's own resource library."
This reverts commit 600d52c278e123dd08bee24c1f00932b55add8de.

This patch still seems to break CrWinClangLLD, reverting until I can
find root problem.

llvm-svn: 307189
2017-07-05 18:59:16 +00:00
Eric Beckmann 8cc9fd31e6 Revert "Replace trivial use of external rc.exe by writing our own .res file."
This patch still seems to break CrWinClangLLD, reverting this once more
until I can discover root problem.

This reverts commit 3dbbc8ce43be50ffde2b1c655c6d3a25796fe78b.

llvm-svn: 307188
2017-07-05 18:59:01 +00:00
Rafael Espindola d7faa9165f Merge createOrphanCommands into addOrphanSections.
This is a bit simpler and avoids a walk over OutputSections.

llvm-svn: 307178
2017-07-05 17:50:43 +00:00
David Blaikie 15309044ba Use LoadedObjectInfoHelper to simplify/delegate the implementation of 'clone'
llvm-svn: 307167
2017-07-05 15:24:42 +00:00
Sean Eveson d54759b236 [ELF] Fix nullptr dereference when creating an error message for a synthetic section.
Differential Revision: https://reviews.llvm.org/D34752

llvm-svn: 307162
2017-07-05 14:55:43 +00:00
Peter Smith 283b9f2de3 [ELF] Fix Windows build error
Attempt to fix Windows buildbots From 307131 Replaced return {ET, false};
with return std::make_pair(ET, false);

llvm-svn: 307137
2017-07-05 10:15:46 +00:00
Peter Smith fa23764278 [ELF] Allow multiple thunks to be added for a symbol.
This change permits there to be more than one thunk to be associated with
a symbol. For interworking thunks we only require one thunk, but range
extension thunks may require more than one.

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

llvm-svn: 307136
2017-07-05 09:53:33 +00:00
Peter Smith 7d66e849fc [ELF] Introduce Thunk reuse compatibility
On ARM the interworking thunks are only produced for branch instructions
that can't be changed into a blx instruction so only Thumb callers would
call Thumb thunks and only ARM callers would call ARM thunks. With range
extension thunks branch and link instructions may need a Thunk. These
instructions can be rewritten as a blx and can use either ARM or Thumb
thunks.

We introduce an isCompatibleWith() function so that a caller can check if
an existing Thunk is compatible before reusing it.

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

llvm-svn: 307132
2017-07-05 09:36:03 +00:00
Peter Smith 5aedebff38 [ELF] Extract allocateHeaders() from assignAddresses()
The allocateHeaders() function is called at the end of assignAddresses(), it
decides whether the ELF header and program header table can be allocated to
a PT_LOAD program header. As the function alters state, it prevents
assignAddresses() from being called multiple times.

This change splits out the call to allocateHeaders() from assignAddresses()
this will permit assignAddresses() to be called while processing range
extension thunks without trying to allocateHeaders().

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

llvm-svn: 307131
2017-07-05 09:12:54 +00:00
Rafael Espindola cf00d4374e Fix PR33635.
This is a semantic revert of r306036.

We have to change the names, otherwise dynamic relocations will point
to the wrong name.

llvm-svn: 307110
2017-07-05 00:43:18 +00:00
Rafael Espindola 9b3f657d21 Move clearOutputSections earlier. NFC.
This is finally getting to the point where output sections are
constructed.

createOrphanCommands and fabricateDefaultCommands are moved out so
they can be merged with existing code in followup commits.

llvm-svn: 307107
2017-07-04 21:05:26 +00:00
Rafael Espindola d48b208833 Move clearOutputSections earlier. NFC.
Now addSectionSymbols operates on the linker script.

llvm-svn: 307102
2017-07-04 19:08:40 +00:00
Rafael Espindola b691545721 Move clearOutputSections earlier. NFC.
Now all of finalizeSections works on the linker script.

llvm-svn: 307101
2017-07-04 19:05:03 +00:00
Rafael Espindola 1eb3a0fa83 Move clearOutputSections earlier. NFC.
Now addPredefinedSections operates only on the linker script.

llvm-svn: 307100
2017-07-04 18:26:21 +00:00
Tom Stellard c17a04c6c8 ELF: Only unlink regular files
Summary:
If the output file is a character file (e.g. /dev/null) unlinking it could
potentially destabilize the user's system.  For example,
unlinking causes `lld %input -o /dev/null` to replace /dev/null with a
regular file, which will lead to unexpected behavior in other programs
that read from /dev/null, and worse than expected peformance for
programs that write to /dev/null.

This makes it possible to run the test-release.sh script as root.
Prior to this patch, the ELF/basic.s test would replace
/dev/null with a regular file, which would cause crashes in llvm
test-suite programs that piped /dev/null to stdin.

For example, if you run the test-relase.sh script as root,

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, llvm-commits

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

llvm-svn: 307092
2017-07-04 16:03:34 +00:00
Rafael Espindola 909899cc47 Improve error message.
Before we would sometimes not mention that the relocation was in a ro
area before.

llvm-svn: 307089
2017-07-04 15:53:57 +00:00
Simon Atanasyan 2e5c46cbac [ELF] Do not use `this` to access members of non-template class. NFC
llvm-svn: 307083
2017-07-04 15:04:30 +00:00
Rafael Espindola aec6287f5d Make the test more strict.
We now don't produce "has undefined version" errors when producing
binaries even when there is a linker script.

llvm-svn: 307082
2017-07-04 14:59:28 +00:00
George Rimar 4d2f976208 [ELF] - Resolve references properly when using .symver directive
This is PR28414. 
Previously LLD was unable to link following:
(failed with undefined symbol bar)

Version script:
SOME_VERSION { global: *; };

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
  jmp bar
Manual has next description:

.symver name, name2@@nodename
In this case, the symbol name must exist and be defined within the file being assembled. It is similar to name2@nodename. 
The difference is name2@@nodename will also be used to resolve references to name2 by the linker
https://sourceware.org/binutils/docs/as/Symver.html

Patch implements that. If we have name@@ver symbol and name is undefined, name@@ver is used to resolve references to name.
If name is defined then multiple definition error is emited, that is consistent with what bfd do.

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

llvm-svn: 307077
2017-07-04 13:19:13 +00:00
George Rimar a951d5c40b [ELF] - Use llvm::find_if instead std::find_if where possible. NFC.
Two more places.

llvm-svn: 307076
2017-07-04 13:10:37 +00:00
Rafael Espindola 43ee36040d fix msvc build
llvm-svn: 307044
2017-07-03 17:32:09 +00:00
Rafael Espindola c080ff64dc Move clearOutputSections earlier.
Now removeUnusedSyntheticSections operates entirely on the linker
script.

llvm-svn: 307043
2017-07-03 16:54:39 +00:00
Rafael Espindola bd9682a1ad Add a test for a recent regression.
llvm-svn: 307041
2017-07-03 16:49:17 +00:00
George Rimar d971e7030e [ELF] - Simplify allocateHeaders(). NFC.
* Return type changed to void, because it was unused.
* std::find_if -> llvm::find_if

llvm-svn: 307039
2017-07-03 16:05:51 +00:00
Petr Hosek 52db9a4fe6 [ELF] Remove unused synthetic sections from script commands
Script commands are processed before unused synthetic sections are
removed. Therefore, if a linker script matches one of these sections
it'll get emitted as an empty output section because the logic for
removing unused synthetic sections ignores script commands which
could have already matched and captured one of these sections. This
patch fixes that by also removing the unused synthetic sections from
the script commands.

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

llvm-svn: 307037
2017-07-03 15:49:25 +00:00
George Rimar bd4943e2ca [ELF] - Remove use of precomipled binary for invalid-relocation-x64.test
Since yaml2obj is now able to parse integer values as relocation types,
there is no need to keep hex edited elf object for this test,
we can produce it on fly, just like this patch do.

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

llvm-svn: 307032
2017-07-03 15:24:50 +00:00
Andrew Ng a020d3487e [LLD][LinkerScript] Allow non-alloc sections to be assigned to segments.
This patch makes changes to allow sections without the SHF_ALLOC bit to be
assigned to segments in a linker script.

The assignment of output sections to segments is performed in
LinkerScript::createPhdrs. Previously, this function would bail as soon as it
encountered an output section which did not have the SHF_ALLOC bit set, thus
preventing any output section without SHF_ALLOC from being assigned to a
segment.

This restriction has now been removed from LinkerScript::createPhdrs and instead
a check for SHF_ALLOC has been added to LinkerScript::adjustSectionsAfterSorting
to not propagate program headers to sections without SHF_ALLOC which matches the
behaviour of bfd linker scripts.

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

llvm-svn: 307013
2017-07-03 10:11:25 +00:00
Rui Ueyama 80cbc776cb Revert r306813: "[ELF] - Resolve references properly when using .symver directive"
This reverts commit r306813 because it broke linking of the
FreeBSD base system.

llvm-svn: 306996
2017-07-03 03:26:07 +00:00
Martin Storsjo 94fce50950 [COFF] Add initial support for linking ARM64 binaries
A plain empty entry point function that returns 0 seems to produce
a binary that loads and runs fine in wine.

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

llvm-svn: 306963
2017-07-01 20:29:27 +00:00
Eric Beckmann 602afcf7e9 Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file.""
Summary:
This reverts commit 51931072a7c9a52540baf76fc30ef391d2529a2f.

This revert was originally done because the integrations of the new
WindowsResource library into LLD was causing error in chromium, due to
bugs in how resource sections were handled.  These bugs were fixed,
meaning that the features may be reintegrated.

Subscribers: hiraditya, llvm-commits

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

llvm-svn: 306941
2017-07-01 03:59:54 +00:00
Zachary Turner af8c75a8c0 [llvm-pdbutil] Output the symbol offset when dumping.
Type records have a unique type index, but symbol records do
not.  Instead, symbol records refer to other symbol records
by referencing their offset in the symbol stream.  In a sense
this is the analogue of the TypeIndex, but we are not printing
it in the dumper.  Printing it not only gives us more useful
information when manually investigating the contents of a PDB,
but also allows us to write better tests by enabling us to
verify that fields that reference other symbol records do
so correctly.

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

llvm-svn: 306890
2017-06-30 21:35:00 +00:00
Richard Smith 4451cb63fb Fix ODR violations due to abuse of LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR
This is a short-term fix for PR33650 aimed to get the modules build bots green again.

Remove all the places where we use the LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR
macros to try to locally specialize a global template for a global type. That's
not how C++ works.

Instead, we now centrally define how to format vectors of fundamental types and
of string (std::string and StringRef). We use flow formatting for the former
cases, since that's the obvious right thing to do; in the latter case, it's
less clear what the right choice is, but flow formatting is really bad for some
cases (due to very long strings), so we pick block formatting. (Many of the
cases that were using flow formatting for strings are improved by this change.)

Other than the flow -> block formatting change for some vectors of strings,
this should result in no functionality change.

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

Corresponding LLVM change is r306878.

llvm-svn: 306880
2017-06-30 20:57:21 +00:00
Eric Beckmann 5de7361097 Tighten up tests for .rsrc section emission.
Summary:
There have been bugs with the WindowsResource library, such as incorrect
symbols for addresses.  Directly checking the .rsrc in the final PE will
help ensure this doesn't happen again.

Subscribers: llvm-commits

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

llvm-svn: 306854
2017-06-30 18:22:11 +00:00
George Rimar aad84e2ee2 [ELF] - Resolve references properly when using .symver directive
This is PR28414. 
Previously LLD was unable to link following:
(failed with undefined symbol bar)

```
Version script:
SOME_VERSION { global: *; };

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
  jmp bar
```

Manual has next description:
//
.symver name, name2@@nodename
In this case, the symbol name must exist and be defined within the file being assembled. It is similar to name2@nodename. 
**The difference is name2@@nodename will also be used to resolve references to name2 by the linker**
https://sourceware.org/binutils/docs/as/Symver.html
//

Patch implements that. If we have name@@ver symbol and name is undefined, 
name@@ver is used to resolve references to name.

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

llvm-svn: 306813
2017-06-30 10:19:54 +00:00
Martin Storsjo e24f434eb2 Update a test case after LLVM r306794
llvm-svn: 306796
2017-06-30 07:02:59 +00:00
Sam Clegg c090962255 Remove unused declarations
Differential Revision: https://reviews.llvm.org/D34852

llvm-svn: 306772
2017-06-30 00:34:35 +00:00
Paul Robinson c60318af24 Tweak to match change in LLVM API, in r306699
llvm-svn: 306700
2017-06-29 16:52:29 +00:00
Eric Beckmann d40dd64ff0 Revert "Replace trivial use of external rc.exe by writing our own .res file."
This reverts commit d4c7e9fc63c10dbab0c30186ef8575474a704496.

This is done in order to address the failure of CrWinClangLLD etc. bots.
These throw an error of "side-by-side configuration is incorrect" during
compilation, which sounds suspiciously related to these manifest
changes.

Revert "Switch external cvtres.exe for llvm's own resource library."

This reverts commit 71fe8ef283a9dab9a3f21432c98466cbc23990d1.

llvm-svn: 306618
2017-06-29 00:17:26 +00:00
Rafael Espindola b04290569c Delete comparison with GlobalOffsetTable.
Now that _GLOBAL_OFFSET_TABLE_ is defined, we can just use R_PC for it
if needed.

llvm-svn: 306614
2017-06-28 23:19:32 +00:00
Rafael Espindola 85de6786ab Fix indentation.
llvm-svn: 306609
2017-06-28 22:44:11 +00:00
Rui Ueyama b2269ec4d3 Move copy function from Symbol to SymbolBody.
We could have add this function either Symbol or SymbolBody. I added it
to Symbol at first. But I noticed that if I've added it to SymbolBody,
we could've removed SymbolBody::setName(). So I'll do that in this patch.

llvm-svn: 306590
2017-06-28 19:43:02 +00:00
Rui Ueyama 8e11b6d94b Define Symbol::copyBody function.
This patch adds a utility function to Symbol. This function should
be useful in https://reviews.llvm.org/D33680 too.

llvm-svn: 306587
2017-06-28 19:28:49 +00:00