Commit Graph

10957 Commits

Author SHA1 Message Date
Fangrui Song b6772b86e2 [ELF] Move `// REQUIRES:` line to the top
llvm-svn: 335676
2018-06-26 22:20:04 +00:00
Fangrui Song 3d87323a7e [ELF] Make non-writable non-executable PROGBITS sections closer to .text
This generalizes the old heuristic placing SHT_DYNSYM SHT_DYNSTR first in the readonly SHF_ALLOC segment.

Reviewers: espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 335674
2018-06-26 22:13:32 +00:00
Sean Fertile f60cb34c91 [PPC64] Thread-local storage general-dynamic to initial-exec relaxation.
Patch adds support for relaxing the general-dynamic tls sequence to
initial-exec.

the relaxation performs the following transformation:
addis r3, r2, x@got@tlsgd@ha --> addis r3, r2, x@got@tprel@ha
addi r3, r3, x@got@tlsgd@l   --> ld r3, x@got@tprel@l(r3)
bl __tls_get_addr(x@tlsgd)   --> nop
nop                          --> add r3, r3, r13

and instead of emitting a DTPMOD64/DTPREL64 pair for x, we emit a single
R_PPC64_TPREL64.

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

llvm-svn: 335651
2018-06-26 19:38:18 +00:00
Fangrui Song 68fa4e8c34 [ELF] Assign RF_EXEC rank even if --no-rosegment or SECTIONS command is used
Summary:
Currently when --no-rosegment is specified or a linker script with SECTIONS command is used,
.rodata (A) .text (AX) are assigned the same rank and .rodata may be placed after .text .
This increases the gap between .text and .bss and can cause pc-relative relocation overflow (e.g. gcc crtbegin.o crtbegin.S have R_X86_64_PC32 relocation from .text to .bss).

This patch makes SingleRoRx affect only segment layout, not section layout. As a consequence, .rodata will be placed before .text regardless of SingleRoRx.

Reviewers: espindola, ruiu, grimar, echristo, javed.absar

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 335627
2018-06-26 17:04:47 +00:00
Fangrui Song eb75b8f8f7 [ELF] Move `# REQUIRES:` line to the top
llvm-svn: 335625
2018-06-26 16:58:19 +00:00
George Rimar 8f53b6d71e [ELF] - Change the way of sorting local symbols.
rLLD329787 added the stable sorting to SymbolTableBaseSection::postThunkContents.

I profiled the Mozilla (response-O0.txt) from lld-speed-test package and found
std::stable_sort is showing up in profile results and consuming the 3.1% of the total
CPU time in the RelWithDebug build. Total time of postThunkContents is 3.54%, 238ms.

This change reduces postTimeContents time to 50ms, making it to take 0.73% of Total CPU time.

So, instead of sorting the local part I suggest to just rebuild it.
That is what this patch does.

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

llvm-svn: 335583
2018-06-26 08:50:09 +00:00
Fangrui Song 74282efee1 [ELF] Fix sort-non-script.s
llvm-svn: 335499
2018-06-25 17:16:01 +00:00
Fangrui Song 5ea154402e [ELF] Change test files for style consistency. NFC
* Move `REQUIRES:` line to the top
* llvm-mc ... -o %t -> llvm-mc ... -o %t.o
* Don't check "TEXT" "DATA" columns (they are bfd-style names that do
not fit into llvm well) in llvm-objdump output

llvm-svn: 335498
2018-06-25 17:07:40 +00:00
Fangrui Song 65c50074c2 [ELF] readobj -elf-output-style=GNU -> readelf
Style change for consistency. NFC

llvm-svn: 335494
2018-06-25 16:49:52 +00:00
George Rimar 32287ad897 [ELF] - ICF: add one more test case #3.
ICF is able to merge sections which relocations referring regular input sections
or mergeable sections, so it handles InputSection and MergeInputSection cases.

The following "return false" line which is executed in case of another type
of the sections is uncovered by our test cases:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L285
Patch fixes code coverage for this place.

llvm-svn: 335482
2018-06-25 15:27:09 +00:00
George Rimar 871b059129 [ELF] - Rewrote comment. NFC.
llvm-svn: 335479
2018-06-25 14:35:47 +00:00
George Rimar 1286c535bc [ELF] - ICF: add one more test case #2.
Check that ICF does not merge sections which relocations
have equal addends, but different target values.

This covers the following line, which was uncovered:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L278

llvm-svn: 335477
2018-06-25 14:28:40 +00:00
George Rimar 6facf4715c [ELF] - ICF: add one more test case.
This test case check that ICF does not merge 2 sections which relocations
efer to symbols that live in sections of the different types
(regular input section and mergeable input sections in this case).

It covers the following line of code, which was uncovered previously:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L271

llvm-svn: 335475
2018-06-25 14:00:05 +00:00
George Rimar 2f5ca59497 Revert r335460 "[ELF] - ICF: Remove dead code. NFC."
My mistake, it was not NFC.

llvm-svn: 335471
2018-06-25 13:46:39 +00:00
George Rimar fb66ad5ea1 [ELF] - ICF: Remove dead code. NFC.
Code is dead. We use only InputSections when building the list of
sections elegible for the ICF:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L439
And 'isEligible' filters out SyntheticSections as well for us. 

That way the only Kind we have in the Sections vector is SectionBase::Regular,
so we do not need to check sections kind at all, it is always the same.

llvm-svn: 335460
2018-06-25 12:51:55 +00:00
George Rimar afcd983a49 [ELF] - ICF: test we do not merge sectinons which relocations points to symbols of the different types.
This test case covers the following line of code:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L261

Previously it was uncovered.

llvm-svn: 335453
2018-06-25 11:37:27 +00:00
George Rimar 2051bd02a7 [ELF] - Replace llvm::find_if with the loop. NFC.
Requested during post commit review.

llvm-svn: 335447
2018-06-25 09:30:39 +00:00
Fangrui Song e737e75491 [ELF] Change llvm-objdump output for D48472: TEXT DATA -> TEXT
Reviewers: jyknight, Bigcheese, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 335404
2018-06-23 00:15:23 +00:00
George Rimar 0cde82ade5 [ELF] - ICF: test we do not merge sections which relocations differs only in addend.
This is to test the following `return false` line which
was uncovered by our tests earlier:

https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L255

llvm-svn: 335357
2018-06-22 15:21:38 +00:00
Sam Clegg ffd0aaf810 Revert "[WebAssembly] Error on mismatched function signature in final output"
This caused a lot of issues on the WebAssembly waterfall.
In particular, until with the signature of `main`.  We
probably want a better solution for main before we re-land.

Reverts rL335192

