Commit Graph

401 Commits

Author SHA1 Message Date
Rafael Espindola 65c65ce897 Don't include --start-lib/--end-lib files twice.
This should never happen with correct programs, but it is trivial
write a testcase where lld would crash or report duplicated
symbols. We now behave like when an archive is used and include the
file only once.

llvm-svn: 272724
2016-06-14 21:56:36 +00:00
Rafael Espindola d2454d66e3 Fix global version handling.
We should not ignore the symbol, just the version.

Fixes error with -z defs.

llvm-svn: 272270
2016-06-09 15:45:49 +00:00
George Rimar dcddfb63cd [ELF] Simplify shouldMerge() result calculation. NFC.
llvm-svn: 272131
2016-06-08 12:04:59 +00:00
George Rimar d50a1459e9 [ELF] - Replaced hardcode with named constants. NFC.
llvm-svn: 272129
2016-06-08 11:40:24 +00:00
Peter Smith 8646ced053 Initial support for ARM in lld.
Add support for an ARM Target and the initial set of relocations
    and PLT entries that are necessary for an ARM only hello world to
    link. This has been tested against an ARM only sysroot from the
    4.2.0 CodeSourcery Lite release.
    
    Tests have been added to test/ELF for the support that has been
    implemented.
    
    Main limitations:
    - No Thumb support
    - Relocations incomplete
    - No C++ exceptions support
    - No TLS support
    - No range extension or interworking veneer (thunk) support
    - No Build Attribute support
    - No Big-endian support
    
    The deprecated relocations R_ARM_PLT32 and R_ARM_PC24 have been
    implemented as these are used by the 4.2.0 CodeSourcery Lite release.

llvm-svn: 271993
2016-06-07 09:31:52 +00:00
Rafael Espindola acad605df9 Ignore the "globally available" version.
Reduced from a firefox build.

llvm-svn: 271950
2016-06-06 22:42:57 +00:00
Rui Ueyama 0b9a90364b Rename EHInputSection -> EhInputSection.
llvm-svn: 270532
2016-05-24 04:19:20 +00:00
Rui Ueyama 151ff30783 Simplify. NFC.
llvm-svn: 270531
2016-05-24 04:12:52 +00:00
Peter Smith 4df2e14dce Fix typo in comment aligment should be alignment. NFC.
llvm-svn: 269905
2016-05-18 11:40:16 +00:00
Rui Ueyama fe65877c76 Reorganize the cpio archiver as CpioFile class. NFC.
This code separates the code to create cpio archive from the driver.

llvm-svn: 269593
2016-05-15 17:10:23 +00:00
Rafael Espindola 78db5a9dca Print member name in undefined symbol error.
llvm-svn: 268976
2016-05-09 21:40:06 +00:00
Simon Atanasyan add74f37f2 [ELF][MIPS] Read/write .MIPS.options section
MIPS N64 ABI introduces .MIPS.options section which specifies miscellaneous
options to be applied to an object/shared/executable file. LLVM as well as
modern versions of GNU tools read and write the only type of the options -
ODK_REGINFO. It is exact copy of .reginfo section used by O32 ABI.

llvm-svn: 268485
2016-05-04 10:07:38 +00:00
Rafael Espindola 1dd2b3d1d0 Produce cpio files for --reproduce.
We want --reproduce to

* not rewrite scripts and thin archives
* work with absolute paths

Given that, it pretty much has to create a full directory tree. On windows that
is problematic because of the very short maximum path limit. On most cases
users can still work around it with "--repro c:\r", but that is annoying and
not viable for automated testing.

We then need to produce some form of archive with the files. The first option
that comes to mind is .a files since we already have code for writing them.
There are a few problems with them

The format has a dedicated string table, so we cannot start writing it until
all members are known.
Regular implementations don't support creating directories. We could make
llvm-ar support that, but that is probably not a good idea.
The next natural option would be tar. The problem is that to support long path
names (which is how this started) it needs a "pax extended header" making this
an annoying format to write.

The next option I looked at seems a natural fit: cpio files.

They are available on pretty much every unix, support directories and long path
names and are really easy to write. The only slightly annoying part is a
terminator, but at least gnu cpio only prints a warning if it is missing, which
is handy for crashes. This patch still makes an effort to always create it.

llvm-svn: 268404
2016-05-03 17:30:44 +00:00
Rafael Espindola d1cbe4df91 Copy thin archive members with --reproduce.
llvm-svn: 268229
2016-05-02 13:54:10 +00:00
Peter Collingbourne 3db410e865 Should fix all remaining MSVC problems.
llvm-svn: 268187
2016-05-01 06:00:09 +00:00
Peter Collingbourne 4f9527065c ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.

Performance numbers:

           old(s) new(s)
Without debug info:
chrome      7.178  6.432 (-11.5%)
LLVMgold.so 0.505  0.502 (-0.5%)
clang       0.954  0.827 (-15.4%)
llvm-as     0.052  0.045 (-15.5%)
With debug info:
scylla      5.695  5.613 (-1.5%)
clang      14.396 14.143 (-1.8%)

Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.

The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.

In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.

I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.

This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.

