Commit Graph

450 Commits

Author SHA1 Message Date
Rafael Espindola 3f0b575363 Remove an unnecessary constraint.
Our current implementation of SHF_MERGE can already handle over
aligned elements.

llvm-svn: 318310
2017-11-15 17:31:27 +00:00
Paul Robinson e5400f8a6e [DWARFv5] Support DW_FORM_strp in the .debug_line header.
Supporting this form in .debug_line.dwo will be done as a follow-up.

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

llvm-svn: 317607
2017-11-07 19:57:12 +00:00
Rui Ueyama d5e2e8393b Report an error if an inferred alignment for a shared symbol is too large.
Differential Revision: https://reviews.llvm.org/D39697

llvm-svn: 317528
2017-11-07 00:12:05 +00:00
Peter Collingbourne e9a9e0a1e7 ELF: Merge DefinedRegular and Defined.
Now that DefinedRegular is the only remaining derived class of
Defined, we can merge the two classes.

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

llvm-svn: 317448
2017-11-06 04:35:31 +00:00
George Rimar ddd2424929 [ELF] - Fix error reporting with --strip-debug/--strip-all.
Currently LLD tries to use information about functions and variables location
taking it from debug sections. When --strip-* is given we discard such sections
and that breaks error reporting.
Patch stops discarding such sections and just removes them from InputSections list.

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

llvm-svn: 317405
2017-11-04 08:20:30 +00:00
Rui Ueyama f52496e1e0 Rename SymbolBody -> Symbol
Now that we have only SymbolBody as the symbol class. So, "SymbolBody"
is a bit strange name now. This is a mechanical change generated by

  perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF)

nd clang-format-diff.

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

llvm-svn: 317370
2017-11-03 21:21:47 +00:00
George Rimar cbed0e615b [ELF] - Teach LLD to strip .zdebug_* sections when --strip-debug/--strip-all is specified.
Currently we do not strip .zdebug_*, what looks wrong.
Also this simplifies the testcase we have for this options.

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

llvm-svn: 317306
2017-11-03 08:13:16 +00:00
George Rimar 82f0c42dad [ELF] - Teach LLD to report line numbers for data symbols.
This is PR34826.

Currently LLD is unable to report line number when reporting
duplicate declaration of some variable.

That happens because for extracting line information we always use
.debug_line section content which describes mapping from machine
instructions to source file locations, what does not help for
variables as does not describe them.

In this patch I am taking the approproate information about
variables locations from the .debug_info section.

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

llvm-svn: 317080
2017-11-01 07:42:38 +00:00
Rui Ueyama f1f00841d9 Merge SymbolBody and Symbol into one class, SymbolBody.
SymbolBody and Symbol were separated classes due to a historical reason.
Symbol used to be a pointer to a SymbolBody, and the relationship
between Symbol and SymbolBody was n:1.

r2681780 changed that. Since that patch, SymbolBody and Symbol are
allocated next to each other to improve memory locality, and they have
1:1 relationship now. So, the separation of Symbol and SymbolBody no
longer makes sense.

This patch merges them into one class. In order to avoid updating too
many places, I chose SymbolBody as a unified name. I'll rename it Symbol
in a follow-up patch.

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

llvm-svn: 317006
2017-10-31 16:07:41 +00:00
Rui Ueyama 27f95a9ac3 Remove unnecessary code.
Discarded section's Repl always points to itself, so returning
Sec is not different from returning Sec->Repl.

llvm-svn: 316880
2017-10-29 23:41:16 +00:00
Rui Ueyama 63edd9f831 Remove an obscure comment.
llvm-svn: 316878
2017-10-29 22:38:00 +00:00
Rui Ueyama b6f4e722b1 Fix ubsan error that shift amount 64 is too large.
llvm-svn: 316863
2017-10-29 16:49:42 +00:00
Rui Ueyama da42135cef Fix ubsan error.
This patch fixes ubsan's "shift exponent 64 is too large for 32-bit type
'int'" error.

