Commit Graph

11788 Commits

Author SHA1 Message Date
Peter Smith d3511a214e [ELF][ARM] Redesign of .ARM.exidx handling to use a SyntheticSection
Instead of creating extra Synthetic .ARM.exidx sections to account for
gaps in the table, create a single .ARM.exidx SyntheticSection that can
derive the contents of the gaps from a sorted list of the executable
InputSections. This has the benefit of moving the ARM specific code for
SyntheticSections in SHF_LINK_ORDER processing and the table merging code
into the ARM specific SyntheticSection. This also makes it easier to create
EXIDX_CANTUNWIND table entries for executable InputSections that don't
have an associated .ARM.exidx section.

Fixes pr40277

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

llvm-svn: 356666
2019-03-21 14:06:40 +00:00
Thomas Lively f6f4f84378 [WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.

The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.

Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.

Reviewers: aheejin, sbc100, dschuff

Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 356610
2019-03-20 20:26:45 +00:00
Robert Lougher 364cb6b5d7 [TailCallElim] Update tests for LTO pipeline change
D58391 changed the LTO pipelines to add the tailcall elimination pass.
This caused three LLD tests to fail.

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

llvm-svn: 356593
2019-03-20 19:05:05 +00:00
Serge Guelton a1aa7a4054 Python 2/3 compatibility
This should be the only change required to have lld's python code base compatible with both Python 2 and Python 3

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

llvm-svn: 356538
2019-03-20 07:42:13 +00:00
Fangrui Song 1092fc9057 [ELF] Allow sh_entsize to be unrelated to sh_addralign and not a power of 2
Summary:
This implements Rui Ueyama's idea in PR39044.
I've checked that ld.bfd and gold do not have the power-of-2 requirement
and do not require sh_entsize to be a multiple of sh_align.

Now on the updated test merge-entsize.s, all the 3 linkers happily
create .rodata that is not 3-byte aligned.

This has a use case in Linux arch/x86/crypto/sha512-avx2-asm.S
It uses sh_entsize of 640, which is not a power of 2.
See https://github.com/ClangBuiltLinux/linux/issues/417

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: nickdesaulniers, E5ten, emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 356428
2019-03-18 23:49:18 +00:00
Alexandre Ganea 4aeea4cc42 [DebugInfo][PDB] Don't write empty debug streams
Before, empty debug streams were written as 8 bytes (4 bytes signature + 4 bytes for the GlobalRefs count).

With this patch, unused empty streams aren't emitted anymore. Modules now encode 65535 as an 'unused stream' value, by convention.
Also fix the * Linker * contrib section which wasn't correctly emitted previously.

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

llvm-svn: 356395
2019-03-18 19:13:23 +00:00
Nico Weber 2b1dca79f2 lld-link: Run conflict-mangled.test on all systems
It seems to pass fine on my Mac, and it running it only on Windows made
me miss it in r355959 and required r355959.

When the test was added in r288992 we still used Win-only
UnDecorateSymbolName() for demangling. Now we use LLVM's
microsoftDemangle() which is cross-platform.

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

llvm-svn: 356380
2019-03-18 16:51:23 +00:00
Siva Chandra 1915e2be93 [ELF] Emit weak-undef symbols in .dynsym of a PIE binary only if linked against shared libs.
Reviewers: espindola

Subscribers: emaste, arichardson, MaskRay, llvm-commits

Tags: #llvm

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

llvm-svn: 356374
2019-03-18 15:32:57 +00:00
George Rimar 738146ab33 [LLD][ELF] - Replace one of the tests with a YAML version.
This removes one more binary from the inputs.

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

llvm-svn: 356334
2019-03-17 15:46:03 +00:00
Fangrui Song 6778b53e95 [ELF] De-virtualize findOrphanPos, excludeLibs and handleARMTlsRelocation
llvm-svn: 356331
2019-03-17 13:53:42 +00:00
Sam Clegg 632c217921 [WebAssembly] Error on R_WASM_MEMORY_ADDR relocations against undefined data symbols.
For these types of relocations an absolute memory address is
required which is not possible for undefined data symbols.  For symbols
that can be undefined at link time (i.e. external data symbols in
shared libraries) a different type of relocation (i.e. via a GOT) will
be needed.

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

llvm-svn: 356310
2019-03-16 01:18:12 +00:00
Fangrui Song 4ac6d7e4b8 [COFF] Delete unused declarations and add a missing forward declaration. NFC
llvm-svn: 356241
2019-03-15 09:40:03 +00:00
Fangrui Song f9695e166b [ELF] Delete unused forward declarations and unused DynamicReloc::getInputSec(). NFC
llvm-svn: 356239
2019-03-15 07:16:39 +00:00
Fangrui Song 76a7ecb3ae [ELF] De-template wrapSymbols, isReserved and addGotEntry. NFC
llvm-svn: 356237
2019-03-15 06:58:23 +00:00
Fangrui Song 639058d7c9 [ELF] Add a test for large .bss.rel.ro
Reviewers: ruiu, pcc, espindola

Reviewed By: pcc

Subscribers: emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 356230
2019-03-15 03:37:42 +00:00
Fangrui Song f4646a0bb1 [ELF] Fix 3 tests after D56828
arm-plt-reloc.s arm-thumb-plt-reloc.s: update offset calculations

pack-dyn-relocs-loop.s: this test is very sensitive to exact section
offsets and sizes. If we comment out the following two lines in
SyntheticSections.cpp, we should reproduce `ld.lld: error: thunk
creation not converged` caused by oscillation of the section size.

  if (RelocData.size() < OldSize)
    RelocData.append(OldSize - RelocData.size(), 0);

Use -z norelro to counteract the layout change (to be more specific,
we have to place .dynamic below .foo so that offset(foo) remains 0x10004)

llvm-svn: 356229
2019-03-15 03:20:13 +00:00
Fangrui Song e8710ef1fb [ELF] Split RW PT_LOAD on the PT_GNU_RELRO boundary
Summary:
Based on Peter Collingbourne's suggestion in D56828.

Before D56828: PT_LOAD(.data PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .bss)
Old:           PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss)
New:           PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)

