Commit Graph

963 Commits

Author SHA1 Message Date
George Rimar 2c9b7bd326 Replace StringRef with std::string in LinkerDriver::addLibrary(StringRef Name) because std::string is destroyed after assigning what fills the buffer with garbage and StringRef is no more valid.
That fixes few failing tests under windows+msvs2015(debug).

llvm-svn: 259186
2016-01-29 10:52:52 +00:00
Rui Ueyama 9398f86a2a Remove a parameter from Target::writePlt.
llvm-svn: 259158
2016-01-29 04:15:02 +00:00
Rui Ueyama 012eb783b3 ELF: Provide default implemenatations for simple functions.
llvm-svn: 259157
2016-01-29 04:05:09 +00:00
Rui Ueyama 57b676c546 Define stub functions instead of pure virtual functions.
To remove empty functions.

llvm-svn: 259155
2016-01-29 03:51:51 +00:00
Rui Ueyama 900e2d2578 ELF: Do not pass addresses that can be obtained using Out.
llvm-svn: 259154
2016-01-29 03:51:49 +00:00
Rui Ueyama 6251545683 Rename PltZeroEntrySize -> PltZeroSize.
This patch also fixes parameter name. They points to the beginning
of PLT or GOT tables, so GotAddr or PltAddr are better.)

llvm-svn: 259150
2016-01-29 03:00:32 +00:00
Rui Ueyama 69c30edb5e Add a comment.
llvm-svn: 259149
2016-01-29 03:00:30 +00:00
Rui Ueyama c516ae1719 ELF: Make Target's member function names shorter.
llvm-svn: 259147
2016-01-29 02:33:45 +00:00
Rui Ueyama c112c1be69 Rename includeInDynamicSymtab -> includeInDynsym.
llvm-svn: 259144
2016-01-29 02:17:01 +00:00
Rui Ueyama 1940424632 ELF: Report multiple errors from the driver.
This patch let the driver keep going until it parses all
command line options.

http://reviews.llvm.org/D16645

llvm-svn: 259143
2016-01-29 01:54:52 +00:00
Rui Ueyama 572a6f74a7 Rename DynamicSymbolTableIndex -> DynsymIndex.
This is the index in .dynsym, so the new name should make sense.

llvm-svn: 259142
2016-01-29 01:49:33 +00:00
Rui Ueyama 724d625c7a ELF: Remove accessors from Target.
These accessors do not provide values. We can simply make the variables public.

llvm-svn: 259141
2016-01-29 01:49:32 +00:00
Rui Ueyama 74b7df016f Remove unused variable.
llvm-svn: 259140
2016-01-29 01:49:29 +00:00
Rafael Espindola e2c2461a6b Merge identical strings.
This avoids the need to have reserve and addString in sync.

We avoid hashing the global symbols again. This means that we don't
merge a global symbol that has the same name as some other string, but
that doesn't seem very common. The string table size is the same in
clang an scylladb with or without hashing global symbols again.

llvm-svn: 259136
2016-01-29 01:24:25 +00:00
Rui Ueyama baf16512ea Rename isTlsOptimized -> canRelaxTls.
This function is a predicate that a given relocation can be relaxed.
The previous name implied that it returns true if a given relocation
has already been optimized away.

llvm-svn: 259128
2016-01-29 00:20:12 +00:00
Rui Ueyama 0e36e09b9c Update comments.
llvm-svn: 259127
2016-01-29 00:20:09 +00:00
Rui Ueyama c2a0d7e351 ELF: Report more than one undefined symbols if exist.
http://reviews.llvm.org/D16643

llvm-svn: 259107
2016-01-28 22:56:29 +00:00
Rui Ueyama 64cfffd333 ELF: Rename error -> fatal and redefine error as a non-noreturn function.
In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.

In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.

This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.

In this patch, I rename error to fatal, and introduce another version of
error which doesn't call exit. That function instead sets HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.

I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.

http://reviews.llvm.org/D16641

