Commit Graph

219 Commits

Author SHA1 Message Date
Rafael Espindola dd9dd488fc Fix a bogus warning.
We first decide that the symbol is global, than that it should have
version foo. Since it was already not the default version, we were
producing a bogus warning.

llvm-svn: 289284
2016-12-09 22:40:49 +00:00
Peter Smith baffdb8bc2 [ELF] ifunc implementation using synthetic sections
This change introduces new synthetic sections IpltSection, IgotPltSection
that represent the ifunc entries that would previously have been put in
the PltSection and the GotPltSection. The separation makes sure that
the R_*_IRELATIVE relocations are placed after the non R_*_IRELATIVE
relocations, which permits ifunc resolvers to know that the .got.plt
slots will be initialized prior to the resolver being called.

A secondary benefit is that for ARM we can move the IgotPltSection and its
dynamic relocations to the .got and .rel.dyn as the ARM glibc expects all
the R_*_IRELATIVE relocations to be in the .rel.dyn

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

llvm-svn: 289045
2016-12-08 12:58:55 +00:00
Simon Atanasyan 6a4eb75c46 [ELF][MIPS] Make _gp, _gp_disp, __gnu_local_gp global symbols
These MIPS specific symbols should be global because in general they can
have an arbitrary value. By default this value is a fixed offset from .got
section.

This patch adds more checks to the mips-gp-local.s test case but marks
it as XFAIL because LLD does not allow redefinition of absolute symbols
value by a linker script. This should be fixed by D27276.

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

llvm-svn: 289025
2016-12-08 06:19:47 +00:00
Rui Ueyama a13efc2a73 Introduce StringRefZ class to represent null-terminated strings.
StringRefZ is a class to represent a null-terminated string. String
length is computed lazily, so it's more efficient than StringRef to
represent strings in string table.

The motivation of defining this new class is to merge functions
that only differ in string types; we have many constructors that takes
`const char *` or `StringRef`. With StringRefZ, we can merge them.

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

llvm-svn: 288172
2016-11-29 18:05:04 +00:00
Rui Ueyama a3ac17372b Define toString(const SymbolBody &) and remove maybeDemangle instead.
Differential Revision: https://reviews.llvm.org/D27065

