Commit Graph

97 Commits

Author SHA1 Message Date
Peter Collingbourne d0856a6bb2 ELF: Make SymbolBody::compare a non-template function.
Differential Revision: http://reviews.llvm.org/D18781

llvm-svn: 265372
2016-04-05 00:47:58 +00:00
Peter Collingbourne e8afa4971c ELF: Preserve MustBeInDynSym for bitcode symbols.
Make sure to copy the MustBeInDynSym field when replacing shared symbols with
bitcode symbols, and when replacing bitcode symbols with regular symbols
in addCombinedLtoObject. Fixes interposition of DSO symbols with bitcode
symbols in the main executable.

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

llvm-svn: 265371
2016-04-05 00:47:55 +00:00
Rui Ueyama b5792b231b Rename Other -> StOther.
"Other" as a name is too generic, so name it StOther.

llvm-svn: 265332
2016-04-04 19:09:08 +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
Rui Ueyama bfc1d9d976 Remove DefinedElf class.
DefinedElf was a superclass of DefinedRegular and SharedSymbol classes
and represented the notion of defined symbols created for ELF symbols.

It turned out that we didn't use that class often. We had only two
occurrences of dyn_cast'ing to DefinedElf, and both were easily
rewritten without it.

The class was also a bit confusing. The concept of "created for ELF
symbol" is orthogonal to defined/undefined types. However, we had
two distinct classes, DefinedElf and UndefinedElf.

This patch simply removes the class. Now the class hierarchy is one
level shallower.

llvm-svn: 265234
2016-04-02 18:06:18 +00:00
Simon Atanasyan 13f6da1d2c [ELF] Implement infrastructure for thunk code creation
Some targets might require creation of thunks. For example, MIPS targets
require stubs to call PIC code from non-PIC one. The patch implements
infrastructure for thunk code creation and provides support for MIPS
LA25 stubs. Any MIPS PIC code function is invoked with its address
in register $t9. So if we have a branch instruction from non-PIC code
to the PIC one we cannot make the jump directly and need to create a small
stub to save the target function address.
See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

- In relocation scanning phase we ask target about thunk creation necessity
by calling `TagetInfo::needsThunk` method. The `InputSection` class
maintains list of Symbols requires thunk creation.

- Reassigning offsets performed for each input sections after relocation
scanning complete because position of each section might change due
thunk creation.

- The patch introduces new dedicated value for DefinedSynthetic symbols
DefinedSynthetic::SectionEnd. Synthetic symbol with that value always
points to the end of the corresponding output section. That allows to
escape updating synthetic symbols if output sections sizes changes after
relocation scanning due thunk creation.

- In the `InputSection::writeTo` method we write thunks after corresponding
input section. Each thunk is written by calling `TargetInfo::writeThunk` method.

- The patch supports the only type of thunk code for each target. For now,
it is enough.

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

llvm-svn: 265059
2016-03-31 21:26:23 +00:00
Davide Italiano f6523aecd7 Revert r264961. I didn't have asserts enable when testing.
llvm-svn: 264692
2016-03-29 02:20:10 +00:00
Davide Italiano a50e0b97f1 [LTO] Include bitcode symbol name in unreachable messages.
llvm-svn: 264691
2016-03-29 01:40:07 +00:00
Rafael Espindola 5432287bad Make needsPlt a plain function instead of a template.
llvm-svn: 264267
2016-03-24 12:55:27 +00:00
Davide Italiano 901de03fe2 [ELF] Simplify code a bit. No functional change.
llvm-svn: 263999
2016-03-21 22:44:24 +00:00
Rafael Espindola 8381c565c3 Make evaluation order explicit.
llvm-svn: 263762
2016-03-17 23:36:19 +00:00
Rui Ueyama 9328b2cdde Use ELFT instead of ELFFile<ELFT>.
llvm-svn: 263510
2016-03-14 23:16:09 +00:00
George Rimar 343580097d [ELF] implement --warn-common/--no-warn-common
-warn-common
Warn when a common symbol is combined with another common symbol
or with a symbol definition.  Unix linkers allow  this  somewhat
sloppy  practice, but linkers on some other operating systems do
not.  This option allows you to  find  potential  problems  from
combining global symbols.

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

