Commit Graph

317 Commits

Author SHA1 Message Date
Rafael Espindola 49cd09337c Don't crash on an extra symbol in a version script.
llvm-svn: 289217
2016-12-09 15:08:40 +00:00
Rafael Espindola 6239ce6889 Give preempting symbols precedence over linker script.
llvm-svn: 289212
2016-12-09 14:12:02 +00:00
Rui Ueyama 520d9169e6 Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.
llvm-svn: 289084
2016-12-08 18:31:13 +00:00
Rafael Espindola d0ebd84c42 Change the implementation of --dynamic-list to use linker script parsing.
The feature is documented as
-----------------------------
The format of the dynamic list is the same as the version node
without scope and node name.  See *note VERSION:: for more
information.
--------------------------------

And indeed qt uses a dynamic list with an 'extern "C++"' in it. With
this patch we support that

The change to gc-sections-shared makes us match bfd. Just because we
kept bar doesn't mean it has to be in the dynamic symbol table.

The changes to invalid-dynamic-list.test and reproduce.s are because
of the new parser.

The changes to version-script.s are the only case where we change
behavior with regards to bfd, but I would like to see a mix of
--version-script and --dynamic-list used in the wild before
complicating the code.

llvm-svn: 289082
2016-12-08 17:54:26 +00:00
Rafael Espindola 191390a851 Inline function called only once.
llvm-svn: 289067
2016-12-08 16:26:20 +00:00
Rafael Espindola 361da4cef7 Handle C++ names in anon scripts.
llvm-svn: 289066
2016-12-08 16:20:29 +00:00
Rafael Espindola defdfa86c1 Inline two functions called only once. NFC.
llvm-svn: 289065
2016-12-08 16:02:48 +00:00
Rafael Espindola c65aee64ec Add two helper functions. NFC.
llvm-svn: 289064
2016-12-08 15:56:33 +00:00
Rafael Espindola 39c16dfbce Simplify. NFC.
llvm-svn: 289062
2016-12-08 15:36:58 +00:00
Simon Atanasyan 872764f6fe [ELF] Correct addAbsolute function argument name
Follow-up to r289025.

llvm-svn: 289061
2016-12-08 15:29:17 +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 4c5b8cea02 Make demangle() return None instead of "" if a given string is not a mangled symbol.
llvm-svn: 288993
2016-12-07 23:17:05 +00:00
Rafael Espindola 858c092daa Allow duplicated abs symbols with the same value.
This is a fairly reasonable bfd extension since there is one obvious value.

dtrace depends on this feature as it creates multiple absolute
symbols with the same value.

llvm-svn: 288461
2016-12-02 02:58:21 +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
Davide Italiano 3bfa081aa9 [ELF] Be compliant with LLVM and rename Lto into LTO. NFCI.
llvm-svn: 287967
2016-11-26 05:37:04 +00:00
Rui Ueyama da06bfb794 Move getLocation from Relocations.cpp to InputSection.cpp.
The function was used only within Relocations.cpp, but now we are
using it in many places, so this patch moves it to a file that fits
to the functionality.

llvm-svn: 287943
2016-11-25 18:51:53 +00:00
Rui Ueyama 26081caf48 Use toString() to report incompatible files.
llvm-svn: 287901
2016-11-24 20:59:44 +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
Rui Ueyama f373dd76ce Remove HasError and use ErrorCount instead.
HasError was always true if ErrorCount > 0, so we can use ErrorCount instead.

llvm-svn: 287849
2016-11-24 01:43:21 +00:00
Rui Ueyama 3fc0f7e54f Define toString() as a generic function to get a string for error message.
We have different functions to stringize objects to construct
error messages. For InputFile, we have getFilename, and for
InputSection, we have getName. You had to memorize them.

I think this is the case where the function overloading comes in handy.

This patch defines toString() functions that are overloaded for all these
types, so that you just call it in error().

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

llvm-svn: 287787
2016-11-23 18:07:33 +00:00
Rui Ueyama 0cbf749397 Remove one of SymbolTable::addRegular function that forwards other addRegular.
So that we have less number of overloaded functions.

llvm-svn: 287745
2016-11-23 06:59:47 +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 8f47556796 Remove unused #include.
llvm-svn: 287467
2016-11-19 23:18:43 +00:00
Rui Ueyama 8980c92dde Use consistent variable name.
llvm-svn: 287318
2016-11-18 06:30:08 +00:00
Rui Ueyama d84124f043 Add single quotes to error messages.
llvm-svn: 287254
2016-11-17 19:57:47 +00:00
Rui Ueyama 96db27c74f Use consistent variable name.
llvm-svn: 287253
2016-11-17 19:57:45 +00:00
Rui Ueyama cd236a9577 Use llvm::reverse to get a reverse range.
llvm-svn: 287252
2016-11-17 19:57:43 +00:00
Rui Ueyama bac1c3ce85 Pass StringRefs instead of StringMatcher because it's simpler.
llvm-svn: 287234
2016-11-17 16:48:53 +00:00
Rui Ueyama da805c4800 Use uint16_t instead of size_t for symbol version ID.
Because it is uint16_t in the ELF spec. Using size_t was confusing.