llvm-svn: 287899
2016-11-24 20:24:18 +00:00
Simon Atanasyan 8469b8841c [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbols
Offset between beginning of a .got section and _gp symbols used in MIPS
GOT relocations calculations. Usually the expression looks like
VA + Offset - GP, where VA is the .got section address, Offset - offset
of the GOT entry, GP - offset between .got and _gp. Also there two "magic"
symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above.
These symbols might be referenced by MIPS relocations.

Now the linker always defines _gp symbol and uses hardcoded value for
its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp
and __gnu_local_gp defined if required and initialized by 0x7ff0.
In fact that is not correct because _gp symbol might be defined by a linker
script and holds arbitrary value. In that case we need to use this value
in relocation calculation and initialize _gp_disp and __gnu_local_gp
properly.

The patch fixes the problem and completes fixing the bug #30311.
https://llvm.org/bugs/show_bug.cgi?id=30311

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

llvm-svn: 287832
2016-11-23 22:22:16 +00:00
Rui Ueyama 768c6f0ca6 Remove a forwarding constructor that is used only once.
llvm-svn: 287742
2016-11-23 06:31:23 +00:00
Rui Ueyama 35fa6c58ad Parse symbol versions in scanVersionScript() instead of insert().
There are two ways to set symbol versions. One way is to use symbol
definition file, and the other is to embed version names to symbol
names. In the latter way, symbol name is in the form of `foo@version1`
where `foo` is a real name and `version1` is a version.

We were parsing symbol names in insert(). That seems unnecessarily
too early. We can do it later after we resolve all symbols. Doing it
lazily is a good thing because it makes code easier to read
(because now we have a separate pass to parse symbol names). Also
it could slightly improve performance because if two identical symbols
have versions, we now parse them only once.

llvm-svn: 287741
2016-11-23 05:48:40 +00:00
Rui Ueyama c72ba3a4d7 Allow calling getName() on local symbols.
Previously, we stored offsets in string tables to symbols, so
you needed to pass a string table to get a symbol name. This patch
stores const char pointers instead to eliminate the need to pass
a string table.

llvm-svn: 287737
2016-11-23 04:57:25 +00:00
Eugene Leviant afaa934304 [ELF] Add Section() to expression object
This allows making symbols containing ADDR(section) synthetic,
and defining synthetic symbols outside SECTIONS block.

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

llvm-svn: 287090
2016-11-16 09:49:39 +00:00
George Rimar 463984d4bf [ELF] - Better diagnostic for relative relocation to an absolute value error.
Patch adds a filename to that error message.

I faced next error when debugged one of FreeBSD port:
error: relocation R_X86_64_PLT32 cannot refer to absolute symbol __tls_get_addr

error message was poor and this patch improves it to show the locations 
of symbol declaration and using.

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

llvm-svn: 286940
2016-11-15 08:07:14 +00:00
George Rimar 1a33c0f242 [ELF] - Implemented --symbol-ordering-file option.
Patch allows to pass a symbols file to linker.
LLD will map symbols to sections and sort sections
in output according to symbol ordering file.

That can help to reduce the startup time and/or
amount of pagefaults during startup.

Also, interesting benchmark result was produced by Rafael Espíndola. 
After applying the symbols file for clang he timed compiling 
X86MCTargetDesc.ii to an object file.  

The page faults went from just
56,988 to 56,946 since most faults are not in the binary.
Running time went from 4.403053515 to 4.178112244. 
The speedup seems to be because of better cache
locality.

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

llvm-svn: 286440
2016-11-10 09:05:20 +00:00
Rafael Espindola e08e78df6d Make OutputSectionBase a class instead of class template.
The disadvantage is that we use uint64_t instad of uint32_t for some
value in 32 bit files. The advantage is a substantially simpler code,
faster builds and less code duplication.

llvm-svn: 286414
2016-11-09 23:23:45 +00:00
Rui Ueyama 55518e7dd8 Consolidate BumpPtrAllocators.
Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

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

llvm-svn: 285452
2016-10-28 20:57:25 +00:00
Rafael Espindola 5ceeb60c6e Have on addRegular forward to another. NFC.
Another step in making it easier to create symbols without an ELf_Sym.

llvm-svn: 285241
2016-10-26 20:57:14 +00:00
Rui Ueyama 4c1cd45965 Remove a constructor to simplify.
llvm-svn: 285240
2016-10-26 20:44:32 +00:00
Rafael Espindola a8bf71cc4e Make the DefinedRegular constructors more regular. NFC.
All the global ones now just forward to the same constructor. This
makes it easier to construct them without creating a Elf_Sym.

llvm-svn: 285238
2016-10-26 20:34:59 +00:00
Rafael Espindola 5da1d88492 Reduce the number of allocators.
We used to have one allocator per file, which reduces the advantage of
using an allocator in the first place.

This is a small speed up is most cases. The largest speedup was in
1.014X in chromium no-gc. The largest slowdown was scylla at 1.003X.

llvm-svn: 285205
2016-10-26 15:34:24 +00:00
Rafael Espindola 7ae2177262 Use uint32_t for consistency.
llvm-svn: 285149
2016-10-26 00:58:23 +00:00
Rafael Espindola ca656239eb Compact SymbolBody from 56 to 48 bytes.
llvm-svn: 284878
2016-10-21 20:32:41 +00:00
Simon Atanasyan bed04bf1df [ELF][MIPS] Put local GOT entries accessed via a 16-bit index first
Some MIPS relocations used to access GOT entries are able to manipulate
16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle
32-bit indexes. 16-bit relocations are generated by default. The 32-bit
relocations are generated by -mxgot flag passed to compiler. Usually
these relocation are not mixed in the same code but files like crt*.o
contain 16-bit relocations so even if all "user's" code compiled with
-mxgot flag a few 16-bit relocations might come to the linking phase.

Now LLD does not differentiate local GOT entries accessed via a 16-bit
and 32-bit indexes. That might lead to relocation's overflow if 16-bit
entries are allocated to far from the beginning of the GOT.

The patch introduces new "part" of MIPS GOT dedicated to the local GOT
entries accessed by 32-bit relocations. That allows to put local GOT
entries accessed via a 16-bit index first and escape relocation's overflow.

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

llvm-svn: 284809
2016-10-21 07:22:30 +00:00
Rui Ueyama e329a9fad6 Remove unused #include.
llvm-svn: 284758
2016-10-20 18:07:11 +00:00
Benjamin Kramer 922b63b7f1 Remove a use of llvm::AlignOf that I missed.
llvm-svn: 284739
2016-10-20 15:55:41 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Simon Atanasyan f967f090b8 [ELF][MIPS] Setup STO_MIPS_PIC flag for PIC symbols when generate a relocatable object
In case of linking PIC and non-PIC code together and generation of a
relocatable object, all PIC symbols should have STO_MIPS_PIC flag in the
symbol table of the ouput file.

llvm-svn: 282714
2016-09-29 12:58:36 +00:00
Davide Italiano 786d8e33db [ELF/LTO] Switch to the new resolution-based API.
Differential Revision:  https://reviews.llvm.org/D24492

llvm-svn: 282656
2016-09-29 00:40:08 +00:00
Rui Ueyama 38dbd3eea9 Simplify InputFile ownership management.
Previously, all input files were owned by the symbol table.
Files were created at various places, such as the Driver, the lazy
symbols, or the bitcode compiler, and the ownership of new files
was transferred to the symbol table using std::unique_ptr.
All input files were then free'd when the symbol table is freed
which is on program exit.

I think we don't have to transfer ownership just to free all
instance at once on exit.

In this patch, all instances are automatically collected to a
vector and freed on exit. In this way, we no longer have to
use std::unique_ptr.

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

llvm-svn: 281425
2016-09-14 00:05:51 +00:00
Rafael Espindola e7553e4eac Delete unnecessary template.
llvm-svn: 280237
2016-08-31 13:28:33 +00:00
Rafael Espindola a6c9744a6c Delete DefinedBitcode.
Given that we almost always want to handle it as DefinedRegular, just
use DefinedRegular.

llvm-svn: 280226
2016-08-31 12:30:34 +00:00
Davide Italiano 35af5b3d21 [LTO] Fix the logic for dropping unnamed_addr.
Differential Revision:  https://reviews.llvm.org/D24037

llvm-svn: 280144
2016-08-30 20:15:03 +00:00
Petr Hosek 4f7a5c3bb4 [ELF] Define __ehdr_start symbol
This symbol can be used by the program to examine its own headers.

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

llvm-svn: 279452
2016-08-22 18:44:04 +00:00
Rui Ueyama 0778490428 Remove DefinedCommon::Section.
Since CommonInputSection is a singleton class, we don't need
to store pointers to all DefinedCommon symbols.

llvm-svn: 277410
2016-08-02 01:35:13 +00:00
Eugene Leviant 3e6b027705 [ELF] Allows setting section for common symbols in linker script
llvm-svn: 277023
2016-07-28 19:24:13 +00:00
Rui Ueyama dace838138 Simplify symbol version handling.
r275711 for "speedng up symbol version handling" was committed
by misunderstanding; the benchmark number was measured with
a debug build. The number with a release build didn't actually change.
This patch removes false optimizations added in that patch.

llvm-svn: 276267
2016-07-21 13:13:21 +00:00
Rui Ueyama e33579072d Remove SymbolBody::PlaceholderKind.
In the last patch for --trace-symbol, I introduced a new symbol type
PlaceholderKind and store it to SymVector storage. It made all code
that iterates over SymVector to recognize and skip PlaceholderKind
symbols. I found that that's annoying.

In this patch, I removed PlaceholderKind and stop storing them to SymVector.
Now the information whether a symbol is being watched by --trace-symbol
is stored to the Symtab hash table.

llvm-svn: 275747
2016-07-18 01:35:00 +00:00
Rui Ueyama 69c778c084 Implement almost-zero-cost --trace-symbol.
--trace-symbol is a command line option to watch a symbol.
Previosly, we looked up a hash table for a new symbol if the
option is given. Any code that looks up a hash table for each
symbol is expensive because the linker handles a lot of symbols.
In our design, we look up a hash table strictly only once
for a symbol, so --trace-symbol was an exception.

This patch improves efficiency of the option by merging the
hash table into the symbol table.

Instead of looking up a separate hash table with a string,
this patch sets `Traced` flag to symbols specified by --trace-symbol.
So, if you insert a symbol and get a symbol with `Traced` flag on,
you know that you need to print out a log message for the symbol.
This is nearly zero cost.

llvm-svn: 275716
2016-07-17 17:50:09 +00:00
Rui Ueyama b06700fa78 Make Lazy's ctro protected because it shouldn't be instantiated directly.
llvm-svn: 275715
2016-07-17 17:44:41 +00:00
Rui Ueyama bef5d16a90 Remove duplicate public specifier.
llvm-svn: 275714
2016-07-17 17:44:40 +00:00
Rui Ueyama 2a7c1c1507 Print out file names for common symbols for --trace-symbol.
Previously, there was no way to get a file name for a DefinedCommon
symbol. This patch adds it.

llvm-svn: 275712
2016-07-17 17:36:22 +00:00
Rui Ueyama 663b8c2769 Handle versioned symbols efficiently.
Versions can be assigned to symbols in two different ways.
One is the usual version scripts, and the other is special
symbol suffix '@'. If a symbol contains '@', the string after
that is considered to specify a version name.

Previously, we look for '@' for all symbols.

Anything that works on every symbol can be expensive because
the linker has to handle a lot of symbols. The search for '@'
was not an exception.

In this patch, I made two optimizations.

The first optimization is to handle '@' only when at least one
version is defined. If no versions are defined, no versions can
be assigned to any symbols, so it's waste of time to search for '@'.

The second optimization is to scan only suffixes of symbol names
instead of entire symbol names. Symbol names can be very long, but
symbol versions are usually short, so scanning entire symbol names
is waste of time, too.

There are some error cases which we no longer be able to detect
with this patch. I don't think it's a major drawback because they
are minor errors. Speed is more important.

This change improves LLD with debug info self-link time from
6.6993 seconds to 6.3426 seconds (or -5.3%).

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

llvm-svn: 275711
2016-07-17 17:23:17 +00:00
Rui Ueyama 434b56179e Add a pointer to a source file to SymbolBody.
Previously, each subclass of SymbolBody had a pointer to a source
file from which it was created. So, there was no single way to get
a source file for a symbol. We had getSourceFile<ELFT>(), but the
function was a bit inconvenient as it's a template.

This patch makes SymbolBody have a pointer to a source file.
If a symbol is not created from a file, the pointer has a nullptr.

llvm-svn: 275701
2016-07-17 03:11:46 +00:00
Rui Ueyama bc94dd9b28 Rename Version VersionDefinition.
The identifier `Version` was used too often in the code to handle
symbol versions. The struct that contains version definitions is
named `Version`. Local variables for version ID are named `Version`.
Local varaible for version string are named `Version`.

This patch give them different names.

llvm-svn: 275673
2016-07-16 04:02:00 +00:00
Rui Ueyama 8c8db476f1 Attempt to fix buildbots.
llvm-svn: 274917
2016-07-08 19:59:11 +00:00
Rafael Espindola 6091492e2c fix use of uninitialized.
llvm-svn: 274909
2016-07-08 19:28:55 +00:00
Rui Ueyama 8b8d0055fe Fix memory leak.
Symbol's dtors are not called because they are allocated using
BumpPtrAllocators. So, members of std::unique_ptr type are not
freed when symbols are deallocated.

This patch is to allocate Thunks using BumpPtrAllocators.

llvm-svn: 274896
2016-07-08 17:58:54 +00:00
Peter Smith fb05cd997c Recommit R274836 Add Thunk support framework for ARM and Mips
The TinyPtrVector of const Thunk<ELFT>* in InputSections.h can cause 
build failures on certain compiler/library combinations when Thunk<ELFT> 
is not a complete type or is an abstract class. Fixed by making Thunk<ELFT>
non Abstract.

type or is an abstract class 

llvm-svn: 274863
2016-07-08 16:10:27 +00:00
Peter Smith eeb827447e Revert R274836 Add Thunk support framework for ARM and Mips
This seems to be causing a buildbot failure on lld-x86_64-freebsd. Will
reproduce locally and fix. 

llvm-svn: 274841
2016-07-08 12:25:50 +00:00
Peter Smith de01b98a26 Add Thunk support framework for ARM and Mips
Generalise the Mips LA25 Thunk code and implement ARM and Thumb
    interworking Thunks.
    
    - Introduce a new module Thunks.cpp to store the Target Specific Thunk
      implementations.
    - DefinedRegular and Shared have a ThunkData field to record Thunk.
    - A Target can have more than one type of Thunk.
    - Support PC-relative calls to Thunks.
    - Support Thunks to PLT entries.
    - Existing Mips LA25 Thunk code integrated.
    - Support for ARMv7A interworking Thunks.
    
    Limitations:
    - Only one Thunk per SymbolBody, this is sufficient for all currently
      implemented Thunks.
    - ARM thunks assume presence of V6T2 MOVT and MOVW instructions.

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

llvm-svn: 274836
2016-07-08 11:13:40 +00:00
Rui Ueyama f4d9338dfb Move demangle() from Symbols.cpp to Strings.cpp.
Symbols.cpp contains functions to handle ELF symbols.
demangle() function is essentially a function to work on a
string rather than on an ELF symbol. So Strings.cpp is a
better place to put that function.

This change also make demangle to demangle symbols unconditionally.
Previously, it demangled symbols only when Config->Demangle is true.

llvm-svn: 274804
2016-07-07 23:04:15 +00:00
George Rimar 4365158689 [ELF] - Implemented support of default/non-default symbols versions
t is possible to create new version of symbol instead of depricated one
using combination of version script and asm commands. For example:

__asm__(".symver b_1,b@LIBSAMPLE_1.0");
int b_1() { return 10; }
__asm__(".symver b_2,b@@LIBSAMPLE_2.0");
int b_2() { return 20; }

This code makes b_2() to be default implementation for b().
b_1() is used for compatibility with binaries compiled against
library of older version LIBSAMPLE_1.0.

This patch implements support for above functionality in lld.

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

llvm-svn: 274002
2016-06-28 08:21:10 +00:00