llvm-svn: 259069
2016-01-28 18:40:06 +00:00
Rui Ueyama 0de86c1659 Do not use return with a function whose return type is void.
Although it is syntactically correct, it is a bit confusing, and
not necessary here.

llvm-svn: 258996
2016-01-27 22:23:44 +00:00
Rafael Espindola 10d71ffc65 Remove another case of almost duplicated code.
Were had very similar code for deciding to keep a local symbol and for
actually writing it.

llvm-svn: 258958
2016-01-27 18:04:26 +00:00
Rafael Espindola 81e05525e3 Handle local symbols in discarded sections.
We were reserving space for them but never writing them out.

llvm-svn: 258948
2016-01-27 17:09:37 +00:00
Rafael Espindola 0e92f24880 Remove redundant variable.
llvm-svn: 258940
2016-01-27 16:41:24 +00:00
Rui Ueyama 231b5e23c5 Simplify. NFC.
llvm-svn: 258796
2016-01-26 07:17:29 +00:00
Rui Ueyama 3ae28a4758 Simplify. NFC.
llvm-svn: 258795
2016-01-26 07:17:27 +00:00
Rui Ueyama d6cea14cbb Simplify. NFC.
This new code should be logically equivalent to the previous code.

llvm-svn: 258792
2016-01-26 04:58:58 +00:00
Rui Ueyama 5ec41f3b74 Add missing template instantiations.
llvm-svn: 258767
2016-01-26 01:32:00 +00:00
Rafael Espindola cc3ae413ce Fix MSVC build.
llvm-svn: 258766
2016-01-26 01:30:07 +00:00
Rui Ueyama 1546fb2d65 Move code to create RELATIVE reloc for TLS_IE to one place.
llvm-svn: 258760
2016-01-26 01:03:21 +00:00
Rui Ueyama b0210e83b3 ELF: Move code for GNU_IFUNC to one place. NFC.
This does not solve the problem that we call isGnuIFunc function
both from RelocationSection and from the Writer::scanRelocs, but
this at least should improve readability. I'm taking an incremental
approach to reduce complexity.

llvm-svn: 258753
2016-01-26 00:24:57 +00:00
Rui Ueyama ac9fb458fb Define a helper function to make it visually shorter. NFC.
llvm-svn: 258748
2016-01-25 23:38:34 +00:00
Rui Ueyama 304d135f56 Use Symtab.find() instead of Symtab.getSymbols().lookup().
This was the only place we directly called lookup on the internal table
of the symbol table.

llvm-svn: 258724
2016-01-25 21:47:25 +00:00
Rafael Espindola de06936f28 Avoid almost duplication in .dynamic finalize and write.
There are a few cases where we have almost duplicated code.

This patches fixes the simplest: the finalize and write of dynamic
section. Right now they have to have exactly the same structure to
decide if a DT_* entry is needed and then to actually write it.

We cannot just write it to a std::vector in the first pass since
addresses have not been computed yet.

llvm-svn: 258723
2016-01-25 21:32:04 +00:00
George Rimar 45ca88dbdf Fix: added assert condition to EhFrameHeader<ELFT>::assignEhFrame().
Thanks to David Blaikie who found that issue.

