Commit Graph

12081 Commits

Author SHA1 Message Date
Fangrui Song bc4b159bb1 [ELF][X86] Allow R_386_TLS_LDO_32 and R_X86_64_DTPOFF{32,64} to preemptable local-dynamic symbols
Summary:
Fixes PR35242. A simplified reproduce:

    thread_local int i; int f() { return i; }

% {g++,clang++} -fPIC -shared -ftls-model=local-dynamic -fuse-ld=lld a.cc
ld.lld: error: can't create dynamic relocation R_X86_64_DTPOFF32 against symbol: i in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

In isStaticLinkTimeConstant(), Syn.IsPreemptible is true, so it is not
seen as a constant. The error is then issued in processRelocAux().

A symbol of the local-dynamic TLS model cannot be preempted but it can
preempt symbols of the global-dynamic TLS model in other DSOs.
So it makes some sense that the variable is not static.

This patch fixes the linking error by changing getRelExpr() on
R_386_TLS_LDO_32 and R_X86_64_DTPOFF{32,64} from R_ABS to R_DTPREL.
R_PPC64_DTPREL_* and R_MIPS_TLS_DTPREL_* need similar fixes, but they are not handled in this patch.

As a bonus, we use `if (Expr == R_ABS && !Config->Shared)` to find
ld-to-le opportunities. R_ABS is overloaded here for such STT_TLS symbols.
A dedicated R_DTPREL is clearer.

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

llvm-svn: 358870
2019-04-22 03:10:40 +00:00
Fangrui Song e1f3191a0d [ELF][X86] Rename R_RELAX_TLS_GD_TO_IE_END to R_RELAX_TLS_GD_TO_IE_GOTPLT
Summary:
This relocation type is used by R_386_TLS_GD. Its formula is the same as
R_GOTPLT (e.g R_X86_64_GOT{32,64} R_386_TLS_GOTIE). Rename it to be clearer.

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

llvm-svn: 358868
2019-04-22 02:48:37 +00:00
George Rimar 5f7665969a [LLD][ELF] - Fix mistype. NFC.
Change the tripple name from
aarch64-linux-gnux to -triple=aarch64-linux-gnu

llvm-svn: 358810
2019-04-20 10:50:27 +00:00
Thomas Lively 84771e2d21 [WebAssembly] Emit the DataCount section when bulk memory is enabled
Summary:
The DataCount section is necessary for the bulk memory operations
memory.init and data.drop to validate, but it is not recognized by
engines that do not support bulk memory, so emit the section only if
bulk-memory is enabled.

Reviewers: aheejin, dschuff, sbc100

Subscribers: jgravelle-google, sunfish, llvm-commits

Tags: #llvm

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

llvm-svn: 358798
2019-04-19 23:40:36 +00:00
Reid Kleckner a30920c31f [COFF] Pack Name in Symbol as is done in ELF
Summary:
This assumes all symbols are <4GB long, so we can store them as a 32-bit
integer. This reorders the fields so the length appears first, packing
with the other bitfield data in the base Symbol object.

This saved 70MB / 3.60% of heap allocations when linking
browser_tests.exe with no PDB. It's not much as a percentage, but worth
doing. I didn't do performance measurements, I don't think it will be
measurable in time.

Reviewers: ruiu, inglorion, amccarth, aganea

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 358794
2019-04-19 22:51:49 +00:00
Martin Storsjo 2c1f3ea538 [MinGW] Add an --appcontainer flag, passed through to lld-link
GNU ld doesn't have such a flag though, so this is a lld specific
option.

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

llvm-svn: 358759
2019-04-19 13:50:43 +00:00
Ali Tamur 783d84bb39 [llvm] Prevent duplicate files in debug line header in dwarf 5: another attempt
Another attempt to land the changes in debug line header to prevent duplicate
files in Dwarf 5. I rolled back my previous commit because of a mistake in
generating the object file in a test. Meanwhile, I addressed some offline
comments and changed the implementation; the largest difference is that
MCDwarfLineTableHeader does not keep DwarfVersion but gets it as a parameter. I
also merged the patch to fix two lld tests that will strt to fail into this
patch.

Original Commit:

https://reviews.llvm.org/D59515

Original Message:
Motivation: In previous dwarf versions, file name indexes started from 1, and
the primary source file was not explicit. Dwarf 5 standard (6.2.4) prescribes
the primary source file to be explicitly given an entry with an index number 0.

The current implementation honors the specification by just duplicating the
main source file, once with index number 0, and later maybe with another
index number. While this is compliant with the letter of the standard, the
duplication causes problems for consumers of this information such as lldb.
(Some files are duplicated, where only some of them have a line table although
all refer to the same file)

With this change, dwarf 5 debug line section files always start from 0, and
the zeroth entry is not duplicated whenever possible. This requires different
handling of dwarf 4 and dwarf 5 during generation (e.g. when a function returns
an index zero for a file name, it signals an error in dwarf 4, but not in dwarf
5) However, I think the minor complication is worth it, because it enables all
consumers (lldb, gdb, dwarfdump, objdump, and so on) to treat all files in the
file name list homogenously.

llvm-svn: 358732
2019-04-19 02:26:56 +00:00
Fangrui Song 196a440411 [wasm] Simplify. NFC
llvm-svn: 358663
2019-04-18 13:33:29 +00:00
George Rimar 55e1987f81 [LLD][ELF] - Convert out-of-order-section-in-region.s to *.test. NFCI.
This is consistent with the our others tests that has large scripts.

llvm-svn: 358659
2019-04-18 12:13:41 +00:00
George Rimar 69186f82f3 [LLD][ELF] - A fix for "linker script assignment loses relative nature of section" bug.
This is https://bugs.llvm.org//show_bug.cgi?id=39857.
I added the comment with much more details to the bug page,
the short version is below.

The following script and code demonstrates the issue:

aliasto__text = __text;
 SECTIONS {
  .text 0x1000 : { __text = . ; *(.text) }
 }
...
call aliasto__text

LLD fails with "cannot refer to absolute symbol: aliasto__text" error.
It happens because at the moment of scanning the relocations
we do not yet assign the correct/final/any section value for the symbol aliasto__text.
I made a change to Relocations.cpp to fix that.

Also, I had to remove the symbol-location.s test case completely, because now it does not
trigger any error. Since now all linker scripts symbols are resolved to constants, no
errors can be triggered at all it seems. I checked that it is consistent with the behavior
of bfd and gold (they do not trigger errors for the case from symbol-location.s), so it should
be OK. I.e. at least it is probably not the best possible, but natural behavior we obtained.

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

llvm-svn: 358652
2019-04-18 10:00:37 +00:00
Fangrui Song 3deff86657 [ELF] Respect NonAlloc when copying flags from the previous sections
Summary:
If the output section contains only symbol assignments, we copy flags
from the previous sections. Don't set SHF_ALLOC if NonAlloc is true.

We also have to change the type from SHT_NOBITS to SHT_PROGBITS.
In ld.bfd, bfd_elf_get_default_section_type maps non-alloctable sections to SHT_PROGBITS.
Non-alloctable SHT_NOBITS sections do not make sense.

Fixes PR38626

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

llvm-svn: 358650
2019-04-18 09:22:05 +00:00
George Rimar da49faf15e [LLD][ELF] - Fix the different behavior of the linker script symbols on different platforms.
This generalizes code and also fixes the broken behavior shown in
one of our test cases for some targets, like x86-64.

The issue occurs when the forward declarations are used in the script.
One of the samples is:

SECTIONS {
  foo = ADDR(.text) - ABSOLUTE(ADDR(.text));
};

In that case, we have a broken output when output target does
not use thunks. That happens because thunks creating code
(called from maybeAddThunks)
calls Script->assignAddresses() at least one more time,
what fixups the values. As a result final symbols values can
be different on AArch64 and x86, for example.

