Commit Graph

6272 Commits

Author SHA1 Message Date
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
Rafael Espindola 74540516ef bar
llvm-svn: 271365
2016-06-01 06:13:54 +00:00
Davide Italiano e6c8fa4530 [ELF] Unbreak build with GCC.
Differential Revision:  http://reviews.llvm.org/D20777

llvm-svn: 271148
2016-05-28 23:27:38 +00:00
Rui Ueyama 8b972d221e Simplify. NFC.
llvm-svn: 271133
2016-05-28 18:40:38 +00:00
Rafael Espindola 3b1ecb563f Make test more realistic.
It doesn't make mach sense to fetch less than 64 bits from a got
entry.

llvm-svn: 271116
2016-05-28 15:38:13 +00:00
Simon Atanasyan 9a9a3169e3 [ELF][MIPS] Always resolve MIPS GP-relative relocations to 'local' definitions
In case of MIPS, GP-relative relocations always resolve to a definition
in a regular input file, ignoring the one-definition rule. Such
relocations are used to setup GP relative offsets in a function's
prologue. So we, for example, should not attempt to create a dynamic
relocation even if the target symbol is preemptible.

Fixes bug 27880.

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

llvm-svn: 271100
2016-05-28 04:49:57 +00:00
Rui Ueyama 406b469de4 Avoid doing binary search.
MergedInputSection::getOffset is the busiest function in LLD if string
merging is enabled and input files have lots of mergeable sections.
It is usually the case when creating executable with debug info,
so it is pretty common.

The reason why it is slow is because it has to do faily complex
computations. For non-mergeable sections, section contents are
contiguous in output, so in order to compute an output offset,
we only have to add the output section's base address to an input
offset. But for mergeable strings, section contents are split for
merging, so they are not contigous. We've got to do some lookups.

We used to do binary search on the list of section pieces.
It is slow because I think it's hostile to branch prediction.

This patch replaces it with hash table lookup. Seems it's working
pretty well. Below is "perf stat -r10" output when linking clang
with debug info. In this case this patch speeds up about 4%.

Before:

       6584.153205 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.09% )
               238 context-switches          #    0.036 K/sec                    ( +-  6.59% )
                 0 cpu-migrations            #    0.000 K/sec                    ( +- 50.92% )
         1,067,675 page-faults               #    0.162 M/sec                    ( +-  0.15% )
    18,369,931,470 cycles                    #    2.790 GHz                      ( +-  0.09% )
     9,640,680,143 stalled-cycles-frontend   #   52.48% frontend cycles idle     ( +-  0.18% )
   <not supported> stalled-cycles-backend
    21,206,747,787 instructions              #    1.15  insns per cycle
                                             #    0.45  stalled cycles per insn  ( +-  0.04% )
     3,817,398,032 branches                  #  579.786 M/sec                    ( +-  0.04% )
       132,787,249 branch-misses             #    3.48% of all branches          ( +-  0.02% )

       6.579106511 seconds time elapsed                                          ( +-  0.09% )

After:

       6312.317533 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.19% )
               221 context-switches          #    0.035 K/sec                    ( +-  4.11% )
                 1 cpu-migrations            #    0.000 K/sec                    ( +- 45.21% )
         1,280,775 page-faults               #    0.203 M/sec                    ( +-  0.37% )
    17,611,539,150 cycles                    #    2.790 GHz                      ( +-  0.19% )
    10,285,148,569 stalled-cycles-frontend   #   58.40% frontend cycles idle     ( +-  0.30% )
   <not supported> stalled-cycles-backend
    18,794,779,900 instructions              #    1.07  insns per cycle
                                             #    0.55  stalled cycles per insn  ( +-  0.03% )
     3,287,450,865 branches                  #  520.799 M/sec                    ( +-  0.03% )
        72,259,605 branch-misses             #    2.20% of all branches          ( +-  0.01% )

       6.307411828 seconds time elapsed                                          ( +-  0.19% )

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

llvm-svn: 270999
2016-05-27 14:39:13 +00:00
Rafael Espindola 6af546188f Avoid having to check in a binary.
llvm-svn: 270986
2016-05-27 12:27:21 +00:00
Peter Collingbourne 5079f3b727 Update LLD for D20550.
Differential Revision: http://reviews.llvm.org/D20704

llvm-svn: 270968
2016-05-27 05:21:45 +00:00
Sean Silva 8ef190c7b0 Make -L description a bit more precise.
llvm-svn: 270966
2016-05-27 04:48:26 +00:00
Sean Silva 3b536d0916 Explain a bit better what --start-lib and --end-lib do.
llvm-svn: 270965
2016-05-27 04:48:24 +00:00
Sean Silva 688fade4dd Add a help description for --threads to avoid confusion.
llvm-svn: 270964
2016-05-27 04:48:21 +00:00
Sean Silva 2c1a9da83f --threads is a flag, not a number
We would previously accept `--threads=4`, but this option just turns on
threading and does not specify a number of threads.

I ran into this by accident because I was passing `--threads=<n>` but
the number didn't seem to affect anything.