llvm-svn: 316849
2017-10-28 22:18:29 +00:00
Rui Ueyama 1392e84caf Rename V -> Ver for readability.
llvm-svn: 316842
2017-10-28 20:16:11 +00:00
Rui Ueyama 7f9694a42d Pass symbol attributes instead of ElfSym to Shared symbol ctor.
This change allows us to use less templates for Shared symbol and
the functions that deals with shared symbols.

llvm-svn: 316841
2017-10-28 20:15:56 +00:00
Rui Ueyama f405b11224 Simplify error handling.
I don't think we have to aim for precise bug compatibility.
We can return a nullptr if a section is consumed by the linker, and
the rest should naturally work.

llvm-svn: 316817
2017-10-28 00:05:12 +00:00
Bob Haarman b8a59c8aa5 [lld] unified COFF and ELF error handling on new Common/ErrorHandler
Summary:
The COFF linker and the ELF linker have long had similar but separate
Error.h and Error.cpp files to implement error handling. This change
introduces new error handling code in Common/ErrorHandler.h, changes the
COFF and ELF linkers to use it, and removes the old, separate
implementations.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits

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

llvm-svn: 316624
2017-10-25 22:28:38 +00:00
Rui Ueyama 0543343170 Use more precise type.
llvm-svn: 315426
2017-10-11 04:01:13 +00:00
Rui Ueyama a1b79dff2a Handle input section liveness only in MarkLive.cpp.
The condition whether a section is alive or not by default
is becoming increasingly complex, so the decision of garbage
collection is spreading over InputSection.h and MarkLive.cpp,
which is not a good state.

This moves the code to MarkLive.cpp, to keep the file the central
place to make decisions about garbage collection.

llvm-svn: 315384
2017-10-10 22:59:32 +00:00
Rafael Espindola ae5e9ed422 Update for llvm change.
llvm-svn: 315377
2017-10-10 22:18:16 +00:00
Alexander Richardson b9aa9a5500 [ELF] Don't crash when parsing a file with out-of-bounds version references
Summary:
We were crashing when linking telnetd in FreeBSD because lld was emitting
corrupted output files for --norosegment. In this file the version index of some symbols
was set to 9 but lld only found 8 version definitions.

I am not sure how to create a minimal .so file that also exposes this behaviour so I just added the one that initially caused the error to Inputs/

This partially addresses https://bugs.llvm.org/show_bug.cgi?id=34705

Reviewers: ruiu, rafael, pcc, grimar

Reviewed By: ruiu

Subscribers: emaste, krytarowski

Tags: #lld

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

llvm-svn: 315036
2017-10-05 23:28:34 +00:00
Alexander Richardson 57f089775b [ELF] Don't crash when parsing a file with external version definition references
Summary:
We were crashing when linking telnetd in FreeBSD because lld was emitting
corrupted output files for --norosegment. In this file the version index of some symbols
was set to 9 but lld only found 8 version definitions.

I am not sure how to create a minimal .so file that also exposes this behaviour so I just added the one that initially caused the error to Inputs/

This partially addresses https://bugs.llvm.org/show_bug.cgi?id=34705

Reviewers: ruiu, rafael, pcc, grimar

Reviewed By: ruiu

Subscribers: emaste, krytarowski

Tags: #lld

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

llvm-svn: 315035
2017-10-05 23:28:29 +00:00
George Rimar ed906d8e63 [ELF] - Update after LLVM r314883 change. NFC.
llvm-svn: 314884
2017-10-04 08:50:34 +00:00
Rui Ueyama de3d0cc894 Make parameter lists of SymbolTable::add* functions more consistent. NFC.
llvm-svn: 314591
2017-09-30 12:41:34 +00:00
George Rimar 696a7f9ac6 [ELF] - Introduce std::vector<InputFile *> global arrays.
This patch removes lot of static Instances arrays from different input file 
classes and introduces global arrays for access instead. Similar to arrays we
have for InputSections/OutputSectionCommands.