[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html

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

llvm-svn: 268178
2016-05-01 04:55:03 +00:00
Rafael Espindola fb4f2fedd1 Be sure to always increment the Versym pointer.
It was getting out of sync if we had undefined symbols at the start of
the symbol table.

llvm-svn: 268077
2016-04-29 17:46:07 +00:00
Rafael Espindola 18da0e589a Fix producing undefined reference to __progname.
We were not producing them if the library had version info.

llvm-svn: 268060
2016-04-29 16:23:31 +00:00
Rui Ueyama fb6d499ed7 ELF: Add -O0 (produce output as fast as possible) mode.
This patch redefines the default optimization level as 1 and adds
new level 0. In the command line, it is -O0. The flag disables
costly but optional features so that the linker produces semantically
correct but larger output quickly. Currently it only disables
section merging.

This flag is not intended to be used for final production linking.
It is intended to be used in compile-link-test cycle.

Time to link clang with debug info is about 2x faster with the flag.

  Head:
  13.24 seconds
  Output size: 1227189664 bytes

  With this patch:
  7.41 seconds
  Output size: 2490281784 bytes

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

llvm-svn: 268056
2016-04-29 16:12:29 +00:00
Simon Atanasyan ae77ab71d8 [ELF][MIPS] Accept MIPS 64-bit binaries
LLD accepts MIPS 64-bit binaries, supports corresponding eulation (-m)
arguments and emits 64-bit specific ELF flags.

llvm-svn: 268024
2016-04-29 10:39:17 +00:00
Rafael Espindola 156f4ee1c0 Use a single context for lto.
Using multiple context used to be a really big memory saving because we
could free memory from each file while the linker proceeded with the
symbol resolution. We are getting lazier about reading data from the
bitcode, so I was curious if this was still a good tradeoff.

One thing that is a bit annoying is that we still have to copy the
symbol names. The problem is that the names are stored in the Module and
get freed when we move the module bits during linking.

Long term I think the solution is to add a symbol table to the bitcode.
That way IRObject file will not need to use a Module or a Context and we
can drop it while still keeping a StringRef to the names.

This patch is still be an interesting medium term improvement.

When linking llvm-as without debug info this patch is a small speedup:

master: 29.861877513 seconds
patch: 29.814533787 seconds

With debug info the numbers are

master: 34.765181469 seconds
patch: 34.563351584 seconds

The peak memory usage when linking llvm-as with debug info was

master: 599.10MB
patch: 600.13MB
llvm-svn: 267921
2016-04-28 19:30:41 +00:00
Rui Ueyama 62ee16faa8 Remove Size from Undefined symbol.
There seems to be no reason to keep st_size of undefined symbols.
This patch removes the member for it. This patch will change outputs
in cases that undefined symbols are copied to output, but I think
this is unimportant.

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

llvm-svn: 267826
2016-04-28 00:26:54 +00:00
Peter Collingbourne 21a12fc69a ELF: Create .gnu.version and .gnu.version_r sections when linking against versioned DSOs.
Differential Revision: http://reviews.llvm.org/D19464

llvm-svn: 267775
2016-04-27 20:22:31 +00:00
Peter Collingbourne 60976ed7c0 ELF: Merge UndefinedBitcode and UndefinedElf. NFC.
Differential Revision: http://reviews.llvm.org/D19566

llvm-svn: 267640
2016-04-27 00:05:06 +00:00
Davide Italiano 9f8efffe29 [LTO] Create Undefined Bitcode symbol when we drop a comdat member.
Differential Revision:  http://reviews.llvm.org/D19389

llvm-svn: 267181
2016-04-22 18:26:33 +00:00
Rafael Espindola 197d6a882f This reverts commit r267154 and r267161.
It turns out that this will read data from the section to properly
handle Elf_Rel implicit addends.

Sorry for the noise.

Original messages:

Try to fix Windows lld build.

Move getRelocTarget to ObjectFile.
It doesn't use anything from the InputSection.

llvm-svn: 267163
2016-04-22 16:39:59 +00:00
Rafael Espindola ea4d177977 Move getRelocTarget to ObjectFile.
It doesn't use anything from the InputSection.

llvm-svn: 267154
2016-04-22 14:17:14 +00:00
Rafael Espindola 4d480ed545 Internalize linkonce_odr more often.
Since there is a copy in every translation unit that uses them, they can
be omitted from the symbol table if the address is not significant.

This still doesn't catch as many cases as the gold plugin. The
difference is that we check canBeOmittedFromSymbolTable in each file and
use lazy loading which limits what it can do. Gold checks it in the merged file.

I think the correct way of getting the same results as gold is just to
cache in the IR the result of canBeOmittedFromSymbolTable.

llvm-svn: 267063
2016-04-21 21:44:25 +00:00
Peter Collingbourne 7cf73ec4c7 ELF: Implement basic support for module asm in bitcode files.
Differential Revision: http://reviews.llvm.org/D18872

llvm-svn: 265956
2016-04-11 16:39:43 +00:00
Rui Ueyama 029d89ee57 Fix another crash bug in --start-lib.
The previous fix didn't work for bitcode files. This patch fixes
the remaining issue.

llvm-svn: 265854
2016-04-08 21:38:22 +00:00
Rui Ueyama 1f492893ac Fix a crash bug in --start-lib.
Previously, Lazy symbols were created for undefined symbols even though
such symbols cannot be resolved by loading object files. This patch
fixes that bug.

llvm-svn: 265847
2016-04-08 20:49:31 +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 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 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 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
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
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
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 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 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
Rafael Espindola 0d2ad420df Revert "[ELF] SHF_MERGE section with 0 entsize is not fatal"
This reverts commit r263664.

The reason we were getting broken files was lld -r, and that has been
fixed.

llvm-svn: 263944
2016-03-21 14:57:20 +00:00
Ed Maste b321050a93 [ELF] SHF_MERGE section with 0 entsize is not fatal
For now just treat such sections as non-mergeable.

Resubmit r263660 with test fix.

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

llvm-svn: 263664
2016-03-16 21:12:53 +00:00
Ed Maste b30ce583df Revert r263660 as one of the tests is broken.
llvm-svn: 263661
2016-03-16 20:42:27 +00:00
Ed Maste 2e97115a61 [ELF] SHF_MERGE section with 0 entsize is not fatal
For now just treat such sections as non-mergeable.

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

llvm-svn: 263660
2016-03-16 20:32:32 +00:00
Rui Ueyama 9328b2cdde Use ELFT instead of ELFFile<ELFT>.
llvm-svn: 263510
2016-03-14 23:16:09 +00:00
Rui Ueyama 64bd8df458 Error messages should start with lowercase letters.
llvm-svn: 263496
2016-03-14 21:31:07 +00:00
Rui Ueyama 368e1eaa51 Remove uint32_X type.
This type is equivalent to Elf_Word type.

llvm-svn: 263397
2016-03-13 22:02:04 +00:00
Rui Ueyama e270c0a19a ELF: Split initializeSections and add comments.
llvm-svn: 263395
2016-03-13 21:52:57 +00:00
George Rimar 777f96304e Recommit of r263252, [ELF] - Change all messages to lowercase to be consistent.
which was reverted because included
unrelative changes by mistake.

Original commit message:

[ELF] - Change all messages to lowercase to be consistent.

That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

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

llvm-svn: 263337
2016-03-12 08:31:34 +00:00
Rui Ueyama f714955402 Revert r263252: "[ELF] - Change all messages to lowercase to be consistent."
This reverts commit r263252 because the change contained unrelated changes.

llvm-svn: 263272
2016-03-11 18:46:51 +00:00
George Rimar 96bcdae1a5 [ELF] - Change all messages to lowercase to be consistent.
That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

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

llvm-svn: 263252
2016-03-11 16:40:55 +00:00
Rafael Espindola 9b3acf9098 Avoid calling getNamedValue.
In lld we usually avoid hash lookups. In addition to that, IR names are
not fully mangled, so it is best to avoid using them whenever possible.

llvm-svn: 263248
2016-03-11 16:11:47 +00:00
George Rimar 5761042db7 This reverts the r263125
It was discussed to make all messages be 
lowercase to be consistent with clang.
(also reverts the r263128 which fixed 
build bot fail after r263125)

Original commit message:
[ELF] - Consistent spelling for error/warning messages

Previously error and warnings were not consistent in lld.
Some of them started from lowercase letter, others from
uppercase. Also there was one or two which had a dot at the end.
This patch changes all messages to start from uppercase letter if
they were not before.

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

llvm-svn: 263240
2016-03-11 14:43:02 +00:00
Rafael Espindola 1f5b70f64f Represent local symbols with DefinedRegular.
llvm-svn: 263237
2016-03-11 14:21:37 +00:00
Rafael Espindola ccb8b4d4fe Remember the input section of locals.
This is already a simplification, but will allow much more.

llvm-svn: 263224
2016-03-11 12:14:02 +00:00
Rafael Espindola 67d72c02bc Create a SymbolBody for locals.
pr26878 shows a case where locals have to be in the got.

llvm-svn: 263222
2016-03-11 12:06:30 +00:00
Sean Silva 905d349c47 Fix indentation.
Somehow this slipped by in r263197. Thanks to Rui for noticing.

llvm-svn: 263198
2016-03-11 05:48:04 +00:00
Sean Silva 4a0ff22d51 [lto] The previous testcase was not useful enough.
-shared was hiding the fact that the intrinsic wasn't being found.

llvm-svn: 263197
2016-03-11 05:42:34 +00:00
Sean Silva b1b5cc83f1 [lto] Make sure that ctors are added to the combined module.
Summary:
More generally, appending linkage is a special case that we don't want
to create a SymbolBody for.

Reviewers: rafael, ruiu

Subscribers: Bigcheese, llvm-commits, joker.eph

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

llvm-svn: 263179
2016-03-11 00:50:05 +00:00
George Rimar e094388861 [ELF] - Consistent spelling for error/warning messages
Previously error and warnings were not consistent in lld.
Some of them started from lowercase letter, others from
uppercase. Also there was one or two which had a dot at the end.
This patch changes all messages to start from uppercase letter if
they were not before.

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

llvm-svn: 263125
2016-03-10 16:58:34 +00:00
George Rimar 599d77246d Fixed "not all control paths return a value" warning. NFC.
llvm-svn: 263040
2016-03-09 18:05:34 +00:00
George Rimar 3c45ed2f5e [ELF] - Issue an error if trying to link object that uses splitstacks.
Each object file compiled in split stack mode will have an empty
section with a special name: .note.GNU-split-stack

We don't support this in linker now, so patch just adds an error out for that.

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

llvm-svn: 263039
2016-03-09 18:01:45 +00:00
Rafael Espindola 972b236c30 Simplify: SHN_ABS is >= SHN_LORESERVE.
llvm-svn: 263012
2016-03-09 14:31:18 +00:00
Sean Silva 7255d0b068 [lto] Avoid duplicate symbol error for appending linkage.
Summary:
Is there any other code needed for correctly handling appending linkage?
Do we need to do something more with @llvm.global_ctors in
SymbolTable.cpp:addBitcodeFile; otherwise the combined bitcode module
won't have all the global ctors.

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

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

llvm-svn: 262992
2016-03-09 03:42:39 +00:00
Sean Silva 3dbf9a31b5 Avoid unnecessary qualification.
Thanks to Rui for spotting this.

llvm-svn: 262983
2016-03-09 02:02:26 +00:00
Sean Silva 31a5ab9e3b [lto] Record whether a variable is TLS.
Summary:

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

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

llvm-svn: 262975
2016-03-09 00:47:47 +00:00
Rafael Espindola 708453d99f Assume GV is not null for now.
It will come back when we add support for inline asm in .bc files.

llvm-svn: 262972
2016-03-09 00:31:06 +00:00
Sean Silva b284e71e03 [lto] Don't add variables with private linkage to the symbol table.
Summary:
This causes the issue in PR26872 to go away now that we aren't creating
symbols for the string literals, but that may just be concealing a
deeper problem, so best to keep that PR open.

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

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

llvm-svn: 262968
2016-03-08 23:50:56 +00:00
Rafael Espindola 37bcaac179 Add support for common symbols.
llvm-svn: 262848
2016-03-07 19:15:57 +00:00
Rui Ueyama 68fae23475 Do not use "default" for a fully-covered switch.
llvm-svn: 262846
2016-03-07 19:06:14 +00:00
Rafael Espindola 4f29c1a337 lto: Record visibility in defined symbols.
llvm-svn: 262835
2016-03-07 17:14:36 +00:00
Rui Ueyama fd4fee599e Split BitcodeFile::parse. NFC.
llvm-svn: 262813
2016-03-07 00:54:17 +00:00
Rafael Espindola 888f2c33d4 lto: Start taking symbol visibility into consideration.
llvm-svn: 262761
2016-03-05 00:09:37 +00:00
Rui Ueyama a3cb80adfc Use check function.
llvm-svn: 262685
2016-03-04 01:56:52 +00:00
Rafael Espindola 75714f618c Rename 'fatal' to 'check' when it doesn't always fail.
llvm-svn: 262666
2016-03-03 22:24:39 +00:00
Rafael Espindola 1130935c4a Simplify error handling.
This makes fatal return T when there is no error. This avoids the need
for quite a few temporaries.

llvm-svn: 262626
2016-03-03 16:21:44 +00:00
George Rimar 4cfe572932 [ELF] - add support for relocations against local symbols when producing relocatable output.
There was a known limitation for -r option:
relocations against local symbols were not supported. 
For example rel[a].eh_frame sections contained relocations against sections
and that was not supported for -r before. Patch fixes that.

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

llvm-svn: 262590
2016-03-03 07:49:35 +00:00
Rui Ueyama eb3413e43a Replace ECRAII class with a function.
RCRAII class was a bit tricky. This patch removes that.

llvm-svn: 262586
2016-03-03 06:22:29 +00:00
Rafael Espindola 4de44b7ef8 Handle comdat in LTO.
llvm-svn: 262489
2016-03-02 15:43:50 +00:00
Rafael Espindola 1b625535f0 lto: don't fetch members for weak undef.
llvm-svn: 262225
2016-02-29 14:29:48 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rui Ueyama 0b28952993 ELF: Implement ICF.
This patch implements the same algorithm as LLD/COFF's ICF. I'm
not going to repeat the same description about how it works, so you
want to read the comment in ICF.cpp in this patch if you want to know
the details. This algorithm should be more powerful than the ICF
algorithm implemented in GNU gold. It can even merge mutually-recursive
functions (which is harder than one might think).

ICF is a fairly effective size optimization. Here are some examples.

 LLD:   37.14 MB -> 35.80 MB (-3.6%)
 Clang: 59.41 MB -> 57.80 MB (-2.7%)

The lacking feature is "safe" version of ICF. This merges all
identical sections. That is not compatible with a C/C++ language
requirement that two distinct functions must have distinct addresses.

But as long as your program do not rely on the pointer equality
(which is in many cases true), your program should work with the
feature. LLD works fine for example.

GNU gold implements so-called "safe ICF" that identifies functions
that are safe to merge by heuristics -- for example, gold thinks
that constructors are safe to merge because there is no way to
take an address of a constructor in C++. We have a different idea
which David Majnemer suggested that we add NOPs at beginning of
merged functions so that two or more pointers can have distinct
values. We can do whichever we want, but this patch does not
include neither.

http://reviews.llvm.org/D17529

llvm-svn: 261912
2016-02-25 18:43:51 +00:00
Rafael Espindola 148445ef98 Add support for weak symbols in LTO.
llvm-svn: 261881
2016-02-25 16:25:41 +00:00
Rafael Espindola f1ce4cf1f1 Remove unnecessary prefix.
llvm-svn: 261880
2016-02-25 16:20:00 +00:00
George Rimar 58941ee12a [ELF2] - Basic implementation of -r/--relocatable
-r, -relocatable - Generate relocatable output

Currently does not have support for files containing 
relocation sections with entries that refer to local 
symbols (like rel[a].eh_frame which refer to sections
and not to symbols)

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

llvm-svn: 261838
2016-02-25 08:23:37 +00:00
Rui Ueyama 733153de3c ELF: Do not instantiate InputSectionBase::Discarded.
"Discarded" section is a marker for discarded sections, and we do not
use the instance except for checking its identity. In that sense, it
is just another type of a "null" pointer for InputSectionBase. So,
it doesn't have to be a real instance of InputSectionBase class.

In this patch, we no longer instantiate Discarded section but instead
use -1 as a pointer value. This eliminates a global variable which
needed initialization at startup.

llvm-svn: 261761
2016-02-24 18:33:35 +00:00
Rui Ueyama c89bff2ce1 Handle bitcode files in archive files with --whole-archive.
This patch moves BitcodeFile instantiation into createObjectFile.
Previously, we handle bitcode files outside that function and did
not handle for --whole-archive.

http://reviews.llvm.org/D17527

llvm-svn: 261663
2016-02-23 18:17:11 +00:00
Rafael Espindola 6feecec0b0 Handle undef symbols in LTO.
This also handles bc files is archives.

llvm-svn: 261374
2016-02-19 22:50:16 +00:00
Rafael Espindola 7efa5be205 Add support for merging strings with alignment larger than one char.
This reduces the .rodata of scyladb from 4501932 to 4334639 bytes (1.038
times smaller).

I don't think it is critical to support tail merging, just exact
duplicates, but given the code organization it was actually a bit easier
to support both.

llvm-svn: 261327
2016-02-19 14:17:40 +00:00
Rafael Espindola ac458405bf Trying to fix the MSVC build.
llvm-svn: 260743
2016-02-12 21:36:59 +00:00
Rafael Espindola f1d598c2f6 Try to fix the build in some bots.
llvm-svn: 260736
2016-02-12 21:17:10 +00:00
Rafael Espindola 9f77ef0c08 Add initial LTO support.
llvm-svn: 260726
2016-02-12 20:54:57 +00:00
Rafael Espindola 9d13d04138 Sort includes. NFC.
llvm-svn: 260528
2016-02-11 15:24:48 +00:00
Sean Silva 09247f8955 Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
Summary:
LLVM3.3 (and earlier) would fail to include a relocation section in
the group that the section it was relocating is in. Object files
affected by this issue have been encountered in the wild when using LLD.

This would result in a siutation like:

  Section {
    Index: 5
    Name: .text._Z3fooIiEvv (6)
    Type: SHT_PROGBITS (0x1)
    Flags [ (0x206)
      SHF_ALLOC (0x2)
      SHF_EXECINSTR (0x4)
      SHF_GROUP (0x200)
    ]
    Address: 0x0
    Offset: 0x48
    Size: 5
    Link: 0
    Info: 0
    AddressAlignment: 1
    EntrySize: 0
  }
  Section {
    Index: 6
    Name: .rela.text._Z3fooIiEvv (1)
    Type: SHT_RELA (0x4)
    Flags [ (0x0)
    ]
    Address: 0x0
    Offset: 0x3F0
    Size: 24
    Link: 8
    Info: 5
    AddressAlignment: 8
    EntrySize: 24
  }

In LLD, during symbol resolution, we discard the section containing the
weak symbol, but this amounts to replacing it with
InputSection<ELFT>::Discarded.
When we later saw the corresponding relocation section, we would then
end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is
bogus.

Reviewers: ruiu, rafael

Subscribers: llvm-commits, Bigcheese

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

llvm-svn: 259831
2016-02-04 21:41:07 +00:00
Rui Ueyama 71c066d8cf ELF: Include archive names in error messages.
If object files are drawn from archive files, the error message should
be something like "conflict symbols in foo.a(bar.o) and baz.o" instead
of "conflict symbols in bar.o and baz.o". This patch implements that.

llvm-svn: 259475
2016-02-02 08:22:41 +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 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
Rui Ueyama 70eed364fc Simplify MipsReginfoInputSection.
MipsReginfoInputSection is basically just a container of Elf_Mips_Reginfo
struct. This patch makes that struct directly accessible from others.

llvm-svn: 256984
2016-01-06 22:42:43 +00:00
Rui Ueyama 33b3f21168 Rename GroupEntryType -> uint32_X.
GroupEntryType was a 32-bit integral type but that was not obvious
from its name.

llvm-svn: 256971
2016-01-06 20:30:02 +00:00
Rui Ueyama 52d3b67c1d Rename Comdats -> ComdatGroups.
I usually prefer short names, but in this case the new descriptive
name should improve readability a bit.

llvm-svn: 256899
2016-01-06 02:06:33 +00:00
Rui Ueyama 7c713319b9 Rename SharedFile::parse -> SharedFile::parseRest.
Unlike ObjectFile or ArchiveFile, SharedFile had two parse functions,
parseSoName() and parse(). parse must have been called after parseSoName,
but that requirement was not obvious from their names. (So it looked
like you could call parse() on a shared object file right away.)

This patch rename parseRest. It is now obvious that there's no single
parse function for the shared object file.

llvm-svn: 256898
2016-01-06 01:56:36 +00:00
Rui Ueyama e69ab10301 Remove redundant this->.
llvm-svn: 256894
2016-01-06 01:14:11 +00:00
Rui Ueyama 9b09369b3d Simplify --whole-archive handling.
Previously, we handle archive files with --whole-archive this way:
create instances of ArchiveFile, call getMembers to obtain memory
buffers of archive members, and create ObjectFiles for the members.
We didn't call anything except getMembers if --whole-archive was
specified.

I noticed that we didn't actually have to create ArchiveFile instaces
at all for that case. All we need is to get a list of memory buffers
for members, which can be done by a non-member function.

This patch removes getMembers member function from ArchiveFile.
Also removed unnecessary code for memory management.

llvm-svn: 256893
2016-01-06 00:51:35 +00:00
Rui Ueyama 533c03078b Do not use templates to instantiate {Object,Shared}Files.
createELFFile looked complex because of its use of template,
so I want to keep it private within this file.

llvm-svn: 256880
2016-01-06 00:09:43 +00:00
Rui Ueyama f588ac4663 Simplify. NFC.
llvm-svn: 256879
2016-01-06 00:09:41 +00:00
Simon Atanasyan 57830b60dc [ELF][MIPS] Implement R_MIPS_GPREL16/R_MIPS_GPREL32 relocations
The R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations use the following
expressions for calculations:
```
local symbol:  S + A + GP0 - GP
global symbol: S + A - GP

GP  - Represents the final gp value, i.e. _gp symbol
GP0 - Represents the gp value used to create the relocatable object
```
The GP0 value is taken from the .reginfo data section defined by an object
file. To implement that I keep a reference to `MipsReginfoInputSection`
in the `ObjectFile` class. This reference is used by the
`ObjectFile::getMipsGp0` method to return the GP0 value.

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

llvm-svn: 256416
2015-12-25 13:02:13 +00:00
Rafael Espindola 1119191c4f Make it possible to create common symbols from bitcode.
Since the only missing bit was the size, I just replaced the Elf_Sym
with the size.

llvm-svn: 256384
2015-12-24 16:23:37 +00:00
Rafael Espindola 02ce26a1b4 Delete DefinedAbsolute.
There are 3 symbol types that a .bc can provide during lto: defined,
undefined, common.

Defined and undefined symbols have already been refactored. I was
working on common and noticed that absolute symbols would become an
oddity: They would be the only symbol type present in a .o but not in
a.bc.

Looking a bit more, other than the special section number they were only
used for special rules for computing values. In that way they are
similar to TLS, and we don't have a DefinedTLS.

This patch deletes it. With it we have a reasonable rule of the thumb
for having a symbol kind: It exists if it has special resolution
semantics.

llvm-svn: 256383
2015-12-24 14:22:24 +00:00
Rui Ueyama 3f11c8c97e Split functions and add comments. NFC.
llvm-svn: 256369
2015-12-24 08:41:12 +00:00
Rui Ueyama dc8d3a2104 Return early and remove a redundant error check. NFC.
llvm-svn: 256367
2015-12-24 08:36:56 +00:00
Rui Ueyama 215d6a31b7 Add machine type check for MIPS-specific code path.
llvm-svn: 256355
2015-12-24 01:32:39 +00:00
Rafael Espindola 21f7bd4ba1 Simplify memory management.
We no longer need an explicit delete or a polymorphic destructor.

llvm-svn: 256333
2015-12-23 14:35:51 +00:00
Rafael Espindola ce7d39d5e1 Fix the last leak asan found in test/ELF.
llvm-svn: 256316
2015-12-23 03:40:17 +00:00
Rafael Espindola 7300afa36a Fix another asan detected leak.
llvm-svn: 256311
2015-12-23 01:18:40 +00:00
Rafael Espindola 5f2c46d62e Fix two asan found bugs:
We were leaking InputFile subclasses data.
UndefinedElf was missing a classof.

llvm-svn: 256309
2015-12-23 01:06:39 +00:00
Rafael Espindola 5d7593bc59 Split Undefined and UndefinedElf.
I am working on adding LTO support to the new ELF lld.

In order to do that, it will be necessary to represent defined and
undefined symbols that are not from ELF files. One way to do it is to
change the symbol hierarchy to look like

Defined : SymbolBody
Undefined : SymbolBody

DefinedElf<ELFT> : Defined
UndefinedElf<ELFT> : Undefined

Another option would be to use bogus Elf_Sym, but I think that is
getting a bit too hackish.

This patch does the Undefined/UndefinedElf. Split. The next one
will do the Defined/DefinedElf split.

llvm-svn: 256289
2015-12-22 23:00:50 +00:00
Simon Atanasyan 1d7df40711 [ELF][MIPS] MIPS .reginfo sections handling
MIPS .reginfo section provides information on the registers used by
the code in the object file. Linker should collect this information and
write .reginfo section in the output file. This section contains a union
of used registers masks taken from input .reginfo sections and final
value of the `_gp` symbol.

For details see the "Register Information" section in Chapter 4 in the
following document:
ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

The patch implements .reginfo sections handling with a couple missed
features: a) it does not put output .reginfo section into the separate
REGINFO segment; b) it does not merge `ri_cprmask` masks from input
section. These features will be implemented later.

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

