Commit Graph

11780 Commits

Author SHA1 Message Date
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
James Y Knight 94b9709d84 Fix some sphinx doc errors.
llvm-svn: 352887
2019-02-01 17:06:41 +00:00
Sam Clegg 7cc0753118 [WebAssembly] Support imports from custom module names
Fixes: https://bugs.llvm.org/show_bug.cgi?id=37168

This is only a first pass at supporting these custom import
modules.  In the long run we most likely want to treat these
kinds of symbols very differently.  For example, it should not
be possible to resolve such as symbol at static link type.

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

llvm-svn: 352828
2019-02-01 02:29:57 +00:00
Fangrui Song b4744d306c [ELF] Support --{,no-}allow-shlib-undefined
Summary:
In ld.bfd/gold, --no-allow-shlib-undefined is the default when linking
an executable. This patch implements a check to error on undefined
symbols in a shared object, if all of its DT_NEEDED entries are seen.

Our approach resembles the one used in gold, achieves a good balance to
be useful but not too smart (ld.bfd traces all DSOs and emulates the
behavior of a dynamic linker to catch more cases).

The error is issued based on the symbol table, different from undefined
reference errors issued for relocations. It is most effective when there
are DSOs that were not linked with -z defs (e.g. when static sanitizers
runtime is used).

