Commit Graph

125 Commits

Author SHA1 Message Date
Rafael Espindola 9bcbfd7d42 Remove bogus assert.
llvm-svn: 262219
2016-02-29 13:46:39 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rafael Espindola 18f0950783 Report duplicated symbols in bitcode.
llvm-svn: 262076
2016-02-26 21:49:38 +00:00
Rafael Espindola 297ce4ece9 Make SymbolBodies private.
This makes BitcodeFile a bit closer to ObjectFile.

If anyone prefers I can go the other way and delete getSymbols from
ObjectFile.

llvm-svn: 262072
2016-02-26 21:31:34 +00:00
Rafael Espindola 8176d57d62 Handle a weak undefined tls to archive member.
A weak undefined should not fetch archive members, so we have to keep
the Lazy symbol.

That means the lazy symbol has to encode information about the original
weak undef.

Fixes pr25762.

llvm-svn: 261591
2016-02-22 23:19:29 +00:00
Rafael Espindola 5e8b54afdb Remove a trivial getter.
llvm-svn: 261590
2016-02-22 23:16:05 +00:00
Rafael Espindola 9f77ef0c08 Add initial LTO support.
llvm-svn: 260726
2016-02-12 20:54:57 +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 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 16ba669c87 ELF: Report duplicate symbols as many as possible instead of the first one.
http://reviews.llvm.org/D16647

llvm-svn: 259233
2016-01-29 19:41:13 +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
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
Rui Ueyama a4a628fb51 Demangle symbols when including them in error messages.
llvm-svn: 257647
2016-01-13 18:55:39 +00:00
Rui Ueyama 09eb0b3b3f Rename IgnoredUndef -> Ignored since it is not an undefined symbol.
Also rename Ignored -> IgnoredWeak and IgnoredStrong -> Ignored,
since strong symbol is a norm.

llvm-svn: 257507
2016-01-12 19:24:55 +00:00
Simon Atanasyan 188558e5eb [ELF][MIPS] Prevent substitution of _gp_disp symbol
On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
start of function and gp pointer into GOT. To make seal with such symbol
we add new method addIgnoredStrong(). It adds ignored symbol with global
binding to prevent the symbol substitution. The addIgnored call is not
enough here because this call adds a weak symbol which might be
substituted by symbol from shared library.

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

llvm-svn: 257449
2016-01-12 06:23:57 +00:00
Rui Ueyama 131e0ffa10 Use shorter name. NFC.
llvm-svn: 257217
2016-01-08 22:17:42 +00:00
Rui Ueyama 8b4879aec0 Remove an empty constructor.
We used to have code in SymbolTable constructor to add entry symbols, etc.
That code has been moved to Driver. We can remove the constructor.

llvm-svn: 257214
2016-01-08 22:06:25 +00:00
Rui Ueyama b4de595c46 Add comments.
llvm-svn: 257212
2016-01-08 22:01:33 +00:00
Rui Ueyama 79c7373232 ELF: Consistently return SymbolBody * from SymbolTable::add functions.
For historical reasons, some add* functions for SymbolTable returns a
pointer to a SymbolBody, while some are not. This patch is to make them
consistently return a pointer to a newly added symbol.

llvm-svn: 257211
2016-01-08 21:53:28 +00:00
Rui Ueyama deb154001d ELF: Implement --wrap.
In this patch, all symbols are resolved normally and then wrap options
are applied. Renaming is implemented by mutating `Body` pointers of
Symbols. (As a result, Symtab.find(SymbolName)->getName() may return
a string that's different from SymbolName, but that is by design.
I designed the symbol and the symbol table to allow this kind of
operations.)

http://reviews.llvm.org/D15896

llvm-svn: 257075
2016-01-07 17:20:07 +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 f588ac4663 Simplify. NFC.
llvm-svn: 256879
2016-01-06 00:09:41 +00:00
Rui Ueyama 2e0a9fff12 Fix local variable naming.
llvm-svn: 256878
2016-01-06 00:09:39 +00:00
Rui Ueyama c9559d9378 Add comments.
llvm-svn: 256872
2016-01-05 20:47:37 +00:00
Rui Ueyama 2ef58a18af Remove SymbolTable::isUndefined.
Because it can be implemented outside of the symbol table.

llvm-svn: 256869
2016-01-05 20:35:16 +00:00
Rui Ueyama 2a65a49bcf Make findFile() a member function of SymbolTable to simplify. NFC.
llvm-svn: 256867
2016-01-05 20:01:29 +00:00
Rui Ueyama a246e094bc Factor out static members from DefinedRegular.
This patch moves statically-allocated Elf_Sym objects out
of DefinedRegular class, so that the class definition becomes
smaller.