llvm-svn: 256119
2015-12-20 10:57:34 +00:00
Rui Ueyama 784b769d32 ELF: Avoid string concatenation if there's no error.
llvm-svn: 255870
2015-12-17 01:51:23 +00:00
Rui Ueyama 7b19c34550 Revert "ELF: Make .note.GNU-stack more compatible with traditional linkers."
This reverts commit r253797 because it was based on a misunderstanding
that lld wouldn't work on NetBSD without this change.

llvm-svn: 254003
2015-11-24 18:48:16 +00:00
Rui Ueyama e79b09a616 ELF: Make .note.GNU-stack more compatible with traditional linkers.
With this patch, lld creates PT_GNU_STACK segments only when all input
files have .note.GNU-stack sections. This is in line with other linkers
with a minor difference (we don't care about .note.GNU-stack rwx bits as
you can always remove .note.GNU-stack sections instead of setting x bit.)

At least, NetBSD loader does not understand PT_GNU_STACK segments and
reject any executables that have the section. This patch makes lld
compatible with such operating systems.

llvm-svn: 253797
2015-11-21 22:19:32 +00:00
Rui Ueyama d94478b04e Remove redundant namespace specifiers.
llvm-svn: 253635
2015-11-20 02:19:36 +00:00
Rui Ueyama 2022e81af0 Make a function out-of-line.
There's no need to write it in a .h file.

