Commit Graph

1408 Commits

Author SHA1 Message Date
Rafael Espindola 66a69ceed9 Make helper function static. NFC.
llvm-svn: 265501
2016-04-06 01:30:49 +00:00
Ivan Krasin bfc9131454 Fix a memory leak found by check-lld asan tests.
Summary:
This bug was introduced by http://reviews.llvm.org/rL265059,
where InputSectionBase got Thunks field, which can do memory allocations.
Since InputSectionBase destructors were never called (I count it as another bug),
that caused a memory leak when 2 or more thunks are added to a section.

The fix to is properly call InputSectionBase destructors from ~ObjectFile.

Reviewers: atanasyan, ruiu, rafael

Subscribers: rafael, krasin, pcc

Differential Revision: http://reviews.llvm.org/D18809

llvm-svn: 265497
2016-04-06 01:11:10 +00:00
Rafael Espindola f7085871fd Delete broken code.
A synthetic symbol can be global or local, and with the current
infrastructure we don't need any special code for it.

Fixes PR27228.

llvm-svn: 265478
2016-04-05 22:08:39 +00:00
Ed Schouten 639a333730 Make TLS work for PIE executables on x86-64.
While trying to get PIE work on CloudABI for x86-64, I noticed that even
though GNU ld would generate functional binaries, LLD would not. It
turns out that we generate relocations for referencing TLS objects
inside of the text segment, which shouldn't happen.

This change extends the isRelRelative() function to list some additional
relocation types that should be treated as relative. This makes my C
library unit testing binary work on x86-64.

Approved by:	ruiu
Differential Revision:	http://reviews.llvm.org/D18688
Fixes bug:	https://llvm.org/bugs/show_bug.cgi?id=27174

llvm-svn: 265462
2016-04-05 20:51:50 +00:00
Ed Schouten f2fdd013a2 Don't omit dynamic relocations for the GOT.
Where Clang's AArch64 backend seems to differ from the X86 backend is
that it tends to use the GOT more aggressively.

After getting CloudABI PIEs working on x86-64, I noticed that accessing
global variables would still crash on aarch64. Tracing it down, it turns
out that the GOT was filled with entries assuming the base address was
zero.

It turns out that we skip generating relocations for GOT entries in case
the relocation pointing towards the GOT is relative. Whether the thing
pointing to the GOT is absolute or relative shouldn't make any
difference; the GOT entry itself should contain the absolute address,
thus needs a relocation regardless.

Approved by:	rafael
Differential Revision:	http://reviews.llvm.org/D18739

llvm-svn: 265453
2016-04-05 20:17:33 +00:00
Rui Ueyama 376ab7cc7b Fix formatting.
llvm-svn: 265424
2016-04-05 17:47:29 +00:00
Rafael Espindola 0f7ccc3d92 Update for llvm change.
llvm-svn: 265404
2016-04-05 14:47:28 +00:00
Rafael Espindola d9a1717efc Remove redundant argument. NFC.
llvm-svn: 265386
2016-04-05 11:47:46 +00:00
Rafael Espindola 5cea969dca Fix another case of propagating IsUsedRegularObj.
I have an idea on how to clean this up, but lets get the tests passing
first.

llvm-svn: 265374
2016-04-05 01:38:43 +00:00
Peter Collingbourne d0856a6bb2 ELF: Make SymbolBody::compare a non-template function.
Differential Revision: http://reviews.llvm.org/D18781

llvm-svn: 265372
2016-04-05 00:47:58 +00:00
Peter Collingbourne e8afa4971c ELF: Preserve MustBeInDynSym for bitcode symbols.
Make sure to copy the MustBeInDynSym field when replacing shared symbols with
bitcode symbols, and when replacing bitcode symbols with regular symbols
in addCombinedLtoObject. Fixes interposition of DSO symbols with bitcode
symbols in the main executable.

Differential Revision: http://reviews.llvm.org/D18780