llvm-svn: 335355
2018-06-22 15:13:10 +00:00
George Rimar a99b3759bf [ELF] - Repair (re-enable) few ICF test cases.
--verbose is not used to report ICF sections since r324755,
--print-icf-sections is used instead.

These tests were at fact disabled since that time.

llvm-svn: 335354
2018-06-22 15:08:01 +00:00
George Rimar 6366c76fa5 [ELF] - ICF: Add 2 more test cases.
These test cases covers the following condition:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L243

It was uncovered by our tests. I was able to delete the whole `if`
and no test failed.

llvm-svn: 335351
2018-06-22 14:29:22 +00:00
George Rimar 50c6be9630 [ELF] - ICF: remove excessive check. NFC.
Change removes the excessive comparsion of
the relocation arrays sizes.

This code was dead, because at the higer level,
equalsConstant function contains the following check:

`A->NumRelocations != B->NumRelocations`
where NumRelocations contains the size of the relocations array.
So removed check did the same job twice.

This was found with use of code coverage analysis.

llvm-svn: 335346
2018-06-22 13:21:37 +00:00
George Rimar c9c0ccc8a9 [ELF] - Change how we handle suplicate -wrap. [NFC]
This avoids doing llvm::sort and std::unique for -wrap options.
I think it is more clean way.

llvm-svn: 335337
2018-06-22 11:18:11 +00:00
Sam Clegg 084d360f69 [WebAssembly] Only mark non-hidden symbols as live if they are also defined
Previously we were also marking undefined symbols (i.e. imports)
as live.

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

llvm-svn: 335243
2018-06-21 15:00:00 +00:00
Sam Clegg 1369dfa30b [WebAssembly] Error on mismatched function signature in final output
During symbol resolution, emit warnings for function signature
mismatches.  During GC, if any mismatched symbol is marked as live
then generate an error.

This means that we only error out if the mismatch is written to the
final output.  i.e. if we would generate an invalid wasm file.

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

llvm-svn: 335192
2018-06-21 00:12:25 +00:00
Sam Clegg e16a7d3faf [WebAssembly] Minor cleanup to test inputs. NFC.
Update load-undefined.test such that it doesn't rely on
ret32 and ret64 having default visibility.

Split out from: https://reviews.llvm.org/D48394

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

llvm-svn: 335187
2018-06-20 22:52:33 +00:00
Sam Clegg ddaab86972 [WebAssembly] Update function signature mismatch error message. NFC.
We don't start our error messages with capital letters.

Split out from https://reviews.llvm.org/D48394

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

llvm-svn: 335186
2018-06-20 22:45:03 +00:00
Simon Atanasyan 6d163c5feb [ELF][MIPS] Fill a primary-GOT as much as possible
While building a Global Offset Table try to fill the primary GOT as much
as possible because the primary GOT can be accessed in the most
effective way. If it is not possible, try to fill the last GOT in the
multi-GOT list, and finally create a new GOT if both attempts failed.

llvm-svn: 335140
2018-06-20 15:58:48 +00:00
Fangrui Song bd3684f25b [ELF] Support -z initfirst
Summary:
glibc uses this option to link libpthread.so

glibc/nptl/Makefile:
LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst

Reviewers: ruiu, echristo, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 335090
2018-06-20 02:06:01 +00:00
Simon Atanasyan bcd6416123 [ELF][MIPS] Temporarily mark failed MIPS tests as XFAIL.
microMIPS 64-bit is unsupported by LLVM starting from r335057. But such 
code can be generated by GCC. Mark failed test cases as XFAIL while
decide to drop microMIPS 64-bit support from LLD too or use binary
inputs for the test.                               

llvm-svn: 335059
2018-06-19 16:48:30 +00:00
Fangrui Song d9c3c1cd9d [ELF] Uniquify --wrap list.
Summary: For --wrap foo --wrap foo, bfd/gold wrap the symbol only once but LLD would rotate it twice.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, mgrang, llvm-commits

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

llvm-svn: 334991
2018-06-18 22:32:15 +00:00
George Rimar 507a924e21 [ELF] - Simplify the conflict-variable-linkage-name.s test case. [NFC]
This is a follow up requested during post commit review for
"[lld] r333880 - [ELF] - Also use DW_AT_linkage_name when gathering information about variables for error messages."

It removes checking of the input objects since it is really excessive.

llvm-svn: 334946
2018-06-18 14:14:35 +00:00
Paul Robinson 7555c589af Update copyright year to 2018.
llvm-svn: 334936
2018-06-18 12:22:17 +00:00
Benjamin Kramer 88e7be2e6b [ELF] Pass callables by function_ref
No need to create a heavyweight std::function if it's not stored. No
functionality change intended.

llvm-svn: 334885
2018-06-16 12:11:34 +00:00
Simon Atanasyan 9655fe6322 [ELF][MIPS] Fix stable_sort predicate to satisfy strict-ordering requirement. NFC
Fix for PR37785.

llvm-svn: 334851
2018-06-15 18:15:26 +00:00
Reid Kleckner 0c09acd32d Fix wasm responsefile lld test on Windows
llvm-svn: 334762
2018-06-14 19:59:22 +00:00
Reid Kleckner 3408568392 [COFF] Fix /wholearchive: to do libpath search again
Fixes https://crbug.com/852882

llvm-svn: 334761
2018-06-14 19:56:03 +00:00
Simon Atanasyan 9629d7897d [ELF][MIPS] Replace calls to MapVector::find by MapVector::lookup. NFC
llvm-svn: 334705
2018-06-14 11:53:31 +00:00
Fangrui Song 4ff63648ad [ELF][X86_64] Use R_GOTREL_FROM_END instead of R_GOTREL for R_X86_64_GOTOFF64
Summary:
R_X86_64_GOTOFF64: S + A - GOT
R_X86_64_GOTPC{32,64}: GOT + A - P (R_GOTONLY_PC_FROM_END)

R_X86_64_GOTOFF64 should use R_GOTREL_FROM_END so that in conjunction with
R_X86_64_GOTPC{32,64}, the `GOT` term is neutralized. This also matches
the handling of R_386_GOTOFF (S + A - GOT).

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 334672
2018-06-13 23:29:28 +00:00
Rui Ueyama 1ebde333e8 Remove needless bitwise-AND.
Because applyMask ignores upper bits, we don't need to mask them.

llvm-svn: 334647
2018-06-13 19:58:33 +00:00
Rui Ueyama 3cc4a0825b Make a function non-member because it doesn't depend on any class.
llvm-svn: 334646
2018-06-13 19:50:10 +00:00
Rui Ueyama 803ffdbc7b Apply clang-format.
llvm-svn: 334645
2018-06-13 19:49:58 +00:00
Brian Gesiak 4fcebf6cf6 [Darwin] Do not error on '-lto_library' option
Summary:
Any invocation of `clang -fuse-ld=lld` that results in a link command
on a macOS host currently fails, because the Darwin lld driver does not
recognize the `-lto_library` option that Clang passes it. Fix the error
by having the Darwin driver ignore the option.