llvm-svn: 287198
2016-11-17 03:39:21 +00:00
Rui Ueyama aade0e29ad Add single quotes to a warning message for consistency.
llvm-svn: 287197
2016-11-17 03:32:41 +00:00
Rui Ueyama 77d917de57 Simplify handleAnonymousVersion even more.
We used to create a vector contantaining all version definitions
with wildcards because doing that was efficient. All patterns were
compiled to a regexp and matched against symbol names. Because
a regexp can be converted to a DFA, matching against union of patterns
is as cheap as matching against one patter.

We are no longer converting them to regexp. Our own glob pattern
handler doesn't do such optimization. Therefore, creating a vector
no longer makes sense.

llvm-svn: 287196
2016-11-17 03:19:34 +00:00
Rui Ueyama 4162baa4bb Simplify. NFC.
llvm-svn: 287192
2016-11-17 02:16:06 +00:00
Rui Ueyama 94bcfae26d Split scanVersionScript. NFC.
llvm-svn: 287191
2016-11-17 02:09:42 +00:00
George Rimar 17c65af82f [ELF] - Separate locals list from versions.
This change separates all versioned locals to be a separate list in config,
that was suggested by Rafael and simplifies the logic a bit.

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

llvm-svn: 287132
2016-11-16 18:46:23 +00:00
Rafael Espindola 95eae57d78 Don't error if __tls_get_addr is defined.
Turns out some systems do define it. Not producing an error in this
case matches gold and bfd.

llvm-svn: 287125
2016-11-16 18:01:41 +00:00
George Rimar e0fc24210d [ELF] - Added support for extern "c++" local symbols in version script.
Previously we did not support them,
patch implements this functionality

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

llvm-svn: 287124
2016-11-16 17:59:10 +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
Rui Ueyama 8249214299 Refactor symbol version assignmnt code.
The code to handle symbol versions is getting tricky and hard to
understand, so it is probably time to simplify it. This patch does
the following.

 - Add `DemangledSyms` variable to SymbolTable so that we don't
   need to pass it around to findDemangled.
 - Define `initDemangledSyms` to initialize the variable lazily.
 - hasExternCpp is removed because we no longer have to initialize
   the map eagerly.
 - scanScriptVersion is split.
 - Comments are updated.

llvm-svn: 287002
2016-11-15 18:41:52 +00:00
Rui Ueyama baf7ee3c5e Rename variables of type SymbolVersion.
In this file, `sym` was used for both SymbolBody and SymbolVersion
although the two are completely different.

llvm-svn: 286992
2016-11-15 17:51:09 +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 92ca6f4b7d [ELF] - Fix mistype. NFC.
llvm-svn: 286801
2016-11-14 09:56:35 +00:00
George Rimar bb6c01e7c3 [ELF] - Add support for locals list in version script.
Previously we did not support anything except "local: *", patch changes that.

Actually GNU rules of proccessing wildcards are more complex than that (http://www.airs.com/blog/archives/300):
There are 2 iteration for wildcards, at first iteration "*" wildcards are ignored and handled at second iteration.

Since we previously decided not to implement such complex rules,
I suggest solution that is implemented in this patch. So for "local: *" case nothing changes,
but if we have wildcarded locals,
they are processed before wildcarded globals. 

This should fix several FreeBSD ports, one of them is jpeg-turbo-1.5.1 and
currently blocks about 5k of ports.

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

llvm-svn: 286713
2016-11-12 07:04:15 +00:00
Teresa Johnson 1e390897ba Mirror the llvm changes that split Bitcode/ReaderWriter.h
The change in D26502 splits ReaderWriter.h, which contains the APIs
into both the BitReader and BitWriter libraries, into BitcodeReader.h
and BitcodeWriter.h.

Change lld uses to the appropriate split header, removing it
completely in one case where it wasn't needed.

llvm-svn: 286568
2016-11-11 05:35:22 +00:00
Rui Ueyama 1bdaf3e30c Remove an overloaded function to simplify.
This version of addRegular is almost identical to the other except
it lacked "size" parameter.

llvm-svn: 286416
2016-11-09 23:37:40 +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 edc183e437 Simplify getLocation() function.
All tests pass without the first parameter, so I guess we don't need it.

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

llvm-svn: 286287
2016-11-08 20:30:19 +00:00
Rui Ueyama 9c5a69d2ac Rename a function to avoid function overloading. NFC.
llvm-svn: 286282
2016-11-08 20:02:23 +00:00
Eugene Leviant 825e538559 [ELF] Better error reporting for duplicate symbol
Differential revision: https://reviews.llvm.org/D26397

llvm-svn: 286244
2016-11-08 16:26:32 +00:00
Simon Atanasyan 9e0297b8bc [ELF][MIPS] N32 ABI support
In short the patch introduces support for linking object file conform
MIPS N32 ABI [1]. This ABI is similar to N64 ABI but uses 32-bit
pointer size.

The most non-trivial requirement of this ABI is one more relocation
packing format. N64 ABI puts multiple relocation type into the single
relocation record. The N32 ABI uses series of successive relocations
with the same offset for this purpose. In this patch, new function
`mergeMipsN32RelTypes` handle this case and "convert" N32 relocation to
the N64 relocation so the rest of the code keep unchanged.

For now, linker does not support series of relocations applied to sections
without SHF_ALLOC bit. Probably later I will add the support or insert
some sort of assert into the `relocateNonAlloc` routine to catch this
case.

[1] ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/MIPS-N32-ABI-Handbook.pdf

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

llvm-svn: 286052
2016-11-05 22:58:01 +00:00