gold has a comment that some system libraries on GNU/Linux may have
spurious undefined references and thus system libraries should be
excluded (https://sourceware.org/bugzilla/show_bug.cgi?id=6811). The
story may have changed now but we make --allow-shlib-undefined the
default for now. Its interaction with -shared can be discussed in the
future.

Reviewers: ruiu, grimar, pcc, espindola

Reviewed By: ruiu

Subscribers: joerg, emaste, arichardson, llvm-commits

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

llvm-svn: 352826
2019-02-01 02:25:05 +00:00
Sam Clegg dfbd19033b Fix names of functions in TargetOptionsCommandFlags.h. NFC.
Differential Revision: https://reviews.llvm.org/D57555

llvm-svn: 352825
2019-02-01 02:24:50 +00:00
Nico Weber 9aa55d3c66 lld-link: Allow mixing 'discard' and 'largest' comdat selections
cl.exe and clang-cl.exe put vftables in a 'discard' comdat when building with
RTTI disabled (/GR-) but in a 'largest' comdat when building with RTTI enabled.
To be able to link /GR- code with /GR code, lld-link needs to accept comdats
that have this type of comdat selection conflict.

For example, static libraries in the Visual Studio standard library are built
with /GR, and without this it's impossible to build client code with /GR- and
still link to the standard library.

link.exe also accepts merging 'discard' with 'largest', and it accepts merging
'largest' with any other selection type. lld-link is still a bit stricter since
it only allows merging 'largest' with 'discard' for symmetry.

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

llvm-svn: 352765
2019-01-31 16:14:33 +00:00
Sam Clegg 5cdc91d003 [LTO] Set CGOptLevel in LTO config.
Previously we were never setting this which means it was always being
set to Default (-O2/-Os).

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

llvm-svn: 352667
2019-01-30 20:46:18 +00:00
Sam Clegg 89e4dcb4be [WebAssembly] Fix crash with LTO + relocatable + undefined symbols
Change the way we create the symbol table to be closer to how its done
on ELF.  Now the output symbol table matches the internal symtab order
and includes local and undefined symbols.

Fixes PR40204

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

llvm-svn: 352645
2019-01-30 18:55:15 +00:00
Dimitry Andric 19b134cc44 Recognize FreeBSD specific BFD names in OUTPUT_FORMAT
Summary:
After rLLD344952 ("Add OUTPUT_FORMAT linker script directive support"),
using BFD names such as `elf64-x86-64-freebsd` the `OUTPUT_FORMAT`
linker script command does not work anymore, resulting in errors like:

```
ld: error: /home/dim/src/clang800-import/stand/efi/loader/arch/amd64/ldscript.amd64:2: unknown output format name: elf64-x86-64-freebsd
>>> OUTPUT_FORMAT("elf64-x86-64-freebsd", "elf64-x86-64-freebsd", "elf64-x86-64-freebsd")
>>>               ^
```

To fix this, recognize a `-freebsd` suffix in BFD names, and also set
`Configuration::OSABI` to `ELFOSABI_FREEBSD` for those cases.

Add and/or update several test cases to check for the correct results of
these new `OUTPUT_FORMAT` arguments.

Reviewers: ruiu, atanasyan, grimar, hokein, emaste, espindola

Reviewed By: ruiu

Subscribers: nemanjai, javed.absar, arichardson, krytarowski, kristof.beyls, kbarton, llvm-commits

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

llvm-svn: 352606
2019-01-30 06:31:52 +00:00
Nico Weber 48dc110eea lld/coff: Implement some support for the comdat selection field
LLD used to handle comdats as if the selection field was always set to
IMAGE_COMDAT_SELECT_ANY. This means for obj files produced by `cl /Gy`, LLD
would never report a duplicate symbol error.

This change:
- adds validation for the Selection field (should make no difference in
  practice for compiler-generated obj inputs)
- rejects comdats that have different Selection fields in different obj files
  (likewise). This is a bit more strict but also more self-consistent thank
  link.exe (see comment in code)
- implements handling for all the selection kinds

In practice, compilers only generate comdats with
IMAGE_COMDAT_SELECT_NODUPLICATES (LLD now produces duplicate symbol errors for
these), IMAGE_COMDAT_SELECT_ANY (no behavior change), and
IMAGE_COMDAT_SELECT_LARGEST (for RTTI data; here LLD should no longer create
broken executables when linking some TUs with RTTI enabled and some with it
disabled – but see below).

The implementation of `IMAGE_COMDAT_SELECT_LARGEST` is incomplete: If one
SELECT_LARGEST comdat replaces an earlier one, the comdat symbol is replaced
correctly, but the old section stays loaded and if /opt:ref is disabled (via
/opt:noref or /debug) it's still written to the output. That's not ideal, but
better than the current treatment of just picking any one of those comdats. I
hope to fix this better later.

Fixes most of PR40094.

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

llvm-svn: 352590
2019-01-30 02:17:27 +00:00
Nico Weber bdcefcb241 lld-link: Add test I forgot to add in 332012
Differential Revision: https://reviews.llvm.org/D46693

llvm-svn: 352589
2019-01-30 02:15:08 +00:00
Sam Clegg e320cea5b9 [WebAssembly] Fix undefined weak function symbols in LTO builds
Summary: Fixes PR40219

Subscribers: dschuff, mehdi_amini, inglorion, jgravelle-google, aheejin, sunfish, steven_wu, dexonsmith, llvm-commits

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

llvm-svn: 352575
2019-01-30 00:25:52 +00:00
Sam Clegg 37b4ee523b [WebAssembly] Don't load weak undefined symbols from archive files
Summary: Fixes PR40494

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

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

llvm-svn: 352554
2019-01-29 22:26:31 +00:00
Martin Storsjo d79a4b7ad7 [MinGW] Don't define names for ignored options. NFC.
Move them to the same section as the newly added ignored options
without a defined name.

Also move options that actually weren't ignored to the right section.

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

llvm-svn: 352529
2019-01-29 19:24:32 +00:00
James Y Knight 5d71fc5d7b Adjust documentation for git migration.
This fixes most references to the paths:
 llvm.org/svn/
 llvm.org/git/
 llvm.org/viewvc/
 github.com/llvm-mirror/
 github.com/llvm-project/
 reviews.llvm.org/diffusion/

to instead point to https://github.com/llvm/llvm-project.

This is *not* a trivial substitution, because additionally, all the
checkout instructions had to be migrated to instruct users on how to
use the monorepo layout, setting LLVM_ENABLE_PROJECTS instead of
checking out various projects into various subdirectories.

I've attempted to not change any scripts here, only documentation. The
scripts will have to be addressed separately.

Additionally, I've deleted one document which appeared to be outdated
and unneeded:
  lldb/docs/building-with-debug-llvm.txt

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

llvm-svn: 352514
2019-01-29 16:37:27 +00:00
Nico Weber 5b04e0a3fd lld-link: Allow backward references between associated comdats
References between associated comdats are invalid per COFF spec, but the newest
Windows SDK contains obj files that have these references
(https://bugs.chromium.org/p/chromium/issues/detail?id=925943#c13). So add back
support for them and add tests for them. The old code handled them fine.

This makes lld-link match the behavior of newer link.exe versions as far as I
can tell. (The behavior before this change matched the behavior of older
link.exe versions.)

This mostly reverts r352254.

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

llvm-svn: 352508
2019-01-29 15:50:31 +00:00
Fangrui Song ae82599a30 [ELF] Simplify. NFC
llvm-svn: 352499
2019-01-29 14:24:35 +00:00
George Rimar ff193c473e [ELF] - Remove dead `readBfdName` declaration. NFC.
`readBfdName` was removed recently.

llvm-svn: 352482
2019-01-29 11:46:00 +00:00
Martin Storsjo 5d1862b76c [MinGW] Ignore the --plugin and --plugin-opt option
GCC can use LLD with -fuse-ld=lld for MinGW these days, but by
default these options are passed to the linker (unless -fno-lto
is passed to the GCC driver).

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

llvm-svn: 352459
2019-01-29 08:38:48 +00:00
Rui Ueyama 0068d223ee Attempt to fix build failure with GCC 5.4.
llvm-svn: 352435
2019-01-28 21:45:50 +00:00
Nico Weber 38170e444f lld/coff: Make assoc comdat diag a bit more detailed
Many different sections can have the same name, so include the indices of the
sections mentioned in the diagnostic too.

I'm debugging something I can't repro locally, maybe this will help.

llvm-svn: 352428
2019-01-28 21:16:15 +00:00
Peter Collingbourne ff35dbac47 ELF: Set sh_info on RelaIplt to point to the IgotPlt output section.
Previously we were setting it to the GotPlt output section, which is
incorrect on ARM where this section is in .got. In static binaries
this can lead to sh_info being set to -1 (because there is no .got.plt)
which results in various tools rejecting the output file.

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

llvm-svn: 352413
2019-01-28 19:29:41 +00:00
Rui Ueyama 4f8c82281d Refactoring. NFC.
llvm-svn: 352407
2019-01-28 19:11:52 +00:00
George Rimar 8bb8433a1a [LLD][ELF] - Update tests after r352366.
r352366 "[llvm-objdump] - Print LMAs when dumping section headers." changed the format of
llvm-objdump output. We have to update the LLD tests.

llvm-svn: 352372
2019-01-28 15:03:47 +00:00
Alexandre Ganea 864d2639f1 [LLD][COFF] Partial sections
Persist (input) sections that make up an OutputSection. This is a supporting patch for the upcoming D54802.

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

llvm-svn: 352336
2019-01-28 01:45:35 +00:00
Martin Storsjo acaa78b171 [COFF] Add support for the new relocation IMAGE_REL_ARM{,64}_REL32
Differential Revision: https://reviews.llvm.org/D57292

llvm-svn: 352325
2019-01-27 19:57:50 +00:00
Nico Weber b1a110c961 Follow-up to r352254: Initialize Selection field.
The diagnostic there fired spuriosly due to uninitialized memory.

llvm-svn: 352304
2019-01-27 03:56:37 +00:00
Nick Desaulniers 6cff0cb35a lld: elf: discard more specific .gnu.linkonce section
Summary:
lld discards .gnu.linonce.* sections work around a bug in glibc.
https://sourceware.org/bugzilla/show_bug.cgi?id=20543

Unfortunately, the Linux kernel uses a section named
.gnu.linkonce.this_module to store infomation about kernel modules. The
kernel reads data from this section when loading kernel modules, and
errors if it fails to find this section. The current behavior of lld
discards this section when kernel modules are linked, so kernel modules
linked with lld are unloadable by the linux kernel.

The Linux kernel should use a comdat section instead of .gnu.linkonce.
The minimum version of binutils supported by the kernel supports comdat
sections. The kernel is also not relying on the old linkonce behavior;
it seems to have chosen a name that contains a deprecated GNU feature.

Changing the section name now in the kernel would require all kernel
modules to be recompiled to make use of the new section name. Instead,
rather than discarding .gnu.linkonce.*, let's discard the more specific
section name to continue working around the glibc issue while supporting
linking Linux kernel modules.

Link: https://github.com/ClangBuiltLinux/linux/issues/329

Reviewers: pcc, espindola

Reviewed By: pcc

Subscribers: nathanchance, emaste, arichardson, void, srhines

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

llvm-svn: 352302
2019-01-27 02:54:23 +00:00
Rui Ueyama 3749befe74 Remove dead declaration.
llvm-svn: 352257
2019-01-26 00:31:49 +00:00
Nico Weber 6bb3a1aa75 lld-link: Store comdat selection in SectionChunk, reject more invalid associated comdats
I need the comdat selection for PR40094. To keep the patch for that smaller,
I'm adding it here, and as a first application I'm using it to reject
associative comdats referring to earlier associative comdats. Depends on
D56929; together with that all associative comdats referring to other
associative comdats are now rejected.

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

llvm-svn: 352254
2019-01-26 00:14:52 +00:00
Rui Ueyama e14e46b3f1 Simplify. NFC.
llvm-svn: 352242
2019-01-25 21:25:25 +00:00
Zachary Turner 8371da385a [PDB] Increase TPI hash bucket count.
PDBs contain several serialized hash tables. In the microsoft-pdb
repo published to support LLVM implementing PDB support, the
provided initializes the bucket count for the TPI and IPI streams
to the maximum size. This occurs in tpi.cpp L33 and tpi.cpp L398.
In the LLVM code for generating PDBs, these streams are created with
minimum number of buckets. This difference makes LLVM generated
PDBs slower for when used for debugging.

Patch by C.J. Hebert
Differential Revision: https://reviews.llvm.org/D56942

llvm-svn: 352117
2019-01-24 22:25:55 +00:00
James Y Knight c20a5767f9 Define the _fltused symbol in a couple tests post-r352076.
Normally it's defined by MSCRT, but these tests are standalone, so
they need to define it themselves.

llvm-svn: 352110
2019-01-24 21:31:43 +00:00
Rui Ueyama 18972d1ee9 Fix broken export table if .rdata is merged with .text.
Previously, we assumed that .rdata is zero-filled, so when writing
an COFF import table, we didn't write anything if the data is zero.
That assumption was wrong because .rdata can be merged with .text.
If .rdata is merged with .text, they are initialized with 0xcc which
is a trap instruction.

This patch removes that assumption from code.

Should be merged to 8.0 branch as this is a regression.

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

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

llvm-svn: 352082
2019-01-24 19:02:31 +00:00
Nico Weber cf8baa8307 lld/coff: Rename two tests from .s to .test
llvm-svn: 352074
2019-01-24 18:30:33 +00:00
Sean Fertile 83cb252876 [PPC64] Reland r351978 'Sort .toc sections accessed with small code model ...'
Guessing that the slashes used in the scripts SECTION command was causing the
windows related failures in the added test.

Original commit message:
Small code model global variable access on PPC64 has a very limited range of
addressing. The instructions the relocations are used on add an offset in the
range [-0x8000, 0x7FFC] to the toc pointer which points to .got +0x8000, giving
an addressable range of [.got, .got + 0xFFFC]. While user code can be recompiled
with medium and large code models when the binary grows too large for small code
model, there are small code model relocations in the crt files and libgcc.a
which are typically shipped with the distros, and the ABI dictates that linkers
must allow linking of relocatable object files using different code models.

To minimze the chance of relocation overflow, any file that contains a small
code model relocation should have its .toc section placed closer to the .got
then any .toc from a file without small code model relocations.

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

llvm-svn: 352071
2019-01-24 18:17:40 +00:00
Rui Ueyama ec33fd6dd5 Untabify.
llvm-svn: 352070
2019-01-24 18:17:17 +00:00
Serge Guelton 1fa239f500 Partial support of SHT_GROUP without flag
This does *not* implement full SHT_GROUP semantic, yet it is a simple step forward:
Sections within a group are still considered valid, but they do not behave as
specified by the standard in case of garbage collection.

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

llvm-svn: 352068
2019-01-24 17:56:08 +00:00
Sean Fertile 72679cff12 Revert "[PPC64] Sort .toc sections accessed with small code model ..."
This reverts commit ca87c57a3aa4770c9cf0defd4b2feccbc342ee93.
Added test fails on several windows buildbots.

llvm-svn: 351985
2019-01-23 21:46:28 +00:00
Sean Fertile a010cf615a [PPC64] Sort .toc sections accessed with small code model relocs close to .got.
Small code model global variable access on PPC64 has a very limited range of
addressing. The instructions the relocations are used on add an offset in the
range [-0x8000, 0x7FFC] to the toc pointer which points to .got +0x8000, giving
an addressable range of [.got, .got + 0xFFFC]. While user code can be recompiled
with medium and large code models when the binary grows too large for small code
model, there are small code model relocations in the crt files and libgcc.a
which are typically shipped with the distros, and the ABI dictates that linkers
must allow linking of relocatable object files using different code models.

To minimze the chance of relocation overflow, any file that contains a small
code model relocation should have its .toc section placed closer to the .got
then any .toc from a file without small code model relocations.

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

llvm-svn: 351978
2019-01-23 21:04:03 +00:00
Nico Weber 8874aef822 Disable test better.
llvm-svn: 351952
2019-01-23 13:43:42 +00:00
Nico Weber 53c3c2c61c Disable test added in r351916.
It doesn't pass on Windows:
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/3627

FAIL: lld :: ELF/stdout.s (1521 of 1966)
******************** TEST 'lld :: ELF/stdout.s' FAILED ********************
Script:
--
: 'RUN: at line 3';   C:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\llvm-mc.EXE -filetype=obj -triple=x86_64-unknown-linux C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\lld\test\ELF\stdout.s -o C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp.o
: 'RUN: at line 4';   c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\ld.lld.EXE C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp.o -o - > C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp1
: 'RUN: at line 5';   C:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\llvm-objdump.EXE -d C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp1 | C:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\FileCheck.EXE C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\lld\test\ELF\stdout.s
: 'RUN: at line 10';   c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\ld.lld.EXE C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp.o -o C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp2
: 'RUN: at line 11';   diff C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp1 C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp2
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 3"
$ "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\llvm-mc.EXE" "-filetype=obj" "-triple=x86_64-unknown-linux" "C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\lld\test\ELF\stdout.s" "-o" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp.o"
$ ":" "RUN: at line 4"
$ "c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\ld.lld.EXE" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp.o" "-o" "-"
$ ":" "RUN: at line 5"
$ "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\llvm-objdump.EXE" "-d" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp1"
$ "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\FileCheck.EXE" "C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\lld\test\ELF\stdout.s"
$ ":" "RUN: at line 10"
$ "c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\ld.lld.EXE" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp.o" "-o" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp2"
$ ":" "RUN: at line 11"
$ "diff" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp1" "C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp2"
# command output:
*** C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp1
--- C:\b\slave\clang-x64-windows-msvc\build\build\stage1\tools\lld\test\ELF\Output\stdout.s.tmp2
***************
*** 1 ****

llvm-svn: 351949
2019-01-23 12:35:08 +00:00
Nico Weber 0fb18e6e78 lld-link: Use just one code path to process associative comdats, reject some invalid associated comdats
Currently, if an associative comdat appears after the comdat it's associated
with it's processed immediately, else it's deferred until the end of the object
file. I found this confusing to think about while working on PR40094, so this
makes it so that associated comdats are always processed at the end of the
object file.  This seems to be perf-neutral and simpler.

Now there's a natural place to reject the associated comdats referring to later
associated comdats (associated comdats referring to associated comdats is
invalid per COFF spec) that, so reject those. (A later patch will reject
associated comdats referring to earlier comdats.)

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

llvm-svn: 351917
2019-01-23 02:07:10 +00:00
Rui Ueyama 7c8fc8142e MemoryBlock: Do not automatically extend a given size to a multiple of page size.
Previously, MemoryBlock automatically extends a requested buffer size to a
multiple of page size because (I believe) doing it was thought to be harmless
and with that you could get more memory (on average 2KiB on 4KiB-page systems)
"for free".

That programming interface turned out to be error-prone. If you request N
bytes, you usually expect that a resulting object returns N for `size()`.
That's not the case for MemoryBlock.

Looks like there is only one place where we take the advantage of
allocating more memory than the requested size. So, with this patch, I
simply removed the automatic size expansion feature from MemoryBlock
and do it on the caller side when needed. MemoryBlock now always
returns a buffer whose size is equal to the requested size.

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

llvm-svn: 351916
2019-01-23 02:03:26 +00:00
Peter Collingbourne bcd08c16bb COFF, ELF: ICF: Perform 2 rounds of relocation hash propagation.
LLD's performance on PGO instrumented Windows binaries was still not
great even with the fix in D56955; out of the 2m41s linker runtime,
around 2 minutes were still being spent in ICF. I looked into this more
closely and discovered that the vast majority of the runtime was being
spent segregating .pdata sections with the following relocation chain:

.pdata -> identical .text -> unique PGO counter (not eligible for ICF)

This patch causes us to perform 2 rounds of relocation hash
propagation, which allows the hash for the .pdata sections to
incorporate the identifier from the PGO counter. With that, the amount
of time spent in ICF was reduced to about 2 seconds. I also found that
the same change led to a significant ICF performance improvement in a
regular release build of Chromium's chrome_child.dll, where ICF time
was reduced from around 1s to around 700ms.

With the same change applied to the ELF linker, median of 100 runs
for lld-speed-test/chrome reduced from 4.53s to 4.45s on my machine.

I also experimented with increasing the number of propagation rounds
further, but I did not observe any further significant performance
improvements linking Chromium or Firefox.

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

llvm-svn: 351899
2019-01-22 23:54:49 +00:00
Peter Collingbourne 3426111145 COFF, ELF: Adjust ICF hash computation to account for self relocations.
It turns out that sections in PGO instrumented object files on Windows
contain a large number of relocations pointing to themselves. With
r347429 this can cause many sections to receive the same hash (usually
zero) as a result of a section's hash being xor'ed with itself.

This patch causes the COFF and ELF linkers to avoid this problem
by adding the hash of the relocated section instead of xor'ing it.
On my machine this causes the regressing test case
provided by Mozilla to terminate in 2m41s.

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

llvm-svn: 351898
2019-01-22 23:51:35 +00:00
Rui Ueyama 4063cfc745 FileOutputBuffer: Handle "-" as stdout.
I was honestly a bit surprised that we didn't do this before. This
patch is to handle "-" as the stdout so that if you pass `-o -` to
lld, for example, it writes an output to stdout instead of file `-`.

I thought that we might want to handle this at a higher level than
FileOutputBuffer, because if we land this patch, we can no longer
create a file whose name is `-` (there's a workaround though; you can
pass `./-` instead of `-`). However, because raw_fd_ostream already
handles `-` as a special file name, I think it's okay and actually
consistent to handle `-` as a special name in FileOutputBuffer.

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

llvm-svn: 351852
2019-01-22 18:44:04 +00:00
James Henderson b88d6fd7b8 [LLD][ELF]Fix tests for D56910
r351789 changes the output of llvm-readelf --dyn-symbols. This causes 3
LLD tests to break. This patch fixes them.

Reviewed by: ruiu

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

llvm-svn: 351790
2019-01-22 09:35:47 +00:00
Chandler Carruth 4a1b95bda0 Fix typos throughout the license files that somehow I and my reviewers
all missed!

Thanks to Alex Bradbury for pointing this out, and the fact that I never
added the intended `legacy` anchor to the developer policy. Add that
anchor too. With hope, this will cause the links to all resolve
successfully.

llvm-svn: 351731
2019-01-21 09:52:34 +00:00
Serge Guelton 52d777fc4f Tentative fix for r351701 and gcc 6.2 build on ubuntu
llvm-svn: 351728
2019-01-21 07:44:52 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Chandler Carruth 469bdefd44 Install new LLVM license structure and new developer policy.
This installs the new developer policy and moves all of the license
files across all LLVM projects in the monorepo to the new license
structure. The remaining projects will be moved independently.

Note that I've left odd formatting and other idiosyncracies of the
legacy license structure text alone to make the diff easier to read.
Critically, note that we do not in any case *remove* the old license
notice or terms, as that remains necessary until we finish the
relicensing process.

I've updated a few license files that refer to the LLVM license to
instead simply refer generically to whatever license the LLVM project is
under, basically trying to minimize confusion.

This is really the culmination of so many people. Chris led the
community discussions, drafted the policy update and organized the
multi-year string of meeting between lawyers across the community to
figure out the strategy. Numerous lawyers at companies in the community
spent their time figuring out initial answers, and then the Foundation's
lawyer Heather Meeker has done *so* much to help refine and get us ready
here. I could keep going on, but I just want to make sure everyone
realizes what a huge community effort this has been from the begining.

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

llvm-svn: 351631
2019-01-19 06:14:24 +00:00
Nico Weber b166d7e725 Use llvm_canonicalize_cmake_booleans for LLVM_LIBXML2_ENABLED [lld]
r291284 added a nice mechanism to consistently pass CMake on/off toggles to
lit. This change uses it for LLVM_LIBXML2_ENABLED too (which was added around
the same time and doesn't use the new system yet).

No intended behavior change.

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

llvm-svn: 351614
2019-01-19 00:09:43 +00:00
Mandeep Singh Grang f9d76dc354 [lld] Use range-based llvm::sort
llvm-svn: 351612
2019-01-18 23:41:34 +00:00
Sam Clegg 622ad04625 [WebAssembly] Fix windows compiler warning by using explicit 64bit shift. NFC.
Differential Revision: https://reviews.llvm.org/D56874

llvm-svn: 351488
2019-01-17 22:09:09 +00:00
Wouter van Oortmerssen 7ab15a79be [WebAssembly] Changed objdump output to offsets instead of indices.
Summary: This is to accommodate this change: https://reviews.llvm.org/D56684

Reviewers: sbc100

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

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

llvm-svn: 351462
2019-01-17 18:30:35 +00:00
Thomas Lively 2a0868ff48 [WebAssembly] Merge producers section
llvm-svn: 351412
2019-01-17 02:29:41 +00:00
Thomas Lively d24ae47db6 Revert "[WebAssembly] Merge producers section"
This reverts commit 71eaf61c6c121c8c3bcaf3490557e92cf81599cb. One of
the lld tests was breaking, so revert this change until it is fixed.

llvm-svn: 351409
2019-01-17 00:34:44 +00:00
Thomas Lively 7ec7a299a2 [WebAssembly] Merge producers section
Reviewers: sbc100, aheejin, dschuff

Subscribers: jgravelle-google, sunfish, llvm-commits

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

llvm-svn: 351400
2019-01-16 23:46:15 +00:00
Peter Wu 5391489674 [ELF][X86_64] Fix corrupted LD -> LE optimization for TLS without PLT
The LD -> LE optimization for Thread-Local Storage without PLT requires
an additional "66" prefix, otherwise the next instruction will be
corrupted, causing runtime misbehavior (crashes) of the linked object.

The other (GD -> IE/LD) optimizations are the same with or without PLT,
but add tests for completeness. The instructions are copied from
https://raw.githubusercontent.com/wiki/hjl-tools/x86-psABI/x86-64-psABI-1.0.pdf#subsection.11.1.2

This does not try to address ILP32 (x32) support.

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

Reviewed By: ruiu

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

llvm-svn: 351396
2019-01-16 23:28:51 +00:00
Peter Smith e8374614c9 [ELF][AArch64] Add R_AARCH64_PLT_PAGE_PC to isRelExpr
As a follow on to D56666 (r351186) there is a case when taking the address
of an ifunc when linking -pie that can generate a spurious can't create
dynamic relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol in readonly
segment. Specifically the case is where the ifunc is in the same
translation unit as the address taker, so given -fpie the compiler knows
the ifunc is defined in the executable so it can use a non-got-generating
relocation.

The error message is due to R_AARCH64_PLT_PAGE_PC not being added to
isRelExpr, its non PLT equivalent R_AARCH64_PAGE_PC is already in
isRelExpr.

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

llvm-svn: 351335
2019-01-16 13:24:02 +00:00
Peter Smith 13d134684f [ELF] Implement option to force PIC compatible Thunks
By default LLD will generate position independent Thunks when the --pie or
--shared option is used. Reference to absolute addresses is permitted in
other cases. For some embedded systems position independent thunks are
needed for code that executes before the MMU has been set up. The option
--pic-veneer is used by ld.bfd to force position independent thunks.
    
The patch adds --pic-veneer as the option is needed for the Linux kernel
on Arm.
    
fixes pr39886
    
Differential Revision: https://reviews.llvm.org/D55505

llvm-svn: 351326
2019-01-16 12:09:13 +00:00
Hans Wennborg 1fe469ae6c Bump the trunk version to 9.0.0svn
llvm-svn: 351320
2019-01-16 10:57:02 +00:00
Sam Clegg 6320efb4ed [WebAssembly] Store section alignment as a power of 2
This change bumps for version number of the wasm object file
metadata.

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

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

llvm-svn: 351287
2019-01-16 01:43:21 +00:00
Rui Ueyama 6f9d49cdde Do not emit a corrupt symbol table entry for .rela_iplt_{start,end}.
If .rela.iplt does not exist, we used to emit a corrupt symbol table
that contains two symbols, .rela_iplt_{start,end}, pointing to a
nonexisting section.

This patch fixes the issue by setting section index 0 to the symbols
if .rel.iplt section does not exist.

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

llvm-svn: 351218
2019-01-15 18:30:23 +00:00
Hans Wennborg eb60fbfdb4 Update year in license files
In last year's update (D48219) it was suggested that the release manager
might want to do this, so here we go.

llvm-svn: 351194
2019-01-15 15:10:32 +00:00
Peter Smith b20f993df8 [ELF][AArch64] Add missing PLT relocations to isStaticLinkTimeConstant
r347650 fixed pr38074 for AArch64 for static linking. It added two new
RelExpr instances R_AARCH64_GOT_PAGE_PC_PLT and R_GOT_PLT. These need to be
added to isStaticLinkTimeConstant so that the address of an ifunc can be
taken when building a shared library.

fixes pr40250

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

llvm-svn: 351186
2019-01-15 11:17:03 +00:00
Nico Weber 1f3ab98aca lld-link: Spelling fixes in comments and minor style tweaks
Changes a few things I noticed while reading this code.
- fix a few typos in comments
- remove two `auto` uses where the type wasn't clear to me
- add comment saying that two sequential checks for `if (SparseChunks[SectionNumber] == PendingComdat)` are intentional
- name two parameters

No behavior change.

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

llvm-svn: 351101
2019-01-14 19:05:21 +00:00
Nico Weber 6a5d94cc08 lld/include/lld/Core/TODO.txt
- fix minor grammar stuff (I'm not a native speaker either, but it's hopefully a net improvement)
- mention that lld/coff is used in production
- update AArch64, ARM to production quality
- remove lld/include/lld/Core/TODO.txt which looks outdated

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

llvm-svn: 351030
2019-01-14 00:45:27 +00:00
Rui Ueyama 4f194250ec Add a release note about MSP430 support.
llvm-svn: 350975
2019-01-11 22:31:35 +00:00
Alexandre Ganea 7d9fc98db0 Fix unchecked Error introduced in r350956
llvm-svn: 350968
2019-01-11 20:39:38 +00:00
Alexandre Ganea 27ba55914a [LLD][COFF] Support /ignore:4099. Support /ignore with comma-separated arguments.
Differential Revision: https://reviews.llvm.org/D56392

llvm-svn: 350956
2019-01-11 19:10:01 +00:00
Rui Ueyama 69e9fcef6a Remove an external test file. NFC.
llvm-svn: 350855
2019-01-10 17:57:30 +00:00
Rui Ueyama b41a6966e0 TrapInstr must be 4 bytes long. Currently we write two zeros on every two bytes.
llvm-svn: 350853
2019-01-10 17:45:56 +00:00
George Rimar 6552b29867 [LLD][ELF] - Fix tests after r350840.
D56076 (r350840) changed the llvm-objdump output.

This is a follow up commit to fix LLD test cases.

llvm-svn: 350842
2019-01-10 16:26:05 +00:00
Peter Smith 1811e48b7b [ELF] Fix ARM and Thumb V7PILongThunk overflow behavior.
When the range between the source and target of a V7PILongThunk exceeded an
int32 we would trigger a relocation out of range error for the
R_ARM_MOVT_PREL or R_ARM_THM_MOVT_PREL relocation. This case can happen when
linking the linux kernel as it is loaded above 0xf0000000.

There are two parts to the fix.
- Remove the overflow check for R_ARM_MOVT_PREL or R_ARM_THM_MOVT_PREL. The
ELF for the ARM Architecture document defines these relocations as having no
overflow checking so the check was spurious.
- Use int64_t for the offset calculation, in line with similar thunks so
that PC + (S - P) < 32-bits. This results in less surprising disassembly.

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

llvm-svn: 350836
2019-01-10 16:08:23 +00:00
George Rimar ad6b88b481 [LLD][ELF] - A follow up for r350819 ("Support MSP430") : add a test case missing.
It got lost for some reason.

llvm-svn: 350833
2019-01-10 15:34:33 +00:00
Sean Fertile 3ca494b2ee Modify InputSectionBase::getLocation to add section and offset to every loc.
The section and offset can be very helpful in diagnosing certian errors.
For example on a relocation overflow or misalignment diagnostic:

test.c:(function  foo): relocation R_PPC64_ADDR16_DS out of range: ...

The function foo can have many R_PPC64_ADDR16_DS relocations. Adding the offset
and section will identify exactly which relocation is causing the failure.

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

llvm-svn: 350828
2019-01-10 15:08:06 +00:00
Sean Fertile 461725b585 [PPC64] Fix RelType in checkInt and checkAlignment diagnsotics.
In the PPC64 target we map toc-relative relocations, dynamic thread pointer
relative relocations, and got relocations into a corresponding ADDR16 relocation
type for handling in relocateOne. This patch saves the orignal RelType before
mapping to an ADDR16 relocation so that any diagnostic messages will not
mistakenly use the mapped type.

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

llvm-svn: 350827
2019-01-10 15:08:02 +00:00
George Rimar 0552376cc8 [LLD][ELF] - Fix the test cases after r350823.
r350823 changed the output of the llvm-objdump.

llvm-svn: 350824
2019-01-10 14:57:25 +00:00
George Rimar 73af3d4060 [LLD][ELF] - Support MSP430.
Patch by Michael Skvortsov!

This change adds a basic support for linking static MSP430 ELF code.
Implemented relocation types are intended to correspond to the BFD.

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

llvm-svn: 350819
2019-01-10 13:43:06 +00:00
Rui Ueyama c58fbe3c71 Fix formatting. NFC.
llvm-svn: 350767
2019-01-09 22:24:27 +00:00
Nico Weber 64fb85c907 lld-link: Add help strings for /manifest, /nodefaultlib, /noentry; tweak manifest help strings
My main motivation is that I can never remember /nodefaultlib and
`lld-link /? | grep no` didn't display it due to it not having a help string.

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

llvm-svn: 350750
2019-01-09 19:18:03 +00:00
George Rimar 17a9204d0c [LLD][ELF] - Fix BB after r350726.
D56123 changed the llvm-objdump output format.
Now we print the symbol address when dumping.

llvm-svn: 350728
2019-01-09 15:06:57 +00:00
Ryan Prichard d7d2369c09 [ARM][AArch64] Increase TLS alignment to reserve space for Android's TCB
ARM and AArch64 use TLS variant 1, where the first two words after the
thread pointer are reserved for the TCB, followed by the executable's TLS
segment. Both the thread pointer and the TLS segment are aligned to at
least the TLS segment's alignment.

Android/Bionic historically has not supported ELF TLS, and it has
allocated memory after the thread pointer for several Bionic TLS slots
(currently 9 but soon only 8). At least one of these allocations
(TLS_SLOT_STACK_GUARD == 5) is widespread throughout Android/AArch64
binaries and can't be changed.

To reconcile this disagreement about TLS memory layout, set the minimum
alignment for executable TLS segments to 8 words on ARM/AArch64, which
reserves at least 8 words of memory after the TP (2 for the ABI-specified
TCB and 6 for alignment padding). For simplicity, and because lld doesn't
know when it's targeting Android, increase the alignment regardless of
operating system.

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

llvm-svn: 350681
2019-01-09 00:09:59 +00:00
James Henderson 4ba1777a2d [ELF] Remove checking for spurious '@' at the end of dynamic sym names
llvm-readobj currently has a bug (see PR40097) where it prints '@' at
the end of unversioned dynamic symbols. This bug will be fixed in a
separate later commit, but these tests need fixing first.

Reviewed by: ruiu, Higuoxing

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

llvm-svn: 350614
2019-01-08 10:50:59 +00:00
Thomas Lively 25ff893712 [WebAssembly] Instruction renaming
Summary: Associated with D56338.

Reviewers: aheejin, aardappel

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

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

llvm-svn: 350610
2019-01-08 06:25:55 +00:00
Alexandre Ganea 90f4b94da3 [CodeView] More appropriate name and type for a Microsoft precompiled headers parameter. NFC
llvm-svn: 350520
2019-01-07 13:53:16 +00:00
Martin Storsjo 17fb13bb40 [docs] Add a known limitation to the comment about lld supporting GCC/MinGW object files. NFC.
Differential Revision: https://reviews.llvm.org/D56335

llvm-svn: 350465
2019-01-05 10:44:03 +00:00
Martin Storsjo 5abe10ac21 [MinGW] Expand comment for MinGW driver. NFC.
Originally authored by Rui Ueyama.

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

llvm-svn: 350464
2019-01-05 10:43:59 +00:00
Alexandre Ganea 383be892fc [LLD][COFF] PDB: Parallel sort publics
Saves up to 1.3 sec on large PDBs.
Figures below are for the "Globals Stream Layout" pass:

                            Before	This patch
Large EXE (PDB is ~2 GB)	3330 ms	2022 ms
Large EXE (PDB is ~2 GB)	2680 ms	1608 ms
Large DLL (PDB is ~1 GB)	1455 ms	938 ms
Large DLL (PDB is ~800 MB)	1215 ms	800 ms
Small DLL (PDB is ~200 MB)	224 ms	146 ms

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

llvm-svn: 350452
2019-01-05 01:16:24 +00:00
Alexandre Ganea e6ed8540c5 [LLD][COFF] Fix namespace compilation issue with a upcoming patch. NFC
llvm-svn: 350450
2019-01-05 01:08:10 +00:00
Alexandre Ganea 79d4851678 [LLD][COFF] Fix file/line retrieval when a undefined symbol is to be printed
Differential Revision: https://reviews.llvm.org/D55951

llvm-svn: 350438
2019-01-04 21:49:22 +00:00
Michal Gorny ceacc63e1f [test] Enable system-linker-elf feature on NetBSD [NFC]
Since NetBSD uses ELF linker, enable the relevant feature.  It's not
currently used for anything, though.

llvm-svn: 350253
2019-01-02 19:39:26 +00:00
Thomas Anderson 4a401e9479 Fix linker-defined symbols possibly not being defined when -wrap is used
Fixes https://bugs.llvm.org/show_bug.cgi?id=40134

addWrappedSymbols() must be called before addReservedSymbols() because the
latter only defines reserved symbols when they are undefined in the symbol
table. If addWrappedSymbols() is called after, then addUndefined() is called
which may lazily pull in more object files that could reference reserved
symbols.

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

llvm-svn: 350251
2019-01-02 19:28:00 +00:00
Fangrui Song 50394f6e01 [ELF] A shared object is needed if any of its occurrences is needed
Summary:
If a DSO appears more than once with and without --as-needed, ld.bfd and gold consider --no-as-needed to takes precedence over --as-needed. lld didn't and this patch makes it do so.

This makes it a bit away from the position-dependent behavior (how
different occurrences of the same DSO interact) and protects us from
some mysterious runtime errors: if some interceptor libraries add their
own --no-as-needed dependencies (e.g. librt.so), and the user
application specifies -Wl,--as-needed -lrt , the absence of the
DT_NEEDED entry would make dlsym(RTLD_NEXT, "clock_gettime") return NULL
and would break at runtime.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 350105
2018-12-27 22:24:45 +00:00
Rui Ueyama 56c5343e5a Use error() instead of fatal() to report an invalid address range.
In this patch we also use toString() to stringize a section.

llvm-svn: 350070
2018-12-26 19:15:04 +00:00
George Rimar 4c66df8584 [LLD][ELF] - Cleanup gdb-index-dwarf5-low-high.s. NFC.
Remove tabs and .debug_macinfo sections.

llvm-svn: 350051
2018-12-24 10:18:07 +00:00
Kamil Rytarowski ae1ab910cd Tolerate flaky LLD tests on NetBSD
Summary:
For unknown reasons  LLD tests are flaky on the NetBSD buildbot,
but not on local machines of developers.

Unless the linker will be fully functional on this target,
allow to pass flaky tests with optional retry.

Reviewers: joerg, mgorny, ruiu

Reviewed By: mgorny

Subscribers: lebedev.ri, MaskRay, llvm-commits, #lld

Tags: #lld

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

llvm-svn: 350036
2018-12-23 21:20:09 +00:00
David Blaikie 7c282bf66d Test DWARFv5 with gdb-index and low_pc/high_pc on the CU (rather than ranges)
There was a bug in LLVM's libDebugInfo where it did not porpagate the
section index through the range query built from low_pc/high_pc. Hard to
test in LLVM, so I'm adding a test here.

llvm-svn: 350011
2018-12-22 22:20:47 +00:00
David Blaikie 059b1c5e01 gdb-index: Handle errors when parsing ranges
When parsing CU ranges for gdb-index, handle the error (now propagated
up though the API lld is calling here - previously the error was
printed within the libDebugInfo API, not allowing lld to format or
handle the message at all) - including information about the object and
archive name, as well as failing the link.

llvm-svn: 349979
2018-12-22 00:31:05 +00:00
Fangrui Song f747971bf1 keymethod -> keyfunction
Pointed out by ruiu in rLLD349969

llvm-svn: 349974
2018-12-21 22:57:11 +00:00