llvm-svn: 263413
2016-03-14 09:19:30 +00:00
Rui Ueyama 2df72898c8 Remove `else` after `return`.
llvm-svn: 263392
2016-03-13 20:54:38 +00:00
Rui Ueyama c4466605d8 ELF: Redefine canBeDefined as a member function of SymbolBody.
We want to make SymbolBody the central place to query symbol information.
This patch also renames canBePreempted to isPreemptible because I feel that
the latter is slightly better (the former is three words and the latter
is two words.)

llvm-svn: 263386
2016-03-13 19:48:18 +00:00
Rui Ueyama 7ede54310a Redefine isGnuIfunc as a member function of SymbolBody.
llvm-svn: 263365
2016-03-13 04:40:14 +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 1f5b70f64f Represent local symbols with DefinedRegular.
llvm-svn: 263237
2016-03-11 14:21:37 +00:00
Rafael Espindola 87d9f10733 Compute value of local symbol with getVA.
llvm-svn: 263225
2016-03-11 12:19:05 +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
George Rimar 56e0d53e92 [ELF] - Move initSymbols() to Driver.cpp. NFC.
That is followup for http://reviews.llvm.org/D18047
patch. initSymbols() moved to Driver.cpp and made static.

llvm-svn: 263214
2016-03-11 10:07:18 +00:00
Rui Ueyama 17d6983a4e Rename MaxAlignment -> Alignment.
We can argue about a maximum alignment of a group of symbols,
but for each symbol, there is only one alignment.
So it is a bit weird that each symbol has a "maximum alignment".

llvm-svn: 263151
2016-03-10 18:58:53 +00:00
George Rimar 3498c7fbd0 [ELF] - Refactor of SymbolBody::compare()
That makes it a bit shorter.

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

llvm-svn: 263144
2016-03-10 18:49:24 +00:00
George Rimar 5a3dcf4edf [ELF] - Do not call doInitSymbols for all ELFTs
It looks a bit wierd that we have to initialize symbols for all ELFT 
types when we use only one ELFT for link. We can only init those
that we need. Patch fixes it.

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

llvm-svn: 263133
2016-03-10 17:38:49 +00:00
Rafael Espindola e090fb2891 ELF: Remove non-standard ELF features from AMDGPU target.
Patch by Tom Stellard!

llvm-svn: 263063
2016-03-09 21:37:22 +00:00
Rafael Espindola 4f29c1a337 lto: Record visibility in defined symbols.
llvm-svn: 262835
2016-03-07 17:14:36 +00:00
George Rimar 2f0fab53e4 [ELF] - Simplify a SymbolBody class interface a bit.
Get rid of few accessors in that class, and replace
them with direct fields access.

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

llvm-svn: 262796
2016-03-06 06:26:18 +00:00
Davide Italiano 255730cdc5 [ELF] Generalize symbol type handling.
SymbolBody constructor and friends take isFunc and isTLS boolean arguments.
ELF symbols have already a type so than be easily passed as argument.
If we want to support another type, this scheme is not good enough, that is,
the current code logic would require passing another `bool isObject` around.
Up to two argument, this stretching exercise was a little bit goofy but
still acceptable, but with more types to support, is just too much, IMHO.

Change the code so that the type is passed instead.

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

llvm-svn: 262684
2016-03-04 01:55:28 +00:00
George Rimar aa4dc20f09 [ELF] - Create _DYNAMIC symbol for dynamic output
lld needs to provide _DYNAMIC symbol when creating a shared library
both bfd and gold do that.

This should fix the https://llvm.org/bugs/show_bug.cgi?id=26732

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