In this patch, I generalize and rename maybeAddThunks to
finalizeAddressDependentContent and now it is used and called
by all targets.

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

llvm-svn: 358646
2019-04-18 08:15:54 +00:00
Fangrui Song 957c356ffe [ELF] Place SectionPiece::{Live,Hash} bit fields together
Summary:
We access Live and OutputOff (which may share the same memory location)
concurrently in 2 parallelForEachN loops. Separating them avoids subtle
data races like D41884/PR35788. This patch places Live and Hash
together.

2 reasons this is appealing:

1) Hash is immutable. Live is almost read-only - only written once in MarkLive.cpp where
   Hash is not accessed
2) we already discard low bits of Hash to decide ShardID. It doesn't
   matter much if we make 32-bit Hash to 31-bit.

   For a huge internal clang -O3 executable (1.6GiB),
   `Strings` in StringTableBuilder::finalizeStringTable contains at most 310253 elements.
   The expected number of pair-wise collisions 2^(-31) * C(310253,2) ~= 22.41 is too small to have a negative impact on performance.
   Actually, my benchmark shows there is actually a minor performance improvement.

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

llvm-svn: 358645
2019-04-18 07:46:09 +00:00
Rui Ueyama 14ef9b30b6 lld: elf: Fix sections with explict addresses in regions
Patch by Gabriel Smith.

The address for a section would be evaluated before the region was
switched to. Because of this, the position within the region would not
be updated. After the region is swapped to the dot would be set to the
out of date position within the region, undoing the section address
evaluation.

To fix this, the region is swapped to before the section's address is
evaluated. As part of the fallout of this, expandMemoryRegions needed
to be gated in setDot on the condition that the evaluated address is
less than the dot. This is for the case where sections are not listed
from lowest address to highest address.

Finally, a test for the case where sections are listed "out of order"
was added.

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

llvm-svn: 358638
2019-04-18 02:32:12 +00:00
Fangrui Song 2bc3a19a49 [ELF] Use llvm::bsearch. NFC
Differential Revision: https://reviews.llvm.org/D60813

llvm-svn: 358565
2019-04-17 08:00:46 +00:00
Rui Ueyama 5081e41bda Fix a crash bug caused by a nested call of parallelForEach.
parallelForEach is not reentrant. We use parallelForEach to call
each section's writeTo(), so calling the same function within writeTo()
is not safe.

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

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

llvm-svn: 358547
2019-04-17 02:12:47 +00:00
Rui Ueyama 7f8ca6e367 lld: Fix initial Mach-O load commands size calculation omitting LC_FUNCTION_STARTS
Patch by Nicholas Allegra.

The Mach-O writer calculates the size of load commands multiple times.

First, Util::assignAddressesToSections() (in MachONormalizedFileFromAtoms.cpp)
calculates the size using headerAndLoadCommandsSize() (in
MachONormalizedFileBinaryWriter.cpp), which creates a temporary
MachOFileLayout for the NormalizedFile, only to retrieve its
headerAndLoadCommandsSize.  Later, writeBinary() (in
MachONormalizedFileBinaryWriter.cpp) creates a new layout and uses the offsets
from that layout to actually write out everything in the NormalizedFile.

But the NormalizedFile changes between the first computation and the second.
When Util::assignAddressesToSections is called, file.functionStarts is always
empty because Util::addFunctionStarts has not yet been called. Yet
MachOFileLayout decides whether to include a LC_FUNCTION_STARTS command based
on whether file.functionStarts is nonempty. Therefore, the initial computation
always omits it.

Because padding for the __TEXT segment (to make its size a multiple of the
page size) is added between the load commands and the first section, LLD still
generates a valid binary as long as the amount of padding happens to be large
enough to fit LC_FUNCTION_STARTS command, which it usually is.

However, it's easy to reproduce the issue by adding a section of a precise
size. Given foo.c:

  __attribute__((section("__TEXT,__foo")))
  char foo[0xd78] = {0};

Run:

  clang -dynamiclib -o foo.dylib foo.c -fuse-ld=lld -install_name
  /usr/lib/foo.dylib
  otool -lvv foo.dylib

This should produce:

  truncated or malformed object (offset field of section 1 in LC_SEGMENT_64
  command 0 not past the headers of the file)

This commit:

 - Changes MachOFileLayout to always assume LC_FUNCTION_STARTS is present for
   the initial computation, as long as generating LC_FUNCTION_STARTS is
   enabled. It would be slightly better to check whether there are actually
   any functions, since no LC_FUNCTION_STARTS will be generated if not, but it
   doesn't cause a problem if the initial computation is too high.

 - Adds a test.

 - Adds an assert in MachOFileLayout::writeSectionContent() that we are not
   writing section content into the load commands region (which would happen
   if the offset was calculated too low due to the initial load commands size
   calculation being too low).  Adds an assert in
   MachOFileLayout::writeLoadCommands to validate a similar situation where
   two size-of-load-commands computations are expected to be equivalent.

llvm-svn: 358545
2019-04-17 01:47:16 +00:00
Peter Collingbourne 97d25e068f ELF: Move build id computation to Writer. NFCI.
With partitions, each partition should have the same build id. This means
that the build id needs to be only computed once, otherwise we will end up
with different build ids in each partition as a result of the file contents
changing. This change moves the computation of the build id into Writer so
that it only happens once.

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