It allows to iterate over input files in a non-templated code.

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

llvm-svn: 313619
2017-09-19 09:20:54 +00:00
James Henderson 7594c61d2d [ELF] Prevent crash with binary inputs with non-ascii file names
If using --format=binary with an input file name that has one or more non-ascii
characters in, LLD has undefined behaviour (it crashes on my Windows Debug build)
when calling isalnum with these non-ascii characters. Instead, of calling
std::isalnum, this patch uses an internal version that ignores the locale and
checks a specific subset of characters.

Reviewers: ruiu

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

llvm-svn: 312705
2017-09-07 08:30:09 +00:00
Rui Ueyama 42479e02ca Rename {Lazy,}ObjectKind -> {Lazy,}ObjKind.
I renamed corresponding classes in r309199 but forgot to rename enums
at the moment. Rename them now to make them consistent.

llvm-svn: 311214
2017-08-19 00:13:54 +00:00
Rafael Espindola 6e93d0546a Move File from SymbolBody to Symbol.
With this Symbol has the same size as before, but DefinedRegular goes
from 72 to 64 bytes.

I also find this a bit easier to read. There are fewer places
initializing File for example.

This has a small but measurable speed improvement on all tests (1%
max).

llvm-svn: 310142
2017-08-04 22:31:42 +00:00
George Rimar 70ecb827b4 [ELF] - Move getSymbols() methods to InputFile.
It can help to detemplate code.

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

llvm-svn: 310049
2017-08-04 11:07:42 +00:00
Rafael Espindola 3a8e4d98f8 Use more consistent names
Reviewing another change I noticed that we use "getSymbols" to mean
different things in different files. Depending on the file it can
return

ArrayRef<StringRef>
ArrayRef<SymbolBody*>
ArrayRef<Symbol*>
ArrayRef<Elf_Sym>

With this change it always returns an ArrayRef<SymbolBody*>. The other
functions are renamed getELFsyms() and getSymbolNames().

Note that we cannot return ArrayRef<Symbol*> instead of
ArreyRef<SymbolBody*> because local symbols have a SymbolBody but not
a Symbol.

llvm-svn: 309840
2017-08-02 17:35:18 +00:00
Rui Ueyama 709fb2bb10 Rename ObjectFile -> ObjFile.
Rename it because it was too easy to conflict with llvm::object::ObjectFile
which broke buildbots several times.

llvm-svn: 309199
2017-07-26 22:13:32 +00:00
Rui Ueyama 23f64d229b Remove unnecessary namespace specifier.
I believe this compiles fine on all platforms, even on Windows.

llvm-svn: 309182
2017-07-26 21:24:01 +00:00
Rafael Espindola 244ef98161 Detemplate SymbolTable.
NFC, just makes it easier to access from non templated code.

llvm-svn: 309152
2017-07-26 18:42:48 +00:00
Igor Kudrin 7d2b15a7ab [ELF] Avoid data race in ObjectFile<ELFT>::getDILineInfo().
Differential Revision: https://reviews.llvm.org/D35537

llvm-svn: 308728
2017-07-21 11:26:08 +00:00
Rui Ueyama 875ae82b0b Add the --chroot option for --reproduce.
Summary:
If the linker is invoked with `--chroot /foo` and `/bar/baz.o`, it
tries to read the file from `/foo/bar/baz.o`. This feature is useful
when you are dealing with files created by the --reproduce option.

Reviewers: grimar

Subscribers: llvm-commits, emaste

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

llvm-svn: 308646
2017-07-20 18:17:55 +00:00
Rafael Espindola 8b1afd59c3 Speed up gdb index creation.
With that in place we can use lld's own infrastructure for the low
level detail of dwarf parsing.