The Clang driver's macOS toolchain is written such that it will always
pass the `-lto_library` option to the linker invocation on a macOS host.
And although the DarwinLdDriver is written to ignore any unknown arguments,
because `-lto_library` begins with `-l`, the DarwinLdDriver interprets it
as a library search command, for a library named "to_library". When the
DarwinLdDriver is unable to find a library specified via `-l`, it exits
with a hard error. This causes any invocation of `clang -fuse-ld=lld`
that results in a link command on a macOS host to fail with an error.

To fix the issue, I considered two alternatives:

1. Modify the Clang Darwin toolchain to only pass `-lto_library` if lld
   is *not* being used. lld doesn't support LTO on Darwin anyway, so it
   can't use the option. However, I opted against this because, if and
   when lld *does* support LTO on Darwin, I'll have to make another
   commit to Clang in order to get it to pass the option to lld again.
2. Modify the Darwin lld driver to ignore the `-lto_library` option.
   Just in case users may take this to mean LTO is supported, I also
   added a warning. If and when lld supports LTO on Darwin, the same
   commit that adds support for this option can remove the warning.

Option (2) seemed better to me, and is the rationale behind this commit.

Test Plan: check-lld

Reviewers: ruiu, smeenai, pcc

Reviewed By: smeenai

Subscribers: JDevlieghere, pcc, mehdi_amini, inglorion, steven_wu, llvm-commits

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

llvm-svn: 334641
2018-06-13 18:59:14 +00:00
Sid Manning 95b0c2e1e3 Add Hexagon Support
Differential Revision: https://reviews.llvm.org/D47791

llvm-svn: 334637
2018-06-13 18:45:25 +00:00
Aaron Smith 7e2ea97c9b [WebAssembly] Fix broken build due to missing attributes.inc
WebAssembly depends on attributes.h which includes attributes.inc. 
Unless cmake explicitly specifies this dependency, the .inc file 
is sometimes generated after the build tries to use it.

Patch by Stella Stamenova 

llvm-svn: 334581
2018-06-13 08:38:23 +00:00
Rui Ueyama 92b931d519 Use shorter names for #lo, #hi, #ha, etc. NFC.
Since these functions are file-local, the new names shouldn't be ambiguous.

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

llvm-svn: 334564
2018-06-13 00:50:17 +00:00
Rui Ueyama 4eed6cc433 Fix /WholeArchive bug.
`lld-link foo.lib /wholearchive:foo.lib` should work the same way as
`lld-link /wholearchive:foo.lib foo.lib`. Previously, /wholearchive in
the former case was ignored.

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

llvm-svn: 334552
2018-06-12 21:47:31 +00:00
Shoaib Meenai 02c4344262 [COFF] Fix crash when emitting symbol tables with GC
When running with linker GC (`-opt:ref`), defined imported symbols that
are referenced but then dropped by GC end up with their `Location`
member being nullptr, which means `getChunk()` returns nullptr for them
and attempting to call `getChunk()->getOutputSection()` causes a crash
from the nullptr dereference. Check for `getChunk()` being nullptr and
bail out early to avoid the crash.

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

llvm-svn: 334548
2018-06-12 21:19:33 +00:00
Rui Ueyama 864289990a Handle R_X86_64_GOTOFF64.
R_X86_64_GOTOFF64 is a relocation type to set to a distance betwween
a symbol and the beginning of the .got section. Previously, we always
created a dynamic relocation for the relocation type even though it
can be resolved at link-time.

Creating a dynamic relocation for R_X86_64_GOTOFF64 caused link failure
for some programs that do have a relocation of the type in a .text
section, as text relocations are prohibited in most configurations.

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

llvm-svn: 334534
2018-06-12 20:27:16 +00:00
Fangrui Song 3773c196fc [ELF][PPC64] Support R_PPC64_DTPREL64 which may be emitted in .rela.debug_addr
llvm-svn: 334533
2018-06-12 20:26:49 +00:00
Fangrui Song aa473c5387 [ELF] Support R_X86_64_GOTPC{32,64}
Reviewers: ruiu, grimar, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 334532
2018-06-12 20:18:41 +00:00
Zachary Turner 08426e1f9f Refactor ExecuteAndWait to take StringRefs.
This simplifies some code which had StringRefs to begin with, and
makes other code more complicated which had const char* to begin
with.

In the end, I think this makes for a more idiomatic and platform
agnostic API.  Not all platforms launch process with null terminated
c-string arrays for the environment pointer and argv, but the api
was designed that way because it allowed easy pass-through for
posix-based platforms.  There's a little additional overhead now
since on posix based platforms we'll be takign StringRefs which
were constructed from null terminated strings and then copying
them to null terminate them again, but from a readability and
usability standpoint of the API user, I think this API signature
is strictly better.

llvm-svn: 334518
2018-06-12 17:43:52 +00:00
Sam Clegg 724c217393 Fix -DBUILD_SHARED_LIBS=1 build
This was broken in rL334466

llvm-svn: 334507
2018-06-12 14:51:18 +00:00
Alexander Richardson 127176e59e [ELF][MIPS] Fix TLS GOT entries for local symbols in shared libraries
Summary:
Previously LLD would not add any dynamic relocations and write a module
index of 1 which is not correct for the shared library case.
This can happen when a thread-local global variable is marked as local with
a version script. With this change I am now able to link all of the FreeBSD
base system for MIPS64 with LLD.

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

llvm-svn: 334483
2018-06-12 08:00:38 +00:00
Brian Gesiak b9f7f4b87c [Darwin] Use errorHandler from liblldCommon
Summary:
Error handling in liblldCore and the Darwin toolchain prints to an
output stream. A TODO in the project explained that a diagnostics
interface resembling Clang's should be added.

For now, the simple diagnostics interface defined in liblldCommon seems
like an improvement. It prints colors when they're available, uses locks
for thread-safety, and abstracts away the `"error: "` and newline
literal strings that litter the Darwin toolchain code.

To use the liblldCommon error handler, a link dependency is added to
the liblldDriver library.

Test Plan:
1. check-lld
2. Invoke `ld64.lld -r` in a terminal that supports color output.
   Confirm that "ld64.lld: error: -arch not specified and could not be inferred"
   is output, and that the "error:" is colored red!

Reviewers: ruiu, smeenai

Reviewed By: ruiu

Subscribers: mgorny, llvm-commits

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

