Commit Graph

11863 Commits

Author SHA1 Message Date
Rui Ueyama 8521ba37d7 Make a member function a non-member function.
Since this member function doesn't use anything in the class,
it doesn't have to be a member of the class.

llvm-svn: 357193
2019-03-28 17:35:00 +00:00
Rui Ueyama 676d25ab94 De-template X86_64TargetInfo. NFC.
llvm-svn: 357191
2019-03-28 17:31:12 +00:00
Benjamin Kramer ba2ea93ad1 Make helper functions static. NFC.
llvm-svn: 357187
2019-03-28 17:18:42 +00:00
Rui Ueyama c694633a12 Make TargetInfo const. NFC.
We do not mutate a TargetInfo instance after creating it. This change
makes it explicit.

llvm-svn: 357185
2019-03-28 17:05:09 +00:00
Peter Smith 3ce9af9370 [ELF][ARM] Recommit Redesign of .ARM.exidx handling to use a SyntheticSection
Recommit r356666 with fixes for buildbot failure, as well as handling for
--emit-relocs, which we decide not to emit any relocation sections as the
table is already position independent and an offline tool can deduce the
relocations.

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: 357160
2019-03-28 11:10:20 +00:00
Sam Clegg a9958fc30d [WebAssembly] Fix typo from rL357143
llvm-svn: 357144
2019-03-28 02:04:31 +00:00
Sam Clegg 0805ec5f7b [WebAssembly] Improve invalid relocation error message
This message now matches the equivalent message in the ELF linker.

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

llvm-svn: 357143
2019-03-28 02:02:07 +00:00
Rui Ueyama a0a50a7a5b Inline a trivial function. NFC.
I found that hiding this particular actual expression doesn't help
readers understand the code. So I remove and inline that function.

llvm-svn: 357140
2019-03-28 01:37:48 +00:00
Rui Ueyama 432030e843 [ELF] Dump symbols ordered by profiled guided section layout to file.
Patch by Tiancong Wang.

In D36351, Call-Chain Clustering (C3) heuristic is implemented with
option --call-graph-ordering-file <file>.
This patch adds a flag --print-symbol-order=<file> to LLD, and when
specified, it prints out the symbols ordered by the heuristics to the
file. The symbols printout is helpful to those who want to understand
the heuristics and want to reproduce the ordering with
--symbol-ordering-file in later pass.

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

llvm-svn: 357133
2019-03-27 23:52:22 +00:00
Andrew Ng e6b6ab2c66 [LLD] Restore tests that use "-" as output
No longer require workarounds for output to "-" (stdout) for
Windows. These workarounds were just hiding the actual problem which has
been fixed in r357058.

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

llvm-svn: 357072
2019-03-27 15:30:52 +00:00
Ali Tamur cea9548028 Revert "[lld] Reapply "Prevent duplicate files in debug line header in dwarf 5.""
This reverts commit rL357020

Reason: rL357018, which this commit depend on breaks the test:
llvm/test/tools/llvm-objdump/embedded-source.test on some architectures.

llvm-svn: 357025
2019-03-26 19:57:13 +00:00
Sam Clegg 492f752969 [WebAssembly] Initial implementation of PIC code generation
This change implements lowering of references global symbols in PIC
mode.

This change implements lowering of global references in PIC mode using a
new @GOT reference type. @GOT references can be used with function or
data symbol names combined with the get_global instruction. In this case
the linker will insert the wasm global that stores the address of the
symbol (either in memory for data symbols or in the wasm table for
function symbols).

For now I'm continuing to use the R_WASM_GLOBAL_INDEX_LEB relocation
type for this type of reference which means that this relocation type
can refer to either a global or a function or data symbol. We could
choose to introduce specific relocation types for GOT entries in the
future.  See the current dynamic linking proposal:

https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md

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

llvm-svn: 357022
2019-03-26 19:46:15 +00:00
Ali Tamur 5c2f176ccc [lld] Reapply "Prevent duplicate files in debug line header in dwarf 5."
Reapply rL356943; the previous attempt was reverted because the patch rL356941
that this depended on had broken a test.

Original commit message:

[lld] Prevent duplicate files in debug line header in dwarf 5.

Tags: #llvm

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

llvm-svn: 357020
2019-03-26 18:59:52 +00:00
Thomas Lively 82de51a3ae Reland "[WebAssembly] Add linker options to control feature checking"
Do not pipe binary data between processes in lit tests this time,
since it turns out that can break on Windows.

This reverts commit 84c8652fc3.

llvm-svn: 356975
2019-03-26 04:11:05 +00:00
Fangrui Song 210949a221 [ELF] Change GOT*_FROM_END (relative to end(.got)) to GOTPLT* (start(.got.plt))
Summary:
This should address remaining issues discussed in PR36555.