llvm-svn: 358536
2019-04-16 22:45:14 +00:00
Fangrui Song f10065b68b [MachO] Add -macho to llvm-objdump commands
llvm-svn: 358473
2019-04-16 03:51:53 +00:00
Douglas Yung 45129145b9 Fix test on Windows that uses a different path separator character.
llvm-svn: 358453
2019-04-15 21:43:28 +00:00
Bob Haarman 8b1ec798b5 [LLD][COFF] use offset in archive to disambiguate archive members
Summary:
Archives can contain multiple members with the same name. This would
cause ThinLTO links to fail ("Expected at most one ThinLTO module per
bitcode file"). This change implements the same strategy we use in
the ELF linker: make the offset in the archive part of the module
name so that names are unique.

Reviewers: pcc, mehdi_amini, ruiu

Reviewed By: ruiu

Subscribers: eraman, steven_wu, dexonsmith, llvm-commits

Tags: #llvm

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

llvm-svn: 358440
2019-04-15 19:48:32 +00:00
Martin Storsjo cdf126ebec [COFF] Link crtend.o as the last object file
When faced with command line options such as "crtbegin.o appmain.o
-lsomelib crtend.o", GNU ld pulls in all necessary object files from
somelib before proceeding to crtend.o.

LLD operates differently, only loading object files from any
referenced static libraries after processing all input object files.

This uses a similar hack as in the ELF linker. Here, it moves crtend.o
to the end of the vector of object files. This makes sure that
terminator chunks for sections such as .eh_frame gets ordered last,
fixing DWARF exception handling for libgcc and gcc's crtend.o.

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

llvm-svn: 358394
2019-04-15 10:57:44 +00:00
Fangrui Song abc068fc59 [ELF] Fix typo: .symtab_shndxr -> .symtab_shndx
The typo was introduced to llvm MC in rL204769 (fixed in rL358247) and then to lld.

Also, for relocatable-many-sections.s, the size of .symtab changed at some point and the formula needs update.

llvm-svn: 358248
2019-04-12 02:20:52 +00:00
Hans Wennborg 136a6a612a Fix two sphinx warnings
llvm-svn: 358155
2019-04-11 07:31:03 +00:00
Sam Clegg 0d9f609d82 [WebAssembly] Assign GOT entries symbols used in data relocations
Differential Revision: https://reviews.llvm.org/D60492

llvm-svn: 358090
2019-04-10 15:06:17 +00:00
Xing GUO 8ab7414580 [llvm-readobj] Should declare `ListScope` for `verneed` entries.
Summary: YAML mappings require keys to be unique. See: https://yaml.org/spec/1.2/spec.html#id2764652

Reviewers: jhenderson, grimar, rupprecht, espindola, ruiu

Reviewed By: ruiu

Subscribers: ruiu, emaste, arichardson, MaskRay, llvm-commits

Tags: #llvm

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

llvm-svn: 358078
2019-04-10 12:47:21 +00:00
Rui Ueyama 3a8bb7cd2c Discard debuginfo for object files empty after GC
Patch by Robert O'Callahan.

Rust projects tend to link in all object files from all dependent
libraries and rely on --gc-sections to strip unused code and data.
Unfortunately --gc-sections doesn't currently strip any debuginfo
associated with GC'ed sections, so lld links in the full debuginfo from
all dependencies even if almost all that code has been discarded. See
https://github.com/rust-lang/rust/issues/56068 for some details.

Properly stripping debuginfo for discarded sections would be difficult,
but a simple approach that helps significantly is to mark debuginfo
sections as live only if their associated object file has at least one
live code/data section. This patch does that. In a (contrived but not
totally artificial) Rust testcase linked above, it reduces the final
binary size from 46MB to 5.1MB.

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

llvm-svn: 358069
2019-04-10 10:37:10 +00:00
Rui Ueyama 0c01607bbf Rename a variable and add a comment.
llvm-svn: 358049
2019-04-10 06:32:05 +00:00
Chih-Mao Chen 23e23836d5 Move tests in r357996 to correct location within monorepo
llvm-svn: 357997
2019-04-09 11:46:47 +00:00
Chih-Mao Chen 00100b5d0d [RISCV] Rewrite tests to use llvm-mc/llvm-objdump
Previously the tests in lld for RISC-V were given in yaml format as
LLVM's RISC-V assembler support was incomplete. Now that the
assembler/disassembler has matured we can rewrite all tests to use
LLVM's tools.

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

llvm-svn: 357996
2019-04-09 11:39:50 +00:00
Chih-Mao Chen 949570ce39 [RISCV] Fix range check for HI20/LO12/RVC_LUI relocations
The code previously specified a 32-bit range for R_RISCV_HI20 and
R_RISCV_LO12_[IS], however this is incorrect as the maximum offset on
RV64 that can be formed from the immediate of lui and the displacement
of an I-type or S-type instruction is -0x80000800 to 0x7ffff7ff. There
is also the same issue with a c.lui and LO12 pair, whose actual
addressable range should be -0x20800 to 0x1f7ff.

The tests will be included in the next patch that converts all RISC-V
tests to use llvm-mc instead of yaml2obj, as assembler support has
matured enough to write tests in them.

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

llvm-svn: 357995
2019-04-09 11:39:23 +00:00
Rui Ueyama f432fa6eee De-template SymbolTable::addShared.
Because of r357925, this member function doesn't have to be a
template of ELFT.

llvm-svn: 357982
2019-04-09 08:52:00 +00:00
Sam Clegg 0cfaa2470f [WebAssembly] Ensure ArchiveName is set even in the presence of --whole-archive.
Differential Revision: https://reviews.llvm.org/D60431

llvm-svn: 357966
2019-04-09 05:41:52 +00:00
Peter Collingbourne d3e207057f ELF: Move verneed tracking data structures out of VersionNeedSection.
For partitions I intend to use the same set of version indexes in
each partition for simplicity. Since each partition will need its own
VersionNeedSection this will require moving the verneed tracking out of
VersionNeedSection. The way I've done this is to move most of the tracking
into SharedFile. What will eventually become the per-partition tracking
still lives in VersionNeedSection.

As a bonus the code gets a little simpler and more consistent with how we
handle verdef.

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

llvm-svn: 357926
2019-04-08 17:48:05 +00:00
Peter Collingbourne cc1618e668 ELF: De-template SharedFile. NFCI.
Differential Revision: https://reviews.llvm.org/D60305

llvm-svn: 357925
2019-04-08 17:35:55 +00:00
Rui Ueyama 4af8d47d05 Fix -emit-reloc against local symbols.
Previously, we drop symbols starting with .L from the symbol table, so
if there is a relocation that refers a .L symbol, it ended up
referencing a null -- which happened to be interpreted as an absolute
symbol.

This patch copies all symbols including local ones if -emit-reloc is
given.

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

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

llvm-svn: 357885
2019-04-08 06:45:07 +00:00
Peter Collingbourne 883ab235ee ELF: De-template ELFFileBase. NFCI.
Differential Revision: https://reviews.llvm.org/D60304

llvm-svn: 357806
2019-04-05 20:16:26 +00:00
Peter Collingbourne ad4376e8af ELF: Simplify. NFCI.
Differential Revision: https://reviews.llvm.org/D60299

llvm-svn: 357739
2019-04-05 01:31:40 +00:00
Rui Ueyama 7c28937baf Remove redundant parameters. NFC.
llvm-svn: 357738
2019-04-05 01:30:09 +00:00
Sam Clegg a116d91ba2 [WebAssembly] Include function in wasm table when used in R_WASM_TABLE_INDEX_REL_SLEB
This should have been part of rL357710 but was overlooked because
in our test code the function in question was also used in other
relocations that caused it to be added to the table anyway.

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

llvm-svn: 357737
2019-04-05 00:35:12 +00:00
Sam Clegg 09137be7f8 [WebAssembly] Apply data relocations at runtime in shared objects
See: https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md

Data section relocations in wasm shared libraries are applied by the
library itself at static constructor time.  This change adds a new
synthetic function that applies relocations to relevant memory locations
on startup.

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

llvm-svn: 357715
2019-04-04 18:40:51 +00:00
Sam Clegg 2a7cac932b [WebAssembly] Add new explicit relocation types for PIC relocations
See https://github.com/WebAssembly/tool-conventions/pull/106

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

llvm-svn: 357710
2019-04-04 17:43:50 +00:00
Joseph Tremoulet 9f598ac706 [COFF] Fix delay import directory iterator
Summary:
Take the Index into account in `getDelayImportTable`, otherwise we
always return the entry for the first delay DLL reference.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

llvm-svn: 357697
2019-04-04 14:13:28 +00:00
Peter Collingbourne 8238604259 ELF: Move SymtabSHNDX and getSectionIndex() to ObjFile. NFCI.
Differential Revision: https://reviews.llvm.org/D60244

llvm-svn: 357670
2019-04-04 03:13:51 +00:00
Reid Kleckner e10d00419a [codeview] Remove Type member from CVRecord
Summary:
Now CVType and CVSymbol are effectively type-safe wrappers around
ArrayRef<uint8_t>. Make the kind() accessor load it from the
RecordPrefix, which is the same for types and symbols.

Reviewers: zturner, aganea

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

llvm-svn: 357658
2019-04-04 00:28:48 +00:00
George Rimar ff3397247f [LLD] - Update the test cases after yaml2obj change.
https://reviews.llvm.org/D60122 (r357595) changed the
symbols description format.

This change updates the LLD tests.

llvm-svn: 357596
2019-04-03 14:54:22 +00:00
Reid Kleckner cc525c97b7 [COFF] Reduce the size of Chunk and SectionChunk, NFC
Summary:
Reorder the fields in both to use padding more efficiently, and add more
comments on the purpose of the fields.

Replace `std::vector<SectionChunk*> AssociativeChildren` with a
singly-linked list. This avoids the separate vector allocation to list
associative children, and shrinks the 3 pointers used for the typically
empty vector down to 1.

In the end, this reduces the sum of heap allocations used to link
browser_tests.exe with NO PDB by 13.10%, going from 2,248,728 KB to
1,954,071 KB of heap. These numbers exclude memory mapped files, which
are of course a significant factor in LLD's memory usage.

Reviewers: ruiu, mstorsjo, aganea

Subscribers: jdoerfert, llvm-commits

Tags: #llvm

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

llvm-svn: 357535
2019-04-02 22:11:58 +00:00
Alexandre Ganea 19775a4c67 [LLD][COFF] Move type merging structures out of PDB.cpp. NFC
Introduce a new TypeMerger class, out of some type-merge-specific structures from PDB.cpp

No changes intended / this is only moving code around.

This patch is step 3. in "Proposed commit strategy" in D59226

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

llvm-svn: 357525
2019-04-02 20:43:19 +00:00
Matthew Voss 3c023420d1 [NFC][LLD] Specify namespaces explicity to fix build failure on GCC 5 after r357383
llvm-svn: 357421
2019-04-01 19:23:56 +00:00
Peter Collingbourne a9e847238e ELF: Perform per-section .ARM.exidx processing during combineEhFrameSections(). NFCI.
And rename the function to combineEhSections(). This makes the processing
of .ARM.exidx even more similar to .eh_frame and means that we can avoid an
additional loop over InputSections.

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

llvm-svn: 357417
2019-04-01 18:01:18 +00:00
Alexandre Ganea 30c2f20e55 Fix builder.
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fuzzer/builds/24702/steps/check-fuzzer/logs/stdio

llvm-svn: 357391
2019-04-01 14:37:36 +00:00
Alexandre Ganea bf55c4e3e3 [LLD][COFF] Early dependency detection
We introduce a new class hierarchy for debug types merging (in DebugTypes.h). The end-goal is to parallelize the type merging - please see the plan in D59226.

Previously, dependency discovery was done on the fly, much later, during the type merging loop. Unfortunately, parallelizing the type merging requires the dependencies to be merged in first, before any dependent ObjFile, thus this early discovery.

The overall intention for this path is to discover debug information dependencies at a much earlier stage, when processing input files. Currently, two types of dependency are supported: PDB type servers (when compiling with MSVC /Zi) and precompiled headers OBJs (when compiling with MSVC /Yc and /Yu). Once discovered, an explicit link is added into the dependent ObjFile, through the new debug types class hierarchy introduced in DebugTypes.h.

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

llvm-svn: 357383
2019-04-01 13:36:59 +00:00
Fangrui Song d83fb24533 [ELF] Rename SyntheticSection::empty to more appropriate isNeeded() with opposite meaning
Summary:
Some synthetic sections can be empty while still being needed, thus they
can't be removed by removeUnusedSyntheticSections(). Rename this member
function to more appropriate isNeeded() with the opposite meaning.

No functional change intended.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: jhenderson, grimar, emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 357377
2019-04-01 08:16:08 +00:00
Rui Ueyama a77ea59c4d Simplify. NFC.
llvm-svn: 357373
2019-04-01 00:25:17 +00:00
Rui Ueyama 68b9f45fee Replace `typedef A B` with `using B = A`. NFC.
I did this using Perl.

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

llvm-svn: 357372
2019-04-01 00:11:24 +00:00
Sam Clegg e3a845e25e Re-land "[WebAssembly] Improve invalid relocation error message""
See https://reviews.llvm.org/D59860

The initial version of this change effected more than just the
error message.  This version is scoped down to only effect the error
itself.

llvm-svn: 357328
2019-03-29 22:56:39 +00:00
Alexandre Ganea b13f064b5d Fix build following r357308 : Ensure only live thunks are considered when creating import modules
llvm-svn: 357316
2019-03-29 21:24:19 +00:00
Reid Kleckner ba708619ad Don't copy the .drective section with std::string
Both COFF and bitcode input files expose these as stable strings.

llvm-svn: 357314
2019-03-29 21:00:22 +00:00
Thomas Lively 06391f34bd [WebAssembly] "atomics" feature requires shared memory
Summary:
Makes it a linker error if the "atomics" feature is used but the user
does not opt in to shared memory or if "atomics" is disallowed but the
user does opt in to shared memory. Also check that an appropriate max
memory size is supplied if shared memory is used.

Reviewers: sbc100, aheejin

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

Tags: #llvm

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

llvm-svn: 357310
2019-03-29 20:43:49 +00:00
Alexandre Ganea 09cca5b243 [LLD][COFF] Generate import modules & COFF groups in PDB
Generate import modules for each imported DLL, along with its symbol stream.
Also create COFF groups in the * Linker * module, one for each PartialSection (input, unmerged sections)
Currently COFF groups are disabled for MINGW because it significantly increases PDB sizes. We could enable that later with an option.

The overall objective for this change is to support code hot patching tools. Such tools need to know the import libraries used, from the PDB alone.

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

llvm-svn: 357308
2019-03-29 20:25:34 +00:00
Alexandre Ganea 347a45ccd5 [LLD][COFF] Improve checkFailIfMismatch()
As suggested by ruiu here (https://reviews.llvm.org/D58910#1425484), defer a call to toString(File) until it's really needed (if there's an error)

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

llvm-svn: 357305
2019-03-29 19:58:58 +00:00
Fangrui Song 8048fe2b8c [ELF][MachO][wasm] Simplify range-style std::find{,_if} with STLExtras.h utilities. NFC
llvm-svn: 357269
2019-03-29 16:21:16 +00:00
Derek Schuff 0c9ea10530 Revert "[WebAssembly] Improve invalid relocation error message"
This reverts commit 0805ec5f7b.

llvm-svn: 357225
2019-03-29 00:05:00 +00:00
Derek Schuff ac727e8647 Revert "[WebAssembly] Improve invalid relocation error message"
Also Revert "[WebAssembly] Fix typo from rL357143"

This reverts commit 0805ec5f7b and
a9958fc30d
(rL357143 and rL357144)

They cause failures with address-taken extern (JS) functions
in emscripten.

llvm-svn: 357224
2019-03-29 00:04:58 +00:00
Rui Ueyama 6528f2eac9 Remove a duplicate assignment. NFC.
llvm-svn: 357223
2019-03-28 23:53:38 +00:00
Rumeet Dhindsa 45bd9b2567 Fixed the lld test using ld-lld command to use ld.lld instead.
Differential Revision: https://reviews.llvm.org/D59962

llvm-svn: 357216
2019-03-28 22:14:46 +00:00
Reid Kleckner 1600490af1 [COFF] Optimize range extension thunk insertion memory usage
Summary:
This avoids allocating O(#relocs) of intermediate data for each section
when range extension thunks aren't needed for that section. This also
removes a std::vector from SectionChunk, which further reduces its size.

Instead, this change adds the range extension thunk symbols to the
object files that contain sections that need extension thunks. By adding
them to the symbol table of the parent object, that means they now have
a symbol table index. Then we can then modify the original relocation,
after copying it to read-write memory, to use the new symbol table
index.

This makes linking browser_tests.exe with no PDB 10.46% faster, moving
it from 11.364s to 10.288s averaged over five runs.

Reviewers: mstorsjo, ruiu

Subscribers: aganea, llvm-commits

Tags: #llvm

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

llvm-svn: 357200
2019-03-28 18:30:03 +00:00
Rui Ueyama f28825bc06 Create an instance of Target after reading all input files. NFC.
This change itself doesn't mean anything, but it helps D59780 because
in patch, we don't know whether we need to create a CET-aware PLT or
not until we read all input files.

llvm-svn: 357194
2019-03-28 17:38:53 +00:00
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
Rui Ueyama 81c0880c99 s/method/function/g since function is the correct name in C++.
llvm-svn: 354704
2019-02-22 23:59:51 +00:00
Rui Ueyama c94dad9d97 Remove a function from header and move the implementation to a .cpp file. NFC.
llvm-svn: 354703
2019-02-22 23:59:43 +00:00
James Henderson 0cc32dd4a1 [ELF][test]Remove unnecessary empty symbol references in yaml/add missing symbols for relocs
yaml2obj used to require the Symbol field in relocations, but it hasn't
done so for a couple of years. Another change to yaml2obj will soon land
that will look up the symbol by name or index, if present, and emit an
error if not found. This will mean that an explicit symbol reference
(even to an empty-named symbol) that does not reference a symbol
declared in the yaml will result in an error.

This patch updates tests that would otherwise start emitting errors.

Reviewed by: ruiu, grimar

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

llvm-svn: 354666
2019-02-22 11:22:39 +00:00
Peter Collingbourne f9232b0c00 ELF: Remove dead code. NFCI.
RelocationBaseSection is not used in -r links, so Config->Relocatable will
always be false.

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

llvm-svn: 354607
2019-02-21 18:53:58 +00:00
Rui Ueyama 04661e1084 Update `ld.lld --version` string for monorepo.
This patch basically does the same thing as
https://reviews.llvm.org/rL352729 did to clang.

With this patch, lld now prints out a correct version string including
a git commit id like this:

  $ bin/ld.lld --version
  LLD 9.0.0 (https://github.com/llvm/llvm-project.git c027658504fa9e68173f53dedaf223695a65e910) (compatible with GNU linkers)

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

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

llvm-svn: 354605
2019-02-21 18:37:26 +00:00
George Rimar b173d75c49 [LLD][ELF] - Simplify test case. NFC.
It has an excessive section declaration.

llvm-svn: 354573
2019-02-21 12:18:22 +00:00
Sam Clegg f8d736f1dc [WebAssembly] Remove redundant code added in rL354538. NFC.
The code for encoding the symbols signature into its name
was not actually being used in the final version of this change.

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

llvm-svn: 354539
2019-02-21 01:33:26 +00:00
Richard Trieu 14bab09e11 Fix unused variable warning.
llvm-svn: 354535
2019-02-21 00:36:14 +00:00
Sam Clegg 6540e57002 [WebAssembly] Don't generate invalid modules when function signatures mismatch
Previously we could emit a warning and generate a potentially invalid
wasm module (due to call sites and functions having conflicting
signatures). Now, rather than create invalid binaries we handle such
cases by creating stub functions containing unreachable, effectively
turning these into runtime errors rather than validation failures.

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

llvm-svn: 354528
2019-02-20 23:19:31 +00:00
Simon Atanasyan 14b09810a0 [mips] Put some MIPS-specific sections to separate segments
Three MIPS-specific sections `.reginfo`, `.MIPS.options`, and `.MIPS.abiflags`
are used by loader to read their contents and setup environment for running
a program. Loader looks up these data in the corresponding segments:
`PT_MIPS_REGINFO`, `PT_MIPS_OPTIONS`, and `PT_MIPS_ABIFLAGS` respectively.

This patch put these sections to separate segments like we do already
for ARM `SHT_ARM_EXIDX` section.

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

llvm-svn: 354468
2019-02-20 14:47:02 +00:00
Fangrui Song eaa0db021f ELF: Remove field for .gdb_index in InStruct. NFC.
Summary: This field is unreferenced outside of createSyntheticSections.

Reviewers: ruiu, pcc, espindola, grimar

Reviewed By: grimar

Subscribers: grimar, emaste, arichardson, arphaman, llvm-commits

Tags: #llvm

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

llvm-svn: 354449
2019-02-20 11:34:18 +00:00
Peter Collingbourne 7cca803d4c ELF: Remove field for .interp in InStruct. NFC.
This field is unreferenced outside of createSyntheticSections.

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

llvm-svn: 354428
2019-02-20 02:32:53 +00:00
Tom Stellard 20332cc4ea ELF: Fix typo in --build-id option description
Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 354422
2019-02-20 01:40:35 +00:00
Bob Haarman 61e8735f17 [lld-link] preserve @llvm.used symbols in LTO
Summary:
We translate @llvm.used to COFF by generating /include directives
in the .drectve section. However, in LTO links, this happens after
directives have already been processed, so the new directives do
not take effect. This change marks @llvm.used symbols as GCRoots
so that they are preserved as intended.

Fixes PR40733.

Reviewers: rnk, pcc, ruiu

Reviewed By: ruiu

Subscribers: mehdi_amini, steven_wu, dexonsmith, dang, llvm-commits

Tags: #llvm

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

llvm-svn: 354410
2019-02-20 00:26:01 +00:00
Rui Ueyama 3ae6726234 Sort enum members so that arch-dependent members are at the right place. NFC.
llvm-svn: 354405
2019-02-20 00:01:21 +00:00
Thomas Lively 2e1504091e [WebAssembly] Update MC for bulk memory
Summary:
Rename MemoryIndex to InitFlags and implement logic for determining
data segment layout in ObjectYAML and MC. Also adds a "passive" flag
for the .section assembler directive although this cannot be assembled
yet because the assembler does not support data sections.

Reviewers: sbc100, aardappel, aheejin, dschuff

Subscribers: jgravelle-google, hiraditya, sunfish, rupprecht, llvm-commits

Tags: #llvm

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

llvm-svn: 354397
2019-02-19 22:56:19 +00:00
Rui Ueyama 659f2752a0 Move MinGW-specific code out of LinkerDriver::link. NFC.
LinkerDriver::link is getting too long, it's time to simplify it.

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

llvm-svn: 354391
2019-02-19 22:06:44 +00:00
Martin Storsjo 9705898bf3 [MinGW] Hook up the --exclude-all-symbols option
Differential Revision: https://reviews.llvm.org/D58380

llvm-svn: 354387
2019-02-19 21:57:49 +00:00
Martin Storsjo 272d8c18e0 [COFF] Add -exclude-all-symbols for MinGW
This is a private undocumented option, intended to be used by
the MinGW driver frontend.

Also restructure the condition to put if (Config->MinGW) first.
This changes the behaviour for the tautological combination of
-export-all-symbols without -lldmingw.

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

llvm-svn: 354386
2019-02-19 21:57:44 +00:00
Simon Atanasyan 2fdd159715 [mips] Fix indentations in the test. NFC
llvm-svn: 354341
2019-02-19 16:00:07 +00:00
George Rimar baff199877 [ELF] - Update test case after yaml2obj format change.
yaml2obj was changed in r354338("[yaml2obj][obj2yaml] - Support SHT_GNU_versym (.gnu.version) section.")

llvm-svn: 354339
2019-02-19 15:29:25 +00:00
Simon Atanasyan 37a1d6eca3 Convert the eh-frame-hdr-abs-fde.s test to use x86 as a target architecture
The test checks common functionality. Let's use `x86` (generic LLD target)
as a target architecture.

llvm-svn: 354336
2019-02-19 15:17:43 +00:00
Simon Atanasyan 40fb1c95ee [mips] Remove trailing whitespaces from the test case. NFC
llvm-svn: 354315
2019-02-19 11:15:28 +00:00
Simon Atanasyan a6012a65d4 [mips] Create LA25 thunks for MIPS R6 code
MIPS R6 code uses the `R_MIPS_PC26_S2` relocation for calls which might
cross boundaries of non-PIC-to-PIC code. We need to create a LA25 thunks
for that case.

llvm-svn: 354312
2019-02-19 11:11:12 +00:00
Simon Atanasyan fae2a509fa [MIPS] Handle cross-mode (regular <-> microMIPS) jumps
The patch solves two tasks:

1. MIPS ABI allows to mix regular and microMIPS code and perform
cross-mode jumps. Linker needs to detect such cases and replace
jump/branch instructions by their cross-mode equivalents.

2. Other tools like dunamic linkers need to recognize cases when dynamic
table entries, e_entry field of an ELF header etc point to microMIPS
symbol. Linker should provide such information.

The first task is implemented in the `MIPS<ELFT>::relocateOne()` method.
New routine `fixupCrossModeJump` detects ISA mode change, checks and
replaces an instruction.

The main problem is how to recognize that relocation target is microMIPS
symbol. For absolute and section symbols compiler or assembler set the
less-significant bit of the symbol's value or sum of the symbol's value
and addend. And this bit signals to linker about microMIPS code. For
global symbols compiler cannot do the same trick because other tools like,
for example, disassembler wants to know an actual position of the symbol.
So compiler sets STO_MIPS_MICROMIPS flag in the `st_other` field.

In `MIPS<ELFT>::relocateOne()` method we have a symbol's value only and
cannot access any symbol's attributes. To pass type of the symbol
(regular/microMIPS) to that routine as well as other places where we
write a symbol value as-is (.dynamic section, `Elf_Ehdr::e_entry` field
etc) we set when necessary a less-significant bit in the `getSymVA`
function.

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

llvm-svn: 354311
2019-02-19 10:36:58 +00:00
Nico Weber 3a35a2a51c lld-link: Mention comdat selection work in the 9.0.0 wip release notes
Differential Revision: https://reviews.llvm.org/D58301

llvm-svn: 354241
2019-02-18 01:32:16 +00:00
Rui Ueyama 9efdd7ac5e [PPC64] Preserve LocalEntry when linking
On PowerPC64, it is necessary to keep the LocalEntry bits in st_other,
especially when -r is used. Otherwise, when the resulting object is used
in a posterior linking, LocalEntry info will be unavailable and
functions may be called through the wrong entrypoint.

Patch by Leandro Lupori.

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

llvm-svn: 354184
2019-02-15 23:11:18 +00:00
Konstantin Zhuravlyov 87498153aa LLD/AMDGPU: Preserve ABI version during linking ELF for AMDGPU
Differential Revision: https://reviews.llvm.org/D58026

llvm-svn: 354086
2019-02-14 23:59:44 +00:00
Nick Desaulniers c3aefedc46 Revert "Revert "[lld] Fix elf::unlinkAsync detached thread""
This reverts commit 9934f2ff02dba9fdabe6e27a83f9f95388bf4132.

llvm-svn: 354081
2019-02-14 23:41:23 +00:00
Nick Desaulniers 289d70cf58 Revert "[lld] Fix elf::unlinkAsync detached thread"
This reverts commit 2694810153.

llvm-svn: 354080
2019-02-14 23:39:32 +00:00
Vitaly Buka 2694810153 [lld] Fix elf::unlinkAsync detached thread
Summary:
So this patch just make sure that the thread is at least stated
before we return from main.

If we just detach then the thread may be actually be stated just after
the process returned from main and it's calling atexit handers. Then the thread may try to create own function static variable and it will
add new at exit handlers confusing libc.

GLIBC before 2.27 had race in that case which corrupted atexit handlers
list. Support for this use-case for other implementation is also unclear,
so we can try just avoid that.

PR40162

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, jfb, llvm-commits

Tags: #llvm

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

llvm-svn: 354078
2019-02-14 23:29:28 +00:00
Rui Ueyama 72c3b1ed1d Move a function from .h to .cpp and use a shorter name. NFC.
llvm-svn: 354054
2019-02-14 19:33:26 +00:00
Rui Ueyama 980fb790c1 Remove a comparator from header and instead use lambdas for simplicity. NFC.
llvm-svn: 354052
2019-02-14 19:21:10 +00:00
Rui Ueyama f69bbbbdd2 Add a comment. NFC.
llvm-svn: 354049
2019-02-14 18:50:59 +00:00
Rui Ueyama b8b81e9b43 Improve error message for unknown relocations.
Previously, we showed the following message for an unknown relocation:

  foo.o: unrecognized reloc 256

This patch improves it so that the error message includes a symbol name:

  foo.o: unknown relocation (256) against symbol bar

llvm-svn: 354040
2019-02-14 18:02:20 +00:00
Nico Weber 04db8cb92b lld/coff: Simplify error message for comdat selection mismatches
Turns out nobody understands what "conflicting comdat type" is supposed to
mean, so just emit a regular "duplicate symbol" error and move the comdat
selection information into /verbose output.

This also fixes a problem where the error output would depend on the order of
.obj files passed. Before this patch:

- If passed `one_only.obj discard.obj`, lld-link would only err "conflicting
  comdat type"

- If passed `discard.obj one_only.obj`, lld-link would err "conflicting comdat
  type" and then "duplicate symbol"

Now lld-link only errs "duplicate symbol" in both cases.

I considered adding a "Detail" parameter to reportDuplicate() that's printed in
parens at the end of the "duplicate symbol" diag if present, and then put the
comdat selection mismatch details there, but since users don't know what it's
supposed to mean decided against it. I also considered special-casing the
Detail message for one_only/discard mismatches, which in practice means
"function defined as inline in TU 1 but as out-of-line in TU 2", but I wasn't
sure how useful it is so I omitted that too.

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

llvm-svn: 354006
2019-02-14 03:16:44 +00:00
Peter Collingbourne 8331f61a51 ELF: Allow GOT relocs pointing to non-preemptable ifunc to resolve to an IRELATIVE where possible.
Non-GOT non-PLT relocations to non-preemptible ifuncs result in the
creation of a canonical PLT, which now takes the identity of the IFUNC
in the symbol table. This (a) ensures address consistency inside and
outside the module, and (b) fixes a bug where some of these relocations
end up pointing to the resolver.

Fixes (at least) PR40474 and PR40501.

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

llvm-svn: 353981
2019-02-13 21:49:55 +00:00
Rui Ueyama 4134143cf5 Recover elf32-bigmips and elf32-powerpc support in LLD
This fixes a 7.0 -> 8.0 regression when parsing
OUTPUT_FORMAT("elf32-powerpc"); or elf32-bigmips directive in ldscripts
as well as an unknown emulation error when lld is invoked by clang due
to missed elf32ppclinux case.

Patch by vit9696

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

llvm-svn: 353968
2019-02-13 18:51:15 +00:00
Rui Ueyama 265e8e8252 Show "Unknown -z option" error message even if --version or --help are given.
Previously, we validated -z options after we process --version or --help flags.
So, if one of these flags is given, we wouldn't show an "unknown -z option"
error. This patch fixes that behavior.

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

llvm-svn: 353967
2019-02-13 18:48:39 +00:00
Sean Fertile 0205828be4 [PPC64] Update tests to reflect change in printing of call operand. [NFC]
The printing of branch operands for call instructions was changed to properly
handle negative offsets. Updating the tests to reflect that.

llvm-svn: 353866
2019-02-12 17:49:04 +00:00
Sean Fertile d694160e66 [PPC64] Sort .toc sections accessed with small code model relocs.
A follow up to the intial patch that unblocked linking against libgcc.
For lld we don't need to bother tracking which objects have got based small
code model relocations. This is due to the fact that the compilers on
powerpc64 use the .toc section to generate indirections to symbols (rather then
using got relocations) which keeps the got small. This makes overflowing a
small code model got relocation very unlikely.

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

llvm-svn: 353849
2019-02-12 15:35:49 +00:00
Rui Ueyama 016833bac2 lld: unquote possibly quoted `EXTERN("symbol")` entry in linker script.
gold accepts quoted strings. binutils requires quoted strings for some
kinds of symbols, e.g.:

  it accepts quoted symbols with @ in name:

  $ echo 'EXTERN("__libc_start_main@@GLIBC_2.2.5")' > a.script
  $ g++ a.script
  /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o: In function `_start':
  (.text+0x20): undefined reference to `main'
  collect2: error: ld returned 1 exit status

  but rejects them if unquoted:

  $ echo 'EXTERN(__libc_start_main@@GLIBC_2.2.5)' > a.script
  $ g++ a.script
  a.script: file not recognized: File format not recognized
  collect2: error: ld returned 1 exit status

To maintain compatibility with existing linker scripts support quoted
strings in lld as well.

Patch by Lucian Adrian Grijincu.

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

llvm-svn: 353756
2019-02-11 22:01:32 +00:00
Rui Ueyama 031fe10927 Convert CRLF. NFC.
llvm-svn: 353751
2019-02-11 21:38:20 +00:00
George Rimar 85ff1b5420 [LLD][ELF] - Update test case after yaml2obj change. NFCI.
.dynamic section format accepted by yaml2obj was
changed in r353606

llvm-svn: 353607
2019-02-09 11:34:59 +00:00
Fangrui Song 283d103bde [ELF] Delete a comment that is no longer correct. Fix a typo. NFC
llvm-svn: 353605
2019-02-09 10:09:40 +00:00
David L. Jones c5cb2ce905 [LLD][ELF] Ensure tests use -o /dev/null instead of attempting to write to the bin directory. [NFC]
This error was introduced in r353508.

llvm-svn: 353602
2019-02-09 05:00:50 +00:00
Bob Haarman 3edf63c55a [lld-link] better error message when failing to open archive members
Summary:
The message "could not get the buffer for the member defining symbol"
now also contains the name of the archive and the name of the archive
member that we tried to open.

Reviewers: ruiu

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 353572
2019-02-08 21:59:35 +00:00
James Henderson 6bb9b5943f [LLD][ELF]Add test for missing thin archive member
The code producing error messages relating to missing thin archive
members was missing any testing as far as I could see, so this patch
adds a test for it.

Reviewed by: ruiu

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

llvm-svn: 353508
2019-02-08 10:31:38 +00:00
Sam Clegg 230dc11d24 [WebAssembly] Refactor handling of weak undefined functions. NFC.
Also add to the docs.

This is refactor in preparation for https://reviews.llvm.org/D57909

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

llvm-svn: 353478
2019-02-07 22:42:16 +00:00
Dan Gohman 9b84eeaa3e [WebAssembly] Fix imported function symbol names that differ from their import names in the .o format
Add a flag to allow symbols to have a wasm import name which differs from the
linker symbol name, allowing the linker to link code using the import_module
attribute.

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

llvm-svn: 353473
2019-02-07 22:00:48 +00:00
Sam Clegg adf0aad794 [WebAssembly] Improve docs for wasm linker
Differential Revision: https://reviews.llvm.org/D57913

llvm-svn: 353451
2019-02-07 19:05:26 +00:00
Rui Ueyama 04cbd988f9 Fix a bug in R_X86_64_PC{8,16} relocation handling.
R_X86_64_PC{8,16} relocations are sign-extended, so when we check
for relocation overflow, we had to use checkInt instead of checkUInt.
I confirmed that GNU linkers create the same output for the test case.

llvm-svn: 353437
2019-02-07 18:12:57 +00:00
Hans Wennborg ccebc7e38c docs: add missingkeyfunction to doctree, fix title
llvm-svn: 353399
2019-02-07 12:39:35 +00:00
George Rimar 55f7c72bea [LLD][ELF] - Set DF_STATIC_TLS flag for X64 target
This is the same as D57749, but for x64 target.

"ELF Handling For Thread-Local Storage" p41 says (https://www.akkadia.org/drepper/tls.pdf):
R_X86_64_GOTTPOFF relocation is used for IE TLS models.
Hence if linker sees this relocation we should add DF_STATIC_TLS flag.

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

llvm-svn: 353378
2019-02-07 07:59:43 +00:00
Sam Clegg af3b9d0570 [WebAssembly] Honor WASM_SYMBOL_EXPORT symbol flag
This flag means that symbol should be exported in the final binary.

The reason for this change is to allow source level annotations to
trigger a given symbol to be exported:
https://github.com/emscripten-core/emscripten/issues/7702

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

llvm-svn: 353364
2019-02-07 01:53:50 +00:00
Sam Clegg 34583e5f55 [WebAssembly] Update test expectations to match llvm-readobj change. NFC.
Differential Revision: https://reviews.llvm.org/D57868

llvm-svn: 353358
2019-02-07 01:21:58 +00:00
Martin Storsjo dfb2fcd224 [MinGW] Add --insert-timestamp as complement to the --no-insert-timestamp option
Differential Revision: https://reviews.llvm.org/D57808

llvm-svn: 353342
2019-02-06 21:05:29 +00:00
Ed Maste e9932c103b Correct "varaible" typo in comment
llvm-svn: 353340
2019-02-06 20:36:02 +00:00
Rui Ueyama 1b11e9e8a4 Remove a small header that is used only by one file. NFC.
llvm-svn: 353331
2019-02-06 19:28:23 +00:00
Rui Ueyama 7c77044a38 Add comment.
llvm-svn: 353323
2019-02-06 18:53:17 +00:00
Rui Ueyama 33dbcbb2bc Support R_X86_64_PC8 and R_X86_64_PC16.
They are defined by the x86-64 ELF ABI standard.

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

llvm-svn: 353314
2019-02-06 16:50:09 +00:00
George Rimar ae54e58b90 Recommit r353293 "[LLD][ELF] - Set DF_STATIC_TLS flag for i386 target."
With the following changes:
1) Compilation fix:
std::atomic<bool> HasStaticTlsModel = false; ->
std::atomic<bool> HasStaticTlsModel{false};

2) Adjusted the comment in code.

Initial commit message:

DF_STATIC_TLS flag indicates that the shared object or executable
contains code using a static thread-local storage scheme.

Patch checks if IE/LE relocations were used to check if the code uses
a static model. If so it sets the DF_STATIC_TLS flag.

Differential revision: https://reviews.llvm.org/D57749
----
Modified : /lld/trunk/ELF/Arch/X86.cpp
Modified : /lld/trunk/ELF/Config.h
Modified : /lld/trunk/ELF/SyntheticSections.cpp
Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model1.s
Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model2.s
Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model3.s
Added : /lld/trunk/test/ELF/Inputs/i386-static-tls-model4.s
Added : /lld/trunk/test/ELF/i386-static-tls-model.s
Modified : /lld/trunk/test/ELF/i386-tls-ie-shared.s
Modified : /lld/trunk/test/ELF/tls-dynamic-i686.s
Modified : /lld/trunk/test/ELF/tls-opt-iele-i686-nopic.s

llvm-svn: 353299
2019-02-06 14:43:30 +00:00
George Rimar 52fafcb919 Revert r353293 "[LLD][ELF] - Set DF_STATIC_TLS flag for i386 target."
It broke BB:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/43450
http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/27891

Error is:
tools/lld/ELF/Config.h:84:41: error: copying member subobject of type
'std::atomic<bool>' invokes deleted constructor std::atomic<bool> HasStaticTlsModel = false;

llvm-svn: 353297
2019-02-06 13:53:32 +00:00
George Rimar da60ad220b [LLD][ELF] - Set DF_STATIC_TLS flag for i386 target.
DF_STATIC_TLS flag indicates that the shared object or executable
contains code using a static thread-local storage scheme.

Patch checks if IE/LE relocations were used to check if the code uses
a static model. If so it sets the DF_STATIC_TLS flag.

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

llvm-svn: 353293
2019-02-06 13:38:10 +00:00
Peter Smith aa192bb776 [ELF][ARM] Add test case that will fail if toPlt() is removed [NFC]
When a thunk is created to a PLT entry, the call to the thunk is converted
to a non-plt expression with fromPlt(). If the thunk becomes unusable we
retarget the relocation back to its original target and try again. When we
do this we need to make sure that we restore the PLT form of the expression
with toPlt().

This change adds a test case that will fail if toPlt() is removed. We need
to have a call to a preemptible symbol defined within the link unit. If
toPlt() is removed then the relocation to the thunk to the PLT entry for the
preemptible symbol will be retargeted to the preemptible symbol itself
instead of its PLT entry.

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

llvm-svn: 353285
2019-02-06 10:03:05 +00:00
David L. Jones 4c3ba38429 [wasm-ld] Fix wasm trace test to use %t for temporary files.
llvm-svn: 353272
2019-02-06 04:49:46 +00:00
Sam Clegg 1f3f774f10 [WebAssembly] Implement --trace and --trace-symbol
Differential Revision: https://reviews.llvm.org/D57725

llvm-svn: 353264
2019-02-06 02:35:18 +00:00
Fangrui Song c1950aa183 [PPC64] Delete the unnecessary __tls_get_addr from ppc64-tls-ld-le.s
The definition is harmful here as it suppresses R_PPC64_REL24 which is
supposed to follow R_PPC64_TLSLD.

llvm-svn: 353263
2019-02-06 02:13:40 +00:00
Fangrui Song f55e9a2d2e [PPC64] Set the number of relocations processed for R_PPC64_TLS[GL]D to 2
Summary:
R_PPC64_TLSGD and R_PPC64_TLSLD are used as markers on TLS code sequences. After GD-to-IE or GD-to-LE relaxation, the next relocation R_PPC64_REL24 should be skipped to not create a false dependency on __tls_get_addr. When linking statically, the false dependency may cause an "undefined symbol: __tls_get_addr" error.

R_PPC64_GOT_TLSGD16_HA
R_PPC64_GOT_TLSGD16_LO
R_PPC64_TLSGD R_TLSDESC_CALL
R_PPC64_REL24 __tls_get_addr

Reviewers: ruiu, sfertile, syzaara, espindola

Reviewed By: sfertile

Subscribers: emaste, nemanjai, arichardson, kbarton, jsji, llvm-commits, tamur

Tags: #llvm

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

llvm-svn: 353262
2019-02-06 02:00:24 +00:00
Sam Clegg edd2e05851 [ELF] Fix typo in test/ELF/trace.s
Differential Revision: https://reviews.llvm.org/D57796

llvm-svn: 353254
2019-02-06 01:00:49 +00:00
Zachary Turner c5d68d499a [PDB] Remove dots and normalize slashes with /PDBSOURCEPATH.
In a previous patch, I made changes so that PDBs which were
generated on non-Windows platforms contained sensical paths
for the host.  While this is an esoteric use case, we need
it to be supported for certain cross compilation scenarios
especially with LLDB, which can debug things on non-Windows
platforms.

However, this regressed a case where you specify /PDBSOURCEPATH
and use a windows-style path.  Previously, we would still remove
dots and canonicalize slashes to backslashes, but since my
change intentionally tried to support non-backslash paths, this
was broken.

This patch fixes the situation by trying to guess which path
style the user is specifying when /PDBSOURCEPATH is passed.
It is intentionally conservative, erring on the side of a
Windows path style unless absolutely certain.  All dots are
removed and slashes canonicalized to whatever the deduced
path style is after appending the file path to the /PDBSOURCEPATH
argument.

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

llvm-svn: 353250
2019-02-06 00:50:35 +00:00
Matt Davis 0d0e9c08a4 [llvm-readobj] Display sections that do not belong to a segment in the section-mapping
Summary:
The following patch adds the "None" line to the section to segment mapping dump.
That line lists the sections that do not belong to any segment.
I realize that this change differs from GNU readelf which does not display the latter information.

I'd rather not add this "feature" under a command line option.  I think that might introduce confusion, since users would have to
make an additional decision as to if they want to see all of the section-to-segment map or just a subset of it.

Another option is to only print the "None" line if the `--section-mapping` option is passed; however,
that might also introduce some confusion, because the section-to-segment map would be different between`--program-headers`
and the `--section-mapping` output.  While the difference is just the "None" line, it seems that if we choose to display
the segment-to-section mapping, then we should always display the whole map including the sections
that do not belong to segments.

```
Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .note.ABI-tag .gnu.hash
   03     .init_array .fini_array .dynamic
   04     .dynamic
   05     .note.ABI-tag
   06     .eh_frame_hdr
   07
   08     .init_array .fini_array .dynamic .got
   None   .comment .symtab .strtab .shstrtab <--- THIS LINE
```

Reviewers: grimar, rupprecht, jhenderson, espindola

Reviewed By: rupprecht

Subscribers: khemant, emaste, arichardson, llvm-commits

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

llvm-svn: 353217
2019-02-05 21:01:01 +00:00
Rui Ueyama 3fdb07258b Inline a trivial function and update comment. NFC.
llvm-svn: 353200
2019-02-05 19:19:45 +00:00
Sam Clegg 4d0cc83be7 [WebAssembly] Use wasm-ld rather than lld with -flavor in tests. NFC.
Differential Revision: https://reviews.llvm.org/D57758

llvm-svn: 353187
2019-02-05 16:53:33 +00:00
Martin Storsjo ccd4e5e016 [COFF] Avoid O(n^2) accesses into PartialSections
For MinGW, unique partial sections are much more common, e.g.
comdat functions get sections named e.g. text$symbol.

A moderate sized example of this contains over 200K Chunks
which create 174K unique PartialSections. Prior to SVN r352928
(D57574), linking this took around 1,5 seconds for me, while
it afterwards takes around 13 minutes. After this patch, the
linking time is back to what it was before.

The std::find_if in findPartialSection will do a linear scan of
the whole container until a match is found. To use something like
binary_search or the std::set container's own methods, we'd need
to already have a PartialSection*.

Reinstate a proper map instead of having a set with a custom sorting
comparator.

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

llvm-svn: 353146
2019-02-05 08:16:10 +00:00
Martin Storsjo 537a718fcb [MinGW] Hook up the --no-insert-timestamp option
This fixes PR40582.

Patch by Georg Koppen!

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

llvm-svn: 353145
2019-02-05 08:16:06 +00:00
Sam Clegg b30623ff16 [WebAssembly] Update test to match new readobj output. NFC.
Differential Revision: https://reviews.llvm.org/D57715

llvm-svn: 353105
2019-02-04 22:34:07 +00:00
Heejin Ahn a1cc4ea7bb [WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`.)

The list of fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident

Reviewers: sbc100

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

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

llvm-svn: 353076
2019-02-04 19:13:46 +00:00
Sam Clegg 79e33171d6 [WebAssembly] Update relocation naming to match llvm change. NFC.
Differential Revision: https://reviews.llvm.org/D57698

llvm-svn: 353066
2019-02-04 17:49:33 +00:00
Fangrui Song ae0294375f [ELF] Default to --no-allow-shlib-undefined for executables
Summary:
This follows the ld.bfd/gold behavior.

The error check is useful as it captures a common type of ld.so undefined symbol errors as link-time errors:

    // a.cc => a.so (not linked with -z defs)
    void f(); // f is undefined
    void g() { f(); }

    // b.cc => executable with a DT_NEEDED entry on a.so
    void g();
    int main() { g(); }

    // ld.so errors when g() is executed (lazy binding) or when the program is started (-z now)
    // symbol lookup error: ... undefined symbol: f

Reviewers: ruiu, grimar, pcc, espindola

Reviewed By: ruiu

Subscribers: llvm-commits, emaste, arichardson

Tags: #llvm

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

llvm-svn: 352943
2019-02-02 00:34:28 +00:00
Martin Storsjo c9f4d25f26 [COFF] Create range extension thunks for ARM64
On ARM64, this is normally necessary only after a module exceeds
128 MB in size (while the limit for thumb is 16 MB). For conditional
branches, the range limit is only 1 MB though (the same as for thumb),
and for the tbz instruction, the range is only 32 KB, which allows for
a test much smaller than the full 128 MB.

This fixes PR40467.

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

llvm-svn: 352929
2019-02-01 22:08:09 +00:00
Martin Storsjo b2b0cab0c3 [COFF] Fix crashes when writing a PDB after adding thunks.
When writing a PDB, the OutputSection of all chunks need to be set.
The thunks are added directly to OutputSection after the normal
machinery that sets it for all other chunks.

This fixes part of PR40467.

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

llvm-svn: 352928
2019-02-01 22:08:03 +00:00