llvm-svn: 334466
2018-06-12 02:34:04 +00:00
Sean Fertile e6b2e06f28 [PPC64] Support R_PPC64_DTPREL relocations.
Patch adds support for most of the dynamic thread pointer based relocations
for local-dynamic tls. The HIGH and HIGHA versions are missing becuase they
are not supported by the llvm integrated assembler yet.

llvm-svn: 334465
2018-06-12 01:47:02 +00:00
Konstantin Zhuravlyov d70c367267 AMDGPU/LLD: Handle R_AMDGPU_REL64 relocation
Requires r334443 from llvm

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

llvm-svn: 334444
2018-06-11 21:42:53 +00:00
Fangrui Song 2389a240d0 [ELF] Fix copy relocation when two symbols share the same Symbol instance.
In glibc libc.so.6, the multiple versions of sys_errlist share the same Symbol instance. When sys_errlist is copy relocated, we would replace SharedSymbol with Defined in the first iteration of the following loop:

  for (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS))

Then in the second iteration, we think the symbol (which has been changed to Defined) is still SharedSymbol and screw up (the address ends up in the `Size` field).

llvm-svn: 334432
2018-06-11 19:42:57 +00:00
Simon Atanasyan 00d8843fa3 [ELF] Pass a pointer to InputFile to the getRelocTargetVA to escape dereferencing of nullptr. NFC
llvm-svn: 334392
2018-06-11 08:37:19 +00:00
Simon Atanasyan ed9ee69ccf [ELF][MIPS] Multi-GOT implementation
Almost all entries inside MIPS GOT are referenced by signed 16-bit
index. Zero entry lies approximately in the middle of the GOT. So the
total number of GOT entries cannot exceed ~16384 for 32-bit architecture
and ~8192 for 64-bit architecture. This limitation makes impossible to
link rather large application like for example LLVM+Clang. There are two
workaround for this problem. The first one is using the -mxgot
compiler's flag. It enables using a 32-bit index to access GOT entries.
But each access requires two assembly instructions two load GOT entry
index to a register. Another workaround is multi-GOT. This patch
implements it.

Here is a brief description of multi-GOT for detailed one see the
following link https://dmz-portal.mips.com/wiki/MIPS_Multi_GOT.

If the sum of local, global and tls entries is less than 64K only single
got is enough. Otherwise, multi-got is created. Series of primary and
multiple secondary GOTs have the following layout:
```
- Primary GOT
    Header
    Local entries
    Global entries
    Relocation only entries
    TLS entries

- Secondary GOT
    Local entries
    Global entries
    TLS entries
...
```

All GOT entries required by relocations from a single input file
entirely belong to either primary or one of secondary GOTs. To reference
GOT entries each GOT has its own _gp value points to the "middle" of the
GOT. In the code this value loaded to the register which is used for GOT
access.

MIPS 32 function's prologue:
```
lui     v0,0x0
0: R_MIPS_HI16  _gp_disp
addiu   v0,v0,0
4: R_MIPS_LO16  _gp_disp
```

MIPS 64 function's prologue:
```
lui     at,0x0
14: R_MIPS_GPREL16  main
```

Dynamic linker does not know anything about secondary GOTs and cannot
use a regular MIPS mechanism for GOT entries initialization. So we have
to use an approach accepted by other architectures and create dynamic
relocations R_MIPS_REL32 to initialize global entries (and local in case
of PIC code) in secondary GOTs. But ironically MIPS dynamic linker
requires GOT entries and correspondingly ordered dynamic symbol table
entries to deal with dynamic relocations. To handle this problem
relocation-only section in the primary GOT contains entries for all
symbols referenced in global parts of secondary GOTs. Although the sum
of local and normal global entries of the primary got should be less
than 64K, the size of the primary got (including relocation-only entries
can be greater than 64K, because parts of the primary got that overflow
the 64K limit are used only by the dynamic linker at dynamic link-time
and not by 16-bit gp-relative addressing at run-time.

The patch affects common LLD code in the following places:

- Added new hidden -mips-got-size flag. This flag required to set low
maximum size of a single GOT to be able to test the implementation using
small test cases.

- Added InputFile argument to the getRelocTargetVA function. The same
symbol referenced by GOT relocation from different input file might be
allocated in different GOT. So result of relocation depends on the file.

- Added new ctor to the DynamicReloc class. This constructor records
settings of dynamic relocation which used to adjust address of 64kb page
lies inside a specific output section.

With the patch LLD is able to link all LLVM+Clang+LLD applications and
libraries for MIPS 32/64 targets.

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

llvm-svn: 334390
2018-06-11 07:24:31 +00:00
Rui Ueyama ea62c5bbde Fix build broken by r334341.
llvm-svn: 334342
2018-06-09 00:58:05 +00:00
Rui Ueyama c020064655 Remove a dead variable.
llvm-svn: 334341
2018-06-09 00:54:18 +00:00
Zaara Syeda 4455b37666 [PPC64] Add support for local-exec TLS model
This patch adds the relocations needed support the local-exec TLS model:

R_PPC64_TPREL16
R_PPC64_TPREL16_HA
R_PPC64_TPREL16_LO
R_PPC64_TPREL16_HI
R_PPC64_TPREL16_DS
R_PPC64_TPREL16_LO_DS
R_PPC64_TPREL16_HIGHER
R_PPC64_TPREL16_HIGHERA
R_PPC64_TPREL16_HIGHEST
R_PPC64_TPREL16_HIGHESTA

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

llvm-svn: 334304
2018-06-08 17:04:09 +00:00
Rui Ueyama e53890f33e Expand comments.
llvm-svn: 334250
2018-06-08 00:18:32 +00:00
Sam Clegg 177b458c8a [WebAssembly] Add --export-all flag
This causes all symbols to be exported in the final wasm binary
even if they were not compiled with default visibility.

This feature is useful for the emscripten toolchain that has a
corresponding EXPORT_ALL feature which allows the JS code to
interact with all C function.

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

llvm-svn: 334157
2018-06-07 01:27:07 +00:00
Bob Haarman 30913ac39d [COFF] report file containing unsupported relocation
Summary:
When reporting an unsupported relocation type, let's also report the
file we encountered it in to aid diagnosis.

Reviewers: ruiu, rnk

Reviewed By: rnk

Subscribers: llvm-commits

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

llvm-svn: 334154
2018-06-07 00:50:03 +00:00
Rui Ueyama 09bdd222ef Expand the file comment for the error handlers.
Differential Revision: https://reviews.llvm.org/D47790

llvm-svn: 334148
2018-06-07 00:04:47 +00:00
Teresa Johnson 566b402a13 [ThinLTO/lld] Document constant bool ModuleSummaryIndex parameter (NFC)
Makes this consistent with other ModuleSummaryIndex constructor calls.

llvm-svn: 334141
2018-06-06 22:22:13 +00:00
Han Shen 08d1640535 Correct aligment computation for shared object symbols.
The original computation for shared object symbol alignment is wrong when
st_value equals 0. It is very unusual for dso symbols to have st_value equal 0.
But when it happens, it causes obscure run time bugs.

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

llvm-svn: 334135
2018-06-06 21:43:34 +00:00
Rui Ueyama 69685524aa Remove an unrelated file accidentally submitted as part of r334095.
llvm-svn: 334129
2018-06-06 20:46:08 +00:00
Joel Jones a5752e199c [lld] Add REQUIRES: x86 where needed to tests
If building lld without x86 support, tests that require that support should
be treated as unsupported, not errors.

Tested using:
  1. cmake '-DLLVM_TARGETS_TO_BUILD=AArch64;X86'
     make check-lld
     =>
     Expected Passes    : 1406
     Unsupported Tests  : 287

  2. cmake '-DLLVM_TARGETS_TO_BUILD=AArch64'
     make check-lld
     =>
     Expected Passes    : 410
     Unsupported Tests  : 1283

Patch by Joel Jones

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

llvm-svn: 334095
2018-06-06 13:56:51 +00:00
Rui Ueyama 66f28f7cd9 Do not show unrelated "-m is missing" error message.
Previously, "-m is missing" error message is shown if you pass a
nonexistent file or don't pass any file at all to lld, as shown below:

  $ ld.lld nonexistent.o
  ld.lld: error: cannot open nonexistent.o: No such file or directory
  ld.lld: error: target emulation unknown: -m or at least one .o file required

This patch eliminates the second error message because it's not related
and even inaccurate (you passed a .o file though it didn't exist).

llvm-svn: 334024
2018-06-05 16:13:40 +00:00
George Rimar b6480879af [ELF] - Fix BB.
llvm-svn: 333883
2018-06-04 10:47:01 +00:00
George Rimar 64091d5626 [ELF] - Also use DW_AT_linkage_name when gathering information about variables for error messages.
Currently, when LLD do a lookup for variables location, it uses DW_AT_name attribute.
That is not always enough.

Imagine code:

namespace A {
  int bar = 0;
}

namespace Z {
  int bar = 1;
}

int hoho;
In this case there are 3 variables and their debug attributes are following:

A::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x00000006] = "_ZN1A3barE")
Z::bar has: DW_AT_name [DW_FORM_string] ("bar") DW_AT_linkage_name [DW_FORM_strp] ( .debug_str[0x0000003f] = "_ZN1Z3barE")
hoho has: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000004a] = "hoho") and has NO DW_AT_linkage_name attribute. Because it would be
the same as DW_AT_name and DWARF producers avoids emiting excessive data.