llvm-svn: 253633
2015-11-20 02:10:52 +00:00
Rui Ueyama 2dc3f8c278 Remove redundant "using namespace".
llvm-svn: 253632
2015-11-20 01:59:16 +00:00
George Rimar 03220309e1 [ELF2] - Implemented PT_GNU_STACK support, -z execstack option.
PT_GNU_STACK is a entry in the elf file format which contains the access rights (read, write, execute) of the stack,
it is always generated now. By default stack is not executable in this implementation. 
-z execstack can be used to make executable.

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

llvm-svn: 253145
2015-11-14 20:56:08 +00:00
Rafael Espindola 0c6a4f197f Add support for processing .eh_frame.
This adds support for:
* Uniquing CIEs
* Dropping FDEs that point to dropped sections

It drops 657 488 bytes from the .eh_frame of a Release+Asserts clang.

The link time impact is smallish. Linking clang with a Release+Asserts
lld goes from 0.488064805 seconds to 0.504763060 seconds (1.034 X slower).

llvm-svn: 252790
2015-11-11 19:54:14 +00:00
George Rimar 564da7ee87 [ELF2] - Fixed crash for case when section sh_entsize is set to zero for SHF_MERGE type of sections.
Differential revision: http://reviews.llvm.org/D14451

llvm-svn: 252454
2015-11-09 08:40:44 +00:00
Kevin Enderby 35dfc95efe These are the matching changes needed to the lld project for the changes to llvm
in r252192 that changed the Archive and Child interfaces in libObject. These include
Rafael Espindola’s many suggested updates.

