Commit Graph

5553 Commits

Author SHA1 Message Date
Rafael Espindola a15fb15b05 Don't lower the visibility because of shared symbols.
If a shared library has a protected symbol 'foo', that doesn't imply
that the symbol 'foo' in the output should be protected or not.

llvm-svn: 265794
2016-04-08 16:11:42 +00:00
Rafael Espindola b729b2131d Produce STV_DEFAULT for symbols in shared libraries.
The spec says:
If a symbol definition with STV_PROTECTED visibility from a shared
object is taken as resolving a reference from an executable or another
shared object, the SHN_UNDEF symbol table entry created has STV_DEFAULT
visibility.

llvm-svn: 265792
2016-04-08 15:43:43 +00:00
Rafael Espindola badd397aa7 Make getSymbolBinding a local static. NFC.
llvm-svn: 265791
2016-04-08 15:30:56 +00:00
Adhemerval Zanella 15cba9e7e5 [lld] [ELF/AARCH64] Fix dynamic relocation from PIC GOT access
This patch fixes dynamic relocation creation from GOT access in dynamic
objects on aarch64. Current code creates a plt relative one
(R_AARCH64_JUMP_SLOT) instead of a got relative (R_AARCH64_GLOB_DAT).

It leads the programs fails with:

$ cat t.cc

std::string test = "hello...\n";

int main ()
{
  printf ("%s\n", test.c_str());
  return 0;
}
$ clang++ t.cc -fpic -o t
$ ./t
hello...

Segmentation fault (core dumped)

Due the fact it will try to access the plt instead of the got for
__cxa_atexit registration for the std::string destruction.  It will
lead in a bogus function address in atexit.

llvm-svn: 265784
2016-04-08 14:10:41 +00:00
Rui Ueyama 57bbdaf937 Simplify createELFFile. NFC.
llvm-svn: 265758
2016-04-08 00:18:25 +00:00
Rui Ueyama 4655ea3ff8 Define a helper function to simplify. NFC.
llvm-svn: 265757
2016-04-08 00:14:55 +00:00
Rui Ueyama 6c8b0c1b96 Use EM_NONE instead of 0 to represent an invalid value. NFC.
llvm-svn: 265750
2016-04-07 23:54:33 +00:00
Rui Ueyama d86ec30168 ELF: Add --build-id=sha1 option.
llvm-svn: 265748
2016-04-07 23:51:56 +00:00
Peter Collingbourne e217660591 ELF: Ignore --detect-odr-violations flag.
Differential Revision: http://reviews.llvm.org/D18877

llvm-svn: 265744
2016-04-07 23:15:50 +00:00
Rui Ueyama 3a41be277a ELF: Implement --build-id=md5.
Previously, we supported only one hash function, FNV-1, so
BuildIdSection directly handled hash computation. In this patch,
I made BuildIdSection an abstract class and defined two subclasses,
BuildIdFnv1 and BuildIdMd5.

llvm-svn: 265737
2016-04-07 22:49:21 +00:00
Rui Ueyama 5d92af65d3 Sort options.
llvm-svn: 265724
2016-04-07 21:10:42 +00:00
Rui Ueyama c4354a3c18 ELF: Define -S as an alias for --strip-debug.
llvm-svn: 265723
2016-04-07 21:10:09 +00:00
Rui Ueyama fc6a4b045f ELF: Add --strip-debug option.
If --strip-debug option is given, then all sections whose names start
with ".debug" are removed from output.

llvm-svn: 265722
2016-04-07 21:04:51 +00:00
Rui Ueyama 8c76487ee5 ELF: Add --no-gnu-unique option.
When the option is specified, then all STB_GNU_UNIQUE symbols are
converted to STB_GLOBAL symbols.

llvm-svn: 265717
2016-04-07 20:41:41 +00:00
Rui Ueyama f8baa66056 ELF: Implement --start-lib and --end-lib
start-lib and end-lib are options to link object files in the same
semantics as archive files. If an object is in start-lib and end-lib,
the object is linked only when the file is needed to resolve
undefined symbols. That means, if an object is in start-lib and end-lib,
it behaves as if it were in an archive file.

In this patch, I introduced a new notion, LazyObjectFile. That is
analogous to Archive file type, but that works for a single object
file instead of for an archive file.

http://reviews.llvm.org/D18814

llvm-svn: 265710
2016-04-07 19:24:51 +00:00
Rafael Espindola 3828b88d86 Fix an use after free.
Thanks to asan for pointing it out that OutputSections was being
resized.

llvm-svn: 265686
2016-04-07 15:50:23 +00:00
Rafael Espindola 74031ba1e9 Simplify dynamic relocation creation.
The position of a relocation can always be expressed as an offset in an
output section.

llvm-svn: 265682
2016-04-07 15:20:56 +00:00
Rafael Espindola c012db35d7 Delete Off_Bss.
It is now just a special case of Off_Sec.

llvm-svn: 265676
2016-04-07 14:34:15 +00:00
Rafael Espindola 56004c577a Don't create dynamic relocs for discarded .eh_frame entries.
This requires knowing input section offsets in output sections before
scanRelocs. This is generally a good thing and should allow further
simplifications in the creation of dynamic relocations.