llvm-svn: 262348
2016-03-01 16:23:13 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rui Ueyama 72acaa1d17 Add comment on AMDGPU that the difference has no obvious reason.
llvm-svn: 262026
2016-02-26 15:39:26 +00:00
George Rimar 9e8593949d Description of symbols is avalable here:
https://docs.oracle.com/cd/E53394_01/html/E54766/u-etext-3c.html

It is said that:
_etext - The address of _etext is the first 
location after the last read-only loadable segment.

_edata - The address of _edata is the first 
location after the last read-write loadable segment.

_end - If the address of _edata is greater than the address 
of _etext, the address of _end is same as the address of _edata.

In real life _end and _edata has different values for that case.
Both gold/bfd set _edata to the end of the last non SHT_NOBITS section.
This patch do the same for consistency.

It should fix the https://llvm.org/bugs/show_bug.cgi?id=26729.

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

llvm-svn: 262019
2016-02-26 14:36:36 +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
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 9f77ef0c08 Add initial LTO support.
llvm-svn: 260726
2016-02-12 20:54:57 +00:00
Rafael Espindola a0a65f973a Use the plt entry as the address of some symbols.
This is the function equivalent of a copy relocation.

Since functions are expected to change sizes, we cannot use copy
relocations. In situations where one would be needed, what is done
instead is:
* Create a plt entry
* Output an undefined symbol whose addr is the plt entry.

The dynamic linker makes sure any shared library uses the plt entry as
the function address.

llvm-svn: 260224
2016-02-09 15:11:01 +00:00
Rafael Espindola abebed982a Rename IsUsedInDynamicReloc to MustBeInDynSym.
The variable was marking various cases where a symbol must be included
in the dynamic symbol table. Being used by a dynamic relocation was only
one of them.

llvm-svn: 259889
2016-02-05 15:27:15 +00:00
Rui Ueyama 512c61df1c Define SymbolBody::getSize instead of getSymSize(SymbolBody&). NFC.
llvm-svn: 259613
2016-02-03 00:12:24 +00:00
George Rimar 5c36e5938d [ELF] Implemented -Bsymbolic-functions command line option
-Bsymbolic-functions: 
When creating a shared library, bind references to global 
function symbols to the definition within the shared library, if any.

This patch also fixed behavior of already existent -Bsymbolic:
previously PLT entries were created even if -Bsymbolic was specified.

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

llvm-svn: 259481
2016-02-02 09:28:53 +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 b5a6970ace ELF: Teach SymbolBody about how to get its addresses.
Previously, the methods to get symbol addresses were somewhat scattered
in many places. You can use getEntryAddr returns the address of the symbol,
but if you want to get the GOT address for the symbol, you needed to call
Out<ELFT>::Got->getEntryAddr(Sym). This change adds new functions, getVA,
getGotVA, getGotPltVA, and getPltVA to SymbolBody, so that you can use
SymbolBody as the central place to ask about symbols.

http://reviews.llvm.org/D16710

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

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

llvm-svn: 258672
2016-01-25 08:44:38 +00:00
Rafael Espindola 65e80b963a Rename IgnoredWeak to Ignored.
Thanks to Rui for the suggestion.

llvm-svn: 258189
2016-01-19 21:19:52 +00:00
Rafael Espindola 3a6a0a0109 Delete addIgnoredStrong.
It is not needed now that we resolve symbols is shared libraries
correctly.

llvm-svn: 258104
2016-01-19 00:05:54 +00:00
Rafael Espindola 0bc0c02387 Prefer symbols from .o over .so.
This matches the behavior of gold and bfd ld.

llvm-svn: 258102
2016-01-18 23:54:05 +00:00
Rui Ueyama df1545163f Update comment for __cxa_demangle again to make it precise.
Thanks for Ed Maste for the suggestion.

llvm-svn: 257685
2016-01-13 22:09:09 +00:00