Currently R_GOT*_FROM_END are exclusively used by x86 and x86_64 to
express relocations types relative to the GOT base. We have
_GLOBAL_OFFSET_TABLE_ (GOT base) = start(.got.plt) but end(.got) !=
start(.got.plt)

This can have problems when _GLOBAL_OFFSET_TABLE_ is used as a symbol, e.g.
glibc dl_machine_dynamic assumes _GLOBAL_OFFSET_TABLE_ is start(.got.plt),
which is not true.

  extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
  return _GLOBAL_OFFSET_TABLE_[0]; // R_X86_64_GOTPC32

In this patch, we

* Change all GOT*_FROM_END to GOTPLT* to fix the problem.
* Add HasGotPltOffRel to denote whether .got.plt should be kept even if
  the section is empty.
* Simplify GotSection::empty and GotPltSection::empty by setting
  HasGotOffRel and HasGotPltOffRel according to GlobalOffsetTable early.

The change of R_386_GOTPC makes X86::writePltHeader simpler as we don't
have to compute the offset start(.got.plt) - Ebx (it is constant 0).

We still diverge from ld.bfd (at least in most cases) and gold in that
.got.plt and .got are not adjacent, but the advantage doing that is
unclear.

Reviewers: ruiu, sivachandra, espindola

Subscribers: emaste, mehdi_amini, arichardson, dexonsmith, jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 356968
2019-03-25 23:46:19 +00:00
Rui Ueyama e6c24299d2 Use a class instead of lambda-based callbacks to organize garbage collector.
lld's mark-sweep garbage collector was written in the visitor pattern.
There are functions that traverses a given graph, and the functions calls
callback functions to dispatch according to node type.

The code was originaly pretty simple, and lambdas worked pretty
well. However, as we add more features to the garbage collector, that became
more like a callback hell. We now have a callback function that wraps
another callback function, for example. It is not easy to follow the flow of
the control.

This patch rewrites it as a regular class. What was once a lambda is now a
regular class member function. I think this change fixes the readability
issue.

No functionality change intended.

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

llvm-svn: 356966
2019-03-25 23:28:47 +00:00
Ali Tamur 800fe977d0 Revert "[lld] Prevent duplicate files in debug line header in dwarf 5."
This reverts commit 5aa7478a55.

Some things are broken; I will fix and try to commit again.

llvm-svn: 356949
2019-03-25 21:06:02 +00:00
Ali Tamur 5aa7478a55 [lld] Prevent duplicate files in debug line header in dwarf 5.
Summary:
Changes to a couple of tests that will start failing after https://reviews.llvm.org/D59515 is submitted.

Reviewers: echristo, ruiu, espindola

Reviewed By: echristo, ruiu

Subscribers: emaste, arichardson, MaskRay, llvm-commits

Tags: #llvm

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

llvm-svn: 356943
2019-03-25 20:18:27 +00:00
Thomas Lively 84c8652fc3 Revert "[WebAssembly] Add linker options to control feature checking"
This reverts commit 5991328c96.

llvm-svn: 356932
2019-03-25 18:10:26 +00:00
Alexandre Ganea 74d5b33222 [LLD][COFF] Separate module descriptors creation from type/symbol merging
Take module DBI creation out of PDBLinker::addObjFile() into its own function.

This is groundwork towards parallelizable type merging, as proposed in D59226.

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

llvm-svn: 356815
2019-03-22 22:07:27 +00:00
Rui Ueyama d2e0ed7755 Simplify PltSection.
Previously, `Entries` contains pairs of symbols and their indices.
The indices are always 0, x, 2x, 3x, ..., where x is the size of
relocation entry. We didn't have to store that values because we can
compute them when we consume them.

llvm-svn: 356812
2019-03-22 21:17:25 +00:00
Thomas Lively 5991328c96 [WebAssembly] Add linker options to control feature checking
Summary:
Adds --check-features and --no-check-features. The default for now is
to enable the checking, but this might change in the future.

Also adds --features=foo,bar for precisely controlling the features
used in the output binary.

Depends on D59173.

Reviewers: sbc100, aheejin

Subscribers: dschuff, jgravelle-google, sunfish, jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 356805
2019-03-22 20:43:06 +00:00
Fangrui Song dc6c0cf94d [DWARF] Refactor RelocVisitor and fix computation of SHT_RELA-typed relocation entries
Summary: This is the lld-side change of D57939

Reviewers: echristo, dblaikie, ruiu, espindola

Reviewed By: echristo, ruiu