llvm-svn: 270963
2016-05-27 04:30:27 +00:00
Simon Atanasyan 84bb355c3a [ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo section
MIPS .reginfo and .MIPS.options sections are consumed by the linker, and
the linker produces a single output section. But it is possible that
input files contain section symbol points to the corresponding input
section. In case of generation a relocatable output we need to write
such symbols to the output file.

Fixes bug 27878.

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

llvm-svn: 270910
2016-05-26 20:46:01 +00:00
Rafael Espindola a5cefffc33 Update for llvm change.
llvm-svn: 270907
2016-05-26 20:31:06 +00:00
George Rimar a8f9cf18ad Removed redundant argument. NFC.
llvm-svn: 270847
2016-05-26 13:37:12 +00:00
George Rimar 95433df129 [ELF] - Added support for jmp/call relaxations when R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX are used.
D15779 introduced basic approach to support new relaxations.
This patch implements relaxations for jmp and call instructions,
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/D20622

llvm-svn: 270721
2016-05-25 16:51:08 +00:00
Rui Ueyama d884927463 Make SectionPiece 8 bytes smaller on LP64.
This patch makes SectionPiece class 8 bytes smaller on platforms
on which pointer size is 8 bytes. Sean suggested in a post commit
review for r270340 that this could make a differentce, and it
actually is. Time to link clang (with debug info) improved from
6.725 seconds to 6.589 seconds or by about 2%.

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

llvm-svn: 270717
2016-05-25 16:37:01 +00:00
Rui Ueyama 1795f782e9 Do not ignore --no_ctors_in_init_array flag.
That flag is probably too dangerous to ignore silently.

llvm-svn: 270711
2016-05-25 15:30:11 +00:00
Ed Maste 2e04361a21 ELF: improve CIE no-augmentation test
Add another possible error that may be reported for the same case. The
original reproduction case that prompted r270706 produced the error
"corrupted CIE" instead of "corrupted or unsupported CIE information".
The specific error depends on arbitrary data later in the file so
check that neither is emitted in case the input is ever changed.

Document the process used to create the input .o and rename the test
file to .s, as requested by Rafael.

llvm-svn: 270709
2016-05-25 15:14:08 +00:00
Ed Maste 594e06b879 ELF: Handle empty CIE augmentation string
"A zero length string indicates that no augmentation data is present."

The FreeBSD/mips toolchain (GCC 4.2.1) generates .debug_frame sections
containing CIE records that have an empty augmentation string.

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

llvm-svn: 270706
2016-05-25 14:45:28 +00:00
George Rimar 5c33b91bbe [ELF] - Implemented optimization for R_X86_64_GOTPCREL relocation.
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")
introduces possible relaxations for R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX.

That patch implements the next relaxation: 
mov foo@GOTPCREL(%rip), %reg => lea foo(%rip), %reg
and also opens door for implementing all other ones.

Implementation was suggested by Rafael Ávila de Espíndola with few additions and testcases by myself.

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

llvm-svn: 270705
2016-05-25 14:31:37 +00:00
Rui Ueyama c789b631f3 Really define --export-dynamic-symbol= as an alias to --export-dynamic-symbol.
Thanks to Sean for pointing it out.

llvm-svn: 270660
2016-05-25 04:29:55 +00:00
Rui Ueyama 02fcf11a9c Fix comment.
llvm-svn: 270659
2016-05-25 04:29:53 +00:00
Rui Ueyama e66f45c6eb Reduce code duplication.
llvm-svn: 270657
2016-05-25 04:10:14 +00:00
Rui Ueyama 2487f19258 Add `static` to a file-scope function.
llvm-svn: 270652
2016-05-25 03:40:02 +00:00
Rui Ueyama dadda2fe08 Add a few options for compatibility with GNU.
llvm-svn: 270651
2016-05-25 03:38:16 +00:00
Rui Ueyama 0fcdc730ad Create Relocations.cpp and move scanRelocs there.
scanReloc and the functions on which scanReloc depends is in total
more than 600 lines of code. Since scanReloc does not depend on Writer,
it is better to move it into a separate file.

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

llvm-svn: 270606
2016-05-24 20:24:43 +00:00
Rafael Espindola 5ee9e7fd80 Use range loop.
Thanks to Rui for the suggestion.

llvm-svn: 270601
2016-05-24 19:14:09 +00:00
Rafael Espindola 1f5696f9c1 Fix a wrong assumption.
llvm-svn: 270573
2016-05-24 16:03:27 +00:00
Rui Ueyama 19ccffe4bc Do not start over relocation search from beginning.
This patch addresses a post-commit review for r270325. r270325
introduced getReloc function that searches a relocation for a
given range. It always started searching from beginning of relocation
vector, so it was slower than before. Previously, we used to use
the fact that the relocations are sorted. This patch restore it.

llvm-svn: 270572
2016-05-24 15:40:46 +00:00
Rafael Espindola 820f4bb972 Handle terminator .eh_frame when creating the index.
llvm-svn: 270568
2016-05-24 15:17:47 +00:00
Rafael Espindola bfffa94ea7 Fix crash in .eh_frame marker section.
llvm-svn: 270563
2016-05-24 14:51:50 +00:00
Rafael Espindola 29da3e3577 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270555
2016-05-24 12:17:11 +00:00
Rafael Espindola fe3a2f1b81 Revert "Simplify. Thanks to Rui for the suggestion."
This reverts commit r270551.

Sorry, I commited the wrong branch :-(

llvm-svn: 270554
2016-05-24 12:12:06 +00:00
Rafael Espindola dba64b8ea4 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270551
2016-05-24 11:53:15 +00:00
Rafael Espindola 97434957ef Update for llvm change.
llvm-svn: 270550
2016-05-24 11:16:14 +00:00
Rui Ueyama 70595aae64 Inline SymbolBody::init. NFC.
I think this function was too short to be an independent function.

llvm-svn: 270534
2016-05-24 04:51:49 +00:00
Rui Ueyama ace4f90cf3 Do not pass the symbol table. NFC.
Since the symbol table is a singleton class and globally accessible,
we don't need to pass it around.

llvm-svn: 270533
2016-05-24 04:25:47 +00:00
Rui Ueyama 0b9a90364b Rename EHInputSection -> EhInputSection.
llvm-svn: 270532
2016-05-24 04:19:20 +00:00
Rui Ueyama 151ff30783 Simplify. NFC.
llvm-svn: 270531
2016-05-24 04:12:52 +00:00
Rui Ueyama 022d8e8a86 Make scanReloc and related functions non-member functions.
scanReloc does not depend on Writer, so it doesn't have to be
in the class.

llvm-svn: 270530
2016-05-24 03:36:07 +00:00
Rui Ueyama afa35a2a37 Remove Writer::ensureBss().
Previously, we created a .bss section when needed. We had a function
ensureBss() for that purpose. Turned out that was error-prone
because it was easy to forget to call that function before accessing
the .bss section.

This patch always make the BSS section. The section is added to the
output when it's not empty.

llvm-svn: 270527
2016-05-24 03:16:51 +00:00
Rui Ueyama f5febef249 Create a new file EhFrame.cpp and move code to read .eh_frame there.
llvm-svn: 270526
2016-05-24 02:55:45 +00:00
Rui Ueyama 98843087cb Reject zero-sized symbols when creating copy relocations.
Copy relocations are relocations to copy data from DSOs to
executable's .bss segment at runtime. It doesn't make sense to
create such relocations for zero-sized symbols.

GNU linkers don't agree with each other. ld rejects such
relocation/symbol pair. gold don't reject that but do not create
copy relocations as well.  I took the former approach because
I don't think the latter is what user wants.

llvm-svn: 270525
2016-05-24 02:37:40 +00:00
Rui Ueyama b7eda28aaa Use range-based for.
llvm-svn: 270523
2016-05-24 02:10:28 +00:00
Rui Ueyama 6de2e6829d Make getFdeEncoding a non-member function.
This function does not depend on EhOutputSection class.

llvm-svn: 270522
2016-05-24 02:08:38 +00:00
Rui Ueyama fa2f307c54 Remove dead code.
The dead declarations made MSVC to warn on explicit template
instantiations of the classes.

llvm-svn: 270471
2016-05-23 18:08:27 +00:00
Rui Ueyama b91bf1a9a0 Do not split mergeable sections if they are gc'ed.
Previously, mergeable section's constructors did more than just
setting member variables; it split section contents into small
pieces. It is not always computationally cheap task because if
the section is a mergeable string section, it needs to scan the
entire section to split them by NUL characters.

If a section would be thrown away by GC, that cost ended up
being a waste of time. It is going to be larger problem if the
section is compressed -- the whole time to uncompress it and
split it up is going to be a waste.

Luckily, we can defer section splitting after GC. We just have
to remember which offsets are in use during GC and apply that later.
This patch implements it.

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

llvm-svn: 270455
2016-05-23 16:55:43 +00:00
Rui Ueyama 2ab3d20819 Fix typos.
llvm-svn: 270451
2016-05-23 16:36:47 +00:00
Rui Ueyama de9777af1b Remove EhFrameHeader<ELFT>::reserveFde. NFC.
llvm-svn: 270448
2016-05-23 16:30:41 +00:00
Rui Ueyama 8a6ef4e6b2 Remove dead code.
Since now we always set SHT_PROGBITS to .eh_frame sections,
this code path is not executed at runtime.

llvm-svn: 270446
2016-05-23 16:24:22 +00:00
Rui Ueyama 3b31e6711b Make .eh_frame a singleton output object.
.eh_frame_hdr assumes that there is only one .eh_frame and
ensures it by assertions. This patch makes .eh_frame a real
singleton object to simplify.

llvm-svn: 270445
2016-05-23 16:24:16 +00:00
Rui Ueyama f86cb90a2d Do not propagate section name and attributes to .eh_frame.
.eh_frame is always ".eh_frame" and its attribute is fixed.
No need to copy from inputs to outputs. GNU gold also sets
SHT_PROGBITS.

llvm-svn: 270443
2016-05-23 15:12:41 +00:00
Rui Ueyama 1e479c23aa Rename EHOutputSection -> EhOutputSection for consistency.
llvm-svn: 270442
2016-05-23 15:07:59 +00:00
Rui Ueyama e75e933efc Refactor EhFrameHdr.
Previously, EhFrameHdr section computed addresses to which FDEs are
applied to. This is not an ideal design because EhFrameHdr does not
know much about FDEs unless EhFrame passes the information to EhFrameHdr.
It is what we did.

This patch simplifies the code by making EhFrame to compute the
values and pass the cooked information to EhFrameHdr. EhFrameHdr no
longer have to know about the details of FDEs such as FDE encodings.

llvm-svn: 270393
2016-05-23 03:00:33 +00:00
Rui Ueyama 95a232e5c9 Add comment.
llvm-svn: 270390
2016-05-23 01:45:05 +00:00
Rui Ueyama 1b2936fc82 Simplify. NFC.
llvm-svn: 270388
2016-05-23 01:31:10 +00:00
Rui Ueyama 744d47ea05 Make file-local function file-local. NFC.
llvm-svn: 270387
2016-05-23 00:45:54 +00:00
Rui Ueyama 518f1af04d Split MergeInputSection's ctor. NFC.
llvm-svn: 270386
2016-05-23 00:40:24 +00:00
Rui Ueyama 88abd9b300 Move splitInputSection from EHOutputSection to EHInputSection.
llvm-svn: 270385
2016-05-22 23:53:00 +00:00
Rui Ueyama e2060aa747 Attempt to unbreak buildbots.
My last commit made Clang to fail with an assertion failure.
https://llvm.org/bugs/show_bug.cgi?id=27835
This is a patch to avoid that.

llvm-svn: 270384
2016-05-22 23:52:56 +00:00
Rui Ueyama f8b285c037 Refactor EHOutputSection.
This patch refactors EHOutputSection using SectionPiece struct.
EHRegion class was removed since we can now directly use SectionPiece.

An incomplete support of large CIE/FDE record (> 2^32 bytes) was removed
because it silently created broken executable. There are several places
in the existing code that "size" field is always 4 bytes and at offset 4
in the record, which is not true for 64-bit size records. We will have to
support that in future, but it is better to error out instead of creating
malformed eh_frame sections.

llvm-svn: 270382
2016-05-22 23:16:14 +00:00
Rui Ueyama 34dc99e2c5 Store section contents to SectionPiece. NFC.
So that we don't need to cut a slice when we use a SectionPiece.

llvm-svn: 270348
2016-05-22 01:15:32 +00:00
Rui Ueyama c6ebb02fca Use StringPiece::Size instead of calculating it again. NFC.
llvm-svn: 270347
2016-05-22 01:03:41 +00:00
Rui Ueyama 90fa3722d2 Simplify SplitInputSection::getRangeAndSize.
This patch adds Size member to SectionPiece so that getRangeAndSize
can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.
Also renamed the function.

llvm-svn: 270346
2016-05-22 00:41:38 +00:00
Rui Ueyama 1080351987 Use slightly longer names. NFC.
We generally prefer short names, but this code went probably a bit too far.
This patch renames single letter local/member varables.

llvm-svn: 270342
2016-05-22 00:25:30 +00:00
Rui Ueyama 644ac656b1 Use ArrayRef<uint8_t> for binary data instead of StringRef. NFC.
llvm-svn: 270341
2016-05-22 00:17:11 +00:00
Rui Ueyama 3ea8727188 Define SectionPiece and use it instead of std::pair<uint_t, uint_t>.
We were using std::pair to represents pieces of splittable section
contents. It hurt readability because "first" and "second" are not
meaningful. This patch give them names.

One more thing is that piecewise liveness information is stored to
the second element of the pair as a special value of output section
offset. It was confusing, so I defiend a new bit, "Live", in the
new struct.

llvm-svn: 270340
2016-05-22 00:13:04 +00:00
Simon Atanasyan 1c980ca5aa [ELF] Take into account offset in the output section when read addends for a non-alloc input section
llvm-svn: 270328
2016-05-21 19:48:54 +00:00
Rui Ueyama 4f798fc358 Use uintX_t instead of unsigned.
This fixes a potential bug when cross linking very large executables
on LLP64 machines such as Windows. On such platform, uintX_t is 64 bits
while unsigned is 32 bits.

llvm-svn: 270327
2016-05-21 19:22:46 +00:00
Rui Ueyama 46207cc1c9 Remove dead variable.
llvm-svn: 270326
2016-05-21 19:08:39 +00:00
Rui Ueyama 6bf7d915ac Split EHOutputSection<ELFT>::addSectionAux. NFC.
llvm-svn: 270325
2016-05-21 19:06:33 +00:00
Rui Ueyama c0449a6d84 Swap the arguments of writeAlignedCieOrFde. NFC.
Most functions take destination buffers as the first arguments
just like memcpy, so this order is easier to read.
Also simplified the function.

llvm-svn: 270324
2016-05-21 18:10:13 +00:00
Rui Ueyama f57a5905d3 Simplify. NFC.
llvm-svn: 270281
2016-05-20 21:39:07 +00:00
Rafael Espindola ebed1fe0de Refactor R_RELAX_TLS_* value computation.
This makes it explicit that each R_RELAX_TLS_* is equivalent to some
other expression.

With this I think we are at a sweet spot for how much is done in
Target.cpp. I did experiment with moving *all* the value math out of it.
It has the advantage that we know the final value in target independent
code, but it gets quite verbose.

llvm-svn: 270277
2016-05-20 21:23:52 +00:00
Rafael Espindola 50223310ba Simplify a bit. NFC.
llvm-svn: 270275
2016-05-20 21:14:06 +00:00
Rafael Espindola 91e9fc0931 Document some constants. NFC.
llvm-svn: 270274
2016-05-20 21:09:59 +00:00
Rafael Espindola 74f3dbe438 Directly compute the right value for R_RELAX_TLS_GD_TO_IE.
This avoid doing math in Target.cpp to compensate.

llvm-svn: 270266
2016-05-20 20:09:35 +00:00
Rafael Espindola fb0ceb5153 Check pc relative relocations too.
llvm-svn: 270264
2016-05-20 20:02:27 +00:00
Rafael Espindola 8818ca69dc Make tp offset computation target independent.
This adds direct support for computing offsets from the thread pointer
for both variants. Of the architectures we support, variant 1 is used
only by aarch64 (but that doesn't seem to be documented anywhere.)

llvm-svn: 270243
2016-05-20 17:41:09 +00:00
Dima Stepanov fb8978fc6a Fix the function to set the section VMA/LMA fields in case of using
the linker script. The cycle in the ELF/LinkerScript.cpp:assignAddresses()
routine will be used to go through all the sections and set all the
addresses correctly.

Add new test to check this case.

llvm-svn: 270090
2016-05-19 18:15:54 +00:00
Rafael Espindola 6989ebf661 Simplify, NFC.
llvm-svn: 269983
2016-05-18 21:05:18 +00:00
Rafael Espindola e4c86d83fe Drop vestigial support for UseLazyBinding=false.
Lazy binding is quite important for use case like a shared build of
llvm. Also, if someone wants to disable it, it is better done in the
compiler (disable plt generation).

The only reason to keep it is to make it easier to add a new
architecture. But it doesn't really help much as it is possible to start
with non lazy relocation and plt code but still let the generic part
create a dedicated .got.plt and .rela.plt.

llvm-svn: 269982
2016-05-18 21:03:36 +00:00
Rafael Espindola e2f43770a4 UseLazyBinding is always true in here, simplify.
llvm-svn: 269979
2016-05-18 20:44:24 +00:00
Peter Smith 4df2e14dce Fix typo in comment aligment should be alignment. NFC.
llvm-svn: 269905
2016-05-18 11:40:16 +00:00
Saleem Abdulrasool 5e9944ee0a ELF: accept and ignore --no-undefined-version for compatibility
This is currently unsupported.  Accept and ignore the flag for invocation
compatibility.

llvm-svn: 269788
2016-05-17 17:34:50 +00:00
Rui Ueyama 147036605e Add `explicit`.
llvm-svn: 269703
2016-05-16 21:06:31 +00:00
Davide Italiano 5020d2ade5 Sort includes, and don't look into system headers.
llvm-svn: 269607
2016-05-15 19:43:02 +00:00
Davide Italiano c26f981da2 Remove unused include. NFC.
llvm-svn: 269606
2016-05-15 19:36:23 +00:00
Davide Italiano d26c4a14ca [LTO] Add the ability to specify a subset of passes to run.
Differential Revision:  http://reviews.llvm.org/D20267

llvm-svn: 269605
2016-05-15 19:29:38 +00:00
Simon Atanasyan 4e3a15c9f3 [ELF][MIPS] Rename R_MIPS_GOT_xxx relocation expression kinds
New names reflect purpose of corresponding GOT entries better.
Both expression types related to entries allocated in the 'local'
part of MIPS GOT. R_MIPS_GOT_LOCAL_PAGE is for entries contain 'page'
addresses. R_MIPS_GOT_LOCAL is for entries contain 'full' address.

llvm-svn: 269597
2016-05-15 18:13:50 +00:00
Rui Ueyama fe65877c76 Reorganize the cpio archiver as CpioFile class. NFC.
This code separates the code to create cpio archive from the driver.

llvm-svn: 269593
2016-05-15 17:10:23 +00:00
Rui Ueyama 109ff37430 Update for a recent format change.
llvm-svn: 269496
2016-05-13 21:58:46 +00:00
Rui Ueyama 9194db78fb Support --build-id=0x<hexstring>.
If you specify the option in the form of --build-id=0x<hexstring>,
that hexstring is set as a build ID. We observed that the feature
is actually in use in some builds, so we want this feature.

llvm-svn: 269495
2016-05-13 21:55:56 +00:00
Rafael Espindola 7229496787 When using Rela, don't write the addend to the output section.
The Elf_Rela has an explicit addend. It doesn't need the addend to be
written to the section being relocated.

Since relative relocations are very common in the output, this is a
noticeable speedup. The results I got were

chromium
  master 4.778149487
  patch  4.761120792 0.996436131802
chromium fast
  master 1.896253636
  patch  1.840990582 0.970856718241
the gold plugin
  master 0.399337811
  patch  0.392279276 0.982324401032
clang
  master 0.666873675
  patch  0.665895708 0.998533504865
llvm-as
  master 0.037101095
  patch  0.037123149 1.00059442989
the gold plugin fsds
  master 0.422473396
  patch  0.414192879 0.980399909016
clang fsds
  master 0.747302008
  patch  0.744843964 0.996710775599
llvm-as fsds
  master 0.033146245
  patch  0.033064531 0.997534743377
scylla
  master 4.08857525
  patch  4.082245184 0.998451767275

llvm-svn: 269417
2016-05-13 14:15:37 +00:00
Rafael Espindola 686ffc6f4c Slit the relocation scan in two parts.
The first part handles whatever has to be written to the r_offset
position.

The second part handles creating got and plt entries.

llvm-svn: 269375
2016-05-12 22:51:22 +00:00
Rafael Espindola 203b0773a3 Move addend computation to a helper function.
llvm-svn: 269369
2016-05-12 22:19:35 +00:00
Rafael Espindola 01f1636408 Handle thunks in adjustExpr.
This is similar to the other changes this function does. With this all
Relocations.push_back calls look similar.

llvm-svn: 269362
2016-05-12 21:53:34 +00:00
Rafael Espindola 62cb02eef1 This reverts commit r269359 and r269360.
I will commit again with a fixed commit message.

llvm-svn: 269361
2016-05-12 21:51:16 +00:00
Rafael Espindola cc42a90b76 Handle thunks in adjustExpr.
This is similar to the other changes this function does. With this all
Relocations.push_back calls look similar.

llvm-svn: 269360
2016-05-12 21:47:26 +00:00
Rafael Espindola 01a94f8336 bra
llvm-svn: 269359
2016-05-12 21:47:24 +00:00
Peter Collingbourne 0ef3874de3 Move undefine to a separate function.
llvm-svn: 269331
2016-05-12 19:46:14 +00:00
George Rimar fa91000290 [ELF] implemented -z defs option
Just do not allow to link shared library if there are
undefined symbols.

This fixes PR27447

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

llvm-svn: 269183
2016-05-11 13:48:41 +00:00
George Rimar 71e64b2df9 [ELF] - Fixed failture of mips-64-got.s on x32 configuration.
win32 was my case.
Before that change test failed with next error for me:
23>  ******************** TEST 'lld :: ELF/mips-64-got.s' FAILED ********************
....
23>  Command 3 Stderr:
23>  relocation R_MIPS_GOT_PAGE out of range

llvm-svn: 269166
2016-05-11 09:41:15 +00:00
Davide Italiano 334fce92d9 [LTO] Don't crash on old DebugInfo.
Drop them and produce a graceful warning instead.

llvm-svn: 269149
2016-05-11 01:07:22 +00:00
Rafael Espindola f72914f42a Add a link to the format description.
llvm-svn: 269102
2016-05-10 19:26:55 +00:00
Rafael Espindola e502751c42 Fix typo.
llvm-svn: 269072
2016-05-10 16:23:46 +00:00
George Rimar c191acf097 [ELF] - Implemented -z combrelocs/nocombreloc.
This is the option which sorts relocs to optimize dynamic linker performance.
-z combelocs is the default in gold, also it ignores -z nocombreloc,
this patch do the same.

Patch sorts relocations by symbols only and do not create any
DT_REL[A]COUNT entries. That is different with what gold/bfd do.

More information about option is here:
http://www.airs.com/blog/archives/186
http://people.redhat.com/jakub/prelink.pdf, p.2

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

llvm-svn: 269066
2016-05-10 15:47:57 +00:00
Rafael Espindola 78db5a9dca Print member name in undefined symbol error.
llvm-svn: 268976
2016-05-09 21:40:06 +00:00
Rafael Espindola 4ee6cb3a70 Document and test the first few .got.plt entries.
llvm-svn: 268945
2016-05-09 18:12:15 +00:00
Rafael Espindola 45a33fb799 Allow user defined __init_aray_start.
Fixes pr27683.

llvm-svn: 268926
2016-05-09 15:25:54 +00:00
Daniel Sanders dcb98e61c7 [mips] Fix mips-got16.s following r268900.
$LC0 and $LC1 are no longer present in the symbol table because they are
rewritten to .text+offset and .data+offset.

llvm-svn: 268911
2016-05-09 13:01:01 +00:00
Simon Atanasyan 8c8a5b5f81 [ELF][MIPS] Handling 'packed' N64 ABI relocations
MIPS N64 ABI packs multiple relocations into the single relocation
record. In general, all up to three relocations can have arbitrary types.
In fact, Clang and GCC uses only a few combinations. For now, we support
two of them. That is allow to pass at least all LLVM test suite cases.

<any relocation> / R_MIPS_SUB / R_MIPS_HI16 | R_MIPS_LO16
<any relocation> / R_MIPS_64 / R_MIPS_NONE

The first relocation is a 'real' relocation which is calculated using
the corresponding symbol's value. The second and the third relocations
used to modify result of the first one: extend it to 64-bit, extract
high or low part etc. For details, see part 2.9 'Relocation' at
https://dmz-portal.mips.com/mw/images/8/82/007-4658-001.pdf

llvm-svn: 268876
2016-05-08 14:08:40 +00:00
Simon Atanasyan 10296c2344 [ELF][MIPS] Remove redundant local variable. NFC
llvm-svn: 268852
2016-05-07 07:36:47 +00:00
Simon Atanasyan 5b9ac41c13 [ELF][MIPS] Reduce code duplication. NFC
llvm-svn: 268743
2016-05-06 15:02:54 +00:00
Simon Atanasyan 9ac819860f [ELF][MIPS] Reduce all MIPS R_GOTREL addends by MipsGPOffset in the single place. NFC
llvm-svn: 268742
2016-05-06 15:02:50 +00:00
Simon Atanasyan 1a728fdf5c [ELF][MIPS] Simplify `if` condition. NFC
In case of MIPS ABI relocation has R_GOTREL expression's type iif the
relocation type is either R_MIPS_GPREL16 or R_MIPS_GPREL32. So it is
enough to check expression's type only.

llvm-svn: 268741
2016-05-06 15:02:45 +00:00
Rui Ueyama 31f9f6100e Use the new type for StringTableBuilder::getMap.
llvm-svn: 268699
2016-05-06 00:52:08 +00:00
Rafael Espindola d39dadeb64 Don't produce a relocation to read only memory.
This is hopefully last case where we would produce a relocation to a
read only section.

llvm-svn: 268688
2016-05-05 21:19:38 +00:00
Rafael Espindola 66434562e7 Fix copy relocations in pie.
We were creating the copy relocations just fine, but then thinking that
the .bss position could be preempted and creating a dynamic relocation
to it, which would crash at runtime since that memory is read only.

llvm-svn: 268668
2016-05-05 19:41:49 +00:00
Peter Collingbourne 3ad1c1e242 ELF: Undefine all symbols, not just those that we expect to be defined.
This allows the combined LTO object to provide a definition with the same
name as a symbol that was internalized without causing a duplicate symbol
error. This normally happens during parallel codegen which externalizes
originally-internal symbols, for example.

In order to make this work, I needed to relax the undefined symbol error to
only report an error for symbols that are used in regular objects.

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

llvm-svn: 268649
2016-05-05 17:13:49 +00:00
Rafael Espindola 474eb019b4 Move static function to avoid forward declaration. NFC.
llvm-svn: 268646
2016-05-05 16:40:28 +00:00
Rafael Espindola 462220de47 Reuse logic for deciding whether to keep a local symbol or not.
llvm-svn: 268644
2016-05-05 16:38:46 +00:00
Rafael Espindola 3e0b7837bf Cache result when tail merging too.
This speeds up a link of chromium with -O2 (but no icf,gc) from
1.940664632 to 1.925578119.

llvm-svn: 268639
2016-05-05 16:12:25 +00:00
Rafael Espindola d89fbca21d Fix --gc-sections when .eh_frame has a lsda.
We have to add sections to the work list, not just mark them live.

llvm-svn: 268628
2016-05-05 13:51:14 +00:00
Peter Collingbourne e29e142a10 ELF: Do not use -1 to mark pieces of merge sections as being tail merged.
We were previously using an output offset of -1 for both GC'd and tail
merged pieces. We need to distinguish these two cases in order to filter
GC'd symbols from the symbol table -- we were previously asserting when we
asked for the VA of a symbol pointing into a dead piece, which would end
up asking the tail merging string table for an offset even though we hadn't
initialized it properly.

This patch fixes the bug by using an offset of -1 to exclusively mean GC'd
pieces, using 0 for tail merges, and distinguishing the tail merge case from
an offset of 0 by asking the output section whether it is tail merge.

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

llvm-svn: 268604
2016-05-05 04:10:12 +00:00
Rui Ueyama ca16c104c6 Merge two tests for the same purpose.
I accidentally added another test file as I didn't notice
that the test file existed.

llvm-svn: 268598
2016-05-05 02:32:09 +00:00
Rui Ueyama ac75a27809 Add a test for --reproduce on Windows.
It is insanely hard to write a test that works both on Windows and Unix.
I tried to workaround it with cpio's minor options, but the behaviors of
the options were myterious. It just doesn't worth to spend time on it.
And probably minor options could break buildbots that doesn't have the
GNU version of cpio command.

In this patch, I simply added a separate test file that runs only on
Windows.

llvm-svn: 268596
2016-05-05 02:18:04 +00:00
Rui Ueyama af2312feb7 Make --reproduce to not produce undesired whitespace.
Fixes bug 27648.

llvm-svn: 268569
2016-05-04 23:12:55 +00:00
Simon Atanasyan da83bbc1a1 [ELF][MIPS] Create combined dynamic relocation type R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE
MIPS N64 ABI packs multiple relocations into the single relocation
record. Particularly it requires to represent dynamic relative
relocation as a combination of R_MIPS_REL32 and R_MIPS_64 relocations.

llvm-svn: 268565
2016-05-04 22:39:40 +00:00
Rafael Espindola de17d28a32 Don't produce relative relocs to ro segments.
We were already checking for non relative relocations.

If we ever decide to add support for rw text segments this means we will
have a single spot to add the flag.

llvm-svn: 268558
2016-05-04 21:40:07 +00:00
Rafael Espindola 3fa5bbd91b Rename isRelRelative.
What it is computing is if we need a dynamic relocation or not.

llvm-svn: 268556
2016-05-04 21:28:56 +00:00
Rafael Espindola 946ca27b61 Use early return. NFC.
llvm-svn: 268554
2016-05-04 21:09:24 +00:00
Rui Ueyama 0cfed297de Handle errors on file opening as soft error.
Also improves the error message. Previously it would just print out
the cause (e.g. "permission denied"). Now it prints out something like
"--reproduce: failed to open foo.cpio: permission denied".

llvm-svn: 268551
2016-05-04 21:05:11 +00:00
Rafael Espindola ac95264d62 Don't depend on dynamic relocatinos in ro sections.
Currently we don't check when creating relative relocations if the
section is read only or not. I am about to fix that, so first update the
patches that depend on the current behavior.

llvm-svn: 268542
2016-05-04 20:25:19 +00:00
Rafael Espindola 1bf2f191b6 Split a testcase.
I will make changes to the -shared side and this reduces the noise in
the other patch.

llvm-svn: 268538
2016-05-04 20:06:49 +00:00
Simon Atanasyan be804559f8 [ELF][MIPS] R_MIPS_GOT_DISP, R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST relocations support
These relocations introduced by MIPS N64 ABI. R_MIPS_GOT_DISP references
GOT entry with full symbol's address, R_MIPS_GOT_PAGE creates GOT entry
with address of memory page which includes symbol's address,
R_MIPS_GOT_OFST used together with R_MIPS_GOT_PAGE. This relocation
calculates offset from beginning of memory page to the symbol address.

llvm-svn: 268525
2016-05-04 17:47:11 +00:00
Rafael Espindola 38bd217d0c Delete getTlsGotRel.
It was an old hack to avoid duplicating expression computation, but that
is not needed with getExprRel.

llvm-svn: 268515
2016-05-04 15:51:23 +00:00
George Rimar 5ed31e2f58 Removed another dead code. NFC.
llvm-svn: 268505
2016-05-04 15:04:08 +00:00
Rafael Espindola ebb04b9eb6 Simplify handling of hint relocations.
llvm-svn: 268501
2016-05-04 14:44:22 +00:00
Rafael Espindola de2c76ed73 Sort entries. NFC.
llvm-svn: 268499
2016-05-04 14:38:55 +00:00
George Rimar fbfe10f221 Removed dead code. NFC.
llvm-svn: 268497
2016-05-04 13:44:49 +00:00
Daniel Sanders c07f06aeee [mips][ias] Only round section sizes when explicitly requested.
As requested by Rafael Espindola in his post-commit comments on r268036. This
makes the previous behaviour the default while still allowing verification of
IAS.

llvm-svn: 268496
2016-05-04 13:21:06 +00:00
Rafael Espindola 2c51e619d5 Print the cpio trailer after every member.
This is both simpler and safer. If we crash at any point, there is a
valid cpio file to reproduce the crash.

Thanks to Rui for the suggestion.

llvm-svn: 268495
2016-05-04 12:47:56 +00:00
Simon Atanasyan 5e85a1b5be [ELF][MIPS] Fix typo in the comment. NFC.
llvm-svn: 268486
2016-05-04 10:15:12 +00:00
Simon Atanasyan add74f37f2 [ELF][MIPS] Read/write .MIPS.options section
MIPS N64 ABI introduces .MIPS.options section which specifies miscellaneous
options to be applied to an object/shared/executable file. LLVM as well as
modern versions of GNU tools read and write the only type of the options -
ODK_REGINFO. It is exact copy of .reginfo section used by O32 ABI.

llvm-svn: 268485
2016-05-04 10:07:38 +00:00
Rafael Espindola c5b8ed241d Implement --build-id=none.
Both bfd and gold have this. It allows disabling build-id when it is the
default with by adding -Wl,--build-id=none no the clang command line.

llvm-svn: 268435
2016-05-03 20:55:47 +00:00
Peter Collingbourne f3a2b0e8f7 ELF: Fix regression in TLS attribute mismatch logic.
Introduce a special symbol type to indicate that we have not yet seen a type
for the symbol, so we should not report TLS mismatches for that symbol.

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

llvm-svn: 268411
2016-05-03 18:03:47 +00:00
Peter Collingbourne 6f535b744f Check return value of addOptionalSynthetic before calling a member function on it.
Found with UBSan.

llvm-svn: 268410
2016-05-03 18:03:45 +00:00
Rafael Espindola 1dd2b3d1d0 Produce cpio files for --reproduce.
We want --reproduce to

* not rewrite scripts and thin archives
* work with absolute paths

Given that, it pretty much has to create a full directory tree. On windows that
is problematic because of the very short maximum path limit. On most cases
users can still work around it with "--repro c:\r", but that is annoying and
not viable for automated testing.

We then need to produce some form of archive with the files. The first option
that comes to mind is .a files since we already have code for writing them.
There are a few problems with them

The format has a dedicated string table, so we cannot start writing it until
all members are known.
Regular implementations don't support creating directories. We could make
llvm-ar support that, but that is probably not a good idea.
The next natural option would be tar. The problem is that to support long path
names (which is how this started) it needs a "pax extended header" making this
an annoying format to write.

The next option I looked at seems a natural fit: cpio files.

They are available on pretty much every unix, support directories and long path
names and are really easy to write. The only slightly annoying part is a
terminator, but at least gnu cpio only prints a warning if it is missing, which
is handy for crashes. This patch still makes an effort to always create it.

llvm-svn: 268404
2016-05-03 17:30:44 +00:00
Rafael Espindola d8dfdfd268 Don't depend on checking the response file when lld fails.
llvm-svn: 268388
2016-05-03 14:29:42 +00:00
Rafael Espindola 630ccd6a3f Remove unused includes.
llvm-svn: 268381
2016-05-03 13:57:49 +00:00
Peter Collingbourne c357278a38 ELF: Remove the function SymbolTable<ELFT>::findFile.
We already have the function SymbolBody::getSourceFile which does the same thing.

llvm-svn: 268353
2016-05-03 01:48:25 +00:00
Sean Silva 92fbd8df15 Try harder to get the bots green.
The test is now unexpectedly passing on
llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast which is treated as an error.
For now, disable Windows testing of the feature.
Rafael is working on generating an archive, which will hopefully allow
us to turn this test back on.

Unfortunately, we don't have a way to temporarily XFAIL this test just
on llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast.

llvm-svn: 268351
2016-05-03 01:25:28 +00:00
Peter Collingbourne 6a4225962d ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak undefined.
Weak undefined symbols resolve to the image base. This is a little strange,
but it allows us to link function calls to such symbols. Normally such a
call will be guarded with a comparison, which will load a zero from the GOT.

There's one example of such a function call in crti.o in Linux's CRT.

As part of this change, I also needed to make the synthetic start and end
symbols image base relative in the case where their sections were empty,
so that PC-relative references to those symbols would continue to work.

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

llvm-svn: 268350
2016-05-03 01:21:08 +00:00
Sean Silva 2b34def662 Temporarily disable this test on llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast
`REQUIRES: shell` is not appropriate because that would mean that there
are no windows bots testing this, and that is precisely where it needs
the most testing.

Rafael or Rui are working on generating an archive directly, which
should avoid this issue.
We can try to move the bot to a shorter build directory path.

llvm-svn: 268345
2016-05-03 00:36:15 +00:00
Rui Ueyama dd368fcb05 Pass all buffers to BuildId hash function at once. NFC.
This change simplifies the BuildId classes by removing a few member
functions and variables from them. It should also make it easy to
parallelize hash computation in future because now each BuildId object
see all inputs rather than one at a time.

llvm-svn: 268333
2016-05-02 23:35:59 +00:00
Rafael Espindola 133ebe5bc7 Simplify. NFC.
llvm-svn: 268324
2016-05-02 22:52:15 +00:00
Rui Ueyama 6d0cd2b62b Teach Undefined symbols from which file they are created from.
This patch increases the size of Undefined by the size of a pointer,
but it wouldn't actually increase the size of memory that LLD uses
because we are not allocating the exact size but the size of the
largest SymbolBody.

llvm-svn: 268310
2016-05-02 21:30:42 +00:00
Rafael Espindola 6bbd78df6f Revert "Temporary hack to see what is going on on a windows bot."
This reverts commit r268302.

llvm-svn: 268308
2016-05-02 21:21:26 +00:00
Rafael Espindola 732c4646ee Temporary hack to see what is going on on a windows bot.
llvm-svn: 268302
2016-05-02 20:47:06 +00:00
Rui Ueyama 5002a67ef2 Remove unnecessary namespace specifiers.
llvm-svn: 268292
2016-05-02 19:59:56 +00:00
Rui Ueyama 4f8d21f387 Do not pass Symtab to markLive/doICF since Symtab is globally accessible.
llvm-svn: 268286
2016-05-02 19:30:42 +00:00
Rui Ueyama fc28827216 Remove unnecessary namespace specifiers.
llvm-svn: 268278
2016-05-02 18:51:08 +00:00