The new layout reflects the runtime memory mappings.
By having two PT_LOAD segments, we can utilize the NOBITS part of the
first PT_LOAD and save bytes for .bss.rel.ro.

.bss.rel.ro is currently small and only used by copy relocations of
symbols in read-only segments, but it can be used for other purposes in
the future, e.g. if a relro section's statically relocated data is all
zeros, we can move it to .bss.rel.ro.

Reviewers: espindola, ruiu, pcc

Reviewed By: ruiu

Subscribers: nemanjai, jvesely, nhaehnle, javed.absar, kbarton, emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 356226
2019-03-15 01:29:57 +00:00
Alexandre Ganea 3e60ee9f10 [LLD][COFF] Add /summary to print statistics
/summary prints information about the data (OBJ/LIB/PDB) processed by LLD. The goal is have an estimate about the inputs and outputs, to better understand where the timings go.

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

llvm-svn: 356188
2019-03-14 18:45:08 +00:00
Rui Ueyama cc8e4e839f Make a hack for LTO work only when you are actually doing LTO.
We allow an archive file without symbol table as a linker input as a
workaround for a very common error in LTO build. But that logic worked
even for an archive file containing non-bitcode files, which is not
expected. This patch limits that workaround to one that contains only
bitcode files.

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

llvm-svn: 356186
2019-03-14 18:21:32 +00:00
Fangrui Song 07f8daf05e [ELF] Simplify RelRo, TLS, NOBITS section ranks and make RW PT_LOAD start with RelRo
Old: PT_LOAD(.data | PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .bss)
New: PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) | .data .bss)

The placement of | indicates page alignment caused by PT_GNU_RELRO. The
new layout has simpler rules and saves space for many cases.

Old size: roundup(.data) + roundup(.data.rel.ro)
New size: roundup(.data.rel.ro + .bss.rel.ro) + .data

Other advantages:

* At runtime the 3 memory mappings decrease to 2.
* start(PT_TLS) = start(PT_GNU_RELRO) = start(RW PT_LOAD). This
  simplifies binary manipulation tools.
  GNU strip before 2.31 discards PT_GNU_RELRO if its
  address is not equal to the start of its associated PT_LOAD.
  This has been fixed by https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2731e0c374e5323ce4cdae2bcc7b7fe22da1a6f
  But with this change, we will be compatible with GNU strip before 2.31