Subscribers: jdoerfert, emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 356730
2019-03-22 02:43:17 +00:00
Reid Kleckner 05ea3a6be3 Fix lld wasm tests after r356610
Apparently stdout is not opened in binary mode, so the executable gets
corrupted when piping to obj2yaml.

llvm-svn: 356694
2019-03-21 18:24:05 +00:00
Peter Smith 54dab70bb7 [ELF][ARM] Revert Redesign of .ARM.exidx handling to use a SyntheticSection
There is a reproducible buildbot failure (segfault) on the 2 stage
clang-cmake-armv8-lld bot. Reverting while I investigate.

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

llvm-svn: 356684
2019-03-21 17:17:54 +00:00
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
Peter Collingbourne 5ee9abd4c8 ELF: De-template OutputSection::finalize() and MipsGotSection::build(). NFCI.
Differential Revision: https://reviews.llvm.org/D58810

llvm-svn: 355479
2019-03-06 03:07:57 +00:00
Peter Collingbourne 704dfd6e28 ELF: Extract a non-ELFT base class for VersionNeedSection.
We're going to need a separate VersionNeedSection for each partition, and
the partition data structure won't be templated.

With this the VersionTableSection class no longer needs ELFT, so detemplate it.

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

llvm-svn: 355478
2019-03-06 03:07:48 +00:00
Heejin Ahn 47db2262eb [WebAssembly] Test change after disabling MachineBlockPlacement
Summary:
We disabled MachineBlockPlacement pass in D58953, and this test result
changes as the result of it.

Reviewers: kripken

Subscribers: dschuff, sbc100, jgravelle-google, sunfish, llvm-commits

Tags: #llvm

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

llvm-svn: 355438
2019-03-05 20:36:20 +00:00
Fangrui Song 5eaa55f616 [ELF][test] chmod u+w to prevent annoying rm prompt
If the permission does not permit writing and the standard input is a
terminal, rm gives an annoying prompt. chmod u+w to make the output
directory easier to delete.

llvm-svn: 355382
2019-03-05 09:56:50 +00:00
Alexey Lapshin ded118079b [LLD] add test for line number info related to differrent .text sections
There is a bug for llvm-objdump which incorrectly reported line number
   info for object file if several .text sections presented.
   https://bugs.llvm.org/show_bug.cgi?id=40703 .
   This patch adds test for the same situation.

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

llvm-svn: 355306
2019-03-04 10:42:54 +00:00
Sam Clegg 61f13b3f30 [WebAssembly] Fix crash when __wasm_call_ctor is GCd in programs containing static init/fini
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

Tags: #llvm

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

llvm-svn: 355263
2019-03-02 04:55:02 +00:00
Sam Clegg 0e6b42f5eb [WebAssebmly] Allow __wasm_call_ctors to be GC'ed
Differential Revision: https://reviews.llvm.org/D58806

llvm-svn: 355240
2019-03-01 22:35:47 +00:00
Peter Collingbourne 16d9a0acfd ELF: Change FileSize back to a uint64_t.
This lets us detect file size overflows when creating a 64-bit binary on
a 32-bit machine.

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

llvm-svn: 355218
2019-03-01 18:53:41 +00:00
Matt Davis b95daf0b77 [lld][test] Fix tests. llvm-readobj now emits symbol section names.
This is the result of patch 99e9c4cad08164b9c0ca565ab9ad48ce132e98e5
See the related patch https://reviews.llvm.org/D58796

llvm-svn: 355211
2019-03-01 18:01:41 +00:00
George Rimar aee005291c [LLD][ELF] - Convert 3 testcases to use yaml instead of binaries.
This change makes 3 tests to use yaml instead of binaries.

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

llvm-svn: 355196
2019-03-01 10:58:45 +00:00
Peter Smith 22ce712c19 [ELF][ARM] Fix clang-armv7-linux-build-cache builds of LLD [NFC]
r355153 introduced a build failure on a build bot that uses clang natively
on an armv7-a machine. This a temporary fix to use size_t rather than
uint64_t.

llvm-svn: 355195
2019-03-01 10:52:25 +00:00
George Rimar f56def4ea4 [LLD][ELF] - Convert invalid/undefined-local-symbol-in-dso.test to use YAML
This removes a binary from the inputs and reduces the test case.

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

llvm-svn: 355194
2019-03-01 10:37:51 +00:00
Fangrui Song 7507208a9a [ELF] Explain some options in ld.lld.1
Reviewers: ruiu, grimar

Reviewed By: ruiu

Subscribers: srhines, jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 355173
2019-03-01 04:49:42 +00:00
Peter Collingbourne 7fb9eabda5 ELF: Write .eh_frame_hdr explicitly after writing .eh_frame.
This lets us remove the special case from Writer::writeSections(), and also
fixes a bug where .eh_frame_hdr isn't necessarily written in the correct
order if a linker script moves .eh_frame and .eh_frame_hdr into the same
output section.

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

