Commit Graph

6536 Commits

Author SHA1 Message Date
Rafael Espindola f53f4f5a5e Use iterators to avoid dereferencing end().
Thanks to George Rimar for finding the problem.

llvm-svn: 276144
2016-07-20 17:41:18 +00:00
Rui Ueyama a7f7884df8 Simplify output section ownership.
This patch simplifies output section management by making
Factory class have ownership of sections that creates.

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

llvm-svn: 276141
2016-07-20 17:19:03 +00:00
George Rimar 31d842f55f [ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection
Previously it was harder to read and also has a error:
command kind was not checked.

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

llvm-svn: 276137
2016-07-20 16:43:03 +00:00
Eugene Leviant f2ea038a4e [ELF] Attempt to fix FreeBSD build bot (no template instantiation for getOutputSectionName)
llvm-svn: 276133
2016-07-20 15:42:34 +00:00
George Rimar 70ce0a9f74 Removed trailing whitespaces. NFC.
llvm-svn: 276126
2016-07-20 15:09:10 +00:00
Peter Smith 441cf5d818 Initial support for the local dynamic model ARM TLS relocations:
- R_ARM_TLS_LDM32
- R_ARM_TLS_LDO32

The local dynamic implementation and tests follows the same model as 
the other ARM TLS models. The R_ARM_TLS_LDO32 is implemented as R_ABS 
expr type as the getVA() for a TLS symbol will return the offset from the 
start of the TLS block.

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

llvm-svn: 276123
2016-07-20 14:56:26 +00:00
Eugene Leviant e63d81bd05 [ELF] Create output sections in LinkerScript class
llvm-svn: 276121
2016-07-20 14:43:20 +00:00
George Rimar b084125dbf [ELF] - Fixed integral constant overflow warning under MSVS 2015. NFC.
Under MSVS 2015 I observed integral constant overflow warning when aggregate initialization was used
to init the bit field. Patch fixes that.

llvm-svn: 276118
2016-07-20 14:26:48 +00:00
Rafael Espindola 5b7a79f92a Avoid some binary searches.
In here we are iterating relocations in order, so we can do the same
with the pieces of .eh_frame and avoid a binary search.

The link times I got with this patch were:

firefox
  master 7.22977811
  patch  7.141041442 0.987726225252
chromium
  master 4.478966851
  patch  4.506602207 1.00617002914
chromium fast
  master 1.894713371
  patch  1.866446889 0.98508139414
the gold plugin
  master 0.386193907
  patch  0.382374918 0.990111213743
clang
  master 0.654849589
  patch  0.647899815 0.989387220949
llvm-as
  master 0.037212718
  patch  0.036858172 0.990472450843
the gold plugin fsds
  master 0.410876711
  patch  0.407418613 0.991583611562
clang fsds
  master 0.734623069
  patch  0.728237526 0.991307728726
llvm-as fsds
  master 0.033446197
  patch  0.03302833 0.987506292569
scylla
  master 3.38134402
  patch  3.414188846 1.00971354166

llvm-svn: 276108
2016-07-20 11:47:50 +00:00
Peter Smith 9d450256d2 Support for standard model ARM TLS
Add relocations and identification functions for the Initial Exec
and Global Dynamic TLS model defined in Addenda to, and Errata in,
the ABI for the ARM Architecture.
    
ARM uses variant 1 of the thread local storage data
structures as defined in ELF Handling for Thread-Local Storage.
    
The "experimental" descriptor based model that can be selected in
gcc, but not clang with -mtls-dialect=gnu2 is not supported.
    
The relocations R_ARM_TLS_LE12 and R_ARM_TLS_IE12GP are not
supported, I know of no ARM Toolchain that supports these relocations
as they limit the size of the TLS block.
    
No code relaxation is supported as the standard ARM TLS model puts
the relocations on literal data.
    
Support for the local dynamic model will come in a follow up patch.

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

llvm-svn: 276095
2016-07-20 08:52:27 +00:00
Rafael Espindola 74df5c7eeb Fix build with gcc 6.
llvm-svn: 275972
2016-07-19 12:33:46 +00:00
Eugene Leviant bbe3860244 [ELF] Minimal PHDRS parser and section to segment assignment support
llvm-svn: 275965
2016-07-19 09:25:43 +00:00
George Rimar b91e7118d4 Reformat comment from 3 to 2 lines. NFC.
llvm-svn: 275961
2016-07-19 07:42:07 +00:00
George Rimar 6ad330acaa Fixed comment. NFC.
llvm-svn: 275959
2016-07-19 07:39:07 +00:00
Rafael Espindola 01c078966d Delete dead code.
And make it easier to spot code going dead by using elf::.

llvm-svn: 275858
2016-07-18 18:24:41 +00:00
Hans Wennborg 708cf064ca docs/conf.py: update version to 4.0
llvm-svn: 275847
2016-07-18 18:12:14 +00:00
Hans Wennborg 72acd60772 Trunk release notes are now for 4.0.0
The 3.9 release are on the 3.9 branch.

llvm-svn: 275845
2016-07-18 18:07:03 +00:00
Rafael Espindola 3fab868675 Pass section by reference. NFC.
llvm-svn: 275803
2016-07-18 16:05:09 +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 d6328526ba Iterate over SymVector instead of Symtab hash table.
SymVector contains all symbols, so we can iterate either Symtab or SymVector
to visit all symbols. Iterating over SymVector makes the next change for
--trace-symbol possible.

llvm-svn: 275746
2016-07-18 01:34:57 +00:00
Rui Ueyama 25a6d57b9c Unbreak msan buildbot.
llvm-svn: 275728
2016-07-17 19:55:22 +00:00
Rui Ueyama 77fa5ee160 Remove dead code.
llvm-svn: 275724
2016-07-17 18:27:17 +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 7a7a96e199 Do not invoke FileCheck with `not` command.
We should use CHECK-NOT instead.

llvm-svn: 275700
2016-07-17 01:34:39 +00:00
Rui Ueyama 3ec5c84606 Attempt to unbreak Windows bot.
llvm-svn: 275695
2016-07-16 19:16:15 +00:00
Rui Ueyama 818bb2f8dc Remove redundant namespace specifiers.
llvm-svn: 275694
2016-07-16 18:55:47 +00:00
Rui Ueyama 962b277d2d Resurrect code that was lost in conflicting commits.
llvm-svn: 275693
2016-07-16 18:45:25 +00:00
Rui Ueyama f953a8ac17 Use skip() instead of peek() and expect().
llvm-svn: 275692
2016-07-16 18:45:23 +00:00
George Rimar ee0e63804f Update for r275682:
I think 
# REQUIRES: shell 
is required instead of 
# XFAIL: win32

llvm-svn: 275683
2016-07-16 12:34:06 +00:00
George Rimar 50dcece2a0 Recommit r275257 "[ELF] - Implement extern "c++" version script tag"
BSD toolchain contains a bug:
https://sourceforge.net/p/elftoolchain/tickets/491/

In short demangler works differently, fix was to update the testcase.
It should fix the FreeBSD bot failture:
http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/19432/steps/test_lld/logs/stdio

Original commit message was:
[ELF] - Implement extern "c++" version script tag

Patch implements 'extern' version script tag.
Currently only values in quotes(") are supported.

Matching of externs is performed in the same pass as exact match of globals.

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

llvm-svn: 275682
2016-07-16 12:26:39 +00:00
Rui Ueyama c755599997 Simplify. NFC.
llvm-svn: 275675
2016-07-16 04:19:29 +00:00
Rui Ueyama af469d47e9 Rename SymbolVersions VersionDefinitions.
SymbolVersions sounds like it had versions for a symbol, so rename it.

llvm-svn: 275674
2016-07-16 04:09:27 +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 52654ebb12 Use ScriptParserBase::skip() instead of peek() and next().
skip(S) consumes a token if the next token is S,
so it can be used instead of peek() & next().

llvm-svn: 275672
2016-07-16 03:45:59 +00:00
Rui Ueyama c9b4c073b2 Simplify. NFC.
llvm-svn: 275670
2016-07-16 03:12:16 +00:00
Rui Ueyama 2506866ff6 Simplify default symbol version management. NFC.
llvm-svn: 275669
2016-07-16 03:08:26 +00:00
Rui Ueyama e9381bd2d8 Remove redundant variable.
llvm-svn: 275667
2016-07-16 02:47:42 +00:00
Rui Ueyama f524464e2f Set sh_addralign in the constructor for consistency. NFC.
llvm-svn: 275666
2016-07-16 02:36:00 +00:00
Rui Ueyama 9f61964769 Make Verdef and Verdaux adjacent in the version definition section.
Previously, Verdefs and Verdauxs are separated in the section.
The new layout is easier to write as we do not have to maintain
two pointers and can avoid passing a reference to a pointer.

llvm-svn: 275665
2016-07-16 02:29:45 +00:00
Rui Ueyama 0ff953e811 Use SymbolVersion::Id instead of a hard-coded local variable.
llvm-svn: 275660
2016-07-16 02:00:43 +00:00
Rui Ueyama 429ef2af6a ELF: Include filenames in error messages.
llvm-svn: 275608
2016-07-15 20:38:28 +00:00
Rui Ueyama 188d2c34e6 Remove variables. NFC.
llvm-svn: 275605
2016-07-15 20:05:05 +00:00
Eugene Leviant 0e36f42846 [ELF] Overriding reserved symbols in linker script
llvm-svn: 275549
2016-07-15 11:20:04 +00:00
Rui Ueyama 3d9b26b4ad Inline traceUndefined function.
llvm-svn: 275531
2016-07-15 04:57:46 +00:00
Rui Ueyama eba9b63cbc Update comments.
llvm-svn: 275530
2016-07-15 04:57:44 +00:00
Rui Ueyama 177746a739 Remove redundant `return`.
llvm-svn: 275528
2016-07-15 04:32:11 +00:00
Rui Ueyama 05ef4cff44 Merge SymbolAssignmentKind and ExprKind.
In a linker script, `.` is a special symbol indicating a counter.
Previously, we had two expression types, ExprKind and SymbolAssignmentKind
for `.` and all the other symbol names, respectively. But we could merge
them because the former is a special case of the latter.

llvm-svn: 275527
2016-07-15 04:19:37 +00:00
Rui Ueyama 601b07c7f5 ELF: Remove member variables that are used only in one function.
Differential Revision: https://reviews.llvm.org/D22396

llvm-svn: 275526
2016-07-15 03:06:42 +00:00
Rui Ueyama 112351dc38 Avoid writing to errs().
We should write to ErrorOS instead. Normaly, *ErrorOS == errs(),
but they can be different if LLD is embedded.

llvm-svn: 275525
2016-07-15 02:51:05 +00:00
Rui Ueyama a9d9eda0ce Inline a vairable that is used only once. NFC.
llvm-svn: 275524
2016-07-15 02:42:18 +00:00
Rui Ueyama 48da5cf236 ELF: Simplify path constructions for -save-temps. NFC.
llvm-svn: 275523
2016-07-15 02:17:13 +00:00
Rui Ueyama f8292e9ac9 ELF: Make check() always return a value.
This patch corresponds to r275511 for COFF.

llvm-svn: 275521
2016-07-15 02:01:03 +00:00
Rui Ueyama aa2db88984 ELF: Make error() to always set HasError.
Previously, it checked for the EC parameter and set HasError
only when there was an error. But in most places we called
error only when error had occurred, so this behavior was confusing.

llvm-svn: 275517
2016-07-15 01:38:54 +00:00
Rui Ueyama bb57954241 COFF: Update error messages so that they start with lowercase letters.
llvm-svn: 275513
2016-07-15 01:12:24 +00:00
Rui Ueyama 5694ebbc8b Remove unnecessary explicit call of Twine ctor.
llvm-svn: 275512
2016-07-15 01:06:40 +00:00
Rui Ueyama 659a4f2f38 Make check() always return a value.
Previously, one of two check functions didn't return a value.
It was confusing. This patch makes both functions return values.

llvm-svn: 275511
2016-07-15 01:06:38 +00:00
Rui Ueyama 0d09a865c6 COFF: Remove `void error()` functions and use fatal instead.
This change makes the control flow more explicit.

llvm-svn: 275504
2016-07-15 00:40:46 +00:00
Rui Ueyama 1a3fd13776 COFF: Remove unnecessary explicit calls of Twine ctor.
llvm-svn: 275501
2016-07-14 23:43:36 +00:00
Rui Ueyama 606047939c COFF: Rename noreturn error -> fatal.
This new name is also consistent with ELF.

llvm-svn: 275500
2016-07-14 23:37:14 +00:00
Rui Ueyama 7e75866c51 COFF: Rename non-noreturn error -> check.
The new name is consistent with ELF.

llvm-svn: 275499
2016-07-14 23:37:10 +00:00
Peter Collingbourne 765aa2d1c2 COFF: Update remaining #include paths.
llvm-svn: 275480
2016-07-14 21:30:37 +00:00
Peter Collingbourne 6ccb257925 ELF: Update #include path for D22173.
llvm-svn: 275477
2016-07-14 21:21:20 +00:00
Rui Ueyama cb7d6e955d Update error message to use "ld.lld" instead of "lld -flavor gnu".
Dispatching based on argv[0] seems to be more convenient for users
than dispatching based on -flavor option. Currently, when a user
invoke LLD as "lld", we recommend them pass -flavor option. This
patch changes the message so that we recommend use ld.lld, ld or
lld-link instead.

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

llvm-svn: 275448
2016-07-14 17:57:33 +00:00
Rui Ueyama 941faa77ad Remove TargetInfo::getImageBase. NFC.
llvm-svn: 275447
2016-07-14 17:43:28 +00:00
Rui Ueyama cafc0f2e03 Set DT_MIPS_BASE_ADDRESS correctly if -image-base is given.
Differential Revision: http://reviews.llvm.org/D22323

llvm-svn: 275446
2016-07-14 17:40:18 +00:00
Benjamin Kramer 56a46bc680 Upgrade all the .arcconfigs to https.
llvm-svn: 275409
2016-07-14 13:15:37 +00:00
Eugene Leviant b030411414 [ELF] r275383 reverted due to buildbot failure
llvm-svn: 275385
2016-07-14 09:21:24 +00:00
Eugene Leviant 219d9b2b18 [ELF] Allow overriding reserved symbols in linker scripts
llvm-svn: 275383
2016-07-14 08:26:41 +00:00
Rui Ueyama 3b04d833c4 Set sh_addralign to 1 instead of 0.
ELF spec says that alignment of 0 is equivalent to 1.
Previously, we arbitrary set to 0 or 1, but always setting to 1
makes our program simpler.

llvm-svn: 275374
2016-07-14 05:46:24 +00:00
Rui Ueyama 0fad6ea551 Attempt to unbreak msan bot.
r275301 made .got section be aligned on Target->GotEntrySize,
so GotEntrySize must have been initialized. We didn't initialize
it for AMDGPU.

llvm-svn: 275373
2016-07-14 05:46:22 +00:00
Lang Hames 622ef17f5d [lld] Update LLD for Archive::child_iterator change in LLVM r275361.
llvm-svn: 275362
2016-07-14 02:35:18 +00:00
Rui Ueyama 729822fe39 Update the readme text.
llvm-svn: 275305
2016-07-13 19:14:25 +00:00
Rui Ueyama 803b120ba1 Add GotEntrySize/GotPltEntrySize to ELF target.
Patch by H.J Lu.

For x86-64 psABI, the entry size of .got and .got.plt sections is 8
bytes for both LP64 and ILP32.  Add GotEntrySize and GotPltEntrySize
to ELF target instead of using size of ELFT::uint.  Now we can generate
a simple working x32 executable.

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

llvm-svn: 275301
2016-07-13 18:55:14 +00:00
Rui Ueyama 484a49514f Rename VAStart -> ImageBase. NFC.
Config members are named after corresponding command line options.
This patch renames VAStart ImageBase so that they are in line with
--image-base.

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

llvm-svn: 275298
2016-07-13 18:40:59 +00:00
Petr Hosek 1ddcacb949 [ELF] Rename the test to reflect the option name
This is to follow the convention of naming the test after the name
of the option.

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

llvm-svn: 275295
2016-07-13 18:31:44 +00:00
George Rimar bd69903692 [ELF] - Add predefined sections to output sections list in one place.
Minor cleanup.
Currently it looks wierd that having method addPredefinedSections()
we still add 2 sections outside it without real reasons.
Patch fixes that.

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

llvm-svn: 275269
2016-07-13 14:26:31 +00:00
George Rimar dd64bb38bd Reverted r275257 "[ELF] - Implement extern "c++" version script tag"
It broke build bots:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/8204
http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/19432

llvm-svn: 275258
2016-07-13 08:19:04 +00:00
George Rimar e05103ea11 [ELF] - Implement extern "c++" version script tag
Patch implements 'extern' version script tag.
Currently only values in quotes(") are supported.

Matching of externs is performed in the same pass as exact match of globals.

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

llvm-svn: 275257
2016-07-13 07:46:00 +00:00
Saleem Abdulrasool f27d4068a5 COFF: drop the dependency on LIB.EXE for implibs
lld currently relies on lib.exe in order to generate an empty import library.
The "empty" import library consists of 5 members:
  - first linker member
  - second linker member
  - Import Descriptor
  - NULL Import Descriptor
  - NULl Thunk

The first two entries (first and second linker members) are string tables which
are never updated.  Therefore, they may as well as not be present.  A subsequent
change to add that is probably warranted.  However, this does not prevent the
use of the linker.

The Import Descriptor is the content which is most important.  It provides an
Import Name Table entry for the library (as specified by the LIBRARY directive
in the DEF file).  Additionally, it contains undefined references to the NULL
Import Descriptor and the library NULL Thunk Data.  This ensures that the linker
will pull in the subsequent objects from the import library for the link.  The
Import Descriptor has a single symbol (__IMPORT_DESCRIPTOR_<Library>) which
contains 3 relocations, one to the INT (Import Name Table) entry, one to the ILT
(Import Lookup Table) entry, and one to the IAT (Import Address Table) entry.

The NULL Import Descriptor is the last import descriptor and terminates the
import descriptor array.  It contains a single symbol
(__NULL_IMPORT_DESCRIPTOR).

The NULL Thunk contains a single symbol (\x7f<Library>_NULL_THUNK_DATA) and
provides the terminator for the ILT and IAT.

These files are currently constructed manually following the example of the
Short Import Library format.  This is arguably less than ideal, and it may be
possible to use MCAssembler and feed it the fragments to construct the object.

The major difference between the LIB (LINK) generated objects and the ones
generated here is that they are all one section shorter (.debug$S) as they do
not contain the debug information and one symbol shorter (@comp.id) as they do
not contain the RICH signature.

Move the logic related to the librarian into a new source file (Librarian.cpp).

llvm-svn: 275242
2016-07-13 03:19:27 +00:00
Rui Ueyama 1e52f25d46 Add -m elf32_x86_64.
Patch by H.J. Lu.

This patch adds -m elf32_x86_64 to lld. But it doesn't generate working
x32 binaries.

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

llvm-svn: 275236
2016-07-12 23:28:33 +00:00
Rui Ueyama 46626e1f04 Add ILP32 support to X86_64TargetInfo.
Patch by H.J. Lu.

As x86-64 psABI supports both LP64 and ILP32, this patch adds <ELFT>
template to X86_64TargetInfo.

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

llvm-svn: 275235
2016-07-12 23:28:31 +00:00
Rui Ueyama b933df1835 Simplify. NFC.
Config->Pic is true if (Config->Pie || Config->Shared) is true,
so this extra check was redundant.

llvm-svn: 275234
2016-07-12 23:28:30 +00:00
Petr Hosek d7bd2389ce [ELF] Support for setting the base address
The -image-base option allows for overriding the base address.

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

llvm-svn: 275206
2016-07-12 19:37:53 +00:00
George Rimar 6892afaa2d Recommit r275161 "[ELF] - Move section factory out from writer to make it reusable."
With fix:
* fixed compilation error under linux:

template <class ELFT> class OutputSectionFactory {
...
  typedef typename SectionKey<ELFT::Is64Bits> Key;

changed to:
template <class ELFT> class OutputSectionFactory {
...
  typedef typename elf::SectionKey<ELFT::Is64Bits> Key;

llvm-svn: 275166
2016-07-12 09:49:43 +00:00
George Rimar d8f547fab4 Revert r275161 "[ELF] - Move section factory out from writer to make it reusable."
It broke build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-debian-fast/builds/39652

llvm-svn: 275163
2016-07-12 09:11:13 +00:00
George Rimar 5d53d1f42c [ELF] - Make few members of Writer to be global and export them for reuse
Creating sections on linkerscript side requires some methods
that can be reused if are exported from writer.

Patch implements that change.

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

llvm-svn: 275162
2016-07-12 08:50:42 +00:00
George Rimar e51f7f4d39 [ELF] - Move section factory out from writer to make it reusable.
Since linkerscript should create sections by itself
(if SECTIONS command is present),
then we might want to reuse the OutputSectionFactory (D19976 already do that now),
so this patch moves it out from writer cpp file for that purpose.

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

llvm-svn: 275161
2016-07-12 08:38:04 +00:00
George Rimar 7899d48dff [ELF] - Add Id field to Version struct.
That helps to avoid expressions like I + 2 in code
that assigns version number to symbols.

Change was suggested by Rui Ueyama.

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

llvm-svn: 275159
2016-07-12 07:44:40 +00:00
Eugene Leviant eda81a1b86 [ELF] Support for symbol assignment in linker scripts within SECTIONS {} block
llvm-svn: 275158
2016-07-12 06:39:48 +00:00
Rui Ueyama ec1b80fd11 Remove unused parameters.
llvm-svn: 275153
2016-07-12 03:49:41 +00:00
Rui Ueyama 89c3762a7a Update comments.
llvm-svn: 275003
2016-07-09 23:16:00 +00:00
Rui Ueyama 0d410c265c Attempt to fix buildbots.
llvm-svn: 275001
2016-07-09 23:02:37 +00:00
Rui Ueyama 95d2a9f91a Remove unused forward declarations.
llvm-svn: 274998
2016-07-09 22:54:27 +00:00
Rui Ueyama e2efadced7 Remove Target::writeThunk.
Only MipsThunk were using the function, and the way how it wrote
thunk contents was different from ARM thunks. This patch makes
them consistent.

llvm-svn: 274997
2016-07-09 22:52:32 +00:00
Rui Ueyama 3d2bbb13d0 Make ARM thunks consistent with MIPS in coding style.
Although they are in the same .cpp file, the way they were written
were slightly different, so they looked more different than they were.
This patch makes their styles consistent.

llvm-svn: 274996
2016-07-09 22:52:30 +00:00
Rui Ueyama ec4220d70f Instantiate Thunk classes instead of the class member functions.
llvm-svn: 274994
2016-07-09 22:06:47 +00:00
Rui Ueyama 5e3d604688 Split addThunkARM. NFC.
llvm-svn: 274993
2016-07-09 22:03:51 +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
Saleem Abdulrasool 0561bd5b47 COFF: remove unused function (touchFile)
Remove some dead code.  NFC.

llvm-svn: 274900
2016-07-08 18:36:56 +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
George Rimar c61bcd80af [ELF] - Do not error out when version declaration not found when building executable.
When building executable usually version script is absent.
Before this patch error was shown in the case when
symbol name contained version and there was no script to match it.
  Instead of error out patch allows
to create new version declaration in this case and use it.
gnu linkers do the same.

That is PR28359.

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

llvm-svn: 274828
2016-07-08 06:47:28 +00:00
Rui Ueyama f731d0afed Test --demangle feature.
Previously, it was not tested because the test was written in
a way that it passed on a platform that does not support
abi::__cxa_demangle. Now we restrict this test to Unix (by adding
"REQUIRES: shell") and assume that it always demangle symbols.
Thanks to Davide to find out the issue.

llvm-svn: 274808
2016-07-07 23:43:09 +00:00
Davide Italiano 3f36781dec [ELF] Ignore --demangle. We already demangle symbols by default.
llvm-svn: 274806
2016-07-07 23:32:36 +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
Rafael Espindola 580d7a1b1e -Bsymbolic should not make symbols more preemptable.
But it was doing that for protected undefined symbols.

llvm-svn: 274803
2016-07-07 22:50:54 +00:00
Rafael Espindola 64c32d6f02 Fix formating. NFC.
llvm-svn: 274757
2016-07-07 14:28:47 +00:00
Rafael Espindola d10f0b1eae Use "using namespace llvm" like the rest of ELF lld.
llvm-svn: 274755
2016-07-07 14:06:38 +00:00
Rafael Espindola 4225342e95 This now works on unix too.
With this there are no unsupported tests on linux in test/ELF :-)

llvm-svn: 274752
2016-07-07 13:52:04 +00:00
George Rimar f73a25812f [ELF] - Fixed incorrect logic of version assignments when mixing wildcards with values matching.
Previously we had incorrect logic here. Imagine we would have the next script:

LIBSAMPLE_1.0
{
  global:
   a_2;
 local:
  *;
};

LIBSAMPLE_2.0
{
  global:
   a*;
};
According to previous logic it would assign version 1 to a_2 and then
would try to reassign it to version 2 because of applying wildcard a*.
And show a warning about that.

Generally Ian Lance Tailor wrote about next rules that should be applied:
(http://www.airs.com/blog/archives/300)

Here are the current rules for gold:

"If there is an exact match for the mangled name, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look for an extern C++ or an extern Java exact match. If we find an exact match, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look through the wildcard patterns, ignoring “*” patterns. We look through the version tags in reverse order. For each version tag, we look through the global patterns and then the local patterns. We use the first match we find (i.e., the last matching version tag in the file).
Otherwise, we use the “*” pattern if there is one. We give a warning if there are multiple “*” patterns."

Patch makes wildcard matching to be in revered order and to follow after the regular naming matching.

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

llvm-svn: 274739
2016-07-07 07:45:27 +00:00
Rui Ueyama 287956f72b Correctly define "zlib" feature.
We have "REQUIRES: zlib" in our test, but zlib was not defined,
so the test did not run on any platform.

llvm-svn: 274730
2016-07-07 03:55:57 +00:00
Rui Ueyama 1d12ac1d11 Fix endianness issue.
Previously, ch_size was read in host byte order, so if a host and
a target are different in byte order, we would produce a corrupted
output.

llvm-svn: 274729
2016-07-07 03:55:55 +00:00
Rui Ueyama 523744dd2b Fix formatting.
llvm-svn: 274724
2016-07-07 02:46:30 +00:00
Rui Ueyama 0f282a593f Do not call warning() from ELFOptTable::parse().
warning() depends on Config->FatalWarnings, so we don't want to call
that function before we initialize that member.

llvm-svn: 274723
2016-07-07 01:58:04 +00:00
Rui Ueyama a027d33949 Fix indentation.
llvm-svn: 274719
2016-07-07 01:21:14 +00:00
Rafael Espindola 9639ec1e66 Read the implicit addend of R_386_GOT32X.
llvm-svn: 274690
2016-07-06 21:48:50 +00:00
Rafael Espindola d03e659140 Recognize R_386_GOT32X.
We don't relax it, but we at least recognize it.

llvm-svn: 274687
2016-07-06 21:41:39 +00:00
Davide Italiano f296a7eeae [ELF] Introduce a flag to parse response files according to windows rules.
Differential Revision:  http://reviews.llvm/org/D22015

llvm-svn: 274684
2016-07-06 21:24:34 +00:00
Davide Italiano f8591cf249 [gardening] Switch back to auto. NFCI.
Pointed out by: Rui Ueyama.

llvm-svn: 274643
2016-07-06 17:41:55 +00:00
Rafael Espindola 1f6929bff6 Use / instead of \ on windows created cpio files
Otherwise when extracting these files on a unix system one
ends up with files named like "repro\bar\foo.o".

llvm-svn: 274622
2016-07-06 12:09:51 +00:00
Davide Italiano c03d610cff [ELF] Support --entry= option variant. Update tests while I'm there.
llvm-svn: 274524
2016-07-04 21:50:50 +00:00
Davide Italiano b4b68b64fd [OutputSection] Work around GCC not being able to deduce auto.
The build otherwise fails with:
[ 39%] Building CXX object
tools/lld/ELF/CMakeFiles/lldELF.dir/OutputSections.cpp.o
/export/gnu/import/git/llvm/tools/lld/ELF/OutputSections.cpp: In
member function ‘void
lld:🧝:GnuHashTableSection<ELFT>::addSymbols(std::vector<std::pair<lld:🧝:SymbolBody*,
long unsigned int> >&)’:
/export/gnu/import/git/llvm/tools/lld/ELF/OutputSections.cpp:585:8:
error: inconsistent deduction for ‘auto’: ‘auto’ and then
‘__gnu_cxx::__normal_iterator<std::pair<lld:🧝:SymbolBody*, long
unsigned int>*, std::vector<std::pair<lld:🧝:SymbolBody*, long
unsigned int> > >’

Reported by:  H. J. Liu

llvm-svn: 274518
2016-07-04 19:49:55 +00:00
Tom Stellard 391e3a873e ELF/AMDGPU: Add support for GOT relocations
Reviewers: arsenm, rafael, tony-tye, kzhuravl, ruiu

Subscribers: llvm-commits, kzhuravl

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

llvm-svn: 274514
2016-07-04 19:19:07 +00:00
Rafael Espindola 8e51e67eb7 Add a test for accessing __tls_get_addr with a GOT.
This was already passing, but missing a test.

llvm-svn: 274513
2016-07-04 17:34:53 +00:00
George Rimar 5e37aeaf6a Fixed check-lld msan after r274504 "[ELF] - Implemented --fatal-warnings option."
Bot failed:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/14361/steps/check-lld%20msan/logs/stdio

Fix:
Initialize Config->FatalWarnings with false. As it might be used once a bit earlier than its
initialization from command line arguments.

llvm-svn: 274507
2016-07-04 14:54:23 +00:00
George Rimar 857644cef8 [ELF] - Implemented --fatal-warnings option.
--fatal-warnings: Treat warnings as errors

DIfferential revision: http://reviews.llvm.org/D21969

llvm-svn: 274504
2016-07-04 13:43:12 +00:00
Rui Ueyama 03e1cc6322 Remove duplicate declaration.
llvm-svn: 274429
2016-07-02 08:50:05 +00:00
Rui Ueyama c98e4d8167 Move getAddend to Relocations.h.
Because the function works on relocations, it should be in
Relocations.h instead of OutputSections.h.

llvm-svn: 274428
2016-07-02 08:50:03 +00:00
Rui Ueyama d573844a1f Fix formatting. NFC.
llvm-svn: 274426
2016-07-02 06:08:44 +00:00
Davide Italiano e929f424a4 [BitcodeFile] Simplify shouldSkip(). NFCI.
llvm-svn: 274383
2016-07-01 20:43:28 +00:00
George Rimar 33b9de4b32 [ELF] - Depricate version references.
This is PR28358

According to
https://www.akkadia.org/drepper/dsohowto.pdf

"The fourth point, the VERS 1.0 version being referred to in the VERS 2.0 definition, is not really important in symbol versioning. It marks the predecessor relationship of the two versions and it is done to maintain the similar- ities with Solaris’ internal versioning. It does not cause any problem it might in fact be useful to a human reader so predecessors should always be mentioned."

Patch partially reverts 273423 "[ELF] - Implemented version script hierarchies.",
version references are just ignored now.

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

llvm-svn: 274345
2016-07-01 11:45:10 +00:00
Rui Ueyama 52c4e17f8a Remove trailing whitespaces.
llvm-svn: 274343
2016-07-01 10:42:25 +00:00
Eugene Leviant 467c4d5538 [ELF] Fix first PT_LOAD segment VA calculation, when linker script is used
llvm-svn: 274342
2016-07-01 10:27:36 +00:00
Rui Ueyama 1df56894f8 Do not allow "--" with single-letter options.
In general, we accept both -foo and --foo as command line options,
but if an option is a single letter option, we don't want to allow
double dashes because GNU linkers don't accept such combination.

llvm-svn: 274219
2016-06-30 08:43:23 +00:00
Peter Collingbourne 66ec178c6c Fix logic error in check() function.
llvm-svn: 274195
2016-06-30 00:32:24 +00:00
Peter Collingbourne eadba86c3e COFF: Switch to new archive writer interface (D21721).
Differential Revision: http://reviews.llvm.org/D21722

llvm-svn: 274184
2016-06-29 22:27:45 +00:00
Kevin Enderby b9e053cfd7 Matching change for lld for the llvm change of Archive::create() from ErrorOr<...> to Expected<...> in r274160.
llvm-svn: 274161
2016-06-29 20:36:11 +00:00
Davide Italiano e3fa8f64da [ELF] More self-explanatory error message when e_machine can't be inferred.
Thanks to Sean Silva for the suggestion!

llvm-svn: 274134
2016-06-29 15:58:37 +00:00
George Rimar e86dcd0cbd [ELF] - Added support for --unresolved-symbols option.
Option has next description (http://linux.die.net/man/1/ld):
"--unresolved-symbols=method
Determine how to handle unresolved symbols. There are four possible values for method
according to documentation:

ignore-all: Do not report any unresolved symbols.
report-all: Report all unresolved symbols. This is the default.
ignore-in-object-files: Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files.
ignore-in-shared-libs: Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries."

Since report-all is default and we traditionally do not report about undefined symbols in lld,
report-all does not report about undefines from DSO. 
ignore-in-object-files also does not do that. Handling of that option differs from what gnu linkers do.

Option works in next way in lld:
ignore-all: Do not report any unresolved symbols.
report-all: Report all unresolved symbols except symbols from DSOs. This is the default.
ignore-in-object-files: The same as ignore-all.
gnore-in-shared-libs: The same as report-all.

This is PR24524.

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

llvm-svn: 274123
2016-06-29 12:35:04 +00:00
Rui Ueyama 94f3a731e5 Convert DOS-style newlines.
llvm-svn: 274118
2016-06-29 10:39:00 +00:00
George Rimar dbbf60e590 [ELF] - Check the input bitcode files for compatibility.
Previously BC files were not checked for the same platform etc,
That lead to confusing error "Invalid section header entry size (e_shentsize) in ELF header" when
mixing files for different architectures.

Patch fixes PR28324.

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

llvm-svn: 274113
2016-06-29 09:46:00 +00:00
Rui Ueyama fbbde548cf Move isValidCIdentifier to Strings.cpp.
llvm-svn: 274112
2016-06-29 09:08:02 +00:00
George Rimar 9fc1d4ed75 [ELF] - Updated comments. NFC.
As was suggested by Rafael Espíndola.

llvm-svn: 274111
2016-06-29 08:36:36 +00:00
Rui Ueyama 93c9af425e Create Strings.cpp and move string manipulation functions to that file.
llvm-svn: 274109
2016-06-29 08:01:32 +00:00
Davide Italiano 60976ba86d [LTO] Infer ELFKind/EMachine from Bitcode files
So that users are not forced to pass `-m` on the command line
when the inputs are all bitcode.

PR:   28268
Differential Revision:  http://reviews.llvm.org/D21779

llvm-svn: 274107
2016-06-29 06:12:39 +00:00
Rui Ueyama 722830a51b Rename matchStr -> globMatch.
llvm-svn: 274103
2016-06-29 05:32:09 +00:00
Rui Ueyama 48e4251e1d Make SymbolTable::findAll to return only defined symbols.
We allowed the function to return a vector that contains nullptrs
which is weird. This change makes the function to return only
defined symbols.

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

llvm-svn: 274099
2016-06-29 04:47:39 +00:00
Davide Italiano 8e1131dc46 [ELF] Support for wildcard in version scripts.
Example:

VERSION_1.0 {
  global: foo*;
  local: *; }

now correctly matches all the symbols which name starts with
`foo`.

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

llvm-svn: 274091
2016-06-29 02:46:51 +00:00
Rui Ueyama 5e64d3fb94 Refactor ELF type inference functions.
Previously, we initialized Config->EKind and Config->EMachine when
we instantiate ELF objects. That was not an ideal location to do that
because the logic was buried too deep inside a concrete logic.

This patch moves the code to the driver so that the initialization
becomes explicit.

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

llvm-svn: 274089
2016-06-29 01:30:50 +00:00
Rafael Espindola 857d7c5dd0 Handle empty versions.
They are significant now that we support @ in symbol names.

llvm-svn: 274071
2016-06-28 21:48:33 +00:00
Rafael Espindola 2100aa08b7 Don't check the section index, it is not relevant for this test.
llvm-svn: 274070
2016-06-28 21:47:17 +00:00
Lang Hames a5c7adcb38 [lld][MachO] Remove SimpleFile::definedAtoms().
This method just duplicates the functionality of SimpleFile::defined().

llvm-svn: 274048
2016-06-28 18:42:33 +00:00
George Rimar d84f21b288 [ELF] - Remove Config->ZDefs flag.
-z defs is the same as --no-undefined (http://linux.die.net/man/1/ld).
It looks to be a error to handle it separatelly.

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

llvm-svn: 274003
2016-06-28 12:04:19 +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
George Rimar 36b2c0a683 [ELF] - Implemented --no-undefined-version flag
Option checks for cases where a version script explicitly lists
a symbol, but the symbol is not defined and errors out such
cases if any.

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

llvm-svn: 273998
2016-06-28 08:07:26 +00:00
Davide Italiano 4fdc648592 [ELF] Warn for duplicate symbols in version scripts instead of erroring out.
Emitting an error in this case breaks real-world application (e.g. libreoffice).
See http://reviews.llvm.org/D21555 for context.

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

llvm-svn: 273989
2016-06-28 03:40:49 +00:00
Chris Bieneman 677c6e4173 [yaml2obj] Hopefully the last test case update from r273915
Should fix the last LLD bots.

llvm-svn: 273942
2016-06-27 21:06:40 +00:00
Chris Bieneman 4e5bdaaca4 [yaml2obj] One more missing test case update from r273915
Should fix the last LLD bots.

llvm-svn: 273939
2016-06-27 20:47:00 +00:00
Chris Bieneman ca5170e3e4 [yaml2obj] Updating LLD tests to account for LLVM r273915
This removed the -format flag from yaml2obj in favor of YAML tags.

llvm-svn: 273920
2016-06-27 20:17:08 +00:00
Lang Hames 1fc0023ebf [lld][MachO] Remove stray comment.
llvm-svn: 273917
2016-06-27 20:00:20 +00:00
Rui Ueyama 6a9940260c Define -v and -V as aliases to --version.
This is for GNU compatibility.

llvm-svn: 273847
2016-06-27 07:35:00 +00:00
Rui Ueyama 20d8d55b05 Fix library search order.
Previously, we searched for a .so file from all library paths and
then searched for a .a file. That logic is wrong. What we need to
do is to look for a .so and a .a for each library path.

llvm-svn: 273846
2016-06-27 07:26:28 +00:00
Rui Ueyama 596eba86bc Ignore --sort-common.
Because we always sort common symbols, we can ignore the option.

llvm-svn: 273842
2016-06-27 02:43:27 +00:00
Davide Italiano 47ae3c3e22 [LinkerScript] Spell 'character' correctly. NFC.
llvm-svn: 273817
2016-06-26 19:02:43 +00:00
Rui Ueyama b1421a1cec Do not lookup the same option twice. NFC.
llvm-svn: 273771
2016-06-25 04:37:56 +00:00
Lang Hames 3b3b4d792f [lld][MachO] Add support for x86-64 negDelta64 references and fix negDelta32.
These references are used to implement MachO/x64-64 subtractor relocations
where the minuend is being fixed up, rather than the subtrahend. The 64-bit
version was not previously supported, the 32-bit version was partially
implemented but contained bugs not caught by existing test cases. This
patch fixes both functionality and test coverage.

llvm-svn: 273759
2016-06-25 00:29:54 +00:00
Davide Italiano e160f0d0d6 [ELF] Allow --reproduce to be specified as an environment variable.
PR: 28257
Differential Revision:   http://reviews.llvm.org/D21628

llvm-svn: 273698
2016-06-24 18:02:50 +00:00
George Rimar 6a7cfd039e [ELF] - Fix incorrect logic in VersionScriptParser::parseVersion()
Previously the next sample script would generate 2 entries in 
Config->SymbolVersions with the same version name.

VERSION {
 global: c;
};
That happened because parseVersionSymbols() was called twice.
At first for "global:" and since there is no local tag, it was called again.
Patch fixes the issue, testcase was updated to demonstrate.

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

llvm-svn: 273663
2016-06-24 11:23:55 +00:00
George Rimar 602fbee9fc [ELF] - Support of compressed input sections implemented.
Patch implements support of zlib style compressed sections.
SHF_COMPRESSED flag is used to recognize that decompression is required.
After that decompression is performed and flag is removed from output.

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

llvm-svn: 273661
2016-06-24 11:18:44 +00:00
Simon Atanasyan 002e244717 [ELF][MIPS] Support MIPS TLS relocations
The patch adds one more partition to the MIPS GOT. This time it is for
TLS related GOT entries. Such entries are located after 'local' and 'global'
ones. We cannot get a final offset for these entries at the time of
creation because we do not know size of 'local' and 'global' partitions.
So we have to adjust the offset later using `getMipsTlsOffset()` method.

All MIPS TLS relocations which need GOT entries operates MIPS style GOT
offset - 'offset from the GOT's beginning' - MipsGPOffset constant. That
is why I add new types of relocation expressions.

One more difference from othe ABIs is that the MIPS ABI does not support
any TLS relocation relaxations. I decided to make a separate function
`handleMipsTlsRelocation` and put MIPS TLS relocation handling code
there. It is similar to `handleTlsRelocation` routine and duplicates its
code. But it allows to make the code cleaner and prevent pollution of
the `handleTlsRelocation` by MIPS 'if' statements.

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

llvm-svn: 273569
2016-06-23 15:26:31 +00:00
George Rimar 85dbed53a5 [ELF] - Reorder expressions in parseVersionSymbols()'s loop. NFC.
llvm-svn: 273539
2016-06-23 07:26:05 +00:00
George Rimar da5fa1ebba Revert r273427 "[ELF] - Simplify loop in parseVersionSymbols(). NFC."
llvm-svn: 273538
2016-06-23 07:23:07 +00:00
Rui Ueyama 3cda384e37 Attempt to fix Windows buildbots.
llvm-svn: 273537
2016-06-23 07:14:09 +00:00
Rui Ueyama d60dae8a6a Implement --trace-symbol=symbol option.
Patch by Shridhar Joshi.

This option provides names of all the link time modules which define and
reference symbols requested by user. This helps to speed up application
development by detecting references causing undefined symbols.
It also helps in detecting symbols being resolved to wrong (unintended)
definitions in case of applications containing multiple definitions for
same symbols with different types, bindings.

Implements PR28226.

llvm-svn: 273536
2016-06-23 07:00:17 +00:00
Rui Ueyama 809d8e2d41 Fix a bug that MIPS thunks can overwrite other section contents.
Peter Smith found while trying to support thunk creation for ARM that
LLD sometimes creates broken thunks for MIPS. The cause of the bug is
that we assign file offsets to input sections too early. We need to
create all sections and then assign section offsets because appending
thunks changes file offsets for all following sections.

This patch separates the pass to assign file offsets from thunk
creation pass. This effectively reverts r265673.

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

llvm-svn: 273532
2016-06-23 04:33:42 +00:00
Davide Italiano 30afae1a75 [LTO] Update after API change in LLVM. NFC.
llvm-svn: 273462
2016-06-22 19:51:05 +00:00
Davide Italiano 595ee8cb9c [LTO] Include ASM undefs in llvm.compiler_used.
This fixes PR28218. Thanks to Rafael for spotting a failure in
the SHARED_LIBS build!

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

llvm-svn: 273451
2016-06-22 18:09:23 +00:00
George Rimar ff2d87c7ff [ELF] - Simplify loop in parseVersionSymbols(). NFC.
llvm-svn: 273427
2016-06-22 15:06:21 +00:00
George Rimar 4d8465cbe1 [ELF] - Show explicit error if extern keyword is used in version script.
Since we do not have plans to support it in closest future,
it is better than common script parsing error.

llvm-svn: 273426
2016-06-22 15:02:57 +00:00
George Rimar 0ab48b7334 [ELF] - Implemented version script hierarchies.
Patch implements hierarchies for version scripts. 
This allows to handle script files with dependencies, like next one has:

LIBSAMPLE_1.0{
  global:
  a;
};

LIBSAMPLE_2.0
{
  global:
  b;
}LIBSAMPLE_1.0;

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

llvm-svn: 273423
2016-06-22 14:40:45 +00:00
George Rimar d4245a1ffd Update testcases after r273417, which changed llvm-readobj output slightly.
llvm-svn: 273418
2016-06-22 13:45:08 +00:00
George Rimar 5b2503fb3e Added new line at the end of file. NFC.
llvm-svn: 273399
2016-06-22 11:41:37 +00:00
George Rimar b9f4492ef6 [ELF] - Do not crash on unclosed quote (") in scripts.
Found that during investigation of FreeBsd scripts.
Unclosed quote just crashed lld.

llvm-svn: 273398
2016-06-22 11:39:16 +00:00
George Rimar 50b80359c0 [ELF] - Do not allow to mix global symbols versions.
For next version script:
VER1{
  global:
  a;
};

VER2{
  global:
  a;
};
gold would produce warning like:
"warning: using 'VER1' as version for 'a' which is also named in version 'VER2' in script."

Documentation also says we do not want this duplications (https://people.freebsd.org/~deischen/symver/library_versioning.txt):
"Note that you do not want to duplicate symbols in the map file. The .symver directives are all that is required to add compatibility
symbols into old versions."

This patch restricts such mixing and makes lld to produce error in this case.

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

llvm-svn: 273396
2016-06-22 09:10:38 +00:00
Rui Ueyama d2ada2ea5d Do not scan relocations twice for MIPS.
Previously, relocations for MIPS were scanned twice; once in regular
scanRelocs() and the other is in scanRelocsForThunks. In the former
function, we computed types of relocations and skipped R_THUNK relocations.
In the latter function, we computed the same value again and skipped
all but R_THUNK relocations. It was wasteful. This patch fixes that.
Now R_THUNK relocations are handled in the regular manner.

llvm-svn: 273346
2016-06-22 00:57:09 +00:00
Rui Ueyama 39061a5220 Simplify writeThunk. NFC.
Previously, `Buf + 4` was written twice.

llvm-svn: 273337
2016-06-21 23:53:08 +00:00
Rafael Espindola 254b58dfe3 Revert "Revert "Add a test showing that lto produces relaxable relocations.""
This reverts commit r273247.

lld should always use the new relocations.

llvm-svn: 273266
2016-06-21 14:47:43 +00:00
Rui Ueyama d1188f757c Accept both single and double dashes for all options.
This is a follow-up patch to r273218. GNU ld accepts both "--" and "-"
for all multi-letter options except "-o". This patch makes lld compatible
with that behavior.

llvm-svn: 273256
2016-06-21 08:45:50 +00:00
Rui Ueyama 03a6cec51e Detect invalid use of R_X86_64_GOTTPOFF.
It is an ABI requirement that the relocation must be used
in MOVQ or LEAQ instructions. Previously, we ignored invalid
relocations.

llvm-svn: 273248
2016-06-21 06:03:28 +00:00
James Y Knight fde8f9bd82 Revert "Add a test showing that lto produces relaxable relocations."
This reverts commit r273074.

Reverting this too, after revert in llvm in r273245.

llvm-svn: 273247
2016-06-21 05:54:41 +00:00
Rui Ueyama b319ae2cf1 Refactor X86TargetInfo::relaxTlsIeToLe.
`Inst` and `Op` variables are removed since they are not always
point to an instruction nor an operand. For 5-byte MOV instruction,
Op points to an instruction, which is confusing.

llvm-svn: 273246
2016-06-21 05:44:14 +00:00
Rui Ueyama 73575c4d5e Fix typo in comment.
llvm-svn: 273243
2016-06-21 05:09:39 +00:00
Rui Ueyama 3f5dd1458e Unbreak buildbots.
llvm-svn: 273242
2016-06-21 05:01:31 +00:00
Rui Ueyama 55a9def2bf Refactor X86_64TargetInfo::relaxTlsIeToLe.
This patch is to rewrite the function with a table-lookup-ish approach
so that it can read as a series of "convert this pattern to this" pattern.

llvm-svn: 273238
2016-06-21 03:42:32 +00:00
Rui Ueyama 36a31171ff Allow both one and two dashes for all multi-letter options.
GNU ld's manual page says that all options whose names are
multiple letters, except those who start with "o", can start
either with one or two dashes.

llvm-svn: 273218
2016-06-20 23:10:40 +00:00
Tom Stellard 1cfb9efdf7 ELF/AMDGPU: Add support for R_AMDGPU_REL32 relocations
Reviewers: rafael, ruiu

Subscribers: kzhuravl, llvm-commits

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

llvm-svn: 273192
2016-06-20 19:48:29 +00:00
Davide Italiano a074fe41bf [ELF] Accept --soname= (two dashes).
Update an existing test to exercise the new functionality, while
I'm here.

llvm-svn: 273175
2016-06-20 17:58:09 +00:00
Rafael Espindola ffe2e06f71 Don't go on an infinite loop on a missing ";".
Thanks to Will Dietz for reporting the issue.

llvm-svn: 273157
2016-06-20 14:02:22 +00:00
George Rimar 35728c3465 [ELF] - Lowercase the error messages text. NFC.
llvm-svn: 273156
2016-06-20 13:48:16 +00:00
George Rimar d5d544757e [ELF] - Removed excessive reference from pointer arguments. NFC.
llvm-svn: 273155
2016-06-20 13:30:37 +00:00
George Rimar 086fcae95e [ELF] - Forgot to address these two minors before commit r273152. NFC.
llvm-svn: 273154
2016-06-20 13:22:54 +00:00
George Rimar d3566309eb [ELF] - Recommit r273143("[ELF] - Basic versioned symbols support implemented.")
With fix:
-soname flag was not set in testcase. Hash calculated for base def was different on local
and bot machines because filename fos used for calculating.

Initial commit message:
Patch implements basic support of versioned symbols.
There is no wildcards patterns matching except local: *;
There is no support for hierarchies.
There is no support for symbols overrides (@ vs @@ not handled).

This patch allows programs that using simple scripts to link and run.

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

llvm-svn: 273152
2016-06-20 11:55:12 +00:00
Simon Atanasyan 7b8481bf95 [ELF][MIPS] Fix predicate used for sorting MIPS dynamic symbol tables
Now it conforms requirement for std::stable_sort predicates. That
resolves build-bot failures on Windows hosts.

llvm-svn: 273151
2016-06-20 11:37:56 +00:00
George Rimar d03f97211a Revert r273143 "[ELF] - Basic versioned symbols support implemented."
It broke buildbot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast

llvm-svn: 273146
2016-06-20 10:29:53 +00:00
George Rimar c31fee2212 [ELF] - Basic versioned symbols support implemented.
Patch implements basic support of versioned symbols.
There is no wildcards patterns matching except local: *;
There is no support for hierarchies.
There is no support for symbols overrides (@ vs @@ not handled).

This patch allows programs that using simple scripts to link and run.

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

llvm-svn: 273143
2016-06-20 10:16:33 +00:00
George Rimar 06e930d37a Fixed compilation error under MSVS 2015 (looks like compiler bug). NFC.
llvm-svn: 273142
2016-06-20 10:01:50 +00:00
Rui Ueyama e178c2f7c6 Fix comment.
llvm-svn: 273140
2016-06-20 08:34:50 +00:00
Rui Ueyama 440138c4c8 [COFF] Add /section command line flag.
llvm-svn: 273134
2016-06-20 03:39:39 +00:00
Simon Atanasyan 4132511cdc [ELF][MIPS] Support GOT entries for non-preemptible symbols with different addends
There are two motivations for this patch. The first one is a preparation
for support MIPS TLS relocations. It might sound like a joke but for GOT
entries related to TLS relocations MIPS ABI uses almost regular approach
with creation of dynamic relocations for each GOT enty etc. But we need
to separate these 'regular' TLS related entries from MIPS specific local
and global parts of GOT. ABI declare simple solution - all TLS related
entries allocated at the end of GOT after local/global parts. The second
motivation it to support GOT relocations for non-preemptible symbols
with addends. If we have more than one GOT relocations against symbol S
with different addends we need to create GOT entries for each unique
Symbol/Addend pairs.

So we store all MIPS GOT entries in separate containers. For non-preemptible
symbols we have to maintain two data structures. The first one is MipsLocal
vector. Each entry corresponds to the GOT entry from the 'local' part
of the GOT contains the symbol's address plus addend. The second one
is MipsLocalMap. It is a map from Symbol/Addend pair to the GOT index.

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

llvm-svn: 273127
2016-06-19 21:39:37 +00:00
Rafael Espindola 1040b4479c Add a test showing that lto produces relaxable relocations.
llvm-svn: 273074
2016-06-18 00:36:39 +00:00
Rafael Espindola 6fcbbcb328 This tests depends on non-relaxable relocations.
Make that explicit.

llvm-svn: 273013
2016-06-17 17:01:38 +00:00
Rafael Espindola 678844e68a Don't confuse input and output section offsets.
llvm-svn: 273006
2016-06-17 15:42:36 +00:00
Rafael Espindola f2956a3b18 Simplify. NFC.
llvm-svn: 273004
2016-06-17 15:01:50 +00:00
Rafael Espindola f70fb04e4f Make local: optional.
Doing that in an anonymous version is a bit silly, but this opens the
way for supporting it in general.

Since we don't support actual versions, for now we just disable the
version script if we detect that it is missing a local.

llvm-svn: 273000
2016-06-17 13:38:09 +00:00
Rui Ueyama 424b408165 Rename Align -> Alignment.
I think it is me who named these variables, but I always find that
they are slightly confusing because align is a verb.
Adding four letters is worth it.

llvm-svn: 272984
2016-06-17 01:18:46 +00:00
Rui Ueyama c737ef5d21 Remove default values that vary depending on target.
llvm-svn: 272976
2016-06-16 23:50:25 +00:00
Rui Ueyama 2f524fb7c7 Make a switch-case a function for the sake of simplicity.
llvm-svn: 272975
2016-06-16 23:28:08 +00:00
Rui Ueyama e991a49587 Merge cases that execute the same code.
llvm-svn: 272974
2016-06-16 23:28:06 +00:00
Rui Ueyama a71ba43ed3 Early return. NFC.
llvm-svn: 272973
2016-06-16 23:28:05 +00:00
Rui Ueyama bebf4897a3 Simplify. NFC.
llvm-svn: 272972
2016-06-16 23:28:03 +00:00
Rui Ueyama 595bc5db4b Simplify *(x+y) to x[y]. NFC.
They are equivalent in C (and in C++ in this case).

llvm-svn: 272942
2016-06-16 19:48:07 +00:00
George Rimar 95eeb7730d [ELF] - Handle every global as unversioned export in versioned script.
Patch updates the version script parser to parse versioned files.
In a simple way, just adding them to VersionScriptGlobals list.

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

llvm-svn: 272934
2016-06-16 18:47:04 +00:00
Rui Ueyama 727cd2f73f Simplify. NFC.
llvm-svn: 272924
2016-06-16 17:18:25 +00:00
Rui Ueyama e517de655b Inline a small function. NFC.
llvm-svn: 272923
2016-06-16 17:06:24 +00:00
Rui Ueyama f9d5620029 Early return. NFC.
llvm-svn: 272917
2016-06-16 16:44:52 +00:00
Rui Ueyama d089a43de4 Early return. NFC.
llvm-svn: 272915
2016-06-16 16:40:36 +00:00
Rui Ueyama 4a90f57ef2 Rename PltZero -> PltHeader.
PltZero (or PLT[0]) was an appropriate name for the little code
we have at beginning of the PLT section when we only supported x86
since the code for x86 just fits in the first PLT slot.

It's not the case anymore. The code for ARM64 occupies first two
slots, so PltZero spans PLT[0] and PLT[1], for example.
This patch renames it to avoid confusion.

llvm-svn: 272913
2016-06-16 16:28:50 +00:00
Rui Ueyama c9fee5fee6 Eliminate unnecessary call of SymbolBody::getPltVA.
For ARM and MIPS, we don't need to call this function.
This patch passes a symbol instead of a PLT entry address
so that the target handler can call it if necessary.

llvm-svn: 272910
2016-06-16 16:14:50 +00:00
Rafael Espindola cf1d4987b9 Add support for # comments.
llvm-svn: 272892
2016-06-16 13:29:48 +00:00
Peter Smith fa4d90d5aa Add initial support for Thumb for ARMv7a
Add support for the R_ARM_THM relocations used in the objects present
    in arm-linux-gnueabihf-gcc. These are:
    R_ARM_THM_CALL
    R_ARM_THM_JUMP11
    R_ARM_THM_JUMP19
    R_ARM_THM_JUMP24
    R_ARM_THM_MOVT_ABS
    R_ARM_THM_MOVW_ABS_NC
    
    Interworking between ARM and Thumb is partially supported with BLX.
    The R_ARM_CALL relocation for ARM instructions and R_ARM_THM_CALL
    relocation for Thumb instructions will write out a BL or BLX depending
    on the state of the Target.
    
    Assumptions:
    - Availability of BLX and extended range of Thumb 4-byte Branch
      instructions.
    - In relocateOne if (Val & 0x1) == 1 target is Thumb, 0 is ARM.
      This will hold for objects that comply with the ABI for the
      ARM architecture.
    
    This is sufficient for hello world to work with a recent
    arm-linux-gnueabihf distribution.
    
    Limitations:
    No interworking for R_ARM_JUMP24, R_ARM_THM_JUMP24, R_ARM_THM_JUMP19
    and the deprecated R_ARM_PLT32 and R_ARM_PC24 instructions as these
    cannot be written out as a BLX and need a state change thunk.
    
    No range extension thunks. The R_ARM_JUMP24 and R_ARM_THM_CALL have a
    range of 16Mb

llvm-svn: 272881
2016-06-16 09:53:46 +00:00
Rafael Espindola 7ce1bc71f4 Document an interesting LTO case.
This is a reduction from the only symbol in a build of clang that the
gold plugin internalizes but lld does not.

llvm-svn: 272845
2016-06-15 21:33:11 +00:00
Rafael Espindola cc70da39ff Internalize symbols in comdats.
We were dropping the CanOmitFromDynSym bit when creating undefined
symbols because of comdat.

llvm-svn: 272812
2016-06-15 17:56:10 +00:00
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 07543a8c2d Use a reference instead of a pointer. NFC.
llvm-svn: 272719
2016-06-14 21:40:23 +00:00
Peter Collingbourne a8bf23d656 ELF: Add a test showing that the new local_unnamed_addr attribute can permit internalization.
Part of the fix for PR27553.

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

llvm-svn: 272711
2016-06-14 21:02:15 +00:00
Rui Ueyama 9337869393 Update numbers.
llvm-svn: 272596
2016-06-13 22:48:36 +00:00
George Rimar 2993ad2248 [ELF] - Change wording of error message.
Previously message told us that relocations could
not be used when making shared object. That was
correct because message could appear (and it is expected) 
when we linked executable.
Message should have being changed to something
that says we can't use a subset of relocations against shared
symbols.

Patch fixes the text.

llvm-svn: 272478
2016-06-11 15:59:09 +00:00
Davide Italiano 3935690433 Merge two if(s) into one, simplifying the code.
llvm-svn: 272475
2016-06-11 14:21:38 +00:00
Simon Atanasyan 9b861181f9 [ELF] Use static function isPreemptible instead of SymbolBody::isPreemptible. NFC
Just for consistency with other parts of the code.

llvm-svn: 272390
2016-06-10 12:26:39 +00:00
Simon Atanasyan 311b4b15e1 [ELF][MIPS] Move MIPS specific code under `if` block to accent its specificity. NFC
llvm-svn: 272389
2016-06-10 12:26:28 +00:00
Simon Atanasyan a26a157b0a [ELF][MIPS] Fix mask used to parse MIPS 3-in-1 relocation packet
In isPreemptible routine we interested in R_MIPS_GPREL16 relocation
only. This relocation fits 0xf. So the new mask 0xff is just to conform
the ABI specification.

llvm-svn: 272388
2016-06-10 12:26:09 +00:00
George Rimar 0a2f19701e [ELF] - Properly check that R_X86_64_PC32 and R_X86_64_32 relocations are disallowed in DSO.
Initially we wanted to check that these two relocations are not present when linking DSO because of 
possible overflow in runtime. Patch moves them to writable segment in testcases to allow
proper error check to trigger.
Otherwise error message about using dynamic relocations against text segment was shown.

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

llvm-svn: 272379
2016-06-10 08:15:12 +00:00
George Rimar 3ed2b08dad [ELF] - Inform user that we do not support dynamic relocations against text segment.
It was reported in PR28020, that lld does not link code which
gold do. But in fact that is expected behavior as we do not
support DT_TEXTREL.

This patch changes error message as it can report about relocations against
text segments exclusively, other dynamic relocations errors can 
be handled separately.

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

llvm-svn: 272377
2016-06-10 08:00:01 +00:00
Rafael Espindola e8b8a347c7 Use errorDynRel like every other target.
llvm-svn: 272305
2016-06-09 20:42:04 +00:00
Rafael Espindola 24de767113 Rename warnDynRel.
It produces an error, so that was a bad name.

llvm-svn: 272304
2016-06-09 20:39:01 +00:00
Rafael Espindola 8dbb7e1d61 Also reject 32 bit dynamic relocs when producing executable.
They point to a shared library, so they would still overflow at runtime.

llvm-svn: 272303
2016-06-09 20:35:27 +00:00
Rafael Espindola c845cb6f23 Don't require a dynamic R_X86_64_32 reloc in a test.
llvm-svn: 272302
2016-06-09 20:22:35 +00:00
Peter Collingbourne ca8c994818 ELF: Compute used bit for --as-needed during symbol resolution.
We can now use this to decide whether to emit a verneed during the final
pass over the symbols. We were previously wrongly creating a verneed entry
in the case where all references to a DSO's symbols were weak.

In a future change we may also want to use the used bit to control whether
shared symbols are preemptible and appear in the dynsym. This seems a little
tricky to do at the moment because isNeeded() is templated.

The only other functional change here is that we emit a DT_NEEDED for DSOs
whose symbols are all preempted by objects that appear later in the link. But
that doesn't seem too important to me.

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

llvm-svn: 272282
2016-06-09 18:01:35 +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 db0168d1d6 [ELF] - Removed excessive variable. NFC.
llvm-svn: 272265
2016-06-09 15:17:29 +00:00
Richard Smith 98520e7019 Update to match LLVM r272232.
llvm-svn: 272234
2016-06-09 00:54:16 +00:00
Rafael Espindola a8777c2ef8 Handle gd tls relocs pointing to local symbols.
If the symbol is local we don't need to create a R_X86_64_DTPOFF64, we
can just write the correct value in the got.

Should fix pr28018.

llvm-svn: 272205
2016-06-08 21:31:59 +00:00
Rui Ueyama 3e097b1a06 Move a function declaration to a header.
llvm-svn: 272146
2016-06-08 14:35:22 +00:00
George Rimar 71a0a40b97 [ELF] - Removed includeInGnuHashTable() function. NFC.
It was one line global static function that looks nicer to inline,
patch do that.

llvm-svn: 272137
2016-06-08 12:57:14 +00:00
George Rimar 95912d07d8 [ELF] - Fixed mistype in comment. NFC.
llvm-svn: 272134
2016-06-08 12:29:29 +00:00
George Rimar e6389d18dc [ELF] Replace getELFRelocationTypeName() calls with getRelName(). NFC.
That made few places in code a bit shorter.

llvm-svn: 272133
2016-06-08 12:22:26 +00:00
George Rimar dcddfb63cd [ELF] Simplify shouldMerge() result calculation. NFC.
llvm-svn: 272131
2016-06-08 12:04:59 +00:00
George Rimar 56efb34901 [ELF] - Replaced one more hardcode with named constant. NFC.
llvm-svn: 272130
2016-06-08 11:49:01 +00:00
George Rimar d50a1459e9 [ELF] - Replaced hardcode with named constants. NFC.
llvm-svn: 272129
2016-06-08 11:40:24 +00:00
George Rimar 2030cacc67 [ELF] - Tweak verneed.s test to use new llvm-readobj functionality
Previously this test performed check of binary data. Since
llvm-readobj currently able to dump all 3 types of version relative
sections, that can be used to make this test more transparent.
Patch do that.

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

llvm-svn: 272120
2016-06-08 06:54:23 +00:00
Rui Ueyama 3621857eac Remove break after return.
llvm-svn: 272046
2016-06-07 19:10:51 +00:00
Rui Ueyama 12ebff22cb Define a helper function to get a relocation name. NFC.
llvm-svn: 272034
2016-06-07 18:10:12 +00:00
Rui Ueyama 45a873d644 Merge duplicate code. NFC.
llvm-svn: 272032
2016-06-07 18:03:05 +00:00
Rui Ueyama 7b14a62d36 Use StringSwitch. NFC.
llvm-svn: 272030
2016-06-07 17:55:05 +00:00
Peter Smith 5dd3c292bc Add missing REQUIRES: arm from test. To fix tests building without ARM.
llvm-svn: 271994
2016-06-07 09:49:40 +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 4ffda7a9cf Create version.txt in a reproduce archive file.
Differential Revision: http://reviews.llvm.org/D21008

llvm-svn: 271901
2016-06-06 15:34:37 +00:00
George Rimar 8b3c5f2b30 [ELF] - Assign sh_link field of SHT_GNU_versym section to DynSymTab section index.
.gnu.version should have sh_link field initialized with index of DynSymTab section.

GNU documentation looks misses that, but Sun docs mention it, according to
https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-54676/index.html 
versym sh_link is indeed supposed to point to the .dynsym section.

Binutils readelf tool also relies on that:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;h=b6454d353279dc57745cd5a2d68b5f3f69f8e17c;hb=5522f910cb539905d6adfdceab208ddfa5e84557#l9988

Both gold/bfd do the same + after this patch I am able to see this section in readelf output, was unable before in my case.

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

llvm-svn: 271874
2016-06-06 08:04:53 +00:00
Rafael Espindola e325b98836 add missing REQUIRES
llvm-svn: 271859
2016-06-05 22:54:11 +00:00
Rafael Espindola 4f5046ce87 Add a missing REQUIRES.
llvm-svn: 271854
2016-06-05 19:28:44 +00:00
Rafael Espindola 6211d9a4fa Move GlobalDynIndex to SymbolBody.
With that we can have local symbols with a tls gd index.

llvm-svn: 271852
2016-06-05 19:03:28 +00:00
Rafael Espindola 698dba74f8 Include version in --reproduce.
llvm-svn: 271829
2016-06-05 13:19:39 +00:00
Davide Italiano cd76e49888 Attempt to fix non-determinism in test.
Otherwise it could just use a leftover a.out from
some other test.

llvm-svn: 271820
2016-06-05 01:04:59 +00:00
Rafael Espindola e1979aed0a Implement gd to ie relaxation for aarch64.
llvm-svn: 271815
2016-06-04 23:33:31 +00:00
Rafael Espindola 69f5402b26 Use adjustRelaxExpr for tls relaxations too.
This remove some EM_386 specific code from InputSection.cpp and opens
the way for more relaxations.

llvm-svn: 271814
2016-06-04 23:22:34 +00:00
Rafael Espindola f807d47164 Rename TlsGdToLeSkip.
It will also be used for GT_TO_IE relaxations.

llvm-svn: 271813
2016-06-04 23:04:39 +00:00
Rafael Espindola 5c66b8260e Rename adjustRelaxGotExpr.
It will be used for more than just gots.

llvm-svn: 271812
2016-06-04 22:58:54 +00:00
Rafael Espindola d167a25eef Add missing REQUIRES.
llvm-svn: 271799
2016-06-04 19:30:58 +00:00
Rafael Espindola 12dc446939 Fix implicit plt creation on aarch64.
We were not handling page relative relocations.

llvm-svn: 271798
2016-06-04 19:11:14 +00:00
Benjamin Kramer bd521201b7 Apply clang-tidy's misc-move-constructor-init to lld.
No functionality change intended.

llvm-svn: 271686
2016-06-03 16:57:13 +00:00
Davide Italiano df24d5b8c8 [LTO] Add --lto-aa-pipeline.
Differential Revision:  http://reviews.llvm.org/D20888

llvm-svn: 271605
2016-06-02 22:58:11 +00:00
Rafael Espindola e37d13b9ec Start adding tlsdesc support for aarch64.
This is mostly extracted from http://reviews.llvm.org/D18960.

The general idea for tlsdesc is that the two GD got entries are used
for a function pointer and its argument. The dynamic linker sets
both. In the non-dlopen case the dynamic linker sets the function to
the identity and the argument to the offset in the tls block.

All that the static linker has to do in the non-dlopen case is
relocate the code to point to the got entries and create a dynamic
relocation.

The dlopen case is more complicated, but can be implemented in another patch.

llvm-svn: 271569
2016-06-02 19:49:53 +00:00
Rafael Espindola 1c0eb972ed Simplify mask computation.
llvm-svn: 271525
2016-06-02 16:00:25 +00:00
Rafael Espindola 1016f19215 Simplify. NFC.
updateAArch64Add takes care of masking.

llvm-svn: 271524
2016-06-02 15:51:40 +00:00
Rafael Espindola 53d0a9fe40 Stort lines. NFC.
llvm-svn: 271523
2016-06-02 15:24:52 +00:00
Rafael Espindola 0f1401a8d9 Delete dead code.
AArch64 uses TLSDESC, so these are dead.

llvm-svn: 271517
2016-06-02 14:12:47 +00:00
George Rimar b720430b47 [ELF] Split too long X86_64TargetInfo::relaxGot method. NFC.
Patch adds relaxGotNoPic() method to handle no-PIC path.

llvm-svn: 271506
2016-06-02 09:22:00 +00:00
George Rimar f10c8290fa [ELF] - Implemented support for test/binop relaxations from latest ABI.
Patch implements next relaxation from latest ABI:

"Convert memory operand of test and binop into immediate operand, where binop is one of adc, add, and, cmp, or,
sbb, sub, xor instructions, when position-independent code is disabled."

It is described in System V Application Binary Interface AMD64 Architecture Processor 
Supplement Draft Version 0.99.8 (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, 
B.2 "B.2 Optimize GOTPCRELX Relocations").

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

llvm-svn: 271405
2016-06-01 16:45:30 +00:00
Davide Italiano 64ebf32ef3 [LTO] Fix (incorrect) TLS attribute mismatch.
When we undefine, we also preserve type of symbol so that we get
it right in the combined LTO object.

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

llvm-svn: 271403
2016-06-01 16:38:13 +00:00
Rafael Espindola 3d6d4c39be Handle the -T option.
We were not reading it or including in the --reproduce archive.

llvm-svn: 271367
2016-06-01 06:17:27 +00:00
Rafael Espindola a8433c1d1b Revert "bar"
This reverts commit r271365.
Sorry, wrong branch.

llvm-svn: 271366
2016-06-01 06:15:22 +00:00