Commit Graph

501 Commits

Author SHA1 Message Date
Rui Ueyama b3e2f74517 Update comments.
llvm-svn: 328604
2018-03-27 02:52:58 +00:00
Rui Ueyama b391288af7 Refactor SharedFile::parseRest. NFC.
SharedFile::parseRest function grew organically and got a bit hard to
understand. This patch refactor it. This patch also adds comments.

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

llvm-svn: 328579
2018-03-26 19:57:38 +00:00
Rui Ueyama d37c33aff2 Do not add a dummy entry to SharedFile::Verdefs. NFC.
Previously, we used 0 as an alias for VER_NDX_GLOBAL and had a dummy
entry in SharedFile::Verdefs so that the access to the array is within
its boundary. But that's not straightforwad. We can just stop doing both.

llvm-svn: 328401
2018-03-24 00:25:24 +00:00
Rui Ueyama bd63adcb26 Remove "FIXME" from a comment.
A bug in BFD linker is not our FIXME item.

llvm-svn: 328381
2018-03-23 22:48:17 +00:00
Rafael Espindola 85e77b26be Fix the MSVC build.
llvm-svn: 328285
2018-03-23 00:42:47 +00:00
Rafael Espindola 3c3ebcc5f4 Fix PR36793.
With this patch lld will iterate over compile units to find the line
tables instead of assuming there is only one at offset 0.

llvm-svn: 328284
2018-03-23 00:35:27 +00:00
Rafael Espindola c08e5afb7c Replace a std::pair with a struct.
This is more readable and should reduce the noise in a followup patch.

llvm-svn: 328164
2018-03-21 22:32:17 +00:00
Rui Ueyama 8e53917a26 Add a comment about ELF spec and the symbol table's sh_info.
llvm-svn: 327645
2018-03-15 17:10:50 +00:00
George Rimar 59ebd4adf0 [ELF] - Formatted comment, fixed mistype. NFC.
llvm-svn: 327280
2018-03-12 15:18:35 +00:00
George Rimar 1136ec64e8 [ELF] - Fix crash relative to SHF_LINK_ORDER sections.
Our code assumes all input sections in an output SHF_LINK_ORDER
section has SHF_LINK_ORDER flag. We do not check that and that can cause a crash.

That happens because we call 
std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);, 
where compareByFilePosition predicate does not expect to see
null when calls getLinkOrderDep. 

The same might happen when sections refer to non-regular sections. 
Test cases demonstrate the issues, patch fixes them.

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

llvm-svn: 327006
2018-03-08 15:06:58 +00:00
Rui Ueyama e66d7a798f Return early. NFC.
We don't need to handle an object file having more than one symbol table,
so as soon as we find the first one, we can process it and then return
from the function.

llvm-svn: 326977
2018-03-08 01:22:30 +00:00
Rui Ueyama c13d858b6d Simplify LazyobjFile and readElfSymbols.
addElfSymbols and readJustSymbolsFile still has duplicate code, but
I didn't come up with a good idea to eliminate them. Since this patch
is an improvement, I'm sending this for review.

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

llvm-svn: 326972
2018-03-08 01:05:58 +00:00
James Henderson cb4c19f315 [ELF] Prevent crash when reporting errors if debug line cannot be parsed
LLD uses the debug info and debug line sections to determine the location of
e.g. references to undefined symbols, when producing error messages. In the
event that debug info was present, but debug line parsing failed for some
reason, then a nullptr would end up being dereferenced by the location-lookup
code.

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

Reviewers: grimar
llvm-svn: 326899
2018-03-07 15:22:58 +00:00
Rui Ueyama 09fcd4c34c Implement --just-symbols.
Differential Revision: https://reviews.llvm.org/D39348

llvm-svn: 326835
2018-03-06 21:25:37 +00:00
Rafael Espindola 3f4c673d38 Put undefined symbols from shared libraries in the symbol table.
With the recent fixes these symbols have more in common than not with
regular undefined symbols.

llvm-svn: 326242
2018-02-27 20:31:22 +00:00
Igor Kudrin 3345c9ac18 [ELF] Create and export symbols provided by a linker script if they referenced by DSOs.
It should be possible to resolve undefined symbols in dynamic libraries
using symbols defined in a linker script.

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

llvm-svn: 326176
2018-02-27 07:18:07 +00:00
Peter Collingbourne 09e04af42f ELF: Stop collecting a list of symbols in ArchiveFile.
There seems to be no reason to collect this list of symbols.