With this we don't decompress sections twice, we don't scan all
realocations and even with this simplistic implementation linking
clang with gdb index goes from 34.09 seconds to 20.80 seconds.

llvm-svn: 308544
2017-07-19 22:27:35 +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
Paul Robinson c60318af24 Tweak to match change in LLVM API, in r306699
llvm-svn: 306700
2017-06-29 16:52:29 +00:00
Rui Ueyama d1f8b8162b Implement the --exclude-libs option.
The --exclude-libs option is not a popular option, but at least some
programs in Android depend on it, so it's worth to support it.

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

llvm-svn: 305920
2017-06-21 15:36:24 +00:00
Leslie Zhai 49ba795d15 [ELF] Initial migration of AVR target
Reviewers: ruiu, rafael, grimar, atanasyan, psmith, dylanmckay

Reviewed By: ruiu, rafael, grimar, dylanmckay

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

llvm-svn: 305444
2017-06-15 02:27:50 +00:00
Rui Ueyama f9f69548a9 Allow the GNU gold-style nonstandard SHT_GROUP section.
The ELF standard defines that the SHT_GROUP section as follows:

 - its sh_link has the symbol index, and
 - the symbol name is used to uniquify section groups.

Object files created by GNU gold does not seem to comply with the
standard. They have this additional rule:

 - if the symbol has no name and a STT_SECTION symbol, a section
   name is used instead of a symbol name.

If we don't do anything for this, the linker fails with a mysterious
error message if input files are generated by gas. It is unfortunate
but I think we need to support it.

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

llvm-svn: 305218
2017-06-12 18:46:33 +00:00
Rui Ueyama a1ba859ad3 Simplify. NFC.
llvm-svn: 305047
2017-06-09 02:42:20 +00:00
George Rimar 3b189d1643 [ELF] - Do not allow -r to eat comdats.
This is PR33052, "Bug 33052 - -r eats comdats ".

To fix it I stop removing group section from out when -r is given
and fixing SHT_GROUP content when writing it just like we do some
other fixup, e.g. for Rel[a]. (it needs fix for section indices that
are in group).

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

llvm-svn: 304140
2017-05-29 08:37:50 +00:00
Rui Ueyama 240b9515e2 Simplify. NFC.
llvm-svn: 303959
2017-05-26 02:17:30 +00:00
Rafael Espindola 1c2baad6dd Revert "Simplify a variable type by using StringRef instead of CachedHashStringRef."
This reverts commit r303787.

It caused a slowdown in fast links. That is, links with no debug info
or optimizations.

llvm-svn: 303925
2017-05-25 21:53:02 +00:00
Rui Ueyama 466c82b74f Simplify a variable type by using StringRef instead of CachedHashStringRef.
A variable `ComdatGroup` is not supposed to contain a large number of
items. Even when linking clang, it ends up having only 300K strings.
It doesn't make sense to use CachedHashStringRef for this hash table.
This patch has neutral or slightly positive impact on performance while
reducing code complexity.

llvm-svn: 303787
2017-05-24 18:22:27 +00:00
Rafael Espindola 895aea6d15 Reduce template usage. NFC.
llvm-svn: 302832
2017-05-11 22:02:41 +00:00
Rafael Espindola 0f6cc65fe9 Remember OffsetInArchive in LazyObjectFile.
LazyObjectFile might turn out to be a BitcodeFile, so we need
OffsetInArchive.

llvm-svn: 302242
2017-05-05 15:17:07 +00:00
Rafael Espindola 80ae8ae186 Remember archive name when creating LazyObjectFile.
It is needed for creating an unique identifier for ThinLTO.

This fixes pr32931.

llvm-svn: 302235
2017-05-05 13:55:51 +00:00
Rafael Espindola 808f2d3c62 Reduce code duplication. NFC.
llvm-svn: 302155
2017-05-04 14:54:48 +00:00