Hence LLD should also use DW_AT_linkage_name when it is available.
(currently, LLD fails to report location correctly because thinks that A::bar and Z::bar are the same things)

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

llvm-svn: 333880
2018-06-04 10:28:45 +00:00
Peter Collingbourne 7234acf5bb ELF: Ignore argument after --plugin.
Clang passes --plugin /path/to/LLVMgold.so to the linker when -flto is
passed. After r333607 we only ignore --plugin as a joined argument,
which means that the following argument (/path/to/LLVMgold.so) is
interpreted as an input file. This means that either every LTO'd
program ends up being linked with the gold plugin or we error out
if the plugin does not exist. The fix is to use Eq to ignore both
--plugin=foo and --plugin foo as before.

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

llvm-svn: 333793
2018-06-01 21:51:21 +00:00
Rui Ueyama 92675dff00 Show choices of multiple-choice options in `ld.lld --help` message.
Differential Revision: https://reviews.llvm.org/D47656

llvm-svn: 333792
2018-06-01 21:46:10 +00:00
Zaara Syeda e4da09f920 [PPC64] Add support for initial-exec TLS model
This patch adds the relocations needed support the initial-exec TLS model:
R_PPC64_GOT_TPREL16_HA
R_PPC64_GOT_TPREL16_LO_DS
R_PPC64_GOT_TPREL16_DS
R_PPC64_GOT_TPREL16_HI
R_PPC64_TLS

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

llvm-svn: 333769
2018-06-01 15:20:56 +00:00
Rui Ueyama a3e5d4982e Print out "Alias for -foo" instead of repeating the same help message for -foo.
Since aliases don't actually need name, I removed it from Options.td
to keep the definitions concise.

Before:

  -(                      Ignored for compatibility with GNU unless you pass --warn-backrefs
  -)                      Ignored for compatibility with GNU unless you pass --warn-backrefs
  --allow-multiple-definition Allow multiple definitions
  --apply-dynamic-relocs  Apply dynamic relocations to place
  --as-needed             Only set DT_NEEDED for shared libraries if used
  --auxiliary=<value>     Set DT_AUXILIARY field to the specified name
  --Bdynamic              Link against shared libraries
  --Bshareable            Build a shared object
  ...

After:

  -(                      Alias for --start-group
  -)                      Alias for --end-group
  --allow-multiple-definition Allow multiple definitions
  --apply-dynamic-relocs  Apply dynamic relocations to place
  --as-needed             Only set DT_NEEDED for shared libraries if used
  --auxiliary=<value>     Set DT_AUXILIARY field to the specified name
  --Bdynamic              Link against shared libraries (default)
  --Bshareable            Alias for --shared
  ...

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

llvm-svn: 333694
2018-05-31 20:46:22 +00:00
Taiju Tsuiki 1cb31049af Fix rpath-link handling
Summary:
After r333596, rpath-link no longer consumes the following argument, and
the path argument left by it confuses LLD.

Reviewers: espindola, ruiu

Reviewed By: ruiu

Subscribers: ruiu, emaste, arichardson, llvm-commits

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

llvm-svn: 333686
2018-05-31 19:37:04 +00:00
Sean Fertile 1a8343fce3 [PPC64] Support R_PPC64_GOT_TLSLD16 relocations.
Add support for the R_PPC64_GOT_TLSLD16 relocations used to build the address of
the tls_index struct used in local-dynamic tls.

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

llvm-svn: 333681
2018-05-31 18:44:12 +00:00
Sean Fertile fb613e552a Rename R_TLSGD/R_TLSLD to add _GOT_FROM_END. NFC.
getRelocTargetVA for R_TLSGD and R_TLSLD RelExprs calculate an offset from the
end of the got, so adjust the names to reflect this.

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

llvm-svn: 333674
2018-05-31 18:07:06 +00:00
Rui Ueyama 62716803fe Remove name from unused options. NFC.
This change makes it impossible to use these options in code.