llvm-svn: 355153
2019-02-28 23:11:35 +00:00
Reid Kleckner 7818144ff3 [COFF] Add address-taken import thunks to the fid table
Summary: Fixes PR39799

Reviewers: dmajor, hans

Subscribers: jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 355141
2019-02-28 21:05:41 +00:00
Thomas Lively f3b4f99007 [WebAssembly] Remove uses of ThreadModel
Summary:
In the clang UI, replaces -mthread-model posix with -matomics as the
source of truth on threading. In the backend, replaces
-thread-model=posix with the atomics target feature, which is now
collected on the WebAssemblyTargetMachine along with all other used
features. These collected features will also be used to emit the
target features section in the future.

The default configuration for the backend is thread-model=posix and no
atomics, which was previously an invalid configuration. This change
makes the default valid because the thread model is ignored.

A side effect of this change is that objects are never emitted with
passive segments. It will instead be up to the linker to decide
whether sections should be active or passive based on whether atomics
are used in the final link.

Reviewers: aheejin, sbc100, dschuff

Subscribers: mehdi_amini, jgravelle-google, hiraditya, sunfish, steven_wu, dexonsmith, rupprecht, jfb, jdoerfert, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

llvm-svn: 355112
2019-02-28 18:39:08 +00:00
George Rimar c6846b8800 [LLD][ELF] - Stop using binary input in invalid/tls-symbol.s test. NFCI.
We can use yaml2obj instead, patch does this.

llvm-svn: 355075
2019-02-28 09:24:12 +00:00
Alexandre Ganea 97b2b0636b [LLD][COFF] Support /threads[:no] like the ELF driver
Differential review: https://reviews.llvm.org/D58594

llvm-svn: 355029
2019-02-27 20:53:50 +00:00
Alexey Lapshin 77fc1f6049 [DebugInfo] add SectionedAddress to DebugInfo interfaces.
That patch is the fix for https://bugs.llvm.org/show_bug.cgi?id=40703
   "wrong line number info for obj file compiled with -ffunction-sections"
   bug. The problem happened with only .o files. If object file contains
   several .text sections then line number information showed incorrectly.
   The reason for this is that DwarfLineTable could not detect section which
   corresponds to specified address(because address is the local to the
   section). And as the result it could not select proper sequence in the
   line table. The fix is to pass SectionIndex with the address. So that it
   would be possible to differentiate addresses from various sections. With
   this fix llvm-objdump shows correct line numbers for disassembled code.

   Differential review: https://reviews.llvm.org/D58194

llvm-svn: 354972
2019-02-27 13:17:36 +00:00
George Rimar cc19dc75fb [LLD][ELF] - Improve "sh_addralign is not a power of 2" diagnostics.
This patch removes the precompiled binary from inputs,
replacing it with a YAML. And teaches LLD to report a
section name in case of such error.

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

llvm-svn: 354959
2019-02-27 10:28:23 +00:00
Bill Wendling 01706bda5b Output ELF files after ThinLTO is run.
Summary:
The gold linker allowed you to output the ELF files after LTO was run. It did
it by using the 'obj-path' option. This replicates that behavior.

Reviewers: espindola, ruiu, MaskRay, pcc

Reviewed By: MaskRay, pcc

Subscribers: grimar, emaste, inglorion, arichardson, steven_wu, dexonsmith, llvm-commits

Tags: #llvm

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

llvm-svn: 354917
2019-02-26 19:29:14 +00:00
Simon Atanasyan 478cd32bcb [mips] Reduce number of tools invocations in the test. NFC
llvm-svn: 354772
2019-02-25 11:30:33 +00:00
Peter Smith 777e1cfdc3 [ELF][ARM] Accept and ignore -p and -no-pipleline-knowledge
The linux kernel uses an old flag -p/-no-pipeline-knowledge that is
accepted by bfd and gold but ignored by modern versions of them. The
original option is very old and is pre-ABI, it sometimes comes up in
code-bases that had support for pre ABI toolchains. The Linux kernel uses
it in 3 places in the ARM specific section.

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

llvm-svn: 354769
2019-02-25 10:48:31 +00:00
Alexandre Ganea d307c4c47f [LLD][COFF] Add support for /FUNCTIONPADMIN command-line option
Initial patch by Stefan Reinalter.

Fixes PR36775

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

llvm-svn: 354716
2019-02-23 01:46:18 +00:00
Rui Ueyama 5945ad5c43 Split a long line to avoid annoying horizontal scrolling on a browser.
llvm-svn: 354707
2019-02-23 00:24:18 +00:00