Also fix a bug where --exclude-libs would apply to all symbols that
appear in an archive's symbol table, even if the relevant archive
member was not added to the link.

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

llvm-svn: 325380
2018-02-16 20:23:54 +00:00
Simon Atanasyan 85815a3149 [ELF][MIPS] Ignore incorrect version definition index for _gp_disp symbol
MIPS BFD linker puts _gp_disp symbol into DSO files and assigns zero
version definition index to it. This value means 'unversioned local
symbol' while _gp_disp is a section global symbol. We have to handle
this bug in the LLD because BFD linker is used for building MIPS
toolchain libraries.

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

llvm-svn: 324467
2018-02-07 10:02:49 +00:00
George Rimar f9dc10cd89 [ELF] - Report valid binary filename when reporting error.
We did not report valid filename for duplicate symbol error when
symbol came from binary input file.
Patch fixes it.

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

llvm-svn: 324217
2018-02-05 09:47:24 +00:00
Rui Ueyama f46d3d1be9 Strip .note.gnu.build-id sections if --build-id is given.
Differential Revision: https://reviews.llvm.org/D42823

llvm-svn: 324146
2018-02-02 21:56:24 +00:00
Paul Robinson bf750c80e9 [DWARFv5] Re-enable dumping a line table with no CU.
r323476 added support for DW_FORM_line_strp, and incorrectly made that
depend on having a DWARFUnit available.  We shouldn't be tracking
.debug_line_str in DWARFUnit after all.  After this patch, I can do an
NFC follow up and undo a bunch of the "plumbing" part of r323476.

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

llvm-svn: 323691
2018-01-29 20:57:43 +00:00
Rafael Espindola 9a84f6b954 Detemplate reportDuplicate.
We normally avoid "switch (Config->EKind)", but in this case I think
it is worth it.

It is only executed when there is an error and it allows detemplating
a lot of code.

llvm-svn: 321404
2017-12-23 17:21:39 +00:00
Rafael Espindola ce3b52c186 Pass an InputFile to the InputSection constructor.
This simplifies toRegularSection and reduces the noise in a followup
patch.

llvm-svn: 321240
2017-12-21 02:11:51 +00:00
Rafael Espindola 604032729c Convert a few more InputFiles to references.
We use null files in sections to represent linker created sections,
so ObjFile<ELFT> is never null.

llvm-svn: 321238
2017-12-21 02:03:39 +00:00
Rafael Espindola 920d7d80e2 clang-format. NFC.
llvm-svn: 321216
2017-12-20 19:59:47 +00:00
Rafael Espindola 8cd6674f5b Use a reference in addLazyArchive. NFC.
llvm-svn: 321194
2017-12-20 17:48:28 +00:00
Rafael Espindola a32ddc4639 Use a reference for the shared symbol file.
Every shared symbol has a file, so we can use a reference.

llvm-svn: 321187
2017-12-20 16:28:19 +00:00
Rafael Espindola 7b5cc6c5dc Use a reference for a value that is never null. NFC.
llvm-svn: 321186
2017-12-20 16:19:48 +00:00
Rafael Espindola f1687125ba Use a reference for a value that is never null. NFC.
llvm-svn: 321185
2017-12-20 16:16:40 +00:00
Rafael Espindola 75ebe9a3bf Handle a VersymIndex of 0 as an error.
I noticed that the continue this patch deletes was not tested. Trying
to add a test I realized that we never put a VER_NDX_LOCAL symbol in
the dynamic symbol table. There doesn't seem to be any reason for a
linker to use VER_NDX_LOCAL for a defined shared symbol.

llvm-svn: 320817
2017-12-15 14:52:40 +00:00
Rui Ueyama 29ceba7961 Fix error messages.
llvm-svn: 320772
2017-12-15 00:07:15 +00:00
Rui Ueyama fbe68a3584 Use warn() instead of error() to report a bad symbol in a DSO.
Specifically, libwidevinecdm.so in Chrome has such bad symbol.
It seems the BFD linker handles them as local symbols, so instead
of inserting them to the symbol table, we should skip them too.

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

llvm-svn: 320770
2017-12-15 00:01:33 +00:00
Rui Ueyama d44a81c3a8 Inline a small function.
Differential Revision: https://reviews.llvm.org/D41204

llvm-svn: 320652
2017-12-13 22:53:59 +00:00
Rafael Espindola cee2933408 Remove unnecessary use of Repl.
This runs before ICF, so Sec->Repl == Sec.