llvm-svn: 333655
2018-05-31 14:10:37 +00:00
Rui Ueyama c2d6418705 Fix formatting. NFC.
llvm-svn: 333654
2018-05-31 14:04:21 +00:00
Nico Weber d657c25649 lld-link: Implement /INTEGRITYCHECK flag
/INTEGRITYCHECK has the effect of setting
IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY. Fixes PR31066.
https://reviews.llvm.org/D47472

llvm-svn: 333652
2018-05-31 13:43:02 +00:00
Rui Ueyama e37a5ce148 Attempt to fix a buildbot.
Broken buildbot log:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/30855/steps/build/logs/stdio

llvm-svn: 333648
2018-05-31 13:24:01 +00:00
Rui Ueyama 312cca50d0 Fix a wrong `ld.lld --help` message.
llvm-svn: 333647
2018-05-31 13:00:38 +00:00
Rui Ueyama f75ea0b995 Implement --{push,pop}-state.
--push-state implemented in this patch saves the states of --as-needed,
--whole-archive and --static. It saves less number of flags than GNU linkers.
Since even GNU linkers save different flags, no one seems to care about the
details. In this patch, I tried to save the minimal number of flags to not
complicate the implementation and the siutation.

I'm not personally happy about adding the --{push,pop}-state flags though.
That options seem too hacky to me. However, gcc started using the options
since GCC 8 when GNU ld is available at the build time. Therefore, lld
is no longer a drop-in replacmenet for GNU linker for that machine
without supporting the flags.

Fixes https://bugs.llvm.org/show_bug.cgi?id=34567

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

llvm-svn: 333646
2018-05-31 13:00:25 +00:00
Rui Ueyama 1c6961d3ba Add "(default)" to default options
This improves the help message shown for `ld.lld --help`.

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

llvm-svn: 333607
2018-05-30 23:32:41 +00:00
Rui Ueyama eea690dae5 Simplify `ld.lld --help` message.
Previously, we printed out two lines of help messages for `--foo bar`
and `--foo=bar` like this:

  --soname=<value>        Set DT_SONAME
  --soname <value>        Set DT_SONAME
  --sort-section=<value>  Specifies sections sorting rule when linkerscript is used
  --sort-section <value>  Specifies sections sorting rule when linkerscript is used

This change eliminates duplicate lines that doesn't contain `=` for such
options like this.

  --soname=<value>        Set DT_SONAME
  --sort-section=<value>  Specifies sections sorting rule when linkerscript is used

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

llvm-svn: 333596
2018-05-30 21:25:53 +00:00
Sam Clegg c729c1b47d [WebAssembly] Initial support for LTO
Differential Revision: https://reviews.llvm.org/D47162

llvm-svn: 333570
2018-05-30 18:07:52 +00:00
Sam Clegg 3d63a409a0 [ELF] Remove -m argument to lld in test files. NFC.
This should be correctly implied by the linker.

This also makes the tests slightly easier to maintain and compare
with the equivalent tests under for other platforms.

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

llvm-svn: 333567
2018-05-30 17:57:08 +00:00
Simon Atanasyan ad6142d57b [ELF][MIPS] Update comments in test cases. NFC
This is a follow-up to the r332374.

llvm-svn: 333516
2018-05-30 08:48:53 +00:00
Sam Clegg bdf8f60126 [ELF] Group LTO options together. NFC.
Differential Revision: https://reviews.llvm.org/D47512

llvm-svn: 333505
2018-05-30 05:01:07 +00:00
Sam Clegg e9ce661e32 [WebAssembly] Add support for response file parsing
Differential Revision: https://reviews.llvm.org/D47500

llvm-svn: 333499
2018-05-30 03:51:56 +00:00
Peter Collingbourne 6c73f9d12f ELF: Run the same test without --thinlto-jobs as we do with --thinlto-jobs.
The comment only made sense a long time ago, when --thinlto-jobs was
tied with --lto-partitions. That was changed in r283817, but the test
wasn't updated at the same time. This patch does so.

llvm-svn: 333480
2018-05-29 23:32:49 +00:00
Shoaib Meenai 663518d61a [COFF] Unify output section code. NFC
Peter Collingbourne suggested moving the switch to the top of the
function, so that all the code that cares about the output section for a
symbol is in the same place.

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

llvm-svn: 333472
2018-05-29 22:49:56 +00:00
Shoaib Meenai 4e51833611 [COFF] Simplify symbol table output section computation
Rather than using a loop to compare symbol RVAs to the starting RVAs of
sections to determine which section a symbol belongs to, just get the
output section of a symbol directly via its chunk, and bail if the
symbol doesn't have an output section, which avoids having to hardcode
logic for handling dead symbols, CodeView symbols, etc. This was
suggested by Reid Kleckner; thank you.

This also fixes writing out symbol tables in the presence of RVA table
input sections (e.g. .sxdata and .gfids). Such sections aren't written
to the output file directly, so their RVA is 0, and the loop would thus
fail to find an output section for them, resulting in a segfault. Extend
some existing tests to cover this case.

Fixes PR37584.

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

llvm-svn: 333450
2018-05-29 19:07:47 +00:00
Jonas Devlieghere 1fc7fc4db8 [COFF] Update CV register names.
Update tests to use the new prefix for CodeView registers added in
r333421.

llvm-svn: 333425
2018-05-29 14:58:41 +00:00
Sean Fertile ef0f7496d1 [PPC64] Support General-Dynamic tls.
Adds handling of all the relocation types for general-dynamic thread local
storage.

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

llvm-svn: 333420
2018-05-29 14:34:38 +00:00
Simon Atanasyan dc86ba4b8b [ELF][MIPS] Add test case to cover handling of microMIPS relocations in 64-bit mode
llvm-svn: 333418
2018-05-29 14:20:05 +00:00
Rui Ueyama 1fa3c728b9 Fix retpoline PLT for x86-64 when used for >4GB address.
Previously, we wrote only the least significant 32 bits.

llvm-svn: 333313
2018-05-25 21:14:45 +00:00
Rui Ueyama 95d6ca52ac Add a comment for retpoline PLT.
llvm-svn: 333312
2018-05-25 21:02:47 +00:00
Rui Ueyama 7ae70fc14a Fix a bug that we truncated GOTPLT entries to 32 bits.
llvm-svn: 333294
2018-05-25 18:26:14 +00:00
James Henderson 620c4ffdab Add llvm-bcanalyzer as an LLD test dependency
Recently an LLD test change was made that introduced the use of
llvm-bcanalyzer. This change adds the tool to the list of LLD test
dependencies.

Reviewed by: rdhindsa, ruiu

Patch by Owen Reynolds.

llvm-svn: 333277
2018-05-25 14:15:02 +00:00
Sean Fertile 4b25b3e4a6 Fix regex in lld ppc64-ifunc test.
One of the regexes for reading in a hex address was missing the a-f part.