llvm-svn: 252193
2015-11-05 19:25:47 +00:00
Rafael Espindola 8f3a6aeadb Avoid implicit Archive::child_iterator construction.
llvm-svn: 252167
2015-11-05 14:40:28 +00:00
Rafael Espindola 115f0f365d Two small fixes to copy relocation processing.
* We can determine the alignment requirement.
* We have to update the bss alignment with it.

llvm-svn: 251914
2015-11-03 14:13:40 +00:00
Rafael Espindola f82ed2a28c Add support for merging string from SHF_STRINGS sections.
llvm-svn: 251212
2015-10-24 22:51:01 +00:00
Rui Ueyama c4aaed9255 ELF2: Implement --gc-sections.
Section garbage collection is a feature to remove unused sections
from outputs. Unused sections are sections that cannot be reachable
from known GC-root symbols or sections. Naturally the feature is
implemented as a mark-sweep garbage collector.

In this patch, I added Live bit to InputSectionBase. If and only
if Live bit is on, the section will be written to the output.
Starting from GC-root symbols or sections, a new function, markLive(),
visits all reachable sections and sets their Live bits. Writer then
ignores sections whose Live bit is off, so that such sections are
excluded from the output.

This change has small negative impact on performance if you use
the feature because making sections means more work. The time to
link Clang changes from 0.356s to 0.386s, or +8%.