llvm-svn: 258707
2016-01-25 19:27:50 +00:00
George Rimar 02ca17906d [ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.
Main executable did not export symbols that exist both in the main executable and in DSOs before this patch.
Symbols from object files that override symbols in DSO should be added to .dynsym table.

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

llvm-svn: 258672
2016-01-25 08:44:38 +00:00
George Rimar 06415e97f2 Use of assert instead of llvm_unreachable in EhFrameHeader<ELFT>::assignEhFrame().
llvm-svn: 258670
2016-01-25 08:20:16 +00:00
Sean Silva f1c5a0f09c [ELF] Avoid unnecessary global variable.
Summary: It looks like this snuck through in r256143/D15383.

Reviewers: ruiu, grimar

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

llvm-svn: 258599
2016-01-23 01:49:37 +00:00
Pete Cooper 6025933789 Fix bug in handling of quoted linker script tokens and update tests to use it.
There was an off by one error because the StringRef.substr functions
second argument is a length, not the end index.

Also updated a few ELF files which failed when run on Jenkins with paths
including the @ character.  This is often used in Jenkins for shared
workspace plugin.

Reviewed by Rui Ueyama

llvm-svn: 258583
2016-01-22 23:46:37 +00:00
Rafael Espindola 25472ee9c2 Remove unnecessary object:: prefix.
llvm-svn: 258563
2016-01-22 21:49:07 +00:00
Rui Ueyama ac2b0a168d Remove dead code.
llvm-svn: 258539
2016-01-22 19:55:01 +00:00
George Rimar 237b218770 [ELF] - fix possible UB when dereferencing null
In InputSection.cpp it was possible to dereference null.
Had to change signature of relocateTlsOptimize to accept pointer instead of reference.

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

llvm-svn: 258508
2016-01-22 18:02:28 +00:00
George Rimar d0cb85b62d Use of llvm_unreachable instead of warning in EhFrameHeader<ELFT>::assignEhFrame().
llvm-svn: 258499
2016-01-22 10:57:39 +00:00
Rui Ueyama bef81f3a70 ELF: Move code to emit copyrel to one place. NFC.
In this code, we avoid calling needsCopyRel in writeTo because
we called that function already in scanRelocs. Making the same
decision twice is a waste and has a risk of a bug that we get
inconsistent resuts.

llvm-svn: 258430
2016-01-21 20:59:22 +00:00
Rui Ueyama 88d79a06b7 Style change. NFC.
llvm-svn: 258427
2016-01-21 20:18:36 +00:00
George Rimar bfd29a1567 [ELF] - Refactoring of Writer<ELFT>::scanRelocs()
Code for handling TLS relocations was moved out scanRelocs() to new function handleTlsRelocations().
That is because scanRelocs already too large to put more TLS code into it.

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

llvm-svn: 258392
2016-01-21 09:14:22 +00:00
Simon Atanasyan 56ab5f0289 [ELF][MIPS] Initial support of MIPS local GOT entries
Some MIPS relocation (for now R_MIPS_GOT16) requires creation of GOT
entries for symbol not included in the dynamic symbol table. They are
local symbols and non-local symbols with 'local' visibility. Local GOT
entries occupy continuous block between GOT header and regular GOT
entries.

The patch adds initial support for handling local GOT entries. The main
problem is allocating local GOT entries for local symbols. Such entries
should be initialized by high 16-bit of the symbol value. In ideal world
there should be no duplicated entries with the same values. But at the
moment of the `Writer::scanRelocs` call we do not know a value of the
symbol. In this patch we create new local GOT entry for each relocation
against local symbol, though we can exhaust GOT quickly. That needs to
be optimized later. When we calculate relocation we know a final symbol
value and request local GOT entry index. To do that we maintain map
between addresses and local GOT entry indexes. If we start to calculate
relocations in parallel we will have to serialize access to this map.

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

llvm-svn: 258388
2016-01-21 05:33:23 +00:00
Rui Ueyama 90f76fbb54 Return early before iterating over local symbols. NFC.
llvm-svn: 258385
2016-01-21 03:07:38 +00:00
Rui Ueyama c5e372db40 Simplify function signature. NFC.
StringTable is a member variable, so we don't need to pass it around.

llvm-svn: 258382
2016-01-21 02:10:12 +00:00
Rui Ueyama 1e056ebe3c Fix indentation.
llvm-svn: 258374
2016-01-21 00:45:39 +00:00
Simon Atanasyan 0d5e1b753e [ELF] Do not keep STT_FILE symbols in the symbol table
STT_FILE symbols usually contain source file names. It is redundant
to keep this information in the output file.

llvm-svn: 258331
2016-01-20 18:59:45 +00:00
Rafael Espindola 65e80b963a Rename IgnoredWeak to Ignored.
Thanks to Rui for the suggestion.

llvm-svn: 258189
2016-01-19 21:19:52 +00:00