llvm-svn: 265371
2016-04-05 00:47:55 +00:00
Peter Collingbourne 4cdade6a2f ELF: Create dynamic symbols for symbol aliases of copy relocations.
For each copy relocation that we create, look through the DSO's symbol table
for aliases and create a dynamic symbol for each one. This causes the copy
relocation to correctly interpose any aliases.

Copy relocations are relatively uncommon (on my machine, 56% of binaries in
/usr/bin have no copy relocations probably due to being PIEs, 97% of them
have <10, and the binary with the largest number of them has 97) so it's
probably fine to do this in a relatively inefficient way.

Differential Revision: http://reviews.llvm.org/D18731

llvm-svn: 265354
2016-04-04 22:29:24 +00:00
Rafael Espindola 28ed95f45e Revert unintentional change.
resolve can remain private.

Thanks to Rui for noticing it.

llvm-svn: 265336
2016-04-04 19:22:51 +00:00
Sean Silva e33321f767 Put these options in sorted order.
Feedback from Davide on r265206.

llvm-svn: 265335
2016-04-04 19:21:52 +00:00
Rui Ueyama b5792b231b Rename Other -> StOther.
"Other" as a name is too generic, so name it StOther.

llvm-svn: 265332
2016-04-04 19:09:08 +00:00
Rui Ueyama dd41807392 Add comments.
llvm-svn: 265320
2016-04-04 18:15:38 +00:00
Rafael Espindola c64119a9bf Regenerate test file.
It had been created with a lld version that was producing an invalid
sh_info.

llvm-svn: 265305
2016-04-04 16:02:39 +00:00
Rafael Espindola 193b99c53c Try to fix the windows build.
MSVC doesn't want StringRef in an union.

llvm-svn: 265297
2016-04-04 14:31:20 +00:00
Rafael Espindola ccfe3cb3d6 Don't store an Elf_Sym for most symbols.
Our symbol representation was redundant, and some times would get out of
sync. It had an Elf_Sym, but some fields were copied to SymbolBody.

Different parts of the code were checking the bits in SymbolBody and
others were checking Elf_Sym.

There are two general approaches to fix this:
* Copy the required information and don't store and Elf_Sym.
* Don't copy the information and always use the Elf_Smy.

The second way sounds tempting, but has a big problem: we would have to
template SymbolBody. I started doing it, but it requires templeting
*everything* and creates a bit chicken and egg problem at the driver
where we have to find ELFT before we can create an ArchiveFile for
example.

As much as possible I compared the test differences with what gold and
bfd produce to make sure they are still valid. In most cases we are just
adding hidden visibility to a local symbol, which is harmless.

In most tests this is a small speedup. The only slowdown was scylla
(1.006X). The largest speedup was clang with no --build-id, -O3 or
--gc-sections (i.e.: focus on the relocations): 1.019X.