* Before, .got.plt (non-relro by default) was placed before .got (relro
  by default), which made it impossible to have _GLOBAL_OFFSET_TABLE_
  (start of .got.plt on x86-64) equal to the end of .got (R_GOT*_FROM_END)
  (https://bugs.llvm.org/show_bug.cgi?id=36555). With the new ordering, we
  can improve on this regard if we'd like to.

Reviewers: ruiu, espindola, pcc

Subscribers: emaste, arichardson, llvm-commits, joerg, jdoerfert

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

llvm-svn: 356117
2019-03-14 03:47:45 +00:00
Sam Clegg a688a42cdd [WebAssembly] Improve support for "needed" list in dylink section
This change adds basic support for shared library dependencies
via the dylink section.

See https://github.com/WebAssembly/tool-conventions/pull/77

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

llvm-svn: 356102
2019-03-13 21:29:20 +00:00
Simon Atanasyan 2e855675eb [mips] Remove redundant setup of less-significant bit. NFC
The less-significant bit for microMIPS symbols configured
in the `getSymVA` function. Do not need to setup it once again.

llvm-svn: 356058
2019-03-13 16:00:35 +00:00
Sam Clegg d425d6b08b [WebAssembly] Handle undefined data symbols in shared libraries
When linking shared libraries, we import a mutable wasm global
to represent the address of each undefined data symbol.

This is a step towards supporting dynamic linking and shared
libraries.

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

llvm-svn: 355988
2019-03-12 21:53:23 +00:00
Francis Visoiu Mistrih dd42236c6c Reland "[Remarks] Add -foptimization-record-passes to filter remark emission"
Currently we have -Rpass for filtering the remarks that are displayed as
diagnostics, but when using -fsave-optimization-record, there is no way
to filter the remarks while generating them.

This adds support for filtering remarks by passes using a regex.
Ex: `clang -fsave-optimization-record -foptimization-record-passes=inline`

will only emit the remarks coming from the pass `inline`.

This adds:

* `-fsave-optimization-record` to the driver
* `-opt-record-passes` to cc1
* `-lto-pass-remarks-filter` to the LTOCodeGenerator
* `--opt-remarks-passes` to lld
* `-pass-remarks-filter` to llc, opt, llvm-lto, llvm-lto2
* `-opt-remarks-passes` to gold-plugin

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

Original llvm-svn: 355964

llvm-svn: 355984
2019-03-12 21:22:27 +00:00
Peter Collingbourne 8a28673a2e ELF: Don't add .dynamic strings to .dynstr early.
This does not appear to be necessary because StringTableSection does not
need to be finalized, which also means that we can remove the call to
finalizeSynthetic on .dynstr.

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

llvm-svn: 355977
2019-03-12 20:58:34 +00:00
Francis Visoiu Mistrih 1d6c47ad2b Revert "[Remarks] Add -foptimization-record-passes to filter remark emission"
This reverts commit 20fff32b7d.

llvm-svn: 355976
2019-03-12 20:54:18 +00:00
Peter Collingbourne e2b8c40a77 ELF: Use bump pointer allocator for uncompressed section buffers. NFCI.
This shaves another word off SectionBase and makes it possible to clone a
section using the implicit copy constructor.

This basically reverts r311056, which removed the mutex in order to
make the code easier to understand. On balance I think it's probably more
straightforward to have a mutex here than to have an unusual copy constructor
in SectionBase.

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

llvm-svn: 355966
2019-03-12 20:32:30 +00:00
Francis Visoiu Mistrih 20fff32b7d [Remarks] Add -foptimization-record-passes to filter remark emission
Currently we have -Rpass for filtering the remarks that are displayed as
diagnostics, but when using -fsave-optimization-record, there is no way
to filter the remarks while generating them.

This adds support for filtering remarks by passes using a regex.
Ex: `clang -fsave-optimization-record -foptimization-record-passes=inline`

will only emit the remarks coming from the pass `inline`.

This adds:

* `-fsave-optimization-record` to the driver
* `-opt-record-passes` to cc1
* `-lto-pass-remarks-filter` to the LTOCodeGenerator
* `--opt-remarks-passes` to lld
* `-pass-remarks-filter` to llc, opt, llvm-lto, llvm-lto2
* `-opt-remarks-passes` to gold-plugin

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

llvm-svn: 355964
2019-03-12 20:28:50 +00:00
Douglas Yung c61573c93f Fixup test to work after changes in r355878.
This should fix the PS4 Windows build bot.

llvm-svn: 355959
2019-03-12 20:04:03 +00:00
Peter Collingbourne 2da7b32684 ELF: Simplify. NFCI.
We don't need to take a slice of SectionCommands in addOrphanSections()
because it is not modified until the end of the function.

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

llvm-svn: 355954
2019-03-12 19:19:23 +00:00
Xing GUO 08dc382465 fix break tests after rL355922. NFCI
llvm-svn: 355925
2019-03-12 14:58:01 +00:00
George Rimar 43b6689e64 [LLD][ELF] - Show symbols visibility in "undefined symbol..." error messages.
This teaches LLD to report visibility when showing undefined symbol errors
and fixes https://bugs.llvm.org/show_bug.cgi?id=40770.

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

llvm-svn: 355909
2019-03-12 11:10:29 +00:00
Eli Friedman 5b1027a908 Fix test to unconditionally create a GNU-format archive.
On Darwin targets, llvm-ar creates a Darwin format archive by default,
which ld.lld can't read, so it was printing an unexpected error.

llvm-svn: 355894
2019-03-12 02:20:01 +00:00
Peter Collingbourne b5a307fa24 ELF: Remove dead code. NFCI.
The Live bit is already set to false by SectionBase.

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

llvm-svn: 355893
2019-03-12 02:18:03 +00:00
Eli Friedman 3751ae4a94 [ELF] Print a better error for an archive containing a non-ELF file.
Hopefully gives a more readable error message for the most obvious
mistake.

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

llvm-svn: 355888
2019-03-12 01:24:39 +00:00
Rui Ueyama 033c4d2126 Include an archive file name in an error message for a corrupted file.
Differential Revision: https://reviews.llvm.org/D59212

llvm-svn: 355886
2019-03-12 00:24:34 +00:00
Nico Weber 020d92cb61 lld-link: Only print demangled symbol names by default
This makes lld-link's output a bit more concise. Since most developers can't
read mangled names, this should make the output a bit easier to understand as
well. It also makes lld-link's output consistent with ld.lld's output.

(link.exe prints both demangled and mangled names; lld-link used to match
link.exe output but now no longer does.)

For people working on toolchains, add a `/demangle:no` flag that makes lld-link
print the mangled name instead of the demangled name. (If desired, people could
pipe that through `demumble -b` to get the old behavior of both demangled and
mangled output.)

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

llvm-svn: 355878
2019-03-11 23:02:18 +00:00
Rong Xu f92e59cbba [PGO] Add options for context-sensitive PGO
Add lld options for CSPGO (context-sensitive PGO).

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

llvm-svn: 355876
2019-03-11 22:51:38 +00:00
Rui Ueyama 7fd99fc475 Fail early if an output file is not writable
Fixes https://bugs.llvm.org/show_bug.cgi?id=36478

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

llvm-svn: 355834
2019-03-11 16:30:55 +00:00
Mitch Phillips 88bea2b49b [LLD] Fixed flaky unit test based on build directory.
This unit test fails if 'zed' appears in your build path, as lld is
echoing out the path of the source file. Change the unit test to
explicitly only match everything after the 'Symbols [' line of the
output, to make sure that this test doesn't inadvertently fail due to
the build path.

llvm-svn: 355748
2019-03-08 22:33:22 +00:00
Sam Clegg d15a4154a8 [WebAssembly] Don't mark lazy symbols as `IsUsedInRegularObj`
This matches the ELF does.  Update the comment in ELF/Symbols.h and
duplicate it in wasm/Symbols.h

This a followup on rL355580 and rL355577.

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

llvm-svn: 355737
2019-03-08 21:10:48 +00:00
Peter Collingbourne dfbb9a793e ELF: Reduce the size of InputSectionBase by two words. NFCI.
- The Assigned bit was previously taking a word on its own. Move
  it into the bit fields in SectionBase.
- NumRelocations and AreRelocsRela were previously also taking up
  a word despite only using half of it. Move them into the alignment gap
  after SectionBase's fields.

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

llvm-svn: 355622
2019-03-07 18:48:12 +00:00
Petar Jovanovic c8955e2293 fix expected format in test/ELF/eh-frame-hdr-augmentation.s
Follow-up for r355605.
Fix expected format in test/ELF/eh-frame-hdr-augmentation.s

llvm-svn: 355621
2019-03-07 18:28:44 +00:00
Alexandre Ganea a5ecceed1f [LLD][COFF] Restrict the failifmismatch test to x86_64-windows-msvc because the ELF container doesn't support llvm.linker.options meta-data with only one operand.
llvm-svn: 355602
2019-03-07 15:07:55 +00:00
Alexandre Ganea e7ec39c123 [LLD][COFF] Attempt fix for failifmismatch test on aarch64-only builder.
Shall fix: http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/6150

llvm-svn: 355595
2019-03-07 13:32:29 +00:00
Sam Clegg 9361217ea2 [WebAssembly] Fix build after rL355577
Turns own that IsUsedInRegularObject is set for lazy (archive) symbols.

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

llvm-svn: 355580
2019-03-07 04:20:04 +00:00
Sam Clegg 815a05ca6b [WebAssembly] LTO: Don't include bitcode-only symbols in the symtab
Fixes https://bugs.llvm.org/show_bug.cgi?id=40654

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

llvm-svn: 355577
2019-03-07 02:43:19 +00:00
Alexandre Ganea d8ec81059e [LLD][COFF] More detailed information for /failifmismatch
When mismatched #pragma detect_mismatch declarations occur, now print the conflicting OBJs.

  lld-link: error: /failifmismatch: mismatch detected for 'TEST':
  >>> test.obj has value 1
  >>> test2.obj has value 2

Fixes PR38579

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

llvm-svn: 355543
2019-03-06 20:18:38 +00:00
George Rimar a033572d67 [LLD][ELF] - Convert common-symbol-alignment.s test to yaml.
This removes 2 precompiled binaries from the inputs.

llvm-svn: 355500
2019-03-06 13:49:41 +00:00
George Rimar d024a9fab3 [LLD][ELF] - Remove unused invalid input object. NFC.
It was introduced by me in 2016: r290335,
but the test did contain the YAML from start,
I think it was committed by mistake.

llvm-svn: 355497
2019-03-06 12:37:46 +00:00