llvm-svn: 333209
2018-05-24 17:07:16 +00:00
Sean Fertile fd69969e54 [PPC64] Set the IRelative relocation type.
Set the IRelative relocation type and extend the related test to verify.
Differential Revision: https://reviews.llvm.org/D46877

llvm-svn: 333203
2018-05-24 16:32:14 +00:00
Zaara Syeda 85197a0842 [PPC64] Add .toc section after .got section
PPC64 maintains a compiler managed got in the .toc section. When accessing a
global variable through got-indirect access, a .toc entry is created for the
variable. The relocation for the got-indirect access will refer to the .toc
section rather than the symbol that is actually accessed. The .toc entry
contains the address of the global variable. We evaluate the offset from
r2 (which is the TOC base) to the address of the toc entry for the global
variable. Currently, the .toc is not near the .got. This causes errors because
the offset from r2 to the toc section is too large. The linker needs to add
all the .toc input sections to the .got output section, merging the compiler
managed got with the linker got. This ensures that the offsets from the TOC
base to the toc entries are not too large.

This patch puts the .toc section right after the .got section.

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

llvm-svn: 333199
2018-05-24 15:59:41 +00:00
Fangrui Song bdbe5d8477 Revert "[ELF] Simplify. NFC"
This reverts commit cc6f052261096dc9d4c9d3123e37b023c3e171df.

llvm-svn: 333099
2018-05-23 16:51:23 +00:00
Nicola Zaghen 5c4fb4566d Replace last DEBUG occurrence with LLVM_DEBUG in lld.
llvm-svn: 333084
2018-05-23 14:03:01 +00:00
Peter Collingbourne 7ab7f149b2 ELF: Do not ICF sections named with a C identifier.
A user program may enumerate sections named with a C identifier using
__start_* and __stop_* symbols. We cannot ICF any such sections because
that could change program semantics.

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

llvm-svn: 333054
2018-05-23 02:14:28 +00:00
Peter Collingbourne 11dc7fcae2 ELF: Do not ICF two sections with different output sections.
Note that this doesn't do the right thing in the case where there is
a linker script. We probably need to move output section assignment
before ICF to get the correct behaviour here.

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

llvm-svn: 333052
2018-05-23 01:58:43 +00:00
Sam Clegg 610ac3bd42 [WebAssembly] Fix crash when relocation synbol is not live
When a symbol is GC'd it can still be references by relocations
in the debug sections, but such symbols are not assigned virtual
addresses.

This change adds a new global data symbol which gets GC'd but
should still appears in the output debug info, albeit with a 0
address.

Fixes 37555

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

llvm-svn: 333047
2018-05-23 01:38:00 +00:00
Peter Collingbourne 52d0abd781 Add missing REQUIRES: x86.
llvm-svn: 333043
2018-05-22 23:30:44 +00:00
Peter Collingbourne 3a9e2ca051 ELF: Allow ICF on .data.rel.ro sections.
Differential Revision: https://reviews.llvm.org/D47234

llvm-svn: 333040
2018-05-22 23:22:35 +00:00
Sam Clegg f377030a95 [WebAssembly] Remove dead code from LEB compression pass.
There are only certain relocation types that can exist in the
wasm code section and they are all LEB types.  Remove the dead
code for handling the other (I32) reloc types.

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

llvm-svn: 333030
2018-05-22 20:52:20 +00:00
Sam Clegg 3ad27e92bc Code cleanup in preparation for adding LTO for wasm. NFC.
- Move some common code into Common/rrorHandler.cpp and
  Common/Strings.h.
- Don't use `fatal` when incompatible bitcode files are
  encountered.
- Rename NameRef variable to just Name

See D47162

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

llvm-svn: 333021
2018-05-22 20:20:25 +00:00
Sam Clegg 65a91288fc [WebAssembly] Fix two bugs in LEB compression: properly calculate function body offset, and write I32 values.
* Gets function size field from right location
* Writes I32 values during compression

Patch by Yury Delendik

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

llvm-svn: 333002
2018-05-22 17:06:55 +00:00
Rui Ueyama f1894fe37e Move code to improve readability. NFC.
llvm-svn: 332995
2018-05-22 16:19:38 +00:00
Rui Ueyama 47055bb197 Simplify. NFC.
We can directly assign to a std::pair without std::tie.

llvm-svn: 332994
2018-05-22 16:16:09 +00:00
Fangrui Song bfd08534b0 [ELF] Simplify. NFC
llvm-svn: 332952
2018-05-22 06:28:00 +00:00
Fangrui Song 8d3fcb45e6 CommandFlags.def -> CommandFlags.inc, leftover after r329840
llvm-svn: 332951
2018-05-22 06:12:23 +00:00
Rui Ueyama 0dd56dcdd4 Handle --plugin-opt= options as alias options.
Previously, we had a loop to iterate over options starting with
`--plugin-opt=` and parse them by hand. But we can make OptTable
do that job for us.

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

llvm-svn: 332935
2018-05-22 02:53:11 +00:00
Rui Ueyama 9867c9e2bf Fix typo.
llvm-svn: 332859
2018-05-21 18:12:46 +00:00
James Henderson 1a7aaf3cd5 [ELF] Update due to API change in .debug_line parsing
See r332845.

Reviewed by: grimar

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

llvm-svn: 332846
2018-05-21 15:31:23 +00:00
Richard Trieu 6ac211667d Fix unused variable warning in non-debug builds.
llvm-svn: 332789
2018-05-19 00:37:23 +00:00
Sam Clegg fb983cda8a [WebAssembly] Add option to remove LEB padding at relocate sites
This change adds the ability for lld to remove LEB padding from
code section. This effectively shrinks the size of the resulting
binary in proportion to the number of code relocations.

Since there will be a performance cost this is currently only active for
-O1 and above. Some toolchains may instead want to perform this
compression as a post linker step (for example running a binary through
binaryen will automatically compress these values).

I imagine we might want to make this the default in the future.

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

llvm-svn: 332783
2018-05-18 23:28:05 +00:00
Peter Collingbourne e3f652973e Support: Simplify endian stream interface. NFCI.
Provide some free functions to reduce verbosity of endian-writing
a single value, and replace the endianness template parameter with
a field.

Part of PR37466.

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

llvm-svn: 332757
2018-05-18 19:46:24 +00:00
Han Shen 3aede9283c Mitigate relocation overflow [part 2 of 2]
_init_array_start/end are placed at 0 if no ".init_array" presents,
this causes .text relocation against them become more prone to overflow.
This CL sets ".init_array" address to that of ".text" to mitigate the situation.

Review: https://reviews.llvm.org/D46200
llvm-svn: 332688
2018-05-18 03:01:06 +00:00
Zachary Turner c762666e87 Resubmit [pdb] Change /DEBUG:GHASH to emit 8 byte hashes."
This fixes the remaining failing tests, so resubmitting with no
functional change.