llvm-svn: 265293
2016-04-04 14:04:16 +00:00
Davide Italiano 842fa53026 [LTO] Implement -disable-verify, which disables bitcode verification.
So, there are some cases when the IR Linker produces a broken
module (which doesn't pass the verifier) and we end up asserting
inside the verifier. I think it's always a bug producing a module
which does not pass the verifier but there are some cases in which
people can live with the broken module (e.g. if only DebugInfo
metadata are broken). The gold plugin has something similar.

This commit is motivated by a situation I found in the
wild. It seems that somebody else discovered it independently
and reported in PR24923.

llvm-svn: 265258
2016-04-03 03:39:09 +00:00
Davide Italiano 8848d44e46 [LTO] Reject invalid optimization levels.
llvm-svn: 265255
2016-04-03 02:41:15 +00:00
Davide Italiano 887d76c392 [LTO] Fix -save-temps in case -o is not specified.
Currently we create a file called .lto.bc. In UNIX,
ls(1) by default doesn't show up files starting with
a dot, as they're (only by convention) hidden.
This makes the output of -save-temps a little bit
hard to find. Use "a.out.lto.bc" instead if the
output file is not specified.

While here, change an existing -save-temps test to
exercise this more interesting behaviour.

llvm-svn: 265254
2016-04-03 02:16:56 +00:00
Davide Italiano c4965009bd [ELF] Prefer 'auto' over explicit type for consistency.
llvm-svn: 265250
2016-04-02 23:47:54 +00:00
Ed Schouten 988b827992 Provide support for Binutils' --no-dynamic-linker option.
GNU ld seems to write a PT_INTERP header into executables containing a
default (read: bogus) value if --dynamic-linker flag is not provided.
LLD is different in the sense that it omits it unless --dynamic-linker
is provided, which seems fair.

Binutils 2.26 added a new flag, --no-dynamic-linker, that can be used to
generate binaries without PT_INTERP. Let's go ahead and also add this
flag to LLD, so that we can invoke the linker in a portable way.

Reviewed by:	ruiu
Differential Revision:	http://reviews.llvm.org/D18723

llvm-svn: 265246
2016-04-02 20:58:02 +00:00
Rui Ueyama 12dff23951 Simplify. NFC.
llvm-svn: 265242
2016-04-02 19:36:36 +00:00
Rui Ueyama 24d0d2f917 Merge two `if`s.
llvm-svn: 265241
2016-04-02 19:31:01 +00:00
Rui Ueyama 8fe7ce5903 Variable names should start with uppercase letters.
llvm-svn: 265239
2016-04-02 19:15:26 +00:00
Rui Ueyama 7e71c61a7a Rename a variable. NFC.
We had variables MB and Mb in this function. Rename of one them.

llvm-svn: 265237
2016-04-02 19:09:07 +00:00
Rui Ueyama d1aa97b5c2 Do not return early.
Early return in this context is a bit confusing, so avoid doing it.

llvm-svn: 265236
2016-04-02 18:52:23 +00:00
Rui Ueyama 1fc5d48877 Move code to initialize LLVM to one place.
llvm-svn: 265235
2016-04-02 18:18:44 +00:00
Rui Ueyama bfc1d9d976 Remove DefinedElf class.
DefinedElf was a superclass of DefinedRegular and SharedSymbol classes
and represented the notion of defined symbols created for ELF symbols.

It turned out that we didn't use that class often. We had only two
occurrences of dyn_cast'ing to DefinedElf, and both were easily
rewritten without it.

The class was also a bit confusing. The concept of "created for ELF
symbol" is orthogonal to defined/undefined types. However, we had
two distinct classes, DefinedElf and UndefinedElf.

This patch simply removes the class. Now the class hierarchy is one
level shallower.

llvm-svn: 265234
2016-04-02 18:06:18 +00:00
Sean Silva abd25c9b3e Call cl::ParseCommandLineOptions from the driver.
Thanks to Rui for the suggestion; this simplifies things.

llvm-svn: 265213
2016-04-02 04:08:02 +00:00
Davide Italiano 4fda708624 [LTO] Fix symbols which were internalized incorrectly.
If a symbol is defined in an archive, when we replace its body
the isUsedInRegularObj wasn't set correctly. Internalize makes
its decision based on that bit so we ended up internalizing
symbols that we shouldn't (because they're referenced).
This should fix. Thanks to Peter and Rafael for discussion
and help diagnosing the issue!

Found during LTO of unittests.

llvm-svn: 265208
2016-04-02 02:10:40 +00:00
Sean Silva 242bbdb7bf Fix MSVC build after r265206
c:\b\slave\sanitizer-windows\llvm\tools\lld\elf\Config.h(94) : error C2797: 'lld:🧝:Configuration::MLlvm': list initialization inside member initializer list or non-static data member initializer is not implemented

llvm-svn: 265207
2016-04-02 01:51:51 +00:00
Sean Silva 8e4ad5dbf8 PR27104: Add -mllvm option
The argv[0] is based on the analogous thing in clang.