It reduces Clang size from 57,764,984 bytes to 55,296,600 bytes.
That is 4.3% reduction.

http://reviews.llvm.org/D13950

llvm-svn: 251043
2015-10-22 18:49:53 +00:00
Rafael Espindola c159c967f6 Add support for merging the contents of SHF_MERGE sections.
For now SHF_STRINGS are not supported.

llvm-svn: 250737
2015-10-19 21:00:02 +00:00
Rafael Espindola 4cda58168a Add a ObjectFile<ELFT>::getSection helper and simplify. NFC.
llvm-svn: 250519
2015-10-16 15:29:48 +00:00
Rui Ueyama f8432d97f3 ELF2: Fix BSD's __progname symbol issue.
BSD's DSO files have undefined symbol "__progname" which is defined
in crt1.o. On that system, both user programs and system shared
libraries depend on each other.

In general, we need to put symbols defined by user programs which are
referenced by shared libraries to user program's .dynsym.

http://reviews.llvm.org/D13637

llvm-svn: 250176
2015-10-13 16:34:14 +00:00
Rui Ueyama e717a7195b ELF2: Rename ElfKind -> EKind.
ELFKind as a type name and ElfKind is a variable name was too subtle.

llvm-svn: 250172
2015-10-13 16:20:50 +00:00
Rafael Espindola 2a4b27111d Remove the EKind member variable.
Now that the base class is templated, it is redundant with the type.

