Commit Graph

4478 Commits

Author SHA1 Message Date
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 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
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
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
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
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
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
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
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
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 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
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 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 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 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
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
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
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
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
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