llvm-svn: 265673
2016-04-07 14:22:09 +00:00
Rafael Espindola 7231c3372f Add a test for the offset of dynamic relocations.
I found that a patch I am working on would have broken this and no
existing test found it.

llvm-svn: 265664
2016-04-07 12:02:42 +00:00
Rui Ueyama e0f1ab87c8 Ignore --warn-execstack.
Stack is not executable by default in LLD-built executables unless
you pass -z execstack option. So --warn-execstack option does not make
sense to us.

llvm-svn: 265619
2016-04-06 23:55:43 +00:00
Kevin Enderby 439453679c Needed change to lld for the change to createBinary() now returning Expected<...>
With the llvm change in r265606 this is the matching needed change to the lld
code now that createBinary() is returning Expected<...> .

llvm-svn: 265607
2016-04-06 22:15:23 +00:00
Adhemerval Zanella b92a34e458 [lld] Fix build failure from r265600
llvm-svn: 265603
2016-04-06 21:33:18 +00:00
Adhemerval Zanella e77b5bf69f [lld] [ELF] Add ScriptParserBase class
This patch add a base script tokenizer class to decouple parsing from
linker script handling.  The idea is to use this base class on dynamic
list parsing (--dynamic-list option). No functionality added.

llvm-svn: 265600
2016-04-06 20:59:11 +00:00
Rafael Espindola 1b6188d2f8 Make this test a bit stronger.
Show that in addition to handling empty .eh_frame, it is merged with any
regular .eh_frame.

llvm-svn: 265588
2016-04-06 19:38:26 +00:00
Ed Schouten 39aca42df6 Sort relocations by name and size.
Approved by:	ruiu
Differential Revision:	http://reviews.llvm.org/D18835

llvm-svn: 265580
2016-04-06 18:21:07 +00:00
Ed Schouten 0a04b03ab2 Make TLS work for PIE executables on aarch64.
Similar to r265462, TLS related relocations aren't marked as relative,
meaning that we end up generating R_AARCH64_RELATIVE relocations for
them. This change adds TLS relocations that I've seen on my system. With
this patch applied CloudABI's unit testing binary now passes on aarch64.

Approved by:	ruiu
Differential Revision:	http://reviews.llvm.org/D18816

llvm-svn: 265575
2016-04-06 17:53:31 +00:00
Lang Hames 33fd854584 [lld][MachO] Clean up some unnecessarily verbose code. NFC.
Suggested by Dave Blaikie in review of r265447. Thanks Dave!

llvm-svn: 265566
2016-04-06 17:18:55 +00:00
Rafael Espindola 5e34568f79 Use a bit in SymbolBody to store CanKeepUndefined.
UndefinedElf for 64 bits goes from 72 to 64 bytes.

llvm-svn: 265543
2016-04-06 14:31:03 +00:00
Rafael Espindola f47657301b Change the type hierarchy for undefined symbols.
We have to differentiate undefined symbols from bitcode and undefined
symbols from other sources.

Undefined symbols from bitcode should not inhibit the symbol being
internalized. Undefined symbols from other sources should.

llvm-svn: 265536
2016-04-06 13:22:41 +00:00
Rafael Espindola 242ffa8da1 Fix use of uninitialized.
The names of undefined locals are not used, so I don't think it is
possible to actually test this.

llvm-svn: 265534
2016-04-06 12:19:25 +00:00
Rafael Espindola f9b79a479e Rename a few Visibility arguments to StOther.
llvm-svn: 265533
2016-04-06 12:14:31 +00:00
George Rimar 2348320d4e [ELF] - Teach linkerscript error handler to show full script line and column marker on error.
When error, this adds the text line of script to the output
and a marks exact incorrect token under it:

line 1: <error text here>
UNKNOWN_TAG {
      ^

Differential revision: http://reviews.llvm.org/D18699

llvm-svn: 265523
2016-04-06 08:08:40 +00:00
George Rimar 7ca0627c51 [ELF] - Do not handle ELF and program header as dummy sections.
ELF and program header are not part of OutputSections list anymore.
That helps to avoid having and working with functions like dummySectionsNum().
Still keeping them as sections helps to simplify the code.

Differential revision: http://reviews.llvm.org/D18743

llvm-svn: 265522
2016-04-06 07:20:45 +00:00
Rui Ueyama ec6aee0927 Do not allocate MipsReginfo using BumpPtrAllocator.
So that MipsReginfo's destructor will be called.

llvm-svn: 265512
2016-04-06 02:52:47 +00:00
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
Lang Hames 24f5a3eb03 [lld][MachO] Check Expected<T> for error prior to destruction.
This should fix the failures on the LLD bots caused by r265446.

llvm-svn: 265477
2016-04-05 22:06:48 +00:00
Rafael Espindola 2d390b6c8b Add a test for relocations in non alloc sections.
We already got this right, but we were not testing it.

llvm-svn: 265471
2016-04-05 21:27:30 +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 c393c028a9 Add triple to llvm-mc command line. Should fix Windows bot.
llvm-svn: 265373
2016-04-05 01:05:42 +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