llvm-svn: 320543
2017-12-13 02:09:14 +00:00
Rafael Espindola 8f619ab826 Compact symbols from 96 to 88 bytes.
By using an index instead of a pointer for verdef we can put the index
next to the alignment field. This uses the otherwise wasted area and
reduces the shared symbol size.

By itself the performance change of this is in the noise, but I have a
followup patch to remove another 8 bytes that improves performance
when combined with this.

llvm-svn: 320449
2017-12-12 01:45:49 +00:00
Rui Ueyama c0081639cc Remove checkToString functions and use toString instead.
Differential Revision: https://reviews.llvm.org/D40928

llvm-svn: 320005
2017-12-07 03:24:57 +00:00
Rui Ueyama bdc5150984 Always evaluate the second argument for CHECK() lazily.
This patch is to rename check CHECK and make it a C macro, so that
we can evaluate the second argument lazily.

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

llvm-svn: 319974
2017-12-06 22:08:17 +00:00
Rafael Espindola b6e2ca4597 Convert a check to checkLazy.
This brings memory allocations when linking clang from 270.96MB to
267.80MB.

llvm-svn: 319932
2017-12-06 19:17:20 +00:00
Rafael Espindola aca3df5479 Convert a few uses of check to checkLazy.
Linking clang goes from 292.68MB to 281.80MB allocated.

llvm-svn: 319927
2017-12-06 19:08:10 +00:00
Rafael Espindola 5b491a29fb Convert a call to check to checkLazy.
Linking clang goes from 300.82MB to 292.68MB allocated.

llvm-svn: 319926
2017-12-06 19:02:12 +00:00
Rafael Espindola c8dfde2051 Replace one use of check with checkLazy.
Reduce total allocation when linking clang from 320.04MB to 300.82MB.

llvm-svn: 319924
2017-12-06 18:56:22 +00:00
Rafael Espindola 9ffa988b5d Add a checkLazy error checking variant.
This avoids allocating the error message when there is no error that
check requires.

It avoids the code duplication of inlining check.

llvm-svn: 319922
2017-12-06 18:52:13 +00:00
Rafael Espindola 8b97611190 Don't allocate memory for an error message on success.
This takes memory allocations when linking clang-fsds from 342.08MB to
320.04MB.

llvm-svn: 319918
2017-12-06 18:39:22 +00:00
Rafael Espindola f4c3239824 Don't allocate an error message when there is no error.
According to heaptrack this takes "bytes allocated in total" when
linking clang-fsds from 405.69MB to 342.08MB.

llvm-svn: 319916
2017-12-06 18:31:11 +00:00
Rafael Espindola dfebd3601d Use Symbol::File directly.
We are already paying the cost of storing a InputFile in every
Symbol, so use it uniformly.

llvm-svn: 319378
2017-11-29 22:47:35 +00:00
Peter Smith 8fca2e12ab [ELF] Make sure SHT_ARM_ATTRIBUTES is only recognized by Arm Targets
The SHT_ARM_ATTRIBUTES section type is in the processor specific space
adding guard to make sure that it is only recognized when EMachine is
EM_ARM.

llvm-svn: 319304
2017-11-29 10:20:46 +00:00
Rui Ueyama 2017d52b54 Move Memory.{h,cpp} to Common.
Differential Revision: https://reviews.llvm.org/D40571

llvm-svn: 319221
2017-11-28 20:39:17 +00:00
Peter Smith 57eb046984 [ELF] Read ARM BuildAttributes section to determine supported features.
lld assumes some ARM features that are not available in all Arm
processors. In particular:
- The blx instruction present for interworking.
- The movt/movw instructions are used in Thunks.
- The J1=1 J2=1 encoding of branch immediates to improve Thumb wide
  branch range are assumed to be present.

This patch reads the ARM Attributes section to check for the
architecture the object file was compiled with. If none of the objects
have an architecture that supports either of these features a warning
will be given. This is most likely to affect armv6 as used in the first
Raspberry Pi.

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

llvm-svn: 319169
2017-11-28 13:51:48 +00:00
Rafael Espindola de56343cf0 Simplify as-needed handling.
This is a reduction of a patch by Rui Ueyama.

llvm-svn: 318852
2017-11-22 17:50:42 +00:00
George Rimar 80355234f7 [ELF] - Allow applying SHF_MERGE optimization for relocatable output.
This fixes PR35223.

Here I enabled SHF_MERGE section content merging for -r like
we do for regular linking.

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

llvm-svn: 318516
2017-11-17 11:27:57 +00:00