llvm-svn: 256408
2015-12-25 06:12:18 +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 01a65b19cf Add comments.
llvm-svn: 256380
2015-12-24 10:37:32 +00:00
Rafael Espindola 4d4b06a0f8 Split Defined and DefinedElf.
This is similar to what was done for Undefined and opens the way for
having a symbol defined in bitcode.

llvm-svn: 256354
2015-12-24 00:47:42 +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 05b0375e93 Fix an asan found leak.
I will make better use of std::unique_ptr in followup patch.

llvm-svn: 256310
2015-12-23 01:14:37 +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
Rafael Espindola 8a9f90e669 Refactor duplicated code. NFC.
llvm-svn: 256180
2015-12-21 19:09:19 +00:00
Rui Ueyama 62d0e3297b ELF: Rename isTLS -> isTls for consistency.
llvm-svn: 255855
2015-12-17 00:04:18 +00:00
Rui Ueyama 3554f59f5d ELF: Remove a dumb constructor.
Symbol is a struct and can be initialized using an initializer.

llvm-svn: 255854
2015-12-17 00:01:25 +00:00
Rui Ueyama 6192c122f4 ELF: Move shouldUseRela to Writer.cpp.
The function was used only in Writer.cpp and did not depend on SymbolTable.
There is no reason to have that function in SymbolTable.cpp.

llvm-svn: 255850
2015-12-16 23:33:56 +00:00
Rui Ueyama 25b44c9b2b ELF: Make checkCompatibility a non-member function.
Because the function does not use any member of SymbolTable class.

llvm-svn: 255849
2015-12-16 23:31:22 +00:00
Rui Ueyama 38dcc9e355 Simplify. NFC.
llvm-svn: 255846
2015-12-16 23:25:31 +00:00
Rui Ueyama c5b9512958 ELF: Remove duplicate code.
We had duplicate code that were called before addMemberFile.
This patch makes them to be called at beginning of addMemberFile.

llvm-svn: 255845
2015-12-16 23:23:14 +00:00
Rui Ueyama 8957574549 ELF: Remove SymbolTable::addELFFile.
addELFFile was called only from addFile, and what it did was actually
just adding a file to the symbol table. There seems to be no reason
to separate the two.

llvm-svn: 255839
2015-12-16 22:59:13 +00:00
Rui Ueyama a71f3a71cc Do not omit * from auto.
We don't do that in other places in the same file.

llvm-svn: 255833
2015-12-16 22:36:10 +00:00
Rui Ueyama dd7d998919 ELF: Drop 'Sym' suffix from member function names for consistency.
Since the functions are members of SymbolTable class, it is obvious
that they are adding symbols.

llvm-svn: 255832
2015-12-16 22:31:14 +00:00
Rui Ueyama 533336a368 ELF: Factor out common code. NFC.
llvm-svn: 255830
2015-12-16 22:26:48 +00:00
Rui Ueyama f09040120f ELF: Separate error message generation from call of error() or warning().
Previously reportConflict returned only when the third argument is false.
Now it always returns a value.

llvm-svn: 255829
2015-12-16 22:26:45 +00:00
Simon Atanasyan 09dae7c3e7 [ELF][MIPS] Handle R_MIPS_HI16/LO16 relocations against _gp_disp symbol
The `_gp_disp` is a magic symbol designates offset between start of
function and gp pointer into GOT. Only `R_MIPS_HI16` and `R_MIPS_LO16`
relocations are permitted with `_gp_disp`. The patch adds the `_gp_disp`
as an ignored symbol and adjusts symbol value before call the `relocateOne`
for `R_MIPS_HI16/LO16` relocations.

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

llvm-svn: 255768
2015-12-16 14:45:09 +00:00
Igor Kudrin 4bc5ad4c37 [ELF] Prevent SEGFAULT in case of conflict with an internally defined symbol.
Differential Revision: http://reviews.llvm.org/D14832

llvm-svn: 253588
2015-11-19 19:08:45 +00:00
Igor Kudrin 15cd9ffd1e [ELF2] Add GOT section for MIPS target.
This patch implements R_MIPS_GOT16 relocation for global symbols in order to
generate some entries in GOT. Only reserved and global entries are supported
for now. For the detailed description about GOT in MIPS, see "Global Offset
Table" in Chapter 5 in the followin document:
ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

In addition, the platform specific symbol "_gp" is added, see "Global Data
Symbols" in Chapter 6 in the aforementioned document.

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

llvm-svn: 252275
2015-11-06 07:43:03 +00:00