llvm-svn: 265206
2016-04-02 01:39:56 +00:00
Rafael Espindola 059f3fb8fb Don't create a plt when LD access is optimized.
llvm-svn: 265203
2016-04-02 00:19:22 +00:00
Rafael Espindola cf3b04dab9 Don't create a PLT when we optimize out the plt use.
llvm-svn: 265202
2016-04-01 23:36:56 +00:00
Rui Ueyama e8a45e48f9 Rename a few variables. NFC.
We had Phdr, PHdr and Phdrs in one line. That was a bit confusing.

llvm-svn: 265194
2016-04-01 22:42:04 +00:00
Rafael Espindola 36404d0030 Simplify if. NFC.
llvm-svn: 265166
2016-04-01 18:04:21 +00:00
George Rimar 687788c90e [ELF] - Split Writer::assignAddresses(): extract code for initializing dummies sections
Extracts code for initializing dummies sections
to avoid possible duplication in following patches.

Differential review: http://reviews.llvm.org/D18691

llvm-svn: 265159
2016-04-01 17:30:52 +00:00
Rui Ueyama f7f52ef65d Make error handling consistent.
Some functions in Writer reports error using HasError, and some reports
their return values. This patch makes them to consistently use HasError.

llvm-svn: 265156
2016-04-01 17:24:19 +00:00
Rui Ueyama 8ecc2ec0e3 Remove dead code.
Thanks to George Rimor for pointing it out.

llvm-svn: 265155
2016-04-01 17:17:14 +00:00
Rui Ueyama a63baf176f Don't do extra work if -r is given.
fixAbsoluteSymbols fixes linker-created symbol addresses. Since we don't
create such symbols for relocatable output, we don't need to call this
function.

llvm-svn: 265154
2016-04-01 17:11:42 +00:00
Rui Ueyama e044e9cf80 Tidy up address and file offset assignments in the Writer.
assignAddressesRelocatable function did not set addresses to sections
despite its name. What it actually did is to set file offsets to sections.
assignAddresses function assigned addresses and file offsets to sections.
So there was a confusion what they were doing, and they had duplicate code.

This patch separates file offset assignments from address assignments.
A new function, assignFileOffsets assign file offsets. assignAddresses
do not care about file offsets anymore.

llvm-svn: 265151
2016-04-01 17:07:17 +00:00
Rafael Espindola 790db9c458 Bring r264761 back with an extra fix.
The extra fix is to note that it still requires copy relocations.

Original message:

Change how we handle R_MIPS_LO16.

Mips aligns PT_LOAD to 16 bits (0x10000). That means that the lower 16
bits are always the same, so we can, effectively, say that the
relocation is relative.

P.S.: Suggestions for a better name for the predicate are welcome :-)

llvm-svn: 265150
2016-04-01 17:00:36 +00:00
Rafael Espindola 2ee0092053 Don't apply a recolation that the dynamic linker will rewrite.
This matches the behavior of both bfd and gold. Looks like we just got
here for mips because of a bad ordering of an if else chain.

llvm-svn: 265147
2016-04-01 16:21:09 +00:00
Rafael Espindola 666625b78c Pass a const pointer to getImplicitAddend. NFC.
llvm-svn: 265143
2016-04-01 14:36:09 +00:00
Rafael Espindola 31d2ada6d5 Refactor duplicated code.
We had almost identical code to handle creating a plt entry in two
places.

llvm-svn: 265142
2016-04-01 14:14:48 +00:00
Rafael Espindola b97f4beec4 Avoid creating duplicated relocations.
llvm-svn: 265139
2016-04-01 12:54:27 +00:00
George Rimar 5a5c39ca2a Fix linux buildbot after r265136
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/20138

Fix: Move method above class that uses it.
Works fine with MSVS.

llvm-svn: 265137
2016-04-01 12:24:28 +00:00