llvm-svn: 332676
2018-05-17 22:55:15 +00:00
Zachary Turner 1de9fce151 Revert "[pdb] Change /DEBUG:GHASH to emit 8 byte hashes."
A few tests haven't been properly updated, so reverting while
I have time to investigate proper fixes.

llvm-svn: 332672
2018-05-17 21:49:25 +00:00
Zachary Turner 3c4c8a0937 [pdb] Change /DEBUG:GHASH to emit 8 byte hashes.
Previously we emitted 20-byte SHA1 hashes.  This is overkill
for identifying debug info records, and has the negative side
effect of making object files bigger and links slower.  By
using only the last 8 bytes of a SHA1, we get smaller object
files and ~10% faster links.

This modifies the format of the .debug$H section by adding a new
value for the hash algorithm field, so that the linker will still
work when its object files have an old format.

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

llvm-svn: 332669
2018-05-17 21:22:48 +00:00
Reid Kleckner ef77870857 Fix lld wasm debug info test on Windows (path separator, sigh)
llvm-svn: 332668
2018-05-17 21:10:31 +00:00
Reid Kleckner f40f85868e [codeview] Include record prefix in global type hashing
The prefix includes type kind, which is important to preserve. Two
different type leafs can easily have the same interior record contents
as another type.

We ran into this issue in PR37492 where a bitfield type record collided
with a const modifier record. Their contents were bitwise identical, but
their kinds were different.

llvm-svn: 332664
2018-05-17 20:47:22 +00:00
Rui Ueyama 52d783962f Fix typo in error message.
llvm-svn: 332658
2018-05-17 20:25:35 +00:00
Rui Ueyama b75d19c36c Make ALIGN work with -r in linker scripts
Patch by Mark Kettenis.

Make ALIGN work in linker scripts used with the -r option. This works in
GNU ld (ld.bfd) and is used to generate the "random gap" object for
linking the OpenBSD kernel.

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

llvm-svn: 332656
2018-05-17 20:22:39 +00:00
Rui Ueyama f06d494f46 Improve error message for -thinlto-object-suffix-replace and simplify code.
llvm-svn: 332643
2018-05-17 18:27:12 +00:00
Zachary Turner c8dd6ccc8a [COFF] Add /Brepro and /TIMESTAMP options.
Previously we would always write a hash of the binary into the
PE file, for reproducible builds.  This breaks AppCompat, which
is a feature of Windows that relies on the timestamp in the PE
header being set to a real value (or at the very least, a value
that satisfies certain properties).

To address this, we put the old behavior of writing the hash
behind the /Brepro flag, which mimics MSVC linker behavior.  We
also match MSVC default behavior, which is to write an actual
timestamp to the PE header.  Finally, we add the /TIMESTAMP
option (an lld extension) so that the user can specify the exact
value to be used in case he/she manually constructs a value which
is both reproducible and satisfies AppCompat.

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

llvm-svn: 332613
2018-05-17 15:11:01 +00:00
George Rimar 848405b164 [ELF] - Do not crash when do --gc-sections for non-allocatable metadata sections.
Currently, LLD marks all non-allocatable sections except SHF_REL[A] as Live
when doing GC.

This can be a reason of the crash when SHF_LINK_ORDER sections
are involved, because their parents can be dead.

We should do GC for them correctly. The patch implements it.

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

llvm-svn: 332589
2018-05-17 10:00:34 +00:00
Fangrui Song 121078bee7 [ELF] PowerOpen ABI -> Power Architecture 64-bit v2 ABI. NFC
Reviewers: sfertile, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 332572
2018-05-17 05:34:29 +00:00
Rumeet Dhindsa d2eb089a0e Add support for ThinLTO plugin option thinlto-object-suffix-replace
Differential Revision: https://reviews.llvm.org/D46608

llvm-svn: 332527
2018-05-16 21:04:08 +00:00
Sam Clegg cfeb646f80 [WebAssembly] Fix R_WEBASSEMBLY_FUNCTION_OFFSET_I32 relocation entries
Fixes: lld: warning: unexpected existing value for R_WEBASSEMBLY_FUNCTION_OFFSET_I32: existing=839 expected=838

The existing solution is trying to erroneously recover correct offset of
the function code from the body (which is not a function segment that
includes its size, locals, and code).

The D46763 is trying to maintain the offset of the function code
allowing properly calculate the new relocation entry.

Patch by Yury Delendik

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

llvm-svn: 332412
2018-05-15 22:27:50 +00:00
Benjamin Kramer 5455038d98 [lld] Make helpers static. NFC.
llvm-svn: 332408
2018-05-15 22:01:54 +00:00
Martin Storsjo 0366155500 [MinGW] Handle the GNU ld option -Map for outputting a linker map
Differential Revision: https://reviews.llvm.org/D46872

llvm-svn: 332398
2018-05-15 21:12:29 +00:00
Han Shen b56030ee9e [lld] Mitigate relocation overflow [part 1 of 2].
This CL places .dynsym and .dynstr at the beginning of SHF_ALLOC
sections. We do this to mitigate the possibility that huge .dynsym and
.dynstr sections placed between ro-data and text sections cause
relocation overflow.

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

llvm-svn: 332374
2018-05-15 17:02:35 +00:00
Fangrui Song c505e06134 Remove \brief commands from doxygen comments.
Summary: This is similar to D46290 D46320.

Reviewers: ruiu, grimar

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 332372
2018-05-15 16:40:54 +00:00
Nicola Zaghen e7245b429b [lld] Update uses of DEBUG macro to LLVM_DEBUG.
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM

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

llvm-svn: 332351
2018-05-15 13:36:20 +00:00
Peter Smith dbef8cc67c [ELF] Implement --keep-unique option
The --keep-unique <symbol> option is taken from gold. The intention is that
<symbol> will be prevented from being folded by ICF. Although not
specifically mentioned in the documentation <symbol> only matches
global symbols, with a warning if the symbol is not found.

The implementation finds the Section defining <symbol> and removes it from
the set of sections considered for ICF.

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

llvm-svn: 332332
2018-05-15 08:57:21 +00:00
Martin Storsjo b7d50115ba [MinGW] Add a LLD specific option -pdb
This allows producing pdb debug info. This is an LLD specific option
since GCC and GNU binutils doesn't support the PDB file format.

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

llvm-svn: 332327
2018-05-15 06:34:18 +00:00
Sam Clegg 65d6380cd6 [WebAssembly] Allow signautre of entry function to be flexible
Since we a no longer using this function for the wasm start
section we don't actually care what its signature is.

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

llvm-svn: 332308
2018-05-14 23:01:16 +00:00