llvm-svn: 250139
2015-10-13 01:17:02 +00:00
Rui Ueyama 1c42afcbdc Remove explicit Twine instantiation if possible.
llvm-svn: 250055
2015-10-12 15:49:06 +00:00
Rui Ueyama 361d8b9350 Early return.
llvm-svn: 250054
2015-10-12 15:49:02 +00:00
Rui Ueyama c4b6506521 ELF2: Move createELFFile() from .h to .cpp.
llvm-svn: 250051
2015-10-12 15:31:09 +00:00
Rui Ueyama 2ee8e113ba Remove redundant namespace specifiers.
llvm-svn: 250050
2015-10-12 15:27:09 +00:00
Rafael Espindola fb677dfd73 Make getStaticELFKind a member function now that we can.
llvm-svn: 250031
2015-10-12 12:14:30 +00:00
Rafael Espindola dfce5a25cb Simplify the InputFile type hierarchy by removing unnecessary middle classses.
llvm-svn: 250006
2015-10-12 02:22:58 +00:00
Rafael Espindola af70764aa1 Simplify the InputFile type hierarchy.
Now that the SymbolTable is templated, we don't need the ELFData class or
multiple inheritance.

llvm-svn: 250005
2015-10-12 01:55:32 +00:00
Rui Ueyama 35da9b6e1c ELF2: Implement --as-needed.
This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit
is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed
bit is off by default. When we adds a symbol to the symbol table for dynamic
linking, we set its SharedFile's IsUsed bit.

If AsNeeded is set but IsUsed is not set, we don't want to write that
file's SO name to DT_NEEDED field.

http://reviews.llvm.org/D13579

llvm-svn: 249998
2015-10-11 20:59:12 +00:00
Rafael Espindola 444576d4c4 Add support for comdats.
The implementation is a direct translation to c++ of the rules in the ELF spec.

llvm-svn: 249881
2015-10-09 19:25:07 +00:00
Rafael Espindola 98af66f9c5 Make this test a bit stricter.
The only way for SecIndex to be zero in here is for an extended section
number to be zero, which would be an error.

llvm-svn: 249736
2015-10-08 20:29:22 +00:00
Rafael Espindola d42f4e5389 Add a convenience variable. NFC.
llvm-svn: 249682
2015-10-08 12:02:38 +00:00
Denis Protivensky 1ef7b3ff55 [ELF2] Handle -m option
Parse and apply emulation given with -m option.
Check input files to match ELF type and machine architecture provided with -m.

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

llvm-svn: 249529
2015-10-07 09:13:03 +00:00
Michael J. Spencer ed3476b79f [elf2] Add STB_GNU_UNIQUE support.
llvm-svn: 249193
2015-10-02 21:57:52 +00:00
Rafael Espindola 3e60379fd9 Don't crash on files with no symbol table.
Thanks to Roman Divacky for the test.

llvm-svn: 249066
2015-10-01 20:26:37 +00:00
Rafael Espindola 6a3b5ded8a Don't include shared libraries multiple times.
llvm-svn: 249061
2015-10-01 19:52:48 +00:00
Igor Kudrin 2696bbeb93 [ELF2] Add --[no-]whole-archive command line switches
Summary:
If --whole-archive is used, all symbols from the following archives are added to the output. --no-whole-archive restores default behavior. These switches can be used multiple times.

NB. We have to keep an ArchiveFile instance within SymbolTable even if --whole-archive mode is active since it can be a thin archive which contains just names of external files. In that case actual memory buffers for the archive members will be stored within the File member of ArchiveFile class.

Reviewers: rafael, ruiu

Subscribers: grimar, llvm-commits

Projects: #lld

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

llvm-svn: 249045
2015-10-01 18:02:21 +00:00
Rafael Espindola c8b158155c Copy DT_SONAME to DT_NEEDED.
If a shared library has a DT_SONAME entry, that is what should be included
in the DT_NEEDED of a program using it.

We don't implement -soname yet, so check in a .so for now.

llvm-svn: 249025
2015-10-01 15:47:50 +00:00
Rui Ueyama 983ed2b749 ELF2: Define Driver::addFile() as a one-stop place to open a file.
Opening a file and dispatching to readLinkerScript() or createFile()
is a common operation. We want to use that at least from Driver and
from LinkerScript. In COFF, we had the same problem. This patch
resolves the problem in the same way as we did for COFF.

Now, if you have a path that you want to open, just call
Driver->addFile(StringRef). That function opens the file and handles
that as if that were given by command line. This function is the
only place we call identify_magic().

llvm-svn: 249023
2015-10-01 15:23:09 +00:00
Rui Ueyama f5c4aca98f ELF2: Add basic linker script support.
This linker script parser and evaluator is powerful enough to read
Linux's libc.so, which is (despite its name) a linker script that
contains OUTPUT_FORMAT, GROUP and AS_NEEDED directives.

The parser implemented in this patch is a recursive-descendent one.
It does *not* construct an AST but consumes directives in place and
sets the results to Symtab object, like what Driver is doing.
This should be very fast since less objects are allocated, and
this is also more readable.

http://reviews.llvm.org/D13232

llvm-svn: 248918
2015-09-30 17:06:09 +00:00
Rui Ueyama d0e5aebf3a Expand `auto` whose real type is not obvious from context.
llvm-svn: 248876
2015-09-30 02:42:27 +00:00
Rui Ueyama 90b3daaa5c Remove `else` after `return`.
llvm-svn: 248875
2015-09-30 02:37:51 +00:00
Rafael Espindola e1901cc33d Simplify memory management by having ELFData contain a ELFObj.
llvm-svn: 248502
2015-09-24 15:11:50 +00:00
Rafael Espindola 503fe9408d Expose ELFFileBase::getEMachine. NFC.
I will use it in a followup patch.

llvm-svn: 248287
2015-09-22 16:53:55 +00:00
Rafael Espindola 7167585c94 Remove the Chunk terminology from ELF.
llvm-svn: 248229
2015-09-22 00:16:19 +00:00
Rafael Espindola 9d06ab6ded Rename Chunks.(h|cpp) to InputSection.(h|cpp). NFC.
llvm-svn: 248226
2015-09-22 00:01:39 +00:00
Rafael Espindola 53d5cea648 Rename SectionChunk to InputSection.
This is more consistent with OutputSection. This is also part of removing
the "Chunk" term from the ELF linker, since we just have input/output sections
and program headers.

llvm-svn: 248183
2015-09-21 17:47:00 +00:00
Davide Italiano 6d328d3841 [ELF2] Initial support for local symbols.
Symbol table is now populated correctly, but some fields are missing,
they'll be added in the future. This patch also adds --discard-all
flag, which was the default behavior until now.

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

llvm-svn: 247849
2015-09-16 20:45:57 +00:00
Michael J. Spencer 88f0d63bea [lld][elf2] Fix style.
llvm-svn: 247064
2015-09-08 20:36:20 +00:00
Rafael Espindola 18173d420e Start adding support for symbols in shared libraries.
llvm-svn: 247019
2015-09-08 15:50:05 +00:00
Michael J. Spencer 1b348a68e5 [elf2] Add basic archive file support.
llvm-svn: 246886
2015-09-04 22:28:10 +00:00
Rafael Espindola 55eed7efcd Avoid gcc warning.
llvm-svn: 246811
2015-09-03 22:25:11 +00:00
Davide Italiano 34812ba258 [ELF2] Don't allocate more SymbolBodies than needed.
Differential Revision:	http://reviews.llvm.org/D12605

llvm-svn: 246802
2015-09-03 20:25:54 +00:00
Rafael Espindola f98d6d84cd Start adding support for shared libraries.
This just adds the types and enough support to detect incompatibilities among
shared libraries and object files.

llvm-svn: 246797
2015-09-03 20:03:54 +00:00
Rafael Espindola 905ad3442d Split out the ELF kind from the InputFile Kind.
There were at least two issues with having them together:
* For compatibility checks, we only want to look at the ELF kind.
* Adding support for shared libraries should introduce one InputFile kind,
  not 4.

llvm-svn: 246707
2015-09-02 20:43:43 +00:00
Rafael Espindola 51d4690b6e Start adding support for common symbols.
For now this just recognizes the special section number.

llvm-svn: 246332
2015-08-28 21:26:51 +00:00
Rafael Espindola 3a63f3fb22 Add support for weak absolute symbols.
On ELF being weak is independent of what we call the kind of the symbol. So
this also makes the code simpler.

llvm-svn: 246326
2015-08-28 20:19:34 +00:00
Michael J. Spencer 67bc8d6b3f [elf2] Add basic relocation support for x86-64.
This currently doesn't handle local symbols.

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

llvm-svn: 246234
2015-08-27 23:15:56 +00:00
Rafael Espindola 0e0c1901c9 Start adding support for absolute symbols.
llvm-svn: 246147
2015-08-27 12:40:06 +00:00
Rafael Espindola 5cd113df01 Diagnose symbols with invalid section indexes.
llvm-svn: 245884
2015-08-24 22:00:25 +00:00
Rafael Espindola 2034822981 Add support for reading files with more than 0xff00 sections.
llvm-svn: 245880
2015-08-24 21:43:25 +00:00
Rafael Espindola 832b93f219 Start recording the section of symbols in the symbol table.
Support for more than 64 K sections to follow shortly.

llvm-svn: 245868
2015-08-24 20:06:32 +00:00
Rafael Espindola 1bd885aba4 ELF: Also record the type of undefined symbols.
Tested with a weak undefined. Testing with a plain undefined will have to wait
for support for -shared.

llvm-svn: 245069
2015-08-14 16:46:28 +00:00
Rafael Espindola c44d17ad45 Add the type of the symbols to the symbol table.
For now only defined symbols are covered. I will add undefined ones in the
next patch.

llvm-svn: 245057
2015-08-14 15:10:49 +00:00
Rafael Espindola cde251370a Include non-alloca sections in the link.
llvm-svn: 244895
2015-08-13 14:45:44 +00:00
Reid Kleckner f7b85e0ce2 Fix mismatched sign comparison
llvm-svn: 244653
2015-08-11 20:06:51 +00:00
Rafael Espindola 76e24ea955 Add support for weak undefined symbols.
llvm-svn: 244640
2015-08-11 17:57:05 +00:00
Rafael Espindola 791e9f9c59 Remove unused templating.
llvm-svn: 244639
2015-08-11 17:51:57 +00:00
Rafael Espindola b13df6582a Add support for weak symbols.
llvm-svn: 244636
2015-08-11 17:33:02 +00:00
Rafael Espindola 7c388187c9 Don't report a conflict between two local symbols.
llvm-svn: 244624
2015-08-11 16:30:34 +00:00
Rafael Espindola d8340dae0c Don't depend on getDotSymtabSec. It is going away.
llvm-svn: 244451
2015-08-10 15:12:17 +00:00
Rafael Espindola 1a9344fa26 Use already available symbol tables. NFC.
llvm-svn: 244336
2015-08-07 17:16:28 +00:00
Rafael Espindola df1e05a26c Delete broken code.
This was using a hard coded string table and getting it for every symbol.

The symbol name was already available.

llvm-svn: 244220
2015-08-06 15:33:21 +00:00
Rafael Espindola 192e1fa59d Move the error handling functions to Error.h. NFC.
llvm-svn: 244216
2015-08-06 15:08:23 +00:00
Rafael Espindola 3c9cb4b3d3 lld elf2: Diagnose trying to mix incompatible files.
This is also a step in instantiating the writer with the correct template
argument.

llvm-svn: 244035
2015-08-05 12:03:34 +00:00
Rafael Espindola 30318518a5 This function never returns null, don't check it.
llvm-svn: 243982
2015-08-04 14:00:56 +00:00
Michael J. Spencer cdae0a4e2d [ELF2] Devirtualize SymbolBody.
llvm-svn: 243496
2015-07-28 22:58:25 +00:00
Michael J. Spencer 84487f1174 [ELF2] Add a new ELF linker based on the new PE/COFF linker.
Differential Revision: http://reviews.llvm.org/D11188

llvm-svn: 243161
2015-07-24 21:03:07 +00:00
Michael J. Spencer bae540e945 Revert ELF port. Posting to mailing list.
llvm-svn: 242118
2015-07-14 04:49:48 +00:00
Michael J. Spencer 50ed5308d1 Fix warnings.
llvm-svn: 242098
2015-07-14 01:02:37 +00:00
Michael J. Spencer f754b1fe12 Put explicit template instantiations in the correct namespace.
llvm-svn: 242093
2015-07-14 00:22:00 +00:00
Michael J. Spencer 8a4145411f Initial ELF port.
This is a direct port of the new PE/COFF linker to ELF.

It can take a single object file and generate a valid executable that executes at the first byte in the text section.

llvm-svn: 242088
2015-07-13 23:48:06 +00:00