Commit Graph

11835 Commits

Author SHA1 Message Date
Diogo N. Sampaio 0c4a184577 [FIX][AArch64] lld test change
Adding AArch64 UDF, in rL345581,
breaks some lld test files, due
different decoding

llvm-svn: 345592
2018-10-30 12:19:55 +00:00
James Henderson 1e74ecab17 [ELF][PPC64]Workaround bogus Visual Studio build warning
Visual Studio has a bug where it converts the integer literal 2147483648
into an unsigned int instead of a long long (i.e. it follows C89 rules).
The bug has been reported as:
https://developercommunity.visualstudio.com/content/problem/141813/-2147483648-c4146-error.html.

Because of this bug, we were getting a signed/unsigned comparison
warning in VS2015 from the old code (the subsequent unary negation had
no effect on the type).

Reviewed by: sfertile

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

llvm-svn: 345579
2018-10-30 10:55:14 +00:00
Konstantin Zhuravlyov f472afd684 AMDGPU: Switch some lld tests to v2
Differential Revision: https://reviews.llvm.org/D53526

llvm-svn: 345530
2018-10-29 19:59:12 +00:00
Rui Ueyama 4c06a6cc90 Rename warnUnorderableSymbol maybeWarnUnorderableSymbol because the function doesn't always emit a warning.
llvm-svn: 345393
2018-10-26 15:07:12 +00:00
Rui Ueyama 2b39ea477c Refactor readCallGraph() and readCallGraphFromObjectFiles(). NFC.
llvm-svn: 345392
2018-10-26 15:07:02 +00:00
Fangrui Song cc18f8aa0f [ELF] Add --{,no-}call-graph-profile-sort (enabled by default)
Summary: Add an option to disable sorting sections with call graph profile

Reviewers: ruiu, Bigcheese, espindola

Reviewed By: Bigcheese

Subscribers: grimar, emaste, arichardson, llvm-commits

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

llvm-svn: 345332
2018-10-25 23:15:23 +00:00
Fangrui Song 018b0634b4 [ELF] Don't check if symbols in .llvm.call-graph-profile are unorderable
Summary: There are too many reasonable cases that would be considered unorderable.

Reviewers: ruiu, espindola, Bigcheese

Reviewed By: ruiu

Subscribers: grimar, emaste, arichardson, llvm-commits

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

llvm-svn: 345322
2018-10-25 22:15:42 +00:00
Rui Ueyama 9db06423d1 Remove full stops from error messages for consistency.
llvm-svn: 345294
2018-10-25 18:07:55 +00:00
Rui Ueyama 444363e931 Do not call computeIsPreemptible() if its result is discarded. NFC.
llvm-svn: 345208
2018-10-24 22:15:32 +00:00
Rui Ueyama 4664280a9c Add more blank lines so that code doesn't look too dense. NFC.
llvm-svn: 345205
2018-10-24 21:59:58 +00:00
Rui Ueyama 6e33f7ac66 Add a comment for PPC64 .toc and GNU relro.
llvm-svn: 345204
2018-10-24 21:59:48 +00:00
Rui Ueyama aa2948776a Include input section name and output section name in an error message.
Differential Revision: https://reviews.llvm.org/D53645

llvm-svn: 345172
2018-10-24 18:15:40 +00:00
Rui Ueyama 8d76024916 Refactor assignFileOffsets. NFC.
llvm-svn: 345154
2018-10-24 15:47:46 +00:00
Rui Ueyama 6d26ed92cc Split a function. NFC.
llvm-svn: 345143
2018-10-24 14:24:01 +00:00
Rui Ueyama 6e763a36c6 Add parenthese around a bitand.
llvm-svn: 345139
2018-10-24 13:44:51 +00:00
Rui Ueyama ee2b61cfd3 Make a local variable scope narrower. NFC.
llvm-svn: 345138
2018-10-24 13:42:33 +00:00
Martin Storsjo 865cb5604c [MinGW] Support for multiarch runtimes layout
Patch by Peiyuan Song!

llvm-svn: 345117
2018-10-24 07:42:10 +00:00
Martin Storsjo c3095ace86 [ELF] Remove a superfluous semicolon, fixing warnings. NFC.
llvm-svn: 345116
2018-10-24 07:42:06 +00:00
Rui Ueyama 02c7fae348 Move forward declarations to the top of the file and sort.
llvm-svn: 345094
2018-10-23 22:37:14 +00:00
Rui Ueyama b0de6c742a Move a function out of a class because it doesn't depend on any class member. NFC.
llvm-svn: 345093
2018-10-23 22:31:08 +00:00
Rui Ueyama 5a30177ef6 Factor out code to a new function. NFC.
llvm-svn: 345088
2018-10-23 22:03:33 +00:00
Rui Ueyama edc3201b11 Simplify. NFC.
A higher order function `applySyntehtic` can be replaced with a simpler function.

llvm-svn: 345081
2018-10-23 21:17:00 +00:00
Rui Ueyama 660e8721a9 Remove a global variable that is set but not used.
llvm-svn: 345080
2018-10-23 21:00:28 +00:00
Rui Ueyama 29d8639732 Add a comment.
llvm-svn: 345062
2018-10-23 17:52:44 +00:00
Rui Ueyama 42ab6c53f8 Remove a global variable that we can live without.
Out::DebugInfo was used only by GdbIndex class to determine if
we need to create a .gdb_index section, but we can do the same
check without it.

Added a test that this patch doesn't change the existing behavior.

llvm-svn: 345058
2018-10-23 17:39:43 +00:00
Dimitry Andric ad5aab8ddb Don't mess up RelIplt symbols during relocatable processing
Summary:
During upgrading of the FreeBSD source tree with lld 7.0.0, I noticed
that it started complaining about `crt1.o` having an "index past the
end of the symbol table".

Such a symbol table looks approximately like this, viewed with `readelf
-s` (note the `Ndx` field being messed up):

```
Symbol table '.symtab' contains 4 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    1
     2: 00000000     0 NOTYPE  WEAK   HIDDEN  RSV[0xffff] __rel_iplt_end
     3: 00000000     0 NOTYPE  WEAK   HIDDEN  RSV[0xffff] __rel_iplt_start
```

At first, it seemed that recent ifunc relocation work had caused this:
<https://reviews.freebsd.org/rS339351>, but it turned out that it was
due to incorrect processing of the object files by lld, when using `-r`
(a.k.a. --relocatable).

Bisecting showed that rL324421 ("Convert a use of Config->Static") was
the commit where this new behavior began.  Simply reverting it solved
the issue, and the `__rel_iplt` symbols had an index of `UND` again.

Looking at Rafael's commit message, I think he simply missed the
possibility of `--relocatable` being in effect, so I have added an
additional check for it.

I also added a simple regression test case.

Reviewers: grimar, ruiu, emaste, espindola

Reviewed By: ruiu

Subscribers: arichardson, krytarowski, llvm-commits

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

llvm-svn: 345002
2018-10-23 05:53:15 +00:00
Shoaib Meenai 3ac97e2ed4 [ELF] Split up emulation.s per backend
emulation.s is testing multiple architectures, which means it needs all
the corresponding backends enabled, which might not be true for all
developers (for example, I don't have PPC or MIPS enabled). Rather than
marking the entire test as unsupported for such developers, split it up
per backend to get better testing granularity.

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

llvm-svn: 344986
2018-10-23 01:19:18 +00:00
Shoaib Meenai 9d7de097d4 [ELF] Actually fix test from r344976
I don't think the offsets and flags are particularly relevant to the
test; the machine type is what matters.

llvm-svn: 344984
2018-10-23 00:34:34 +00:00
Shoaib Meenai 45f143c316 [ELF] Fix test from r344976
Turns out I wasn't actually running this test locally, since I don't
build the PPC and MIPS backends. Whoops.

Perhaps this test should be split up per-architecture?

llvm-svn: 344980
2018-10-23 00:27:27 +00:00
Shoaib Meenai c8e9d2b525 [ELF] Handle elf32-littlearm in OUTPUT_FORMAT
We need this to support 32-bit ARM. Add test cases for emulation
handling for this architecture as well.

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

llvm-svn: 344976
2018-10-22 23:56:10 +00:00
Fangrui Song efc0fe5a72 [ELF] Don't warn on two legitimate cases when reading .llvm.call-graph-profile
Summary:
Before, superfluous warnings were emitted for the following two cases:

1) When from symbol was in a discarded section.
  The profile should be thought of as affiliated to the section.
  It makes sense to ignore the profile if the section is discarded.

2) When to symbol was in a shared object.
  The object file containing the profile may not know about the to
  symbol, which can reside in another object file (useful profile) or a
  shared object (not useful as symbols in the shared object are fixed
  and unorderable). It makes sense to ignore the profile from the object
  file.

  Note, the warning when to symbol was undefined was suppressed in
  D53044, which is still useful for --symbol-ordering-file=

This patch silences the warnings. The check is actually more relaxed (no
warnings if either From or To is not Defined) for simplicity and I don't
see a compelling reason to warn on more cases.

Reviewers: ruiu, davidxl, espindola, Bigcheese

Reviewed By: ruiu

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 344974
2018-10-22 23:43:53 +00:00
Rui Ueyama ea8cd00a1d Add OUTPUT_FORMAT linker script directive support.
This patch adds a support for OUTPUT_FORMAT linker script directive.
Since I'm not 100% confident with BFD names you can use in the directive
for all architectures, I added only a few in this patch. We can add
other names for other archtiectures later.

We still do not support triple-style OUTPUT_FORMAT directive, namely,
OUTPUT_FORMAT(bfdname, big, little). If you pass -EL (little endian)
or -EB (big endian) to the linker, GNU linkers pick up big or little
as a BFD name, correspondingly, so that you can use a single linker
script for bi-endian processor. I'm not sure if we really need to
support that, so I'll leave it alone for now.

Note that -m takes precedence over OUTPUT_FORAMT, but we always parse
a BFD name given to OUTPUT_FORMAT for error checking. You cannot write
an invalid name in the OUTPUT_FORMAT directive.

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

llvm-svn: 344952
2018-10-22 20:50:01 +00:00
Fangrui Song e94d8823d9 [ELF][PPC64] Fix a split-stack comment in rLLD344622
The blt- instruction (predicted not to be taken) uses cr7, not the default cr0.

llvm-svn: 344948
2018-10-22 20:30:06 +00:00
Fangrui Song 8bafbfea9d [ELF] Format PPC64.cpp, NFC
Mainly two mis-indented places. The changes are local so should not interfere with in-review revisions

llvm-svn: 344932
2018-10-22 18:20:18 +00:00
Rui Ueyama ae8c3176b8 Fix typo in a test file name.
llvm-svn: 344899
2018-10-22 13:15:19 +00:00
Sam Clegg ea65647254 Use llvm::arrayRefFromStringRef
Differential Revision: https://reviews.llvm.org/D53432

llvm-svn: 344888
2018-10-22 08:35:39 +00:00
Sam Clegg ad980a75c4 [WebAssembly] Simplify --help message
Update wasm to match ELF changes made rL333596.

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

llvm-svn: 344887
2018-10-22 08:34:37 +00:00
Alexander Richardson 39adc6df0d Add an addAbsolute static function to Writer.cpp
Summary:
SymbolTable::addAbsolute() was removed in rL344305.
To me this is more readable than the lambda named `Add` and in our
out-of-tree CHERI target we use addAbsolute() in another function.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: kristina, emaste, llvm-commits

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

llvm-svn: 344842
2018-10-20 11:12:50 +00:00
Martin Storsjo 28212dfce6 [COFF] Fix error handling on duplicates for import library symbols
Normally one wouldn't run into that case, but it is possible with
a little creative ordering of special libraries.

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

llvm-svn: 344776
2018-10-19 06:39:36 +00:00
Sean Fertile 3acfe400a2 [PPC64] Fix offset checks on rel24 call relocations.
Adjusted the range check on a call instruction from 24 bits signed to
26 bits signed. While the instruction only encodes 24 bits, the target is
assumed to be 4 byte aligned, and the value that is encoded in the instruction
gets shifted left by 2 to form the offset. Also added a check that the offset is
indeed at least 4 byte aligned.

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

llvm-svn: 344747
2018-10-18 15:43:41 +00:00
Fedor Sergeev bd6b2138b9 [NewPM] teach -passes= to emit meaningful error messages
All the PassBuilder::parse interfaces now return descriptive StringError
instead of a plain bool. It allows to make -passes/aa-pipeline parsing
errors context-specific and thus less confusing.

TODO: ideally we should also make suggestions for misspelled pass names,
but that requires some extensions to PassBuilder.

Reviewed By: philip.pfaffe, chandlerc
Differential Revision: https://reviews.llvm.org/D53246

llvm-svn: 344685
2018-10-17 10:36:23 +00:00
Sean Fertile 4b5ec7fb80 Reland "[PPC64] Add split - stack support."
Recommitting https://reviews.llvm.org/rL344544 after fixing undefined behavior
from left-shifting a negative value. Original commit message:

This support is slightly different then the X86_64 implementation in that calls
to __morestack don't need to get rewritten to calls to __moresatck_non_split
when a split-stack caller calls a non-split-stack callee. Instead the size of
the stack frame requested by the caller is adjusted prior to the call to
__morestack. The size the stack-frame will be adjusted by is tune-able through a
new --split-stack-adjust-size option.

llvm-svn: 344622
2018-10-16 17:13:01 +00:00
Sean Fertile 831a1336ff Revert "[PPC64] Add split - stack support."
This reverts commit https://reviews.llvm.org/rL344544, which causes failures on
a undefined behaviour sanitizer bot -->
lld/ELF/Arch/PPC64.cpp:849:35: runtime error: left shift of negative value -1

llvm-svn: 344551
2018-10-15 20:20:28 +00:00
Sean Fertile 795cc9332b [PPC64] Add split - stack support.
This support is slightly different then the X86_64 implementation in that calls
to __morestack don't need to get rewritten to calls to __moresatck_non_split
when a split-stack caller calls a non-split-stack callee. Instead the size of
the stack frame requested by the caller is adjusted prior to the call to
__morestack. The size the stack-frame will be adjusted by is tune-able through a
new --split-stack-adjust-size option.

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

llvm-svn: 344544
2018-10-15 19:05:57 +00:00
Sid Manning 6df0759aad [ELF][HEXAGON] Let input determine e_flag.
Differential Revision: https://reviews.llvm.org/D53204

llvm-svn: 344518
2018-10-15 14:44:52 +00:00
George Rimar ee981860a8 [LLD][ELF] - Check options before processing the -v/-version options.
This is https://bugs.llvm.org/show_bug.cgi?id=39289.

Currently both gold and bfd report errors about invalid options values
even with -v/-versions. But LLD does not.

This makes complicated to check the options available when LLD is used.

Patch makes LLD behavior to be consistent with GNU linkers.

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

llvm-svn: 344514
2018-10-15 14:21:43 +00:00
Rui Ueyama 3d354081e0 Simplify. NFC.
- Removed redundant `llvm::`
 - Typedef a long type name
 - Initialize members by member initializers

llvm-svn: 344427
2018-10-12 22:44:06 +00:00
Rui Ueyama f3fad55787 Remove `Type` parameter from SymbolTable::insert(). NFC.
`Type` parameter was used only to check for TLS attribute mismatch,
but we can do that when we actually replace symbols, so we don't need
to type as an argument. This change should simplify the interface of
the symbol table a bit.

llvm-svn: 344394
2018-10-12 18:29:18 +00:00
Zachary Turner 5bba1cafbe Better support for POSIX paths in PDBs.
This a resubmission of a patch which was previously reverted
due to breaking several lld tests.  The issues causing those
failures have been fixed, so the patch is now resubmitted.

---Original Commit Message---

While it doesn't make a *ton* of sense for POSIX paths to be
in PDBs, it's possible to occur in real scenarios involving
cross compilation.

The tools need to be able to handle this, because certain types
of debugging scenarios are possible without a running process
and so don't necessarily require you to be on a Windows system.
These include post-mortem debugging and binary forensics (e.g.
using a debugger to disassemble functions and examine symbols
without running the process).

There's changes in clang, LLD, and lldb in this patch.  After
this the cross-platform disassembly and source-list tests pass
on Linux.

Furthermore, the behavior of LLD can now be summarized by a much
simpler rule than before: Unless you specify /pdbsourcepath and
/pdbaltpath, the PDB ends up with paths that are valid within
the context of the machine that the link is performed on.

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

llvm-svn: 344377
2018-10-12 17:26:19 +00:00
Rui Ueyama 2e9d40d5f4 [lld] Add more complete support for the INCLUDE command.
Patch by Ian Tessier.

This change adds INCLUDE support to the MEMORY and SECTION commands, and
to output sections, as per:

https://sourceware.org/binutils/docs/ld/File-Commands.html#File-Commands

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

llvm-svn: 344368
2018-10-12 17:07:32 +00:00
Zachary Turner 9f169afab2 Make YAML quote forward slashes.
If you have the string /usr/bin, prior to this patch it would not
be quoted by our YAML serializer.  But a string like C:\src would
be, due to the presence of a backslash.  This makes the quoting
rules of basically every single file path different depending on
the path syntax (posix vs. Windows).

While technically not required by the YAML specification to quote
forward slashes, when the behavior of paths is inconsistent it
makes it difficult to portably write FileCheck lines that will
work with either kind of path.

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

llvm-svn: 344359
2018-10-12 16:31:20 +00:00
Zachary Turner 9c544199cf Revert "Make YAML quote forward slashes."
This reverts commit b86c16ad8c97dadc1f529da72a5bb74e9eaed344.

This is being reverted because I forgot to write a useful
commit message, so I'm going to resubmit it with an actual
commit message.

llvm-svn: 344358
2018-10-12 16:31:08 +00:00
Zachary Turner ec234052a6 Make YAML quote forward slashes.
llvm-svn: 344357
2018-10-12 16:24:09 +00:00
George Rimar 4cb05713de [ELF] - Remove unused variable. NFC.
It triggered a bot failture somehow today:
http://lab.llvm.org:8011/builders/lld-perf-testsuite/builds/7993

llvm-svn: 344344
2018-10-12 13:39:35 +00:00
George Rimar fa91327b51 [ELF] - Remove dead declaration. NFC.
MipsGotSection::FileGot::isOverflow()
was a dead declararion.

llvm-svn: 344342
2018-10-12 13:25:25 +00:00
Rui Ueyama b0d8502049 Remove SymbolTable::addAbsolute().
addAbsolute() could be implemented as a non-member function.

llvm-svn: 344305
2018-10-11 22:15:41 +00:00
Rui Ueyama 936cfa86e5 Remove `else` after `return`.
llvm-svn: 344302
2018-10-11 21:57:52 +00:00
Eli Friedman 8b44cc21c6 [ELF] Fix link failure with Android compressed relocation support.
Android uses a compressed relocation format, which means the size of the
relocation section isn't predictable based on the number of relocations,
and can vary if the layout changes in any way. To deal with this, the
linker normally runs multiple passes until the layout converges.

The layout should converge if the size of the compressed
relocation section increases monotonically: if the size of an encoded
offset increases by one byte, the larget value which can be encoded is
multiplied by 128, so the representable offsets grow much faster than
the size of the section itself.

The problem here is that there is no code to ensure the size of the
section doesn't decrease.  If the size of the relocation section
decreases, the relative offsets can increase due to alignment
restrictions, so that can force the size of the relocation section to
increase again.  The end result is an infinite loop; the loop gets cut
off after 10 iterations with the message "thunk creation not
converged".

To avoid this issue, this patch adds padding to the end of the
relocation section if its size would decrease.  The extra
padding is harmless because of the way the format is defined:
decoding stops after it reaches the number of relocations specified
in the section's header.

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

llvm-svn: 344300
2018-10-11 21:43:06 +00:00
Rui Ueyama 2600e0946b Rename SymbolTable::addRegular -> SymbolTable::addDefined.
We have addAbsolute, addBitcode, addCommon, etc. addRegular looked a
bit inconsistent.

llvm-svn: 344294
2018-10-11 20:43:01 +00:00
Rui Ueyama cf41adaaa0 Remove unused default arguments.
llvm-svn: 344292
2018-10-11 20:38:34 +00:00
Rui Ueyama c7497d3ac5 Remove SymbolTable::addUndefined<ELF32LE>(StringRef).
Because we can implement the function as a non-member function.

llvm-svn: 344290
2018-10-11 20:34:29 +00:00
Zachary Turner e8a6c3eb96 Revert SymbolFileNativePDB plugin.
This was originally causing some test failures on non-Windows
platforms, which required fixes in the compiler and linker.  After
those fixes, however, other tests started failing.  Reverting
temporarily until I can address everything.

llvm-svn: 344279
2018-10-11 18:45:44 +00:00
Zachary Turner e502f8b315 Better support for POSIX paths in PDBs.
While it doesn't make a *ton* of sense for POSIX paths to be
in PDBs, it's possible to occur in real scenarios involving
cross compilation.

The tools need to be able to handle this, because certain types
of debugging scenarios are possible without a running process
and so don't necessarily require you to be on a Windows system.
These include post-mortem debugging and binary forensics (e.g.
using a debugger to disassemble functions and examine symbols
without running the process).

There's changes in clang, LLD, and lldb in this patch.  After
this the cross-platform disassembly and source-list tests pass
on Linux.

Furthermore, the behavior of LLD can now be summarized by a much
simpler rule than before: Unless you specify /pdbsourcepath and
/pdbaltpath, the PDB ends up with paths that are valid within
the context of the machine that the link is performed on.

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

llvm-svn: 344269
2018-10-11 18:01:55 +00:00
Martin Storsjo 8cc0f71261 [COFF] Add and use a Wordsize field in Config. NFCI.
Differential Revision: https://reviews.llvm.org/D53143

llvm-svn: 344265
2018-10-11 17:45:58 +00:00
Martin Storsjo 21eb363302 [COFF] Set proper pointer size alignment for LocalImportChunk
When these are accessed with load/store instructions on ARM64,
it becomes strictly necessary to have them properly aligned.

This fixes PR39228.

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

llvm-svn: 344264
2018-10-11 17:45:51 +00:00
George Rimar 3368643f5e [ELF] - Set sh_info and sh_link for .rela.plt sections.
This is https://bugs.llvm.org/show_bug.cgi?id=37538,

Currently, LLD may set both sh_link and sh_info for
.rela.plt section to zero when we have only .rela.iplt section part used.

ELF spec (https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html)
says that for SHT_REL and SHT_RELA, sh_link references the associated symbol table
and sh_info the "section to which the relocation applies."

When we set the sh_link field, for the regular case we use the .dynsym index.
For .rela.iplt sections, it is unclear what is the associated symbol table,
because R_*_RELATIVE relocations do not use symbol names and we might have no
.dynsym section at all so this patch uses .symtab section index.

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

llvm-svn: 344226
2018-10-11 08:25:35 +00:00
Fangrui Song a535e0543f Eliminate dependency to formatv(). NFC.
llvm-svn: 344212
2018-10-11 00:58:00 +00:00
Rui Ueyama 3c4344810a Make a member function private and rename it to avoid function overloading.
llvm-svn: 344196
2018-10-10 22:49:29 +00:00
Fangrui Song 11ca54f49c [ELF] Don't warn on undefined symbols if UnresolvedPolicy::Ignore is used
Summary:
Add a condition UnresolvedPolicy::Ignore to elf::warnUnorderedSymbol to suppress Sym->isUndefined() warnings from both

1) --symbol-ordering-file=
2) .llvm.call-graph-profile

If --unresolved-symbols=ignore-all is used,

  no "undefined symbol" error/warning is emitted. It makes sense to not warn unorderable symbols.

Otherwise,

  If an executable is linked, the default policy UnresolvedPolicy::ErrorOrWarn will issue a "undefined symbol" error. The unorderable symbol warning is redundant.

  If a shared object is linked, it is possible that only part of object files are used and some symbols are left undefined. The warning is not very necessary.
    In particular for .llvm.call-graph-profile, when linking a shared object, a call graph profile may contain undefined symbols. This case generated a warning before but it will be suppressed by this patch.

Reviewers: ruiu, davidxl, espindola

Reviewed By: ruiu

Subscribers: grimar, emaste, arichardson, llvm-commits

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

llvm-svn: 344195
2018-10-10 22:48:57 +00:00
Rui Ueyama 9ae88c64fa Eliminate dependency to formatv(). NFC.
llvm-svn: 344177
2018-10-10 20:29:29 +00:00
Martin Storsjo 33d43ff851 [COFF] Look for libfoo.a if foo.lib is specified, for MinGW
This allows using #pragma comment(lib, "foo") in MinGW built code,
if built with -fms-extensions. (This works for system libraries and
static libraries only, as it doesn't try to look for .dll.a. As
ld.bfd doesn't support embedded defaultlib directives, this isn't
in widespread use among mingw users.)

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

llvm-svn: 344124
2018-10-10 09:00:10 +00:00
Martin Storsjo 803b37ad5d [MinGW] Pass libpath to the COFF linker
This is necessary for handling defaultlib directives embedded in
object files, unless they use an absolute path.

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

llvm-svn: 344123
2018-10-10 09:00:03 +00:00
Fangrui Song 2043a58abe Adapt OptTable::PrintHelp change in D51009
Summary: Before, OptTable::PrintHelp append "[options] <inputs>" to its parameter `Help`. It is more flexible to change its semantic to `Usage` and let user customize the usage line.

Reviewers: rupprecht, ruiu, espindola

Reviewed By: rupprecht

Subscribers: emaste, sbc100, arichardson, aheejin, llvm-commits

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

llvm-svn: 344099
2018-10-10 00:15:36 +00:00
Rui Ueyama 71cdbb7fe6 Merge two overloaded functions into one function. NFC.
llvm-svn: 344089
2018-10-09 22:44:53 +00:00
Rui Ueyama e65cb4889e Return early. NFC.
llvm-svn: 344088
2018-10-09 22:44:42 +00:00
Rui Ueyama 2b53b4bea6 Attempt to fix ubsan.
Previously, we cast a pointer to Elf{32,64}_Chdr like this

  auto *Hdr = reinterpret_cast<const ELF64_Chdr>(Ptr);

and read from its members like this

  read32(&Hdr->ch_size);

I was thinking that this does not violate alignment requirement,
since &Hdr->ch_size doesn't really access memory, but seems like
it is a violation in terms of C++ spec (?)

In this patch, I use a different struct that allows unaligned access.

llvm-svn: 344083
2018-10-09 21:41:53 +00:00
Rui Ueyama e3ccd28660 Calculate an offset only once. NFC.
llvm-svn: 344076
2018-10-09 20:29:24 +00:00
Rui Ueyama fbc629702d Remove redundant `Symtab->`.
`SymbolTable` is a singleton class and is a global variable for the
unique instance, so we can always refer the symtab by `Symtab->`.
However, we don't need to use the global varaible from member functions
of SymbolTable class.

llvm-svn: 344075
2018-10-09 20:22:18 +00:00
Rui Ueyama 714abece2b Simplify. NFC.
llvm-svn: 344074
2018-10-09 20:16:16 +00:00
Rui Ueyama 659cff37d6 Remove a use of template to make code less abstracted.
Sometimes, code that is a bit longer but doesn't use template is
easier to understand than code that uses template.

llvm-svn: 344072
2018-10-09 19:54:32 +00:00
Zachary Turner 2be11c0260 Fix lld test.
I removed this output from the dumper because it was non-portable,
but I didn't update the test which checked the output.

llvm-svn: 344066
2018-10-09 18:35:06 +00:00
Nico Weber e1b9331d29 lld-link: attempt to fix tests on Windows after r344061.
llvm-svn: 344065
2018-10-09 18:19:09 +00:00
Rui Ueyama c2921f002e Add an entry to the release notes.
llvm-svn: 344062
2018-10-09 17:53:33 +00:00
Nico Weber 4764bb2cb1 lld-link: Use /pdbsourcepath: for more places when present.
/pdbsourcepath: was added in https://reviews.llvm.org/D48882 to make it
possible to have relative paths in the debug info that clang-cl writes.
lld-link then makes the paths absolute at link time, which debuggers require.
This way, clang-cl's output is independent of the absolute path of the build
directory, which is useful for cacheability in distcc-like systems.

This patch extends /pdbsourcepath: (if passed) to also be used for:

1. The "cwd" stored in the env block in the pdb is /pdbsourcepath: if present
2. The "exe" stored in the env block in the pdb is made absolute relative
   to /pdbsourcepath: instead of the cwd
3. The "pdb" stored in the env block in the pdb is made absolute relative
   to /pdbsourcepath: instead of the cwd
4. For making absolute paths to .obj files referenced from the pdb

/pdbsourcepath: is now useful in three scenarios (the first one already working
before this change):

1. When building with full debug info, passing the real build dir to
   /pdbsourcepath: allows having clang-cl's output to be independent
   of the build directory path. This patch effectively doesn't change
   behavior for this use case (assuming the cwd is the build dir).

2. When building without compile-time debug info but linking with /debug,
   a fake fixed /pdbsourcepath: can be passed to get symbolized stacks
   while making the pdb and exe independent of the current build dir.
   For this two work, lld-link needs to be invoked with relative paths for
   the lld-link invocation itself (for "exe"), for the pdb output name, the exe
   output name (for "pdb"), and the obj input files, and no absolute path
   must appear on the link command (for "cmd" in the pdb's env block).
   Since no full debug info is present, it doesn't matter that the absolute
   path doesn't exist on disk -- we only get symbols in stacks.

3. When building production builds with full debug info that don't have
   local changes, and that get source indexed and their pdbs get uploaded
   to a symbol server. /pdbsourcepath: again makes the build output independent
   of the current directory, and the fixed path passed to /pdbsourcepath: can
   be given the source indexing transform so that it gets mapped to a
   repository path. This has the same requirements as 2.

This patch also makes it possible to create PDB files containing Windows-style
absolute paths when cross-compiling on a POSIX system.

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

llvm-svn: 344061
2018-10-09 17:52:25 +00:00
Nico Weber 9d7524160a lld-link: Implement support for %_PDB% and %_EXT% for /pdbaltpath:.
Warn that references to regular env vars are ignored.

Fixes PR38940.

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

llvm-svn: 344003
2018-10-08 23:06:05 +00:00
Rui Ueyama 9b5a495d48 Fix a broken buildbot.
llvm-svn: 343983
2018-10-08 17:24:29 +00:00
Rui Ueyama e28c146423 Avoid unnecessary buffer allocation and memcpy for compressed sections.
Previously, we uncompress all compressed sections before doing anything.
That works, and that is conceptually simple, but that could results in
a waste of CPU time and memory if uncompressed sections are then
discarded or just copied to the output buffer.

In particular, if .debug_gnu_pub{names,types} are compressed and if no
-gdb-index option is given, we wasted CPU and memory because we
uncompress them into newly allocated bufers and then memcpy the buffers
to the output buffer. That temporary buffer was redundant.

This patch changes how to uncompress sections. Now, compressed sections
are uncompressed lazily. To do that, `Data` member of `InputSectionBase`
is now hidden from outside, and `data()` accessor automatically expands
an compressed buffer if necessary.

If no one calls `data()`, then `writeTo()` directly uncompresses
compressed data into the output buffer. That eliminates the redundant
memory allocation and redundant memcpy.

This patch significantly reduces memory consumption (20 GiB max RSS to
15 Gib) for an executable whose .debug_gnu_pub{names,types} are in total
5 GiB in an uncompressed form.

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

llvm-svn: 343979
2018-10-08 16:58:59 +00:00
Sid Manning 307c7901d0 [ELF][HEXAGON] Add R_HEX_GOT_16_X support
Differential Revision: https://reviews.llvm.org/D52909

llvm-svn: 343972
2018-10-08 15:32:46 +00:00
Petr Hosek 62f6462bf9 [llvm-nm] Write "no symbol" output to stderr
This matches the output of binutils' nm and ensures that any scripts
or tools that use nm and expect empty output in case there no symbols
don't break.

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

llvm-svn: 343887
2018-10-05 21:10:03 +00:00
Martin Storsjo 08ab568aaa [COFF] Do MinGW specific entry/subsystem inference
ld.bfd doesn't do any inference of subsystem; unless the windows
subsystem is specified, the console subsystem is used.

For the console subsystem, the entry point is called mainCRTStartup,
regardless of whether the the user code entry point is main or wmain.
The same goes for the windows subsystem, where the entry point always
is WinMainCRTStartup, for both WinMain and wWinMain in user code.

One detail that we don't emulate, is that if the inferred entry point
is undefined, ld.bfd silently just sets the entry point to the start
of the image. And if an explicit entry point is set, but it is
undefined, the link still succeeds but the linker warns about the
entry point not being found.

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

llvm-svn: 343879
2018-10-05 19:43:24 +00:00
Martin Storsjo db9148d21d [docs] Mention some notable feature in the release notes
Differential Revision: https://reviews.llvm.org/D52908

llvm-svn: 343878
2018-10-05 19:43:20 +00:00
Martin Storsjo cab6dafc04 [COFF] Cope with GCC produced weak aliases referring to comdat functions
For certain cases of inline functions written to comdat sections,
GCC 5.x produces a weak symbol in addition, which would end up
undefined in some cases.

This no longer seems to happen with GCC 6.x or newer though.

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

llvm-svn: 343877
2018-10-05 19:43:16 +00:00
Alexandre Ganea 149de8de19 [LLD][COFF] Fix ordering of CRT global initializers in COMDAT sections
(patch by Benoit Rousseau)

This patch fixes a bug where the global variable initializers were sometimes not invoked in the correct order when it involved a C++ template instantiation.

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

llvm-svn: 343847
2018-10-05 12:56:46 +00:00
Ed Maste bf378b808a ReleaseNotes: remove superfluous 's' in 'can promotes'
llvm-svn: 343820
2018-10-04 21:37:32 +00:00
Sid Manning 261eec5fa5 [ELF][HEXAGON] Add support for GOT relocations.
The GOT is referenced through the symbol _GLOBAL_OFFSET_TABLE_ .

The relocation added calculates the offset into the global offset table for
the entry of a symbol.  In order to get the correct TargetVA I needed to
create an new relocation expression, HEXAGON_GOT.  It does
Sym.getGotVA() - In.GotPlt->getVA().

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

llvm-svn: 343784
2018-10-04 14:54:17 +00:00
George Rimar f76dffb90f [ELF] - Simplify. NFCI.
Assign the `Link` to parent directly.

llvm-svn: 343762
2018-10-04 09:31:15 +00:00
Matt Morehouse 8d53ab5e7a Use std::make_pair rather than brace initialization.
r343732 broke the Windows bot.  Seems like the compiler on that bot
doesn't like brace initialization.

llvm-svn: 343749
2018-10-04 00:35:24 +00:00
Shoaib Meenai 509230f68d [ELF] Fix typo. NFC
llvm-svn: 343748
2018-10-04 00:07:59 +00:00
Shoaib Meenai 6883d882f1 [ELF] Fix crash on invalid undefined local symbols
r320770 made LLD handle invalid DSOs where local symbols were found in
the global part of the symbol table. Unfortunately, it didn't handle the
case where those local symbols were also undefined, and r326242 exposed
an assertion failure in that case. Just warn on that case instead of
crashing, by moving the local binding check before the undefined symbol
addition.

The input file for the test is crafted by hand, since I don't know of
any tool that would produce such a broken DSO. I also don't understand
what it even means for a symbol to be undefined but have STB_LOCAL
binding - I don't think that combination makes any sense - but we have
found broken DSOs of this nature that we were linking against. I've
included detailed instructions on how to produce the DSO in the test.

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

llvm-svn: 343745
2018-10-03 23:53:11 +00:00
Jordan Rupprecht dd0f98972d [llvm-nm] Update lld tests based on changed llvm-nm output
llvm-svn: 343743
2018-10-03 23:39:59 +00:00
Derek Schuff 371842b853 [WebAssembly] Refactor use of signatures
Update use of WebAssemblySignature to go along with D52580

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

llvm-svn: 343734
2018-10-03 22:25:32 +00:00
Rui Ueyama 3ed33eade0 Minor refacotring of Relocations.cpp. NFC.
This patch splits ThunkCreator::mergeThunks into two smaller functions.
Also adds blank lines to various places so that the code doesn't look
too dense.

llvm-svn: 343732
2018-10-03 22:20:26 +00:00
Sean Fertile 98da20f0fb [PPC64] Test documenting toc-restore after interposable recursive call. [NFC]
A test verifying that toc restores are properly inserted following recursive
calls, as well as briefly describing why they are needed.

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

llvm-svn: 343729
2018-10-03 21:58:44 +00:00
Sean Fertile 7cbe41f2c7 [PPC64] Add test documenting toc-restore when linking with -Bsymbolic. [NFC]
Differential Revision: https://reviews.llvm.org/D52523

llvm-svn: 343728
2018-10-03 21:58:42 +00:00
Martin Storsjo 2657200274 [COFF] Cope with weak aliases produced by GNU tools
When GNU tools create a weak alias, they produce a strong symbol
named .weak.<weaksymbol>.<relatedstrongsymbol>.

GNU ld allows many such weak alternatives for the same weak symbol, and
the linker picks the first one encountered.

This can't be reproduced by assembling from .s files, since llvm-mc
produces symbols named .weak.<weaksymbol>.default in these cases.

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

llvm-svn: 343704
2018-10-03 18:31:53 +00:00
Nico Weber d377826277 lld-link: Several tweaks to default entry point selection.
Three related changes:

1. link.exe uses the presence of main and wmain to decide if it should call
   mainCRTStartup or wmainCRTStartup, even if /nodefaultlib is passed. For
   compatibility, remove FindMain logic.

2. Default to the non-wide entrypoint if main is not found. This has two effects:

2a. In normal links, lld-link now prints

        lld-link: error: undefined symbol: _main
        >>> referenced by f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78
        >>>               libcmt.lib(exe_main.obj):("int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ))
        >>> referenced by f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
        >>>               libcmt.lib(exe_main.obj):("int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ))

    instead of

        lld-link: error: entry point must be defined

    This is arguably a better error message, since it now mentions that _main is
    missing. (This matches link.exe's diagnostic in this case.)

2b. With /nodefautlib, we now default to mainCRTStartup if no main() is
    present, again matching link.exe. This makes r337407 obsolete.

This means if you have a cc file containing both mainCRTStartup and
wmainCRTStartup and you pass /nodefaultlib /subsystem:console, lld-link will
now call mainCRTStartup, matching link.exe

3. Print a warning if both main and wmain are present, similar to link.exe's
   LNK4067.

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

llvm-svn: 343698
2018-10-03 17:01:39 +00:00
George Rimar db2e641fd7 [ELF] - Fix BB after r343668
This stops testing the value of .rela.plt section offset.

Also makes _start global to eliminate
'cannot find entry symbol _start' warning.

llvm-svn: 343669
2018-10-03 09:59:08 +00:00
George Rimar f79a8ef2ae [ELF] - Do not forget to include to .dymsym symbols that were converted to Defined.
This is the fix for
"Bug 39104 - LLD links incorrect ELF executable if version script contains "local: *;"
(https://bugs.llvm.org/show_bug.cgi?id=39104).

The issue happens when we have non-PIC program call to function in a shared library.
(for example, the PR above has R_X86_64_PC32 relocation against __libc_start_main)

LLD converts symbol to Defined in that case with the use of replaceWithDefined()

The issue is that after above we create a broken relocation because do not
include the symbol into .dynsym.

That happens when the version script is used because we treat the symbol as
STB_LOCAL if the following condition match:
VersionId == VER_NDX_LOCAL && isDefined() and do not include it to
.dynsym because of that. Patch fixes the issue.

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

llvm-svn: 343668
2018-10-03 09:33:00 +00:00
George Rimar 3832d7c25d [LLD] - Do not crash when reporting errors when .debug_line_str (DWARF5) is used
Imagine we have the following code:

int foo();
int main() { return foo(); }

It will crash if you try to compile it with
`clang -O0 -gdwarf-5 test.cpp -o test -g -fuse-ld=lld`

The crash happens inside the LLVM DWARF parser because LLD does not provide
the .debug_line_str section. At the same time for correct parsing and reporting,
we anyways need to provide this section from our side.

The patch fixes the issue.

llvm-svn: 343667
2018-10-03 08:59:46 +00:00
Ali Tamur 63830b2794 Introduce a flag to warn when ifunc symbols are used with text relocations.
Summary:
This patch adds a new flag, --warn-ifunc-textrel, to work around a glibc bug. When a code with ifunc symbols is used to produce an object file with text relocations, lld always succeeds. However, if that object file is linked using an old version of glibc, the resultant binary just crashes with segmentation fault when it is run (The bug is going to be corrected as of glibc 2.19).

Since there is no way to tell beforehand what library the object file will be linked against in the future, there does not seem to be a fool-proof way for lld to give an error only in cases where the binary will crash. So, with this change (dated 2018-09-25), lld starts to give a warning, contingent on a new command line flag that does not have a gnu counter part. The default value for --warn-ifunc-textrel is false, so lld behaviour will not change unless the user explicitly asks lld to give a warning. Users that link with a glibc library with version 2.19 or newer, or does not use ifunc symbols, or does not generate object files with text relocations do not need to take any action. Other users may consider to start passing warn-ifunc-textrel to lld to get early warnings.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: grimar, MaskRay, markj, emaste, arichardson, llvm-commits

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

llvm-svn: 343628
2018-10-02 20:30:22 +00:00
Diogo N. Sampaio a35e55eff9 [NFC][BUG-FIX][ARM] Add missing data symbol
llvm rL343594: [ARM] Emmit data symbol
for constant pool data fixed a bug that ommited
required data symbols.
Such change breaked a test case in lld:
test/ELF/arm-thunk-largesection.s

llvm-svn: 343604
2018-10-02 16:53:12 +00:00
Michael J. Spencer 8222f902ca [ELF] Read the call graph profile from object files.
This uses the call graph profile embedded in the object files to construct the call graph.

This is read from a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight).

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

llvm-svn: 343552
2018-10-02 00:17:15 +00:00
Sid Manning 490429d069 [ELF] [HEXAGON] Add support for PLT_B22_PCREL and HEX_32_PCREL
Update testcase.

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

llvm-svn: 343515
2018-10-01 18:27:26 +00:00
Rui Ueyama 1e591d807b Add an explanation about cross linking.
Differential Revision: https://reviews.llvm.org/D52567

llvm-svn: 343495
2018-10-01 16:41:58 +00:00
James Henderson 194a4eb8f7 Fix typo in LLD man page
llvm-svn: 343449
2018-10-01 09:57:20 +00:00
Martin Storsjo 0f8f0d6d1d [COFF] In MinGW mode, ignore relocations against a discarded section
When GCC produces a jump table as part of a comdat function, the
jump table itself is produced as plain non-comdat rdata section. When
linked with ld.bfd, all of those rdata sections are kept, with
relocations unchanged in the sections that refer to discarded comdat
sections.

This has been observed with at least GCC 5.x and 7.x.

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

llvm-svn: 343422
2018-09-30 18:31:03 +00:00
Alexandre Ganea 91def5cc6a [LLD][COFF] Fix pdb loading when the path points to a removable device
Differential Revision: https://reviews.llvm.org/D52666

llvm-svn: 343366
2018-09-28 21:53:40 +00:00
Sam Clegg 8b0b48f343 [WebAssembly] Preserve function signatures during LTO
With LTO when and undefined function (with a known signature)
in replaced by a defined bitcode function we were loosing the
signature information (since bitcode functions don't have
signatures).

With this change we preserve the original signature from the
undefined function and verify that the post LTO compiled
function has the correct signature.

This change improves the error handling in the case where
there is a signature mismatch with a function defined in
a bitcode file.

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

llvm-svn: 343340
2018-09-28 16:50:14 +00:00
Sid Manning fc50e63a2a [ELF][HEXAGON] Add support for dynamic libraries
Write out the PLT header and stub.
Hexagon uses RELA relocations.

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

llvm-svn: 343320
2018-09-28 14:09:16 +00:00
Sam Clegg 305b0343ce [WebAssembly] Add --[no]-export-dynamic to replace --export-default
In a very recent change I introduced a --no-export-default flag
but after conferring with others it seems that this feature already
exists in gnu GNU ld and lld in the form the --export-dynamic flag
which is off by default.

This change replaces export-default with export-dynamic and also
changes the default to match the traditional linker behaviour.

Now, by default, only the entry point is exported.  If other symbols
are required by the embedder then --export-dynamic or --export can
be used to export all visibility hidden symbols or individual
symbols respectively.

This change touches a lot of tests that were relying on symbols
being exported by default.  I imagine it will also effect many
users but do think the change is worth it match of the traditional
behaviour and flag names.

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

llvm-svn: 343265
2018-09-27 21:06:25 +00:00
Peter Smith fb5a5d09fe [COFF] Add missing Requires x86 to fix buildbot
Add REQUIRES: x86 to pdb-debug-f.s as this is causing the Arm and
AArch64 buildbots to fail as they do not have the x86 backend.

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

llvm-svn: 343196
2018-09-27 12:07:47 +00:00
Sam Clegg 4aad12ce0b [WebAssembly] Update Config member to match command line option
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 343157
2018-09-27 00:46:54 +00:00
Sam Clegg bd37e09355 Revert "[WebAssembly] Update docs"
This change reverts rL343155.  It broke the builtbot, even though
it works for me locally:
http://lab.llvm.org:8011/builders/lld-sphinx-docs/builds/26336

Must be a sphinx version issue I guess.

llvm-svn: 343156
2018-09-27 00:42:49 +00:00
Sam Clegg 77ab7c1b30 [WebAssembly] Update docs
Differential Revision: https://reviews.llvm.org/D52048

llvm-svn: 343155
2018-09-27 00:22:24 +00:00
Fangrui Song dbaeec6892 [ELF] llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, mgrang, llvm-commits

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

llvm-svn: 343146
2018-09-26 20:54:42 +00:00
Ryan Prichard ed5bb932a2 Allow later -z name=<int> args to override earlier args
Summary:
lld already gives later -z options precedence in getZFlag().

This matches the behavior of ld.bfd and ld.gold, where later options
override earlier ones. (I tested with -z max-page-size and -z stack-size.)

Reviewers: ruiu, espindola, grimar

Reviewed By: ruiu, grimar

Subscribers: grimar, emaste, arichardson, llvm-commits

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

llvm-svn: 343145
2018-09-26 20:50:39 +00:00
Ryan Prichard b7c8d2d405 [AArch64] Fix range check of R_AARCH64_TLSLE_ADD_TPREL_HI12
Summary:
An AArch64 LE relocation is a positive ("variant 1") offset. This
relocation is used to write the upper 12 bits of a 24-bit offset into an
add instruction:

    add x0, x0, :tprel_hi12:v1

The comment in the ARM docs for R_AARCH64_TLSLE_ADD_TPREL_HI12 is:

"Set an ADD immediate field to bits [23:12] of X; check 0 <= X < 2^24."

Reviewers: javed.absar, espindola, ruiu, peter.smith, zatrazz

Reviewed By: ruiu

Subscribers: emaste, arichardson, kristof.beyls, llvm-commits

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

llvm-svn: 343144
2018-09-26 20:50:38 +00:00
Fangrui Song 5dffc95b26 [ELF][test] Use llvm-readelf's short option -r instead of -relocations and remove ignored --wide
Reviewers: ruiu, sfertile, espindola

Reviewed By: ruiu

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

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

llvm-svn: 343135
2018-09-26 19:48:07 +00:00
George Rimar 95aae4c59d [ELF] - Do not fail on R_*_NONE relocations when parsing the debug info.
This is https://bugs.llvm.org//show_bug.cgi?id=38919.

Currently, LLD may report "unsupported relocation target while parsing debug info"
when parsing the debug information.

At the same time LLD does that for zeroed R_X86_64_NONE relocations,
which obviously has "invalid" targets.

The nature of R_*_NONE relocation assumes them should be ignored.
This patch teaches LLD to stop reporting the debug information parsing errors for them.

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

llvm-svn: 343078
2018-09-26 08:11:34 +00:00
Martin Storsjo 32e651e169 [COFF] Don't do autoexport of symbols from GNU import libraries
This involves adding more generic list of symbol suffixes/prefixes
to ignore for autoexport; adding a few other entries to these lists
as well from the corresponding lists in binutils.

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

llvm-svn: 343070
2018-09-26 06:13:47 +00:00
Martin Storsjo 2bfa125fd6 [COFF] Allow automatic dllimport from gnu import libraries
Don't assume that the IAT chunk will be a DefinedImportData, it can
just as well be a DefinedRegular for gnu import libraries.

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

llvm-svn: 343069
2018-09-26 06:13:39 +00:00
Sam Clegg 4e62418b25 [WebAssembly] Add --export-default/--no-export-default options
These option control weather or not symbols marked as visibility
default are exported in the output binary.

By default this is true, but emscripten prefers to control the
exported symbol list explicitly at link time and ignore the
symbol attributes.

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

llvm-svn: 343034
2018-09-25 21:50:15 +00:00
Rui Ueyama 378a028d91 Update a --help message and add -execute-only to the man page.
llvm-svn: 343032
2018-09-25 21:39:08 +00:00
Rui Ueyama 12ef7a9575 De-template VersionDefinitionSection. NFC.
When we write a struct to a mmap'ed buffer, we usually use
write16/32/64, but we didn't for VersionDefinitionSection, so
we needed to template that class.

llvm-svn: 343024
2018-09-25 20:37:51 +00:00
Rui Ueyama 4e247522ac Reset input section pointers to null on each linker invocation.
Previously, if you invoke lld's `main` more than once in the same process,
the second invocation could fail or produce a wrong result due to a stale
pointer values of the previous run.

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

llvm-svn: 343009
2018-09-25 19:26:58 +00:00
Rui Ueyama ae34348354 Fix an error message. It must start with a lowercase letter.
llvm-svn: 342992
2018-09-25 17:12:50 +00:00
Rui Ueyama 7d053709d4 Parallelize .gdb_index string table writes.
When we are creating a large .gdb_index, this change makes a difference.

llvm-svn: 342978
2018-09-25 14:34:56 +00:00
Martin Storsjo 57ddec0dd1 [COFF] Add support for creating range extension thunks for ARM
This is a feature that MS link.exe lacks; it currently errors out on
such relocations, just like lld did before.

This allows linking clang.exe for ARM - practically, any image over
16 MB will likely run into the issue.

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

llvm-svn: 342962
2018-09-25 10:59:29 +00:00
George Rimar b5a6538b07 [ELF] - Add -z global option to manual.
This was requested during review of D49374,
but for some unknown reason was not in the final commit.

llvm-svn: 342954
2018-09-25 09:32:31 +00:00
Yury Delendik d66aabc6d7 [WebAssembly] Move .debug_line section address of dead function outside section range
Summary:
Currently we are pointing all debug information that refer removed function code
to the beginning of the code section (offset = 0). A debugger may want to
resolve code offset to the debug information, which will collide with offsets
of the live functions.

Moving offsets of dead functions outside code section range.

Reviewers: sbc100

Reviewed By: sbc100

Subscribers: dblaikie, ruiu, alexcrichton, dschuff, aprantl, jgravelle-google, aheejin, sunfish, JDevlieghere, llvm-commits

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

llvm-svn: 342930
2018-09-24 23:50:55 +00:00
Will Wilson 3cb18346d7 [lld-link] Generalize handling of /debug and /debug:{none,full,fastlink,ghash,symtab}
Implement final argument precedence if multiple /debug arguments are passed on the command-line to match expected link.exe behavior.
Support /debug:none and emit warning for /debug:fastlink with automatic fallback to /debug:full.
Emit error if last /debug:option is unknown.
Emit warning if last /debugtype:option is unknown.

https://reviews.llvm.org/D50404

llvm-svn: 342894
2018-09-24 15:28:03 +00:00
Ed Maste c8ec7a9e1e Correct RISC-V link in release notes
llvm-svn: 342887
2018-09-24 14:47:56 +00:00
Martin Storsjo 5f6d527f09 [COFF] Support linking to import libraries from GNU binutils
GNU binutils import libraries aren't the same kind of short import
libraries as link.exe and LLD produce, but are a plain static library
containing .idata section chunks. MSVC link.exe can successfully link
to them.

In order for imports from GNU import libraries to mix properly with the
normal import chunks, the chunks from the existing mechanism needs to
be added into named sections like .idata$2.

These GNU import libraries consist of one header object, a number of
object files, one for each imported function/variable, and one trailer.
Within the import libraries, the object files are ordered alphabetically
in this order. The chunks stemming from these libraries have to be
grouped by what library they originate from and sorted, to make sure
the section chunks for headers and trailers for the lists are ordered
as intended. This is done on all sections named .idata$*, before adding
the synthesized chunks to them.

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

llvm-svn: 342777
2018-09-21 22:01:06 +00:00
Rui Ueyama c41985a50e Update release notes.
llvm-svn: 342754
2018-09-21 17:48:45 +00:00
Rui Ueyama a3d0f40964 Update release notes.
llvm-svn: 342748
2018-09-21 17:13:55 +00:00
Dimitry Andric c9de3b4d26 Align AArch64 and i386 image base to superpage
Summary:

As for x86_64, the default image base for AArch64 and i386 should be
aligned to a superpage appropriate for the architecture.

On AArch64, this is 2 MiB, on i386 it is 4 MiB.

Reviewers: emaste, grimar, javed.absar, espindola, ruiu, peter.smith, srhines, rprichard

Reviewed By: ruiu, peter.smith

Subscribers: jfb, markj, arichardson, krytarowski, kristof.beyls, llvm-commits

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

llvm-svn: 342746
2018-09-21 16:58:13 +00:00
Petr Hosek e717ae2117 [ELF] Use the Repl point to avoid the segfault when using ICF
This addresses PR38918.

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

llvm-svn: 342704
2018-09-21 00:55:42 +00:00
Rui Ueyama 180cd0717f Make a member function non-member. NFC.
Non-member functions are generally preferred over member functions
because it is clear that non-member functions don't depend on an
internal state of an object.

llvm-svn: 342695
2018-09-20 22:58:00 +00:00
Thomas Lively d661e265c7 [WebAssembly] Add v128 value type
Reviewers: sbc100, aheejin, dschuff

Subscribers: jgravelle-google, sunfish, llvm-commits

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

llvm-svn: 342690
2018-09-20 22:07:18 +00:00
Rui Ueyama a071669956 Rename a function. NFC.
llvm-svn: 342687
2018-09-20 21:40:38 +00:00
Rui Ueyama d19bc04869 Make variable names shorter. NFC.
llvm-svn: 342686
2018-09-20 21:29:14 +00:00
Rui Ueyama 9932091d87 Simplify. NFC.
llvm-svn: 342685
2018-09-20 21:18:56 +00:00
Rui Ueyama 11cda0cbae Add paretntheses around a C macro parameter.
llvm-svn: 342673
2018-09-20 18:24:19 +00:00
Sid Manning 6d0e4fce1a [ELF][HEXAGON] Set DefaultMaxPageSize to 64K
Update testcase to reflect the change.

llvm-svn: 342662
2018-09-20 16:32:19 +00:00
Zachary Turner 77bbd7b19d Fix one more test failure.
llvm-svn: 342660
2018-09-20 16:18:15 +00:00
Sean Fertile 69e09116ba [PPC64] Handle ppc64le triple in getBitcodeMachineKind.
Enables lto and thinlto with bitcode targeting ppc64le.

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

llvm-svn: 342604
2018-09-20 00:26:49 +00:00
Sean Fertile e0e586b997 [PPC64] Helper for offset from a function's global entry to local entry. [NFC]
The PPC64 elf V2 abi defines 2 entry points for a function. There are a few
places we need to calculate the offset from the global entry to the local entry
and how this is done is not straight forward. This patch adds a helper function
mostly for documentation purposes, explaining how the 2 entry points differ and
why we choose one over the other, as well as documenting how the offsets are
encoded into a functions st_other field.

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

llvm-svn: 342603
2018-09-20 00:26:47 +00:00
Sean Fertile 7f3f05e0b7 [PPC64] Optimize redundant instructions in global access sequences.
The access sequence for global variables in the medium and large code models use
2 instructions to add an offset to the toc-pointer. If the offset fits whithin
16-bits then the instruction that sets the high 16 bits is redundant.

This patch adds the --toc-optimize option, (on by default) and enables rewriting
of 2 instruction global variable accesses into 1 when the offset from the
TOC-pointer to the variable (or .got entry) fits in 16 signed bits. eg

addis %r3, %r2, 0           -->     nop
addi  %r3, %r3, -0x8000     -->     addi %r3, %r2, -0x8000

This rewriting can be disabled with the --no-toc-optimize flag

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

llvm-svn: 342602
2018-09-20 00:26:44 +00:00
Martin Storsjo 5fefad793c [COFF] Fix the name mangling of a function in the autoexport exclusion list
The __NULL_IMPORT_DESCRIPTOR symbol has two leading underscores on
architectures other than i386 as well; it is not a mangled symbol name.

llvm-svn: 342448
2018-09-18 07:22:05 +00:00
Martin Storsjo 32d21d6a2d [COFF] Add support for delay loading DLLs for ARM64
Differential Revision: https://reviews.llvm.org/D52190

llvm-svn: 342447
2018-09-18 07:22:01 +00:00
Martin Storsjo cb9570eb22 [COFF] Fix a block with incorrect indentation. NFC.
llvm-svn: 342446
2018-09-18 07:21:55 +00:00
Ryan Prichard 1c33d14bcd [ELF] Set Out::TlsPhdr earlier for encoding packed reloc tables
Summary:
For --pack-dyn-relocs=android, finalizeSections calls
LinkerScript::assignAddresses and
AndroidPackedRelocationSection::updateAllocSize in a loop,
where assignAddresses lays out the ELF image, then updateAllocSize
determines the size of the Android packed relocation table by encoding it.
Encoding the table requires knowing the values of relocation addends.

To get the addend of a TLS relocation, updateAllocSize can call getSymVA
on a TLS symbol before setPhdrs has initialized Out::TlsPhdr, producing an
error:

    <file> has an STT_TLS symbol but doesn't have an SHF_TLS section

Fix the problem by initializing Out::TlsPhdr immediately after the program
headers are created. The segment's p_vaddr field isn't initialized until
setPhdrs, so use FirstSec->Addr, which is what setPhdrs would use.
FirstSec will typically refer to the .tdata or .tbss output section, whose
(tentative) address was computed by assignAddresses.

Android currently avoids this problem because it uses emutls and doesn't
support ELF TLS. This problem doesn't apply to --pack-dyn-relocs=relr
because SHR_RELR only handles relative relocations without explicit addends
or info.

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

Reviewers: ruiu, pcc, chh, javed.absar, espindola

Subscribers: emaste, arichardson, llvm-commits, srhines

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

llvm-svn: 342432
2018-09-18 00:24:48 +00:00
Sean Fertile 72435e5701 [PPC64] Support relaxing R_PPC64_TLSGD16 in TlsGdtoLe relaxation.
A General-dynamic tls access can be written using a R_PPC64_TLSGD16 relocation
if the target got entry is within 16 bits of the TOC-base. This patch adds
support for R_PPC64_TLSGD16 by relaxing it the same as a R_PPC64_GOT_TLSGD16_LO.

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

llvm-svn: 342411
2018-09-17 20:27:02 +00:00
Sean Fertile eed3e43e54 [PPC64] Helpers for read/write an instr while relocating a half16 type. [NFC]
There are a growing number of places when we either want to read or write an
instruction when handling a half16 relocation type. On big-endian the buffer
pointer is pointing into the middle of the word we want and on little-endian it
is pointing to the start of the word. These 2 helpers are to simplify reading
and writing in these contexts.

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

llvm-svn: 342410
2018-09-17 20:27:00 +00:00
Nico Weber 5ffd8cedf4 lld-link: Also demangle undefined dllimported symbols.
dllimported symbols go through an import stub that's called __imp_ followed by
the name the stub points to. Make that work.

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

llvm-svn: 342401
2018-09-17 16:31:20 +00:00
Fangrui Song 3e0a54e9da [ELF] Use llvm::toLower instead of libc call tolower
tolower() has some overhead because current locale is considered (though in lld the default "C" locale is used which does not matter too much). llvm::toLower is more efficient as it compiles to a compare and a conditional jump, as opposed to a libc call if tolower is used.

Disregarding locale also matches gdb's behavior (gdb/minsyms.h):

    #define SYMBOL_HASH_NEXT(hash, c)			\
      ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113)

where TOLOWER (include/safe-ctype.h) is a macro that uses a lookup table under the hood which is similar to llvm::toLower.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 342342
2018-09-15 23:59:13 +00:00
Nico Weber 0bd2d304e6 lld-link: Set PDB GUID to hash of PDB contents instead of to a random byte sequence.
Previously, lld-link would use a random byte sequence as the PDB GUID. Instead,
use a hash of the PDB file contents.

To not disturb llvm-pdbutil pdb2yaml, the hash generation is an opt-in feature
on InfoStreamBuilder and ldb/COFF/PDB.cpp always sets it.

Since writing the PDB computes this ID which also goes in the exe, the PDB
writing code now must be called before writeBuildId(). writeBuildId() for that
reason is no longer included in the "Code Layout" timer.

Since the PDB GUID is now a function of the PDB contents, the PDB Age is always
set to 1. There was a long comment above loadExistingBuildId (now gone) about
how not changing the GUID and only incrementing the age was important, but
according to the discussion in PR35914 that comment was incorrect.

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

llvm-svn: 342334
2018-09-15 18:37:22 +00:00
Nico Weber da15acbd68 lld-link: print demangled symbol names for "undefined symbol" diagnostics
For this, add a few toString() calls when printing the "undefined symbol"
diagnostics; toString() already does demangling on Windows hosts.

Also make lld::demangleMSVC() (called by toString(Symbol*)) call LLVM's
microsoftDemangle() instead of UnDecorateSymbolName() so that it works on
non-Windows hosts – this makes both updating tests easier and provides a better
user experience for people doing cross-links.

This doesn't yet do the right thing for symbols starting with __imp_, but that
can be improved in a follow-up.

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

llvm-svn: 342332
2018-09-15 18:27:09 +00:00
Rui Ueyama 01d250eed9 Style fix. NFC.
llvm-svn: 342300
2018-09-14 23:51:17 +00:00
Rui Ueyama 970573776a Rename GdbIndex.{cpp,h} -> DWARF.{cpp,h}.
These files used to contain classes and functions for .gdb_index,
but they are moved to SyntheticSections.{cpp,h}, so the name is now
irrelevant.

llvm-svn: 342299
2018-09-14 23:51:05 +00:00
Rui Ueyama e7688e6663 Revert r342297: Discard uncompressed buffer after creating .gdb_index contents.
Looks like it broke some local builds that use -gdb-index.

llvm-svn: 342298
2018-09-14 23:28:13 +00:00
Rui Ueyama 751dfbe39b Discard uncompressed buffer after creating .gdb_index contents.
Once we create .gdb_index contents, .zdebug_gnu_pub{names,types}
are useless, so there's no need to keep their uncompressed data
in memory.

I observed that for a test case in which lld creates a 3GB .gdb_index
section, the maximum resident set size reduced from 43GB to 29GB after
this patch.

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

llvm-svn: 342297
2018-09-14 22:57:39 +00:00
Martin Storsjo 7a41693898 [COFF] Provide __CTOR_LIST__ and __DTOR_LIST__ symbols for MinGW
MinGW uses these kind of list terminator symbols for traversing
the constructor/destructor lists. These list terminators are
actual pointers entries in the lists, with the values 0 and
(uintptr_t)-1 (instead of just symbols pointing to the start/end
of the list).

(This mechanism exists in both the mingw-w64 crt startup code and
in libgcc; normally the mingw-w64 one is used, but a DLL build of
libgcc uses the libgcc one. Therefore it's not trivial to change
the mechanism without lots of cross-project synchronization and
potentially invalidating some combinations of old/new versions
of them.)

When mingw-w64 has been used with lld so far, the CRT startup object
files have so far provided these symbols, ending up with different,
incompatible builds of the CRT startup object files depending on
whether binutils or lld are going to be used.

In order to avoid the need of different configuration of the CRT startup
object files depending on what linker to be used, provide these symbols
in lld instead. (Mingw-w64 checks at build time whether the linker
provides these symbols or not.) This unifies this particular detail
between the two linkers.

This does disallow the use of the very latest lld with older versions
of mingw-w64 (the configure check for the list was added recently;
earlier it simply checked whether the CRT was built with gcc or clang),
and requires rebuilding the mingw-w64 CRT. But the number of users of
lld+mingw still is low enough that such a change should be tolerable,
and unifies this aspect of the toolchains, easing interoperability
between the toolchains for the future.

The actual test for this feature is added in ctors_dtors_priority.s,
but a number of other tests that checked absolute output addresses
are updated.

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

llvm-svn: 342294
2018-09-14 22:26:59 +00:00
Ed Maste c0b474f67a lld: add -z interpose support
-z interpose sets the DF_1_INTERPOSE flag, marking the object as an
interposer.

Via FreeBSD PR 230604, linking Valgrind with lld failed.

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

llvm-svn: 342239
2018-09-14 14:25:37 +00:00
Martin Storsjo 4c1b815d39 [COFF] Allow embedded directives to be separated by null bytes
The PE spec says that they will be separated by spaces, but link.exe
handles it just fine if they are separated by null bytes as well.

This adds tests to the lld repo, with the actual functional change
in LLVM in SVN r342204.

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

llvm-svn: 342206
2018-09-14 06:08:56 +00:00
Martin Storsjo 4c201a8ba5 [COFF] Avoid copying of chunk vectors. NFC.
When declaring the pair variable as "auto Pair : Map", it is
effectively declared as
std::pair<std::pair<StringRef, uint32_t>, std::vector<Chunk *>>.
This effectively does a full, shallow copy of the Chunk vector,
just to be thrown away after each iteration.

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

llvm-svn: 342205
2018-09-14 06:08:51 +00:00
Rui Ueyama 11ca38f421 COFF: Add support for /force:multiple option
Patch by Thomas Roughton.

This patch adds support for linking with multiple definitions to LLD's
COFF driver, in line with link.exe's /force:multiple option.

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

llvm-svn: 342191
2018-09-13 22:05:10 +00:00
Nico Weber f1828e3240 lld-link: For nonexisting inputs, omit follow-on diagnostics
For lld-link missing.obj, lld-link currently prints:

  lld-link: error: could not open foo.obj: No such file or directory
  lld-link: warning: /machine is not specified. x64 is assumed
  lld-link: error: subsystem must be defined

The 2nd and 3rd diagnostics are consequences of the input not existing and are
not interesting. If input files are missing, the best thing we can do is point
that out and then return.

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

llvm-svn: 342158
2018-09-13 18:13:21 +00:00
Peter Smith f31f596152 [ELF] Guard --fix-cortex-a53-843419 against --just-syms
If --just-syms is used the mapping symbols from the ELF file will be
absolute symbols with no section. The code to process mapping symbols in
--fix-cortex-a53-843419 assumes that these symbols have a defining section
so a crash will result when --just-syms is used. The simple fix is to not
process the symbol when it doesn't have a section.

Fixes PR37971

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

llvm-svn: 342146
2018-09-13 15:49:13 +00:00
Azharuddin Mohammed 4dce517c47 Add missing REQUIRES x86 to test/COFF/icf-safe.s
Reviewers: ruiu, pcc

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 342145
2018-09-13 15:40:19 +00:00
Azharuddin Mohammed e41386b446 Fix typo in error message. NFC.
Summary: It should be "wasm-ld", not "wasm-lld".

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: aheejin, sunfish, llvm-commits

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

llvm-svn: 342144
2018-09-13 15:37:13 +00:00
Zachary Turner a1f85f8bdd [PDB] Emit old fpo data to the PDB file.
r342003 added support for emitting FPO data from the
DEBUG_S_FRAMEDATA subsection of the .debug$S section to the PDB
file.  However, that is not the end of the story.  FPO can end
up in two different destinations in a PDB, each corresponding to
a different FPO data source.

The case handled by r342003 involves copying data from the
DEBUG_S_FRAMEDATA subsection of the .debug$S section to the
"New FPO" stream in the PDB, which is then referred to by the
DBI stream.  The case handled by this patch involves copying
records from the .debug$F section of an object file to the "FPO"
stream (or perhaps more aptly, the "Old FPO" stream) in the PDB
file, which is also referred to by the DBI stream.

The formats are largely similar, and the difference is mostly
only visible in masm generated object files, such as some of the
low-level CRT object files like memcpy.  MASM doesn't appear to
support writing the DEBUG_S_FRAMEDATA subsection, and instead
just writes these records to the .debug$F section.

Although clang-cl does not emit a .debug$F section ever, lld still
needs to support it so we have good debugging for CRT functions.

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

llvm-svn: 342080
2018-09-12 21:02:01 +00:00
Chih-Hung Hsieh 73e04847bf [ELF] Revert "Also demote lazy symbols."
This reverts commit https://reviews.llvm.org/rL330869
for a regression to link Android dex2oatds.

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

llvm-svn: 342007
2018-09-11 23:00:36 +00:00
Zachary Turner 42e7cc1b0f [PDB] Write FPO Data to the PDB.
llvm-svn: 342003
2018-09-11 22:35:01 +00:00
Reid Kleckner a6f64265ea [codeview] Decode and dump FP regs from S_FRAMEPROC records
Summary:
There are two registers encoded in the S_FRAMEPROC flags: one for locals
and one for parameters. The encoding is described by the
ExpandEncodedBasePointerReg function in cvinfo.h. Two bits are used to
indicate one of four possible values:

  0: no register - Used when there are no variables.
  1: SP / standard - Variables are stored relative to the standard SP
     for the ISA.
  2: FP - Variables are addressed relative to the ISA frame
     pointer, i.e. EBP on x86. If realignment is required, parameters
     use this. If a dynamic alloca is used, locals will be EBP relative.
  3: Alternative - Variables are stored relative to some alternative
     third callee-saved register. This is required to address highly
     aligned locals when there are dynamic stack adjustments. In this
     case, both the incoming SP saved in the standard FP and the current
     SP are at some dynamic offset from the locals. LLVM uses ESI in
     this case, MSVC uses EBX.

Most of the changes in this patch are to pass around the CPU so that we
can decode these into real, named architectural registers.

Subscribers: hiraditya

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

llvm-svn: 341999
2018-09-11 22:00:50 +00:00
Rui Ueyama 98e4a5ca11 Simplify.
Instead of Map<StringRef, bool>, we can simply use Set<StringRef>.

llvm-svn: 341948
2018-09-11 14:37:27 +00:00
Rui Ueyama 10454c4fd5 Style fix.
llvm-svn: 341937
2018-09-11 13:41:58 +00:00
Petr Hosek c6a233a68a [ELF] Don't emit .relr.dyn section if there are no relocs
This resolves PR38875.

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

llvm-svn: 341870
2018-09-10 21:54:56 +00:00
Martin Storsjo db62913f28 [MinGW] Hook up the --require-defined option to -include:
Differential Revision: https://reviews.llvm.org/D51840

llvm-svn: 341846
2018-09-10 17:41:40 +00:00
Alexandre Ganea 472e9b0ab2 Buildfix for r341825
llvm-svn: 341827
2018-09-10 14:07:11 +00:00
Alexandre Ganea d93b07f0b0 [LLD][COFF] Cleanup error messages / add more coverage tests
- Log the reason for a PDB or precompiled-OBJ load failure
- Properly handle out-of-date PDB or precompiled-OBJ signature by displaying a corresponding error
- Slightly change behavior on PDB failure: any subsequent load attempt from another OBJ would result in the same error message being logged
- Slightly change behavior on PDB failure: retry with filename only if previous error was ENOENT ("no such file or directory")
- Tests: a. for native PDB errors; b. cover all the cases above

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

llvm-svn: 341825
2018-09-10 13:51:21 +00:00
Nico Weber cc08366035 Remove an effectively unused local variable.
llvm-svn: 341823
2018-09-10 13:20:16 +00:00
Hans Wennborg 8ec9b16f27 ReleaseNotes: update links to use https
llvm-svn: 341788
2018-09-10 08:52:31 +00:00
Tom Stellard a6749135df MachO: Change getString16() back to inline function
This was accidentally changed in r341670.

llvm-svn: 341672
2018-09-07 15:51:52 +00:00
Tom Stellard 493f3bad3c MachO: Fix out-of-bounds memory access in getString16
Summary:
This fixes the following tests when gcc is compiled with gcc8:

lld :: mach-o/do-not-emit-unwind-fde-arm64.yaml
lld :: mach-o/eh-frame-relocs-arm64.yaml

llvm.org/PR38096

Reviewers: lhames, kledzik, javed.absar

Subscribers: kristof.beyls, llvm-commits

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

llvm-svn: 341670
2018-09-07 15:42:01 +00:00
Fangrui Song 1fe3e8b26f [ELF] Check if LinkSec is nullptr when initializing SHF_LINK_ORDER sections
Summary: This protects lld from a null pointer dereference when a faulty input file has such invalid sh_link fields.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 341611
2018-09-07 00:18:07 +00:00
Bob Haarman 2ba4d231d1 [COFF] don't mark lazy symbols as used in regular objects
Summary:
r338767 updated the COFF and wasm linker SymbolTable code to be
strutured more like the ELF linker's. That inadvertedly changed the
behavior of the COFF linker so that lazy symbols would be marked as
used in regular objects. This change adds an overload of the insert()
function, similar to the ELF linker, which does not perform that
marking.

Reviewers: ruiu, rnk, hans

Subscribers: aheejin, sunfish, llvm-commits

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

llvm-svn: 341585
2018-09-06 20:23:56 +00:00
Nico Weber 13b55bbc2f lld-link: Write an empty "repro" debug directory entry if /Brepro is passed
If the coff timestamp is set to a hash, like lld-link does if /Brepro is
passed, the coff spec suggests that a IMAGE_DEBUG_TYPE_REPRO entry is in the
debug directory. This lets lld-link write such a section.
Fixes PR38429, see bug for details.

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

llvm-svn: 341486
2018-09-05 18:02:43 +00:00
Sterling Augustine b55236f522 When a relocation to an undefined symbol is an R_X86_64_PC32, an input
section will not have an input file. Don't crash under those circumstances.

Neither clang nor llvm-mc generates R_X86_64_PC32 relocations due to
https://reviews.llvm.org/D43383, which makes it hard to write a test case.
However, gcc does generate such relocations. I want to get a fix in now,
but will figure out a way to actually exercise this code path as soon
as I can.

llvm-svn: 341408
2018-09-04 21:06:59 +00:00
Martin Storsjo a47957ab13 [COFF] Allow exporting all symbols from system libraries specfied with -wholearchive:
When building a shared libc++.dll, it pulls in libc++abi.a statically
with the --wholearchive flag. If such a build is done with
--export-all-symbols, it's reasonable to assume that everything
from that library also should be exported with the same rules as normal
local object files, even though we normally avoid autoexporting things
from libc++abi.a in other cases when linking a DLL (user code).

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

llvm-svn: 341403
2018-09-04 20:56:56 +00:00
Alexandre Ganea 6a7efef4af [DebugInfo] Common behavior for error types
Following D50807, and heading towards D50664, this intermediary change does the following:

1. Upgrade all custom Error types in llvm/trunk/lib/DebugInfo/ to use the new StringError behavior (D50807).
2. Implement std::is_error_code_enum and make_error_code() for DebugInfo error enumerations.
3. Rename GenericError -> PDBError (the file will be renamed in a subsequent commit)
4. Update custom error messages to follow the same formatting: (\w\s*)+\.
5. Keep generic "file not found" (ENOENT) errors as they are in PDB code. Previously, there used to be a custom enumeration for that purpose.
6. Remove a few extraneous LF in log() implementations. Printing LF is a responsability at a higher level, not at the error level.

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

llvm-svn: 341228
2018-08-31 17:41:58 +00:00
Ben Dunbobbin d2c2c57f52 [LLD] Add test missed from r341206. NFC.
llvm-svn: 341207
2018-08-31 12:09:21 +00:00
Ben Dunbobbin df6f0ad210 [LLD] Check too large offsets into merge sections earlier
This patch moves the checking for too large offsets into merge sections
earlier.

Without this change the large offset generated in the added test-case
will cause an assert (as it happens to be a value reserved as a
"tombstone" in the DenseMap implementation) when OffsetMap is queried in
getSectionPiece().

To simplify the code and avoid future mistakes I have refactored so that
there is only one function that looks up offsets in the OffsetMap.

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

llvm-svn: 341206
2018-08-31 11:51:51 +00:00
Martin Storsjo 24f590fca6 [ELF] [ARM] Don't mix 'ip' and 'r12' as names for the same register in comments. NFC.
llvm-svn: 341179
2018-08-31 08:03:33 +00:00
Martin Storsjo 802fcb4167 [COFF] When doing automatic dll imports, replace whole .refptr.<var> chunks with __imp_<var>
After fixing up the runtime pseudo relocation, the .refptr.<var>
will be a plain pointer with the same value as the IAT entry itself.
To save a little binary size and reduce the number of runtime pseudo
relocations, redirect references to the IAT entry (via the __imp_<var>
symbol) itself and discard the .refptr.<var> chunk (as long as the
same section chunk doesn't contain anything else than the single
pointer).

As there are now cases for both setting the Live variable to true
and false externally, remove the accessors and setters and just make
the variable public instead.

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

llvm-svn: 341175
2018-08-31 07:45:20 +00:00
Fangrui Song f1126325e8 [PPC64] Improve a test ppc64_entry_point.s
Rename to ppc64-entry-point.s
Deduplicate .text dump of little-endian big-endian

llvm-svn: 341153
2018-08-31 00:33:16 +00:00
Fangrui Song 0f0f8aa2e1 Import lit.llvm after rLLD341134
llvm-svn: 341150
2018-08-31 00:23:09 +00:00
Fangrui Song d958df8324 [PPC64] Improve a test ppc64-toc-rel.s
Deduplicate dump of .text .data for little-endian and big-endian
Fix a RELOCS-NE check line typo

llvm-svn: 341148
2018-08-31 00:16:22 +00:00
Fangrui Song c799893787 [PPC64] Remove unused -z notext from a test
llvm-svn: 341139
2018-08-30 23:01:00 +00:00
Nico Weber abb8febb72 Remove LIT_SITE_CFG_IN_FOOTER, lld
It's always replaced with the same (short) static string, so just put that
there directly.

No intended behavior change.
https://reviews.llvm.org/D51357

llvm-svn: 341134
2018-08-30 22:12:16 +00:00
Martin Storsjo fcd552999f [COFF] Skip exporting artificial symbols when exporting all symbols
Differential Revision: https://reviews.llvm.org/D51457

llvm-svn: 341017
2018-08-30 05:44:41 +00:00
Martin Storsjo e5120a3bd4 [test] Adjust a test to use CHECK-NEXT instead of CHECK-NOT. NFC.
Since the order and placement of the non-wanted elements might not
be obvious, it feels more straightforward to hardcode the whole list
with -NEXT elements (and checking for the end of the output with
CHECK-EMPTY) instead of adding CHECK-NOT lines at the right places
where the unwanted elements would appear if they erroneously
were to included.

llvm-svn: 341016
2018-08-30 05:44:36 +00:00
Peter Collingbourne 6556e6b929 ELF: Don't examine values of linker script symbols during ICF.
These symbols are declared early with the same value, so they otherwise
appear identical to ICF.

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

llvm-svn: 340998
2018-08-29 23:43:38 +00:00
Heejin Ahn 4821ebf73f [WebAssembly] clang-format (NFC)
Summary: This patch runs clang-format on all wasm-only files.

Reviewers: sbc100

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

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

llvm-svn: 340970
2018-08-29 21:03:16 +00:00
Martin Storsjo bb0a3c911d [CMake] Add an lld-test-depends target
This builds all dependencies of lld-test/check-lld, without running
the tests. This matches llvm-test-depends and clang-test-depends.

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

llvm-svn: 340943
2018-08-29 17:30:45 +00:00
Martin Storsjo cfbbb707f5 [COFF] Merge the .ctors, .dtors and .CRT sections into .rdata for MinGW
There's no point in keeping them as separate sections.

This differs from GNU ld, which places .ctors and .dtors content in
.text (implemented by a built-in linker script). But since the content
only is pointers, there's no need to have it executable.

GNU ld also leaves .CRT separate as its own standalone section.

MSVC merges .CRT into .rdata similarly, with a directive embedded in
an object file in msvcrt.lib or libcmt.lib.

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

llvm-svn: 340940
2018-08-29 17:24:10 +00:00
Rui Ueyama 025bb56a86 Always add a .note.GNU-stack section if -r.
With this patch, lld creates a .note.GNU_stack and adds that to an
output file if it is creating a re-linkable object file (i.e. if -r
is given). If we don't do this, and if you use GNU linkers as a final
linker, they create an executable whose stack area is executable,
which is considered pretty bad these days.

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

llvm-svn: 340902
2018-08-29 07:27:09 +00:00
Fangrui Song f9b789eaa4 [ELF] Change llvm-objdump -D to -d for check lines that only inspect text sections
Reviewers: ruiu, sfertile, syzaara, espindola

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

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

llvm-svn: 340890
2018-08-29 02:07:58 +00:00
Sean Fertile 4d354e1199 [PPC64] Fix DQ-form instruction handling and emit error for misalignment.
Relanding r340564, original commit message:

Fixes the handling of *_DS relocations used on DQ-form instructions where we
were overwriting some of the extended opcode bits. Also adds an alignment check
so that the user will receive a diagnostic error if the value we are writing
is not properly aligned.

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

llvm-svn: 340832
2018-08-28 15:16:01 +00:00
George Rimar f0eedbce44 [LLD][ELF] - Simplify Call-Chain Clustering implementation a bit.
Looking at the current implementation and algorithm description,
it does not seem we need to keep vector with all edges for
each cluster and can just remember the best one. This is NFC change.

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

llvm-svn: 340806
2018-08-28 08:49:40 +00:00
George Rimar a46d08ebe6 [LLD][ELD] - Do not reject INFO output section type when used with a start address.
This is https://bugs.llvm.org/show_bug.cgi?id=38625

LLD accept this: 

".stack (INFO) : {", 

but not this:

".stack address_expression (INFO) :"

The patch fixes it.

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

llvm-svn: 340804
2018-08-28 08:39:21 +00:00
George Rimar 27bbe7d0b4 [LLF][ELF] - Support -z global.
-z global is a flag used on Android (see D49198).

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

llvm-svn: 340802
2018-08-28 08:24:34 +00:00
Nico Weber c7bad5767b fix comment typo
llvm-svn: 340742
2018-08-27 14:22:25 +00:00
Sid Manning 569a56d6a0 [ELF][HEXAGON] Add R_HEX_11/10/9_X support
Differential Revision: https://reviews.llvm.org/D51225

llvm-svn: 340739
2018-08-27 12:55:28 +00:00
Matt Arsenault 8d6c7a63a1 Handle identifying AMDGPU bitcode files
llvm-svn: 340738
2018-08-27 12:40:00 +00:00
Martin Storsjo eac1b05f1d [COFF] Support MinGW automatic dllimport of data
Normally, in order to reference exported data symbols from a different
DLL, the declarations need to have the dllimport attribute, in order to
use the __imp_<var> symbol (which contains an address to the actual
variable) instead of the variable itself directly. This isn't an issue
in the same way for functions, since any reference to the function without
the dllimport attribute will end up as a reference to a thunk which loads
the actual target function from the import address table (IAT).

GNU ld, in MinGW environments, supports automatically importing data
symbols from DLLs, even if the references didn't have the appropriate
dllimport attribute. Since the PE/COFF format doesn't support the kind
of relocations that this would require, the MinGW's CRT startup code
has an custom framework of their own for manually fixing the missing
relocations once module is loaded and the target addresses in the IAT
are known.

For this to work, the linker (originall in GNU ld) creates a list of
remaining references needing fixup, which the runtime processes on
startup before handing over control to user code.

While this feature is rather controversial, it's one of the main features
allowing unix style libraries to be used on windows without any extra
porting effort.

Some sort of automatic fixing of data imports is also necessary for the
itanium C++ ABI on windows (as clang implements it right now) for importing
vtable pointers in certain cases, see D43184 for some discussion on that.

The runtime pseudo relocation handler supports 8/16/32/64 bit addresses,
either PC relative references (like IMAGE_REL_*_REL32*) or absolute
references (IMAGE_REL_AMD64_ADDR32, IMAGE_REL_AMD64_ADDR32,
IMAGE_REL_I386_DIR32). On linking, the relocation is handled as a
relocation against the corresponding IAT slot. For the absolute references,
a normal base relocation is created, to update the embedded address
in case the image is loaded at a different address.

The list of runtime pseudo relocations contains the RVA of the
imported symbol (the IAT slot), the RVA of the location the relocation
should be applied to, and a size of the memory location. When the
relocations are fixed at runtime, the difference between the actual
IAT slot value and the IAT slot address is added to the reference,
doing the right thing for both absolute and relative references.

With this patch alone, things work fine for i386 binaries, and mostly
for x86_64 binaries, with feature parity with GNU ld. Despite this,
there are a few gotchas:
- References to data from within code works fine on both x86 architectures,
  since their relocations consist of plain 32 or 64 bit absolute/relative
  references. On ARM and AArch64, references to data doesn't consist of
  a plain 32 or 64 bit embedded address or offset in the code. On ARMNT,
  it's usually a MOVW+MOVT instruction pair represented by a
  IMAGE_REL_ARM_MOV32T relocation, each instruction containing 16 bit of
  the target address), on AArch64, it's usually an ADRP+ADD/LDR/STR
  instruction pair with an even more complex encoding, storing a PC
  relative address (with a range of +/- 4 GB). This could theoretically
  be remedied by extending the runtime pseudo relocation handler with new
  relocation types, to support these instruction encodings. This isn't an
  issue for GCC/GNU ld since they don't support windows on ARMNT/AArch64.
- For x86_64, if references in code are encoded as 32 bit PC relative
  offsets, the runtime relocation will fail if the target turns out to be
  out of range for a 32 bit offset.
- Fixing up the relocations at runtime requires making sections writable
  if necessary, with the VirtualProtect function. In Windows Store/UWP apps,
  this function is forbidden.

These limitations are addressed by a few later patches in lld and
llvm.

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

llvm-svn: 340726
2018-08-27 08:43:31 +00:00
Rui Ueyama 41831204c7 Rename a function to follow the LLVM coding style.
llvm-svn: 340716
2018-08-27 06:18:10 +00:00
Martin Storsjo c4b0061c05 [COFF] Check the instructions in ARM MOV32T relocations
For this relocation, which applies to two consecutive instructions,
it's plausible that the second instruction might not actually be
the right one.

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

llvm-svn: 340715
2018-08-27 06:04:36 +00:00
Sid Manning 2c3d4b37b6 [ELF][HEXAGON] Add R_HEX_B13_PCREL relocation support
Differential Revision: https://reviews.llvm.org/D51166

llvm-svn: 340693
2018-08-25 23:16:37 +00:00
Sid Manning 6d0415e098 [ELF][HEXAGON] Add R_HEX_B9_PCREL and R_HEX_B9_PCREL_X relocation support
Differential Revision: https://reviews.llvm.org/D51045

llvm-svn: 340692
2018-08-25 21:25:35 +00:00
Martin Storsjo 0f3d8e2360 [Common] Discard the temp file while keeping the memory mapping open, on errors
Differential Revision: https://reviews.llvm.org/D51095

llvm-svn: 340635
2018-08-24 18:36:42 +00:00
Joel Galenson 0f6e12bcdf Modify tests to show PLT entry labels
llvm-svn: 340616
2018-08-24 16:22:42 +00:00
Nico Weber 0b87d05679 Attempt to fix ELF/lto-plugin-ignore.s on Windows after r340487.
I removed the ".exe" regex in the wrong place. lld-link in front of the
"error:" no longer has the suffix; the --plugin-opt diagnostic still has it.

llvm-svn: 340590
2018-08-24 00:12:58 +00:00
Sean Fertile 1542b0aef5 Revert "[PPC64] Fix DQ-form instruction handling and emit error for misalign..."
This reverts commit 5125b44dbb5d06b715213e4bec75c7346bfcc7d3.
ppc64-dq.s and ppc64-error-missaligned-dq.s fail on several of the build-bots.
Reverting to investigate.

llvm-svn: 340568
2018-08-23 19:10:40 +00:00
Sean Fertile a6b2ab7a91 [PPC64] Fix DQ-form instruction handling and emit error for misalignment.
Fixes the handling of *_DS relocations used on DQ-form instructions where we
were overwriting some of the extended opcode bits. Also adds an alignment check
so that the user will receive a diagnostic error if the value we are writing
is not properly aligned.

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

llvm-svn: 340564
2018-08-23 18:35:09 +00:00
Peter Collingbourne ab038025a5 COFF: Implement safe ICF on rodata using address-significance tables.
Differential Revision: https://reviews.llvm.org/D51050

llvm-svn: 340555
2018-08-23 17:44:42 +00:00
Nico Weber 386bf1216e win: Omit ".exe" from lld warning and error messages.
This is a minor follow-up to https://reviews.llvm.org/D49189. On Windows, lld
used to print "lld-link.exe: error: ...". Now it just prints "lld-link: error:
...". This matches what link.exe does (it prints "LINK : ...") and makes lld's
output less dependent on the host system.

https://reviews.llvm.org/D51133

llvm-svn: 340487
2018-08-22 23:52:13 +00:00
Nico Weber 7830c6f66f lld-link: Separate 'undefined symbol' errors with just one newline, not two.
newline() in ErrorHandler.cpp already tries to insert newlines between messages
that contain embedded newlines, so getSymbolLocations() shouldn't return a
string that ends in a newline -- else we end up with two newlines between error
messages.

Makes lld-link's output look more like ld.lld output.

https://reviews.llvm.org/D51117

llvm-svn: 340482
2018-08-22 23:45:05 +00:00
Nico Weber 613edd1582 Fix two RUN: lines that were unintentionally spelled "RN:".
https://reviews.llvm.org/D51140

llvm-svn: 340481
2018-08-22 23:44:03 +00:00
Sam Clegg 47078f56f2 [WebAssembly] Optimise relocation processing. NFC.
This is a rebased version https://reviews.llvm.org/D42176 which is patch
by Nicolas Wilson.

Addresses issue:
https://github.com/WebAssembly/tool-conventions/issues/32, and
https://bugs.llvm.org/show_bug.cgi?id=38650

Previously, for each function/segment we iterated over every relocation
to find the relevant ones, which is an n^2 operation. Now, we just make
a single pass.

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

llvm-svn: 340428
2018-08-22 17:50:51 +00:00
Nico Weber ebc27c4873 lld-link: Emit warning if one each of {main,wmain} and {WinMain,wWinMain} exist and no /subsystem: flag is passed.
Similar to link.exe's LNK4031.
https://reviews.llvm.org/D51076

llvm-svn: 340420
2018-08-22 16:47:16 +00:00
Sid Manning 564e65a4c0 [ELF][HEXAGON] Add R_HEX_16_X relocation
This relocation has only 6-bits the remaining are in the extender.

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

llvm-svn: 340413
2018-08-22 15:25:15 +00:00
Martin Storsjo c0ee24033c [COFF] Move a comment close to the code it refers to. NFC.
llvm-svn: 340400
2018-08-22 11:35:02 +00:00
Martin Storsjo 6c67e04345 [COFF] Change fatal() into error() when writing chunks to the output
In most of these cases, it's easy to go on despite the error,
printing as many valuable error messages as possible from one run
as possible.

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

llvm-svn: 340399
2018-08-22 11:34:58 +00:00
Rui Ueyama 07b4536bb7 Change how we handle -wrap.
We have an issue with -wrap that the option doesn't work well when
renamed symbols get PLT entries. I'll explain what is the issue and
how this patch solves it.

For one -wrap option, we have three symbols: foo, wrap_foo and real_foo.
Currently, we use memcpy to overwrite wrapped symbols so that they get
the same contents. This works in most cases but doesn't when the relocation
processor sets some flags in the symbol. memcpy'ed symbols are just
aliases, so they always have to have the same contents, but the
relocation processor breaks that assumption.

r336609 is an attempt to fix the issue by memcpy'ing again after
processing relocations, so that symbols that are out of sync get the
same contents again. That works in most cases as well, but it breaks
ASan build in a mysterious way.

We could probably fix the issue by choosing symbol attributes that need
to be copied after they are updated. But it feels too complicated to me.

So, in this patch, I fixed it once and for all. With this patch, we no
longer memcpy symbols. All references to renamed symbols point to new
symbols after wrapSymbols() is done.

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

llvm-svn: 340387
2018-08-22 07:02:26 +00:00
Bob Haarman 481d224b67 [Support][CachePruning] prune least recently accessed files first
Summary:
Before this change, pruning order was based on size. This changes it
to be based on time of last use instead, preferring to keep recently
used files and prune older ones.

Reviewers: pcc, rnk, espindola

Reviewed By: rnk

Subscribers: emaste, arichardson, hiraditya, steven_wu, dexonsmith, llvm-commits

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

llvm-svn: 340374
2018-08-22 00:52:16 +00:00
Fangrui Song 887ec75173 [ELF] -thinlto-object-suffix-replace=: don't error if the path does not end with old suffix
Summary:
For -thinlto-object-suffix-replace=old\;new, in
tools/gold/gold-plugin.cpp, the thinlto object filename is Path minus
optional old suffix.

    static std::string getThinLTOObjectFileName(StringRef Path, StringRef OldSuffix,
                                                StringRef NewSuffix) {
      if (OldSuffix.empty() && NewSuffix.empty())
        return Path;
      StringRef NewPath = Path;
      NewPath.consume_back(OldSuffix);
      std::string NewNewPath = NewPath;
      NewNewPath += NewSuffix;
      return NewNewPath;
    }

Currently lld will error that the path does not end with old suffix.

This patch makes lld accept such paths but only add new suffix if Path
ends with old suffix. This fixes a link error where bitcode members in
an archive are regular LTO objects without old suffix.

Acording to tejohnson, this will "enable supporting mix and match of
minimized ThinLTO bitcode files with normal ThinLTO bitcode files in a
single link (where we want to apply the suffix replacement to the
minimized files, and just ignore it for the normal ThinLTO files)."

Reviewers: ruiu, pcc, tejohnson, espindola

Reviewed By: tejohnson

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

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

llvm-svn: 340364
2018-08-21 23:28:12 +00:00
Zaara Syeda 662d146c5b [PPC64] Add TLS initial exec to local exec relaxation
This patch adds the target call back relaxTlsIeToLe to support TLS relaxation
from initial exec to local exec model.

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

llvm-svn: 340281
2018-08-21 15:13:53 +00:00
George Rimar 3cd1d27b58 [LLD][ELF] - Fix BB after r340257.
Renamed Filecheck->FileCheck.

llvm-svn: 340259
2018-08-21 08:27:23 +00:00
George Rimar e2684662ee [LLD][ELF] - Check the architecture of lazy objects earlier.
Our code in LazyObjFile::parse() has an ELFT switch and
adds a lazy object by its ELFT kind.
Though it might be possible to add a file using a different
architecture and make LLD to silently accept it (if the file
is empty or contains only week symbols). That itself, not a
huge issue perhaps (because the error would be reported later
if the file is fetched), but still does not look clean and correct.

It is possible to report an error earlier and clean up the
code. That is what the patch does.

Ideally, we might want to reuse isCompatible from SymbolTable.cpp,
but it is static and accepts a file as an argument, what is not
convenient. Since such a situation should be rare, I think it
should be OK to go with the way chosen in this patch.

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

llvm-svn: 340257
2018-08-21 08:13:06 +00:00
Fangrui Song 3a84a093f2 [docs] Add --print-icf-sections to ld.lld.1
llvm-svn: 340253
2018-08-21 07:35:23 +00:00
George Rimar 20f994d350 [LLD][ELF] - Fix warning.
This fixes the following warning when compiling with gcc version 8.0.1 20180319 (experimental) (GCC):

/home/umb/LLVM/llvm/tools/lld/ELF/SyntheticSections.cpp:1951:46: warning: enumeral and non-enumeral type in conditional expression [-Wextra]
     return OS->SectionIndex >= SHN_LORESERVE ? SHN_XINDEX : OS->SectionIndex;

llvm-svn: 340164
2018-08-20 10:29:21 +00:00
Peter Smith a8656c62f5 [ELF] Add support for Armv5 and Armv6 compatible Thunks
Older Arm architectures do not support the MOVT and MOVW instructions so we
must use an alternative sequence of instructions to transfer control to the
destination.

Assuming at least Armv5 this patch adds support for Thunks that load or add
to the program counter. Note that there are no Armv5 Thumb Thunks as there
is no Thumb branch instruction in Armv5 that supports Thunks. These thunks
will not work for Armv4t (arm7tdmi) as this architecture cannot change state
from using the LDR or ADD instruction.

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

llvm-svn: 340160
2018-08-20 09:37:50 +00:00
Peter Smith d1be026ede [ELF] Add support for older Arm Architectures with smaller branch range
The Thumb BL and BLX instructions on older Arm Architectures such as v5 and
v6 have a constrained encoding J1 and J2 must equal 1, later Architectures
relaxed this restriction allowing J1 and J2 to be used to calculate a larger
immediate.

This patch adds support for the old encoding, it is used when the build
attributes for the input objects only contain older architectures.

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

llvm-svn: 340159
2018-08-20 09:19:30 +00:00
Rui Ueyama 4c7d6beb37 Remove unnecessary applyMask() application.
applyMask(0xffffffff, x) is an identity function.

llvm-svn: 340152
2018-08-20 06:33:29 +00:00
Sam Clegg 30161dc28d [WebAssembly] Don't compress LEBs by default
LEB compression breaks debug info so we don't want to enable
it by default, even at high optimization levels.

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

llvm-svn: 340073
2018-08-17 19:42:46 +00:00
George Rimar bf6132c139 [LLD][ELF] - Remove dead code. NFC.
These lines were unused.

llvm-svn: 340011
2018-08-17 11:19:55 +00:00
Reid Kleckner e8299ded5b Update LLD tests for CodeView dumper change in r339907
llvm-svn: 339913
2018-08-16 18:03:06 +00:00
Reid Kleckner bd5d71229d [codeview] Use push_macro to avoid conflicts instead of a prefix
Summary:
This prefix was added in r333421, and it changed our dumper output to
say things like "CVRegEAX" instead of just "EAX". That's a functional
change that I'd rather avoid.

I tested GCC, Clang, and MSVC, and all of them support #pragma
push_macro. They don't issue warnings whem the macro is not defined
either.

I don't have a Mac so I can't test the real termios.h header, but I
looked at the termios.h sources online and looked for other conflicts.
I saw only the CR* macros, so those are the ones we work around.

Reviewers: zturner, JDevlieghere

Subscribers: hiraditya, llvm-commits

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

llvm-svn: 339907
2018-08-16 17:34:31 +00:00
Fangrui Song ebf9607d7d [ELF] mergeSections: remove non-alive MergeInputSection
Summary: This makes it conform to what the comment says. Otherwise when getErrPlace() is called afterwards, cast<InputSection>(D) will cause incompatible cast as MergeInputSection is not a subclass of InputSection.

Reviewers: ruiu, grimar, espindola, pcc

Reviewed By: grimar

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 339904
2018-08-16 17:22:02 +00:00
George Rimar e32c31af31 [LLD][ELF] - Add a test case for DT_SONAME entry reading.
This covers a following line with a test:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L899

llvm-svn: 339880
2018-08-16 14:07:29 +00:00
George Rimar ff22b43c7d [LLD][ELF] - Add a test case.
This covers the following line with a test:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L487

llvm-svn: 339876
2018-08-16 13:02:50 +00:00
George Rimar fc1a547be7 [LLD][ELF] - Add test case.
To cover the following error message:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L463

llvm-svn: 339867
2018-08-16 11:48:18 +00:00
George Rimar 21149aa2fa [LLD][ELF] - Stop using binary input in merge-invalid-size.s test. NFCI.
This rewrites the test using yaml.

llvm-svn: 339775
2018-08-15 14:59:38 +00:00
George Rimar eecc92d7d3 [LLD][ELF] - Convert binary input to yaml in sht-group.s test. NFC.
This removes test that used binary input and adds a yaml based test instead.

llvm-svn: 339774
2018-08-15 14:10:15 +00:00
George Rimar 2835606889 [LLD][ELF] - Handle SHT_GROUP more carefully. NFCI.
This patch solves 2 problems:
1) It adds a test to check the line below:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L334
Test case contains SHT_GROUP section with a broken (0xFF) flag.

2) The patch fixes the case when we silently accepted such broken groups
in the case when there were no other objects with the same group signature.

llvm-svn: 339765
2018-08-15 12:20:38 +00:00
George Rimar 48ca274d2f [LLD][ELF] - Eliminate dead code from OffsetGetter::get().
We have a dead piece of code there which is impossible to trigger
using regular objects I believe.
Patch removes it and adds a test case showing how this condition
can be triggered with use of a broken object and crash the linker.

llvm-svn: 339680
2018-08-14 14:20:34 +00:00
Sid Manning 5b0141c49e [ELF][HEXAGON] Add R_HEX_32 support
Differential Revision: https://reviews.llvm.org/D50657

llvm-svn: 339677
2018-08-14 13:52:38 +00:00
George Rimar 152e3c98ac [LLD][ELF] - Remove UnresolvedPolicy::IgnoreAll and relative code. NFC.
The code involved was simply dead. `IgnoreAll` value is used in
`maybeReportUndefined` only which is never called for -r.
And at the same time `IgnoreAll` was set only for -r.

llvm-svn: 339672
2018-08-14 11:55:31 +00:00
Richard Smith 5a778aa79f Revert r339490 to match revert of llvm r339474 in r339630.
llvm-svn: 339635
2018-08-14 01:23:54 +00:00
Sterling Augustine 48b469746c Support shared objects for split stack.
llvm-svn: 339626
2018-08-13 22:29:15 +00:00
George Rimar 4b3a8bd91e [LLD][ELF] - Remove dead code from handleTlsRelocation. NFC.
Code is dead because R_TLSDESC_CALL is already handled in the
following block of the code:
https://github.com/llvm-mirror/lld/blob/master/ELF/Relocations.cpp#L231

llvm-svn: 339566
2018-08-13 13:59:06 +00:00
George Rimar b44789759b [LLD][ELF] - Remove dead code from handleTlsRelocation. NFC.
That piece of code is really very old and "protected"
from TLS relocations against symbol in non-allocatable sections.
It is useless because normally non-alloc sections have relocations
with allocatable targets, but not the reverse.
And so the code was simply dead.

llvm-svn: 339553
2018-08-13 11:20:18 +00:00
George Rimar c1ef96f593 [LLD][ELF] - Update test case to check the error message reported. NFC.
This updates znotext-plt-relocations-protected.s test case
(adds a file symbol) to check how the error message is built.

It allows to cover/test the following line:
https://github.com/llvm-mirror/lld/blob/master/ELF/Relocations.cpp#L79

llvm-svn: 339550
2018-08-13 10:28:00 +00:00
George Rimar 25cd609a64 [LLD][ELF] - Add one more test case for CallGraphSort.
This adds a coverage for the following early continue:
https://github.com/llvm-mirror/lld/blob/master/ELF/CallGraphSort.cpp#L200

llvm-svn: 339514
2018-08-12 09:16:22 +00:00
George Rimar a5cf8da145 [LLF][ELF] - Simplify. NFC.
llvm-svn: 339510
2018-08-12 07:52:24 +00:00
Richard Trieu f1342bb8b8 Fix WebAssembly tests after r339474
Add flags to llc RUN lines to keep tests passing.

llvm-svn: 339490
2018-08-10 23:58:11 +00:00
Sid Manning 2e20df3e9b [ELF][HEXAGON] Put test back in.
The registers are tied.

llvm-svn: 339487
2018-08-10 23:46:11 +00:00
Sid Manning 98b07a615b [ELF][HEXAGON] Remove test that breaks assembler.
Remove testcase the breaks the assembler parser.  Will fix llvm-mc
and put this back afterward.

llvm-svn: 339486
2018-08-10 22:54:54 +00:00
Sid Manning 07e541a892 [ELF][HEXAGON] Add R_HEX_8_X relocation
Differential Revision: https://reviews.llvm.org/D50577

llvm-svn: 339477
2018-08-10 21:48:40 +00:00
George Rimar 88863a5f62 [ELF] - Get rid of SyntheticSection::postThunkContents(). NFCI.
It turns out that postThunkContents() is only used for
sorting symbols in .symtab.

Though we can instead move the logic to SymbolTableBaseSection::finalizeContents(),
postpone calling it and then get rid of postThunkContents completely.

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

llvm-svn: 339413
2018-08-10 07:24:18 +00:00
George Rimar 00d6f4bd6b [LLD][ELF] - Fix crash when using empty --defsym.
We have a crash issue when handling the empty -defsym.

For parsing this option we are using ScriptParser class which is used
generally for reading the linker script. For empty defsym case, we
pass the empty memory buffer and crash in the place removed in https://reviews.llvm.org/rL336436.

But reverting of the above patch would not help here (we would still crash but a bit later). And
even after fixing the crash we would report something like
"lld.exe: error: -defsym:1: unexpected EOF"
It is probably not the appropriate message because mentions EOF.

I think the issue should be handled on a higher level like this patch does.
So we do not want to pass the empty memory buffer first of all I believe.

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

llvm-svn: 339412
2018-08-10 06:32:39 +00:00
Sid Manning c53078a1e3 [ELF][HEXAGON] Add R_HEX_HI16/R_HEX_LO16 relocations
Differential Revision: https://reviews.llvm.org/D50520

llvm-svn: 339371
2018-08-09 20:04:53 +00:00
Rui Ueyama 5cd9c6bcd8 Support RISC-V
Patch by PkmX.

This patch makes lld recognize RISC-V target and implements basic
relocation for RV32/RV64 (and RVC). This should be necessary for static
linking ELF applications.

The ABI documentation for RISC-V can be found at:
https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md.
Note that the documentation is far from complete so we had to figure out
some details from bfd.

The patch should be pretty straightforward. Some highlights:

 - A new relocation Expr R_RISCV_PC_INDIRECT is added. This is needed as
   the low part of a PC-relative relocation is linked to the corresponding
   high part (auipc), see:
   https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#pc-relative-symbol-addresses

 - LLVM's MC support for RISC-V is very incomplete (we are working on
   this), so tests are given in objectyaml format with the original
   assembly included in the comments. Once we have complete support for
   RISC-V in MC, we can switch to llvm-as/llvm-objdump.

 - We don't support linker relaxation for now as it requires greater
   changes to lld that is beyond the scope of this patch. Once this is
   accepted we can start to work on adding relaxation to lld.

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

llvm-svn: 339364
2018-08-09 17:59:56 +00:00
George Rimar dffc1911e2 [LLD][ELF] - Add a test for elf::getPriority(StringRef S)
It covers the following line with a test:
https://github.com/llvm-mirror/lld/blob/master/ELF/OutputSections.cpp#L383

llvm-svn: 339348
2018-08-09 15:05:25 +00:00
Hans Wennborg bdd8493f2b [COFF] Make the relocation scanning for CFG more discriminating
link.exe ignores REL32 relocations on 32-bit x86, as well as relocations
against non-function symbols such as labels. This makes lld do the same.

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

llvm-svn: 339345
2018-08-09 13:43:22 +00:00
George Rimar cc8f8194ba [LLD][ELF] - Add a test for ScriptParser::readPhdrType().
This adds a test for https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L1289.

llvm-svn: 339342
2018-08-09 13:19:10 +00:00
George Rimar 5570d7d45b [LLD][ELF] - Add a test for ScriptParser::readOutputSectionDescription.
This covers the following line:
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L415

llvm-svn: 339333
2018-08-09 12:14:00 +00:00
Sid Manning 17858207a0 Add R_HEX_6_X relocation support
This is a larger patch.  This relocation has irregular immediate
masks that require a lookup to find the correct mask.

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

llvm-svn: 339332
2018-08-09 12:00:10 +00:00
George Rimar b89367ac46 [LLD][ELF] - Add a test for ScriptParser::readPhdrs(). NFCI.
This covers the following line with a test:
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L415

llvm-svn: 339327
2018-08-09 11:13:30 +00:00
George Rimar fce824e157 [LLD][ELF] - Add a test case for parsing -defsym.
This adds a coverage for the following line of the code:
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L274

llvm-svn: 339326
2018-08-09 10:40:11 +00:00
Peter Collingbourne 98930115ea ELF: Only add libcall symbols to the link if defined in bitcode.
Adding all libcall symbols to the link can have undesired consequences.
For example, the libgcc implementation of __sync_val_compare_and_swap_8
on 32-bit ARM pulls in an .init_array entry that aborts the program if
the Linux kernel does not support 64-bit atomics, which would prevent
the program from running even if it does not use 64-bit atomics.

This change makes it so that we only add libcall symbols to the
link before LTO if we have to, i.e. if the symbol's definition is in
bitcode. Any other required libcall symbols will be added to the link
after LTO when we add the LTO object file to the link.

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

llvm-svn: 339301
2018-08-08 23:48:12 +00:00
Sam Clegg 57694c50bc [WebAssembly] Group rodata into a single output segment
Differential Revision: https://reviews.llvm.org/D50424

llvm-svn: 339279
2018-08-08 18:02:55 +00:00
Peter Smith 5c57957281 Add missing REQUIRES x86 to tests.
Add REQUIRES to tests that fail when an x86 backend is not present.

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

llvm-svn: 339253
2018-08-08 14:50:33 +00:00
Nico Weber f4f5b7eea3 lld-link: Take /SUBSYSTEM into account for automatic /ENTRY detection.
If /subsystem:windows is passed, link.exe only looks for WinMain and wWinMain,
and if /subsystem:console is passed it only looks for main and wmain. lld-link
used to look for all 4 in both cases. This patch makes lld-link match
link.exe's behavior.

This requires that the subsystem is known by the time findDefaultEntry() gets
called. findDefaultEntry() is called before the main link loop, so that the
loop can mark the entry point as undefined. That means inferSubsystem() has to
be called above the main loop as well. This in turn means /subsystem: from
.drectve sections only has an effect on entry point inference for obj files
passed to lld-link directly (and not in obj files found later in .lib files).
link.exe seems to ignore /subsystem: for obj files from lib files completely
(while in lld it's ignored only for entry point detection but it still
overrides /subsystem: flags passed on the command line for the value that gets
written in the output file).

Also, if the subsytem isn't needed (e.g. when only writing a /def: lib file and
not writing a coff file), link.exe doesn't complain if the subsystem isn't
known, so both subsystem and entry point handling should be below the early
return lld has for that case.

Fixes PR36523.
https://reviews.llvm.org/D50316

llvm-svn: 339165
2018-08-07 19:10:28 +00:00
George Rimar 462b74cad3 [LLD][ELF] - Add test cases for ScriptParser::readDynamicList(). NFCI.
This 2 test cases covers the following code:
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L185
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L189

llvm-svn: 339137
2018-08-07 13:13:19 +00:00
George Rimar 6bcbd1ea83 [LLD][ELF] - Added test case for non-nullterminated wide strings.
This covers the following line:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputSection.cpp#L1032

llvm-svn: 339124
2018-08-07 10:29:35 +00:00
George Rimar 65eceee701 [LLD][ELF] - Add a test case for code in Archive::fetch(). NFCI.
This covers the following piece with a test.
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L830

Thanks to Peter Collingbourne for providing the reproducer sample!

llvm-svn: 339114
2018-08-07 08:41:37 +00:00
Martin Storsjo d9fd4a0de6 [COFF] Fix a comment about automatic resolving of dllimports from within a module. NFC.
Differential Revision: https://reviews.llvm.org/D50357

llvm-svn: 339100
2018-08-07 06:42:53 +00:00
Fangrui Song f66d0ce10b [ELF] Use MathExtras.h llvm::SignExtend64
Summary: To be consistent with other files where only SignExtend64 is used.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 339083
2018-08-06 23:50:26 +00:00
Stella Stamenova 38eee643bd [lit, python] Always add quotes around the python path in lit
Summary:
The issue with the python path is that the path to python on Windows can contain spaces. To make the tests always work, the path to python needs to be surrounded by quotes.

This is a companion change to: https://reviews.llvm.org/D50206

Reviewers: asmith, zturner, espindola

Subscribers: emaste, sbc100, arichardson, aheejin, steven_wu, dexonsmith, llvm-commits

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

llvm-svn: 339075
2018-08-06 22:37:49 +00:00
Rui Ueyama e262bb1afb Add TARGET(foo) linker script directive.
GNU ld's manual says that TARGET(foo) is basically an alias for
`--format foo` where foo is a BFD target name such as elf64-x86-64.

Unlike GNU linkers, lld doesn't allow arbitrary BFD target name for
--format. We accept only "default", "elf" or "binary". This makes
situation a bit tricky because we can't simply make TARGET an alias for
--target.

A quick code search revealed that the usage number of TARGET is very
small, and the only meaningful usage is to switch to the binary mode.
Thus, in this patch, we handle only TARGET(elf.*) and TARGET(binary).

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

llvm-svn: 339060
2018-08-06 21:29:41 +00:00
Martin Storsjo 21858a9b63 [COFF] Treat .xdata/.pdata$<sym> as implicitly associative to <sym> for MinGW
MinGW configurations don't use associative comdats, as GNU ld doesn't
support that. Instead they produce normal comdats named .text$sym,
.xdata$sym and .pdata$sym.

GNU ld doesn't discard any comdats starting with .xdata or .pdata,
even if --gc-sections is used (while it does discard other unreferenced
comdats), regardless of what symbol name is used after the $ separator.

For LLD, treat any such comdat as implicitly associative to the base
symbol. This requires maintaining a map from symbol name to section
number, but that is only maintained when the MinGW flag has been
enabled.

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

llvm-svn: 339058
2018-08-06 21:26:09 +00:00
Peter Collingbourne 82a7f144a4 ELF: Enable address-significance tables during LTO.
This allows safe ICF to work when linking with LTO.

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

llvm-svn: 339050
2018-08-06 20:12:12 +00:00
Martin Storsjo 214d69975c [COFF] Remove a superfluous warning about aligncomm for non-common symbols
It's not an error if a common symbol (uninitialized data, with alignment
specified via the aligncomm directive) is replaced with a regular
one with initialized data (with alignment specified via the section
chunk).

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

llvm-svn: 339049
2018-08-06 19:49:18 +00:00
Sam Clegg cb06300ad2 [WebAssembly] --export should fetch lazy symbols
--export now implies --undefined

This is really a requirement from emscripten but I think it
makes sense in general too.

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

llvm-svn: 339047
2018-08-06 19:45:12 +00:00
Fangrui Song 96e6ed645d [ELF] Don't copy STT_TLS in copy relocation
During copy relocation of a variable defined in a DSO, if a TLS variable in that DSO happens to have the same st_value, it would also be copied. This was unnecessary because the addresses of TLS variables are relative to TLS segment. They don't interfere with non-TLS variables.

This copying behavior can be harmful in the following scenario:

For function-scope thread-local variables with non-trivial constructors,
they have guard variables. In the case of x86_64 general-dynamic model:

template <int N>
void foo() {
  thread_local std::string a;
}

GOT[n]   R_X86_64_DTPMOD64 guard variable for a
GOT[n+1] R_X86_64_DTPOFF64 guard variable for a
GOT[n+2] R_X86_64_DTPMOD64 a
GOT[n+3] R_X86_64_DTPOFF64 a

a and its guard variable are both represented as TLS variables, which
should be within the same module. If one is copy relocated to the main
module while the other is not, their module ID will mismatch and can
cause access without prior construction.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 339042
2018-08-06 19:09:40 +00:00
George Rimar e0ff432a48 [ELF] - Remove dead code from LinkerScript::assignOffsets(). NFC-ihope.
Some parts of the code changed are a bit old. I found traces in 2016.

Initiall commits has test cases and perhaps reasonable comments.
For example, we had segfaults earlier and had the code to fix them.

Now, in 2018, I think it is excessive to have these parts, because
we do not have segfaults and our code was changed a lot (softly saying).

I reviewed the current sources and I think that at this point of the
execution flow, we should never face with
the conditions checked and so I removing them in this patch.

This helps to cleanup the code.

llvm-svn: 339003
2018-08-06 10:44:17 +00:00
Peter Smith 23a116f39e [ELF] Test undefined weak symbol for Thumb narrow branch
Add a test for the R_ARM_THM_JUMP11 relocation to an undefined symbol. We
have to use yaml2obj as llvm-mc relaxes the narrow branch to a b.w which
uses the R_ARM_THM_JUMP24 relocation instead.
    
Differential Revision: https://reviews.llvm.org/D50234

llvm-svn: 338999
2018-08-06 10:06:24 +00:00
David Bolvansky 082e0a9af6 Fix one test for changed opt remarks format
Summary:
Optimization remark format is slightly changed by LLVM patch D49412.
One test is fixed with expected messages changed.
Frankly speaking I have not tested this change yet. I will test when manage to setup the project.

Reviewers: xbolva00, espindola

Reviewed By: xbolva00

Subscribers: emaste, arichardson, steven_wu, dexonsmith

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

llvm-svn: 338970
2018-08-05 14:53:14 +00:00
George Rimar 4d535299fc [LLD][ELD] - Revert r338959 "[LLD][ELF] - Added file name and a test for case when we fail to write the output."
It broke BB:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/34382/steps/test/logs/stdio
http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/21932/steps/test_lld/logs/stdio

llvm-svn: 338960
2018-08-04 13:41:12 +00:00
George Rimar 032ed8f186 [LLD][ELF] - Added file name and a test for case when we fail to write the output.
We did not report the file name and had no test for that case.

llvm-svn: 338959
2018-08-04 12:48:38 +00:00
George Rimar 062fca3e47 [LLD][ELF] - Remove excessive requirement from the test.
It feels "shell" is excessive. Lets try without it.

llvm-svn: 338958
2018-08-04 11:33:38 +00:00
George Rimar 0fc18331b4 [LLD][ELF] - Removed dead code from rangeToString(). NFC.
This change removes the dead code and makes cosmetic change
showing why it was dead.

llvm-svn: 338957
2018-08-04 10:56:26 +00:00
George Rimar 434341be5b [LLD][ELF] - Fix bug when reporting memory intersections.
rangeToString() takes addres and length,
previously it was called incorrectly.

llvm-svn: 338956
2018-08-04 10:34:52 +00:00
George Rimar 03b4d0c19f [ELF] - Refactor readCallGraph().
This simplifies the code a bit.

It is NFC except that it removes early exit for Count == 0
which does not seem to be useful (we have no such tests either).

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

llvm-svn: 338953
2018-08-04 07:31:19 +00:00
Sam Clegg 47e2b6b29e [WebAssembly] Don't error when --undefined symbols are not found
This matches the behavior of the ELF linker where -u/--undefined
means symbols will get pulled in from archives but won't result
in link error if they are missing.

Also, don't actually great symbol table entries for the undefined
symbols, again matching more closely the ELF linker.

This also results in simplification of the code.

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

llvm-svn: 338938
2018-08-04 00:04:06 +00:00
Nico Weber 397985db51 lld-link: Simplify LinkerDriver::findDefaultEntry()
No intended behavior change. Not repeating the CRTStartup names makes fixing
PR36523 simpler.

https://reviews.llvm.org/D50253

llvm-svn: 338911
2018-08-03 18:32:44 +00:00
Nico Weber d48d5f086f lld-link: Fix subsystem inference for non-console apps on 32-bit, and fix entry point inference on 32-bit with /nodefaultlib
LinkerDriver::inferSubsystem() used to do Symtab->findUnderscore("WinMain"),
but WinMain is stdcall in 32-bit and is hence is called _WinMain@16. Instead,
Symtab->findMangle(mangle("WinMain")) needs to be called.

But since LinkerDriver::inferSubsystem() and LinkerDriver::findDefaultEntry()
both need to call this, introduce a common helper function for this and call it
from both places. (Also call it for "main" for consistency, even though
findUnderscore() is enough for main since that's __cdecl on 32-bit).

This also exposed a bug for /nodefaultlib entrypoint inference: The code here
called findMangle(Sym) instead of findMangle(mangle(Sym)), again doing the
wrong thing on 32-bit. Fix that too.

While here, make Driver::mangle() a static free function.

https://reviews.llvm.org/D50184

llvm-svn: 338877
2018-08-03 12:00:12 +00:00
Sam Clegg 4c2cbfe68d Set IsUsedInRegularObj in a consistent manor between COFF, ELF and wasm. NFC
Differential Revision: https://reviews.llvm.org/D49147

llvm-svn: 338767
2018-08-02 20:39:19 +00:00
Jordan Rupprecht 0f6d31812e [LLD] Update split stack support to handle more generic prologues. Improve error handling. Add test file for better code-coverage. Update tests to be more complete.
Submitting patch on behalf of saugustine.

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

llvm-svn: 338750
2018-08-02 18:13:40 +00:00
George Rimar 300d363dfd [LLD][ELF] - Remove dead check from adjustSplitStackFunctionPrologues().
In according to the comment, undefined symbol should never reach there.
So, should be able to remove the check. I am assuming this is NFC. 

llvm-svn: 338723
2018-08-02 14:44:39 +00:00
George Rimar 47ec1e07c7 [LLD][ELF] - An attemp to fix BB after rL338718.
BB is unhappy :`-(
http://lab.llvm.org:8011/builders/lld-perf-testsuite/builds/5632

llvm-svn: 338722
2018-08-02 14:34:39 +00:00
George Rimar a7dbe571e6 [LLD][ELF] - Remove excessive cases from getRelocTargetVA(). NFC.
There is no point to explicitly proccess the expressions this patch removes.
We already have a llvm_unreachable for the default case.

llvm-svn: 338718
2018-08-02 14:15:02 +00:00
George Rimar 467505bd31 [LLD][ELF] - Remove dead code. NFC.
It does not seem that this code is alive.
I seems was needed previously but we fixed it.

If it is still needed, it needs new tests,
but for now I do not know how to trigger it,
and so I removed it.

llvm-svn: 338713
2018-08-02 13:18:49 +00:00
George Rimar 830ff2d0b1 [LLD][ELF] - Remove redundant code. NFC.
Code was never executed with our test cases,
though it is valid and I think we can always run it.
This improves code coverage.

llvm-svn: 338708
2018-08-02 12:20:36 +00:00
Chris Jackson 1a721eb3a2 [lld] Make tests calling llvm-ar more robust
Some lit tests that call llvm-ar use the 'r' flag. If the target archive
already exists and is in a corrupt state, this can cause the test to fail. We
have added 'rm -f' calls before the llvm-ar calls to increase the
robustness of the tests.

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

llvm-svn: 338705
2018-08-02 11:33:54 +00:00
George Rimar 6fe30771aa [LLD][ELF] - Simplify. NFC.
isHeaderSection can be useful I believe,
but probably not right now and not
for this case.

llvm-svn: 338699
2018-08-02 10:59:28 +00:00
George Rimar acf8cef80f [LLD] Do not overwrite LMAOffset of PT_LOAD header
Patch by Konstantin Schwarz!

If more than a single output section is added to a PT_LOAD header,
only the first section should set the LMAOffset of the segment.
Otherwise, we get a load-address overlap error

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

llvm-svn: 338697
2018-08-02 10:45:46 +00:00
George Rimar add69e9c19 [LLD] Only increase LMARegion if different from MemRegion
Patch by Konstantin Schwarz!

If both the MemRegion and LMARegion are set for an output section in
a linker script, we should only increase the LMARegion if it is
different from the MemRegion. Otherwise, we reserve the memory twice.

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

llvm-svn: 338684
2018-08-02 08:13:56 +00:00
George Rimar 34bdf27eaa [LLD] - Improve handling of AT> linker script commands
Patch by Konstantin Schwarz!

The condition to create a new phdr must also check the usage of "AT>" 
linker script command, and create a new PT_LOAD header if a new LMARegion is used.

This fixes PR38307

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

llvm-svn: 338679
2018-08-02 08:07:07 +00:00
Rui Ueyama 5530f234f5 Re-submit r338596 with a bug fix and a test.
llvm-svn: 338647
2018-08-01 22:31:31 +00:00
Reid Kleckner c07f9bb83a Update for DWARF API change
llvm-svn: 338642
2018-08-01 21:57:15 +00:00
Nico Weber 11f14904d3 lld-link: Remove /msvclto option
This was useful for LTO bringup in lld-link while lld couldn't write PDBs. Now
that it can, this should no longer be needed. Hopefully the flag is obscure
enough and recent enough, that nobody uses it – but if somebody should use it,
they should be able to just stop passing it and things should continue to work.

https://reviews.llvm.org/D50139

llvm-svn: 338615
2018-08-01 19:00:49 +00:00
Rui Ueyama e981ce04c3 Revert r338596: Simplify. NFC.
This reverts commit r338596 because it contained a functional change.
The patch accidentally replaced StringRef::startswith with the exact match.

llvm-svn: 338600
2018-08-01 17:50:09 +00:00
Rui Ueyama f6d1923c86 Simplify. NFC.
llvm-svn: 338596
2018-08-01 17:33:00 +00:00
Hans Wennborg 5f3be212b1 Update docs version and clear release notes after 8.0.0 version bump
llvm-svn: 338558
2018-08-01 14:07:20 +00:00
Owen Reynolds 035cd8dd75 Test Commit
Removal of extra line

llvm-svn: 338533
2018-08-01 13:16:48 +00:00
George Rimar 676dc17db0 [LLD][ELF] - Apply clang-format to InputSections.cpp. NFC.
llvm-svn: 338498
2018-08-01 08:11:54 +00:00
George Rimar a4211551f1 [LLD][ELF] - Removed excessive llvm:: prefix. NFC.
llvm-svn: 338497
2018-08-01 08:10:50 +00:00
Rumeet Dhindsa 9d9113fc13 Allow oformat to accept format starting with elf as acceptable format. isOutputFormatBinary returns false in such case.
Example: --oformat elf64-x86-64

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

llvm-svn: 338445
2018-07-31 21:58:26 +00:00
David L. Jones 2a895e57af [lld] Fix test RUN commands so they don't fail when run in a read-only filesystem.
Some test setups run tests in a read-only path, which means that opening the
default output path (a.out) for write will fail. This change adds appropriate -o
flags so the tests will not fail spuriously.

llvm-svn: 338440
2018-07-31 21:15:58 +00:00
Peter Collingbourne 2da4e52182 ELF: Add libcall symbols to the link when LTO is being used.
If any of our inputs are bitcode files, the LTO code generator may create
references to certain library functions that might not be explicit in the
bitcode file's symbol table. If any of those library functions are defined
in a bitcode file in an archive member, we need to arrange to use LTO to
compile those archive members by adding them to the link beforehand.

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

llvm-svn: 338434
2018-07-31 20:36:17 +00:00
Rui Ueyama 0e1ba29ac3 Simplify. NFC.
llvm-svn: 338409
2018-07-31 18:13:36 +00:00
Rui Ueyama 7f97570e79 Make ICF log output order deterministic.
This patch does the same thing as r338153 for COFF.
Note that this patch affects only the order of log messages.
The output file is already deterministic.

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

llvm-svn: 338406
2018-07-31 18:04:58 +00:00
George Rimar 7a49ce4ac4 [LLD][ELF] - ICF: Check we do not fold sections which relocations reffering to absolute symbols with a different values.
This adds a test for the following uncovered piece of code:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L263

Without that lines we would crash.

llvm-svn: 338379
2018-07-31 13:55:25 +00:00
Peter Smith 70997f9a4e [ELF][ARM] Implement support for Tag_ABI_VFP_args
The Tag_ABI_VFP_args build attribute controls the procedure call standard
used for floating point parameters on ARM. The values are:
0 - Base AAPCS (FP Parameters passed in Core (Integer) registers
1 - VFP AAPCS (FP Parameters passed in FP registers)
2 - Toolchain specific (Neither Base or VFP)
3 - Compatible with all (No use of floating point parameters)

If the Tag_ABI_VFP_args build attribute is missing it has an implicit value
of 0.
    
We use the attribute in two ways:
- Detect a clash in calling convention between Base, VFP and Toolchain.
we follow ld.bfd's lead and do not error if there is a clash between an
implicit Base AAPCS caused by a missing attribute. Many projects
including the hard-float (VFP AAPCS) version of glibc contain assembler
files that do not use floating point but do not have Tag_ABI_VFP_args.
- Set the EF_ARM_ABI_FLOAT_SOFT or EF_ARM_ABI_FLOAT_HARD ELF header flag
for Base or VFP AAPCS respectively. This flag is used by some ELF
loaders.
    
References:
- Addenda to, and Errata in, the ABI for the ARM Architecture for
Tag_ABI_VFP_args
- Elf for the ARM Architecture for ELF header flags
    
Fixes PR36009
    
Differential Revision: https://reviews.llvm.org/D49993

llvm-svn: 338377
2018-07-31 13:41:59 +00:00
George Rimar 511fed8a24 [LLD][ELF] - ICF: add test case testing we do not fold sections with the different flags. NFCI.
Previously the following condition was not tested at all:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L300

Patch adds a test for `A->Flags != B->Flags` part.

llvm-svn: 338375
2018-07-31 13:32:16 +00:00
Hans Wennborg 1cc3f51b04 windows_support.rst: Add links for downloading
llvm-svn: 338363
2018-07-31 12:02:03 +00:00
Hans Wennborg c7792a6cc7 index.rst: pe/coff does support pdbs now
llvm-svn: 338362
2018-07-31 12:00:26 +00:00
Fangrui Song f35ff042f4 [docs] Sort ld.lld.1 options
Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 338326
2018-07-30 23:07:44 +00:00
Fangrui Song bac187bece [docs] Add missing options to ld.lld.1
Differential Revision: https://reviews.llvm.org/D49938

llvm-svn: 338320
2018-07-30 22:31:00 +00:00
Fangrui Song 05779bfcc8 [docs] Update ld.lld.1
llvm-svn: 338275
2018-07-30 17:36:38 +00:00
David Bolvansky a932cd409b [AArch64] Support execute-only LOAD segments.
Summary:
This adds an LLD flag to mark executable LOAD segments execute-only for AArch64 targets. 

In AArch64 the expectation is that code is execute-only compatible, so this just adds a linker option to enforce this.

Patch by: ivanlozano (Ivan Lozano)

Reviewers: srhines, echristo, peter.smith, eugenis, javed.absar, espindola, ruiu

Reviewed By: ruiu

Subscribers: dokyungs, emaste, arichardson, kristof.beyls, llvm-commits

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

llvm-svn: 338271
2018-07-30 17:02:46 +00:00
George Rimar 9524dee72e [ELF] - Implement SHT_SYMTAB_SHNDX (.symtab_shndxr) section.
This is relative to https://bugs.llvm.org//show_bug.cgi?id=38119.

SHT_SYMTAB section is able to keep symbols with output section indices
up to 0xff00 (SHN_LORESERVE). But if we have indices that are greater
than that (PR shows that it might happen), we need to use
SHT_SYMTAB_SHNDX extended section. It was not supported by LLD.

Description of the SHT_SYMTAB_SHNDX section is here:
https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-94076/index.html.

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

llvm-svn: 338247
2018-07-30 12:39:54 +00:00
Sid Manning bff6719450 [ELF][HEXAGON] Add R_HEX_32_6_X and R_HEX_12_X
And add a test.

llvm-svn: 338213
2018-07-29 11:59:38 +00:00
Peter Collingbourne e6c78eafde Reland r338088, "ELF: Make --print-icf-sections output deterministic."
The xxHash64 function has been made unsigned-char-independent, so
we can reland this change now.

Original commit message:
> The icf-safe.s test currently fails on 32-bit platforms because it uses
> the --print-icf-sections flag and depends on the output appearing in
> a specific order. However, this flag causes the output to depend on
> the order of the sections in the Sections array, which depends on the
> hash values returned from hash_combine, which happen to be different
> for that test between 32-bit and 64-bit platforms.
>
> This change makes the output deterministic by using xxHash64 instead of
> hash_combine.

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

llvm-svn: 338153
2018-07-27 19:10:44 +00:00
Ilya Biryukov cdc92ff254 Revert "ELF: Make --print-icf-sections output deterministic."
This reverts commit r338088. To unbreak our integrate.
The resulting lld output is different if compiled with '-funsigned-char'.

llvm-svn: 338110
2018-07-27 09:01:03 +00:00
Peter Collingbourne b148c9809b ELF: Make --print-icf-sections output deterministic.
The icf-safe.s test currently fails on 32-bit platforms because it uses
the --print-icf-sections flag and depends on the output appearing in
a specific order. However, this flag causes the output to depend on
the order of the sections in the Sections array, which depends on the
hash values returned from hash_combine, which happen to be different
for that test between 32-bit and 64-bit platforms.

This change makes the output deterministic by using xxHash64 instead of
hash_combine.

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

llvm-svn: 338088
2018-07-26 23:34:35 +00:00
Martin Storsjo 6c8cbf6db0 [COFF] Handle comdat sections without leader symbols
Discard them unless they have been associated by other means (yet
uimplemented).

According to MS link.exe, such sections are illegal, but MinGW setups
use them in their take on associative comdats.

This avoids leaving references to the bogus SectionChunk* PendingComdat,
which cannot be dereferenced.

This fixes PR38183.

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

llvm-svn: 338064
2018-07-26 20:14:50 +00:00
Rui Ueyama 279621fbf0 [COFF] clean up global resources after completion
Patch by Andrew Kelley.

Previously, running lld::coff::link() twice in the same process would
access stale pointers because of these global variables not being reset.
After this patch, lld::coff::link() can be called any number of times,
just like its ELF and MACH-O counterparts.

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

llvm-svn: 338042
2018-07-26 17:11:24 +00:00
Fangrui Song 31cc084619 [ELF] Fix linker-script-in-search-path.s
llvm-svn: 337983
2018-07-25 23:29:15 +00:00
Fangrui Song 7610b4d64c [ELF] Make linker-script-in-search-path.s robust per r337972
llvm-svn: 337975
2018-07-25 22:11:00 +00:00
Rui Ueyama 5a0a83daaf Make a test more robust.
Previously, this test fails if there's other test that happens to
create "t.script" in the current directory.

llvm-svn: 337972
2018-07-25 22:01:54 +00:00
Fangrui Song c60f85d073 [ELF] Use search paths for --version-script=
Summary: This behavior matches ld.bfd -Ld --version-script=t.script a.o

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 337969
2018-07-25 21:53:18 +00:00
Peter Collingbourne 6a5368eadb ELF: Do not ICF SHF_LINK_ORDER sections.
We are already ICF'ing these sections as a unit with their dependent
sections, so they don't need to be considered for ICF individually.

This change also "fixes" slowness caused by our quadratic-in-group-size
relocation segregation algorithm on 32-bit ARM platforms with unwind
data and ICF on rodata. In this scenario almost every function's
.ARM.exidx is identical except for the targets of the relocations
that refer to the function and its .ARM.extab, which causes almost
all of the program's .ARM.exidx sections to be initially added to the
same class, which causes us to compare every such section with every
other such section.

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

llvm-svn: 337967
2018-07-25 21:40:54 +00:00
Rui Ueyama 7e95d9e362 Fix error messages for bad symbols.
Previously, the error messages didn't contain symbol name because we
didn't read a symbol name for these error messages.

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

llvm-svn: 337863
2018-07-24 22:52:11 +00:00
Sid Manning 3241724536 [ELF][HEXAGON] Add R_HEX_B15_PCREL_X relocation
Update testcase

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

llvm-svn: 337829
2018-07-24 15:08:13 +00:00
Simon Atanasyan 52854504cc [ELF][MIPS] Fix primary GOT sometimes overflowing by one or two words
If we fail to merge a secondary GOT with the primary GOT but so far only
one merged GOT has been created (the primary one), the final element in
MergedGots is the primary GOT. Thus we should not try to merge with this
final element passing IsPrimary=false, since this will ignore the fact
that the destination GOT does in fact need a header, and those extra two
entries can be enough to allow the merge to incorrectly occur. Instead
we should check for this case before attempting the second merge.

Patch by James Clarke.

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

llvm-svn: 337810
2018-07-24 05:40:37 +00:00
Sam Clegg 8adf7ac5c1 [WebAssembly] Add support for --whole-archive.
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 337777
2018-07-23 23:51:19 +00:00
Peter Collingbourne 00dc23f26e Revert r337638, "ELF: Make sections with KeepUnique bit eligible for ICF."
The gold behaviour with regard to --keep-unique is arguably a bug.
I also noticed a bug in my patch, which is that we mislink the
following program with --icf=safe by merging f3 and f4:

void f1() {}
void f2() {}

__attribute__((weak)) void* f3() { return f1; }
__attribute__((weak)) void* f4() { return f2; }

int main() {
  printf("%p %p\n", f3(), f4());
}

llvm-svn: 337729
2018-07-23 19:36:55 +00:00
Andrew Ng 8d29d74fd0 [LLD] Add llvm-objcopy to test dependencies. NFC.
Dependency on llvm-objcopy was introduced by r337429.

Also sorted the list of dependencies.

llvm-svn: 337693
2018-07-23 14:12:57 +00:00
Andrew Ng e33d691990 [ELF] Fix handling of FDE negative relative PC addr
Signed values for the FDE PC addr were not correctly handled in
readFdeAddr(). If the value is negative and the type of the value is
smaller than 64 bits, the FDE PC addr overflow error would be
incorrectly triggered.

Fixed readFdeAddr() to properly handle signed values by sign extending
where appropriate.

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

llvm-svn: 337683
2018-07-23 11:29:46 +00:00
Peter Collingbourne a052206c4b ELF: Read address significance tables with --icf=all.
Under --icf=all we now only apply KeepUnique to non-executable
address-significant sections. This has the effect of making --icf=all
mean unsafe ICF for executable sections and safe ICF for non-executable
sections.

With this change the meaning of the KeepUnique bit changes to
"does the current ICF mode (together with the --keep-unique and
--ignore-data-address-equality flags) require this section to be
kept unique".

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

llvm-svn: 337640
2018-07-21 02:14:59 +00:00
Peter Collingbourne 37f25a24bb ELF: Make sections with KeepUnique bit eligible for ICF.
The only restriction is that we cannot merge more than one KeepUnique
section together. This matches gold's behaviour and reduces code size
when using --icf=safe.

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

llvm-svn: 337638
2018-07-21 00:17:11 +00:00
Nico Weber bbfe0b79e2 Omit path to lld binary from lld's error, warning, and log output.
lld currently prepends the absolute path to itself to every diagnostic it
emits. This path can be longer than the diagnostic, and makes the actual error
message hard to read.

There isn't a good reason for printing this path: if you want to know which lld
you're running, pass -v to clang – chances are that if you're unsure of this,
you're not only unsure when it errors out. Some people want an indication that
the diagnostic is from the linker though, so instead print just the basename of
the linker's path.

Before:

```
$ out/bin/clang -target x86_64-unknown-linux -x c++ /dev/null -fuse-ld=lld 
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crt1.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crti.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtbegin.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc_s
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lc
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc_s
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtend.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

After:

```
$ out/bin/clang -target x86_64-unknown-linux -x c++ /dev/null -fuse-ld=lld 
ld.lld: error: cannot open crt1.o: No such file or directory
ld.lld: error: cannot open crti.o: No such file or directory
ld.lld: error: cannot open crtbegin.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lc
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: cannot open crtend.o: No such file or directory
ld.lld: error: cannot open crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

https://reviews.llvm.org/D49189

llvm-svn: 337634
2018-07-20 23:09:12 +00:00
Nico Weber f6be416687 Simplify; no behavior change.
Reviewed as part of https://reviews.llvm.org/D49189

llvm-svn: 337633
2018-07-20 23:06:34 +00:00
Reid Kleckner 276d7167d0 [PDB] Write the command line after response file expansion
Summary: Fixes PR38085

Reviewers: ruiu, zturner

Subscribers: llvm-commits

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

llvm-svn: 337628
2018-07-20 22:34:20 +00:00
Fangrui Song a66d77b22b [ELF] Check eh_frame_hdr overflow with PC offsets instead of PC absolute addresses
Reviewers: grimar, ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 337610
2018-07-20 20:27:42 +00:00
Martin Storsjo 98ff9f845d [COFF] Sort .reloc before all other discardable sections
If a binary is stripped, which can remove discardable sections (except
for the .reloc section, which also is marked as discardable as it isn't
loaded at runtime, only read by the loader), the .reloc section should
be first of them, in order not to create gaps in the image.

Previously, binaries with relocations were broken if they were stripped
by GNU binutils strip. Trying to execute such binaries produces an error
about "xx is not a valid win32 application".

This fixes GNU binutils bug 23348.

Prior to SVN r329370 (which didn't intend to have functional changes),
the code for moving discardable sections to the end didn't clearly
express how other discardable sections should be ordered compared to
.reloc, but the change retained the exact same end result as before.

After SVN r329370, the code (and comments) more clearly indicate that
it tries to make the .reloc section the absolutely last one; this patch
changes that.

This matches how GNU binutils ld sorts .reloc compared to dwarf debug
info sections.

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

Signed-off-by: Martin Storsjö <martin@martin.st>
llvm-svn: 337598
2018-07-20 18:43:35 +00:00
George Rimar c2c7d15486 [ELF] - Fix mistypes in test cases.
llvm-svn: 337528
2018-07-20 08:07:33 +00:00
Martin Storsjo a55fc71614 [COFF] Write the debug directory and build id to a separate section for MinGW
For dwarf debug info, an executable normally either contains the debug
info, or it is stripped out. To reduce the storage needed (slightly)
for the debug info kept separately from the released, stripped binaries,
one can choose to only copy the debug data from the original executable
(essentially the reverse of the strip operation), producing a file with
only debug info.

When copying the debug data from an executable with GNU objcopy,
the build id and debug directory need to reside in a separate section,
as this will be kept while the rest of the .rdata section is removed.

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

llvm-svn: 337526
2018-07-20 05:44:34 +00:00
Sid Manning 690b544f41 [ELF][HEXAGON] Add support for R_HEX_B15_PCREL
Add support and update the testcase.

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

llvm-svn: 337494
2018-07-19 20:27:43 +00:00
Sid Manning bdd71f358d Add support for R_HEX_B32_PCREL_X, R_HEX_B22_PCREL_X relocations
A couple more basic relocations plus testcase.

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

llvm-svn: 337484
2018-07-19 19:10:56 +00:00
George Rimar ed2605d36d [ELF] - Eliminate dead code. NFC.
Code was dead because we call postThunkContents only for SHT_SYMTAB.

llvm-svn: 337460
2018-07-19 14:39:56 +00:00
George Rimar ad760e3ec6 [ELF] - One more test case for .eh_frame_hdr.
This is to test the following error message:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L544

Which occurs when LLD meets unsupported address encoding when scans
.eh_frame to build .eh_frame_hdr section.

llvm-svn: 337458
2018-07-19 14:27:19 +00:00
Takuto Ikuta d855928ec3 [PDB] Add PDBSourcePath flag to support absolutize source file path
This patch changes relative path for source files in obj files to
absolute path in PDB when linking with added flag.

I will make obj file generated by clang-cl independent from build
directory for chromium build. But I don't want to confuse visual studio
debugger or require additional configuration. To attain this goal, I
added flag to convert relative source file path in obj to absolute path
when emitting PDB.

By removing absolute path from obj files, we can share build cache
between chromium developers even when they are doing debug build.
That will make build time faster.

More context:
https://bugs.chromium.org/p/chromium/issues/detail?id=712796
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/5HXSVX-7fPc

llvm-svn: 337439
2018-07-19 04:56:22 +00:00
Martin Storsjo c35e4bf7eb [COFF] Don't produce base relocs for discardable sections
Dwarf debug info contains some data that contains absolute addresses.
Since these sections are discardable and aren't loaded at runtime,
there's no point in adding base relocations for them.

This makes sure that after stripping out dwarf debug info, there are no
base relocations that point to nonexistent sections.

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

llvm-svn: 337438
2018-07-19 04:25:22 +00:00
Peter Collingbourne a327a4c34e ELF: Implement --icf=safe using address-significance tables.
Differential Revision: https://reviews.llvm.org/D48146

llvm-svn: 337429
2018-07-18 22:49:31 +00:00
Fangrui Song 4a2948253f [ELF] Error if -r --gdb-index are used together
Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 337427
2018-07-18 22:02:48 +00:00
Sam Clegg 2df314d17f [WebAssembly] Fix archive member display in error messages
Add a test for this by causing a symbol collision
between archive members.

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

llvm-svn: 337426
2018-07-18 21:46:09 +00:00
Rui Ueyama f43fba739c Revert r336609: Fix direct calls to __wrap_sym when it is relocated.
This reverts commit r336609 as it doesn't seem to work with AArch64
thunk creation when used with ASan.

llvm-svn: 337413
2018-07-18 18:24:46 +00:00
Rui Ueyama c93530d873 Look for an entry point function if /nodefaultlib is given.
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=38018

Reviewers: thakis

Subscribers: llvm-commits

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

llvm-svn: 337407
2018-07-18 17:48:14 +00:00
Rui Ueyama 9b784ae75a Fix `ld.lld --help` message.
llvm-svn: 337405
2018-07-18 17:19:17 +00:00
George Rimar 7d8e632e98 [ELF] - Stop silently producing a broken .eh_frame_hdr.
Currently, getFdePC() returns uint64_t. Its because the following
encodings might use 8 bytes: DW_EH_PE_absptr and DW_EH_PE_udata8.

But caller assigns returned value to uint32_t field:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L508

Value is used for building .eh_frame_hdr section.
We use DW_EH_PE_sdata4 encoding for building it at this moment:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L2545

And that means that an overflow issue might happen if
DW_EH_PE_absptr/DW_EH_PE_udata8 address encodings are present
in .eh_frame. In that case, before this patch, we silently would
truncate the address and produced broken .eh_frame_hdr section.

It would be not hard to support real 64-bit values for
DW_EH_PE_absptr/DW_EH_PE_udata8 encodings, but it is
unclear if it is usefull and if we should do it.

Since nobody faced/reported it, int this patch I only implement
a check to stop producing broken output silently for now.

llvm-svn: 337382
2018-07-18 11:56:53 +00:00
George Rimar a1bb8f7a0c [ELF] - Add a test case to check DW_EH_PE_absptr address encoding.
This covers the following line of the code:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L525

llvm-svn: 337377
2018-07-18 11:02:37 +00:00
George Rimar c51b81de9c [ELF] - Improve eh-frame-value-format7.s test case.
This adds .eh_frame_hdr content checking to test
that DW_EH_PE_udata2 address was decoded correctly.

llvm-svn: 337374
2018-07-18 10:42:10 +00:00
George Rimar 2566c0a2f2 [ELF] - Improve relocatable-many-sections.s test case. NFC.
This adds a check for .shstrtab section index.

llvm-svn: 337365
2018-07-18 08:52:09 +00:00
George Rimar b9f3ea3e1c [ELF] - Do not produce broken output when amount of sections is > ~65k
This is a part of ttps://bugs.llvm.org//show_bug.cgi?id=38119

We produce broken ELF header now when the number of output sections is >= SHN_LORESERVE (0xff00).

ELF spec says (http://www.sco.com/developers/gabi/2003-12-17/ch4.eheader.html):

e_shnum:
If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the value zero
and the actual number of section header table entries is contained in the sh_size field of the section header at index 0.
(Otherwise, the sh_size member of the initial entry contains 0.)

e_shstrndx
If the section name string table section index is greater than or equal to SHN_LORESERVE (0xff00), this member has the
value SHN_XINDEX (0xffff) and the actual index of the section name string table section is contained in the sh_link field of
the section header at index 0. (Otherwise, the sh_link member of the initial entry contains 0.)

We did not set these fields correctly earlier. The patch fixes the issue.

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

llvm-svn: 337363
2018-07-18 08:44:38 +00:00
George Rimar 9958f620f9 [ELF] — Add a test case for DW_EH_PE_udata2 encoding.
This adds a test to check LLD can handle such address format correctly.
Test case covers the following line:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L519

llvm-svn: 337362
2018-07-18 08:39:31 +00:00
Sterling Augustine 2526104ee4 Workaround warning bug in old versions of gcc.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

llvm-svn: 337340
2018-07-18 00:33:25 +00:00
Sterling Augustine 4fd84c18df Implement framework for linking split-stack object files, and x86_64 support.
llvm-svn: 337332
2018-07-17 23:16:02 +00:00
Sam Clegg f989a92dea [WebAssemlby] Set IsUsedInRegularObj correctly for undefined data symbols
Differential Revision: https://reviews.llvm.org/D49113

llvm-svn: 337314
2018-07-17 19:15:02 +00:00
Sam Clegg c4c3633a38 Add wasm-ld to help text Improve error text
Differential Revision: https://reviews.llvm.org/D48838

llvm-svn: 337300
2018-07-17 16:34:48 +00:00
George Rimar 46ae0afba7 [ELF] - Eliminate dead 'return' in EhFrameSection::finalizeContents(). NFC.
EhFrameSection::finalizeContents() is called from a single place:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L1559

So code was dead.

llvm-svn: 337287
2018-07-17 14:36:19 +00:00
George Rimar b892e4194f [ELF] - Remove dead code from EhFrameSection::addCie. NFC.
Code was dead because caller of the addCie() already
checks that ID is equal to 0:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L431

llvm-svn: 337281
2018-07-17 13:56:23 +00:00
George Rimar 7da3f388e3 [ELF] - Eliminate dead code. NFC.
Code was dead because at the moment of BssSection creation
it can never have a parent. Also, code simply does not
make sence as alignment adjastment happens when
BssSection is added to its parent later.

llvm-svn: 337276
2018-07-17 13:13:08 +00:00
George Rimar 1f1dc636d3 [ELF] - Add test for checking unknown -color-diagnostics arguments.
This covers a following line with the test:
https://github.com/llvm-mirror/lld/blob/master/ELF/DriverUtils.cpp#L73

llvm-svn: 337268
2018-07-17 12:14:48 +00:00
George Rimar da4302ce0d [ELF] - Add a test for --no-warn-symbol-ordering.
Mentioned flag was never tested together with
--call-graph-ordering-file. And the following line
was uncovered:

https://github.com/llvm-mirror/lld/blob/master/ELF/Symbols.cpp#L248

llvm-svn: 337266
2018-07-17 12:04:23 +00:00
George Rimar 904ed692a1 [ELF] - Simplify Symbol::getSize(). NFC.
There are following symbols currently available:
DefinedKind, SharedKind, UndefinedKind, LazyArchiveKind, LazyObjectKind.

Our code calls getSize() only for first two and there
seems to be no reason to return 0 for the rest.

llvm-svn: 337265
2018-07-17 11:35:28 +00:00
George Rimar 448ef7793d [ELF] - Check we able to report function symbols that encloses a location in error messages.
InputSectionBase::getLocation() have the following block of the code which
is uncovered by our test cases:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputSection.cpp#L238

Patch adds a test to trigger this branch.

llvm-svn: 337256
2018-07-17 09:37:53 +00:00
George Rimar ea5d3f23e0 [ELF] - Fix BB. 'Filecheck' -> 'FileCheck'.
llvm-svn: 337254
2018-07-17 09:10:16 +00:00
George Rimar ff71afe809 [ELF] - Check we are able to report zlib decompressor errors.
This test case adds a check for the following line of the code:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputSection.cpp#L194

llvm-svn: 337252
2018-07-17 08:42:42 +00:00
George Rimar e25b1c35bb [ELF] - Check we are able to report errors when DW_AT_decl_file is invalid.
We did not try to support this intentionally but have
an error handling and reporting logic that can take care
of that and hence needs a test. 

llvm-svn: 337250
2018-07-17 08:04:27 +00:00
Yunlian Jiang 588afe422e remove temporal file directory before testing in thinlto-debug-fission.ll
Summary:
This removes the %T/dwo directory before calling ld.lld in ELF/lto/thinlto-debug-fission.ll so that
files aren't left over from previous runs.

Reviewers: espindola, pcc

Reviewed By: pcc

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

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

llvm-svn: 337210
2018-07-16 20:28:48 +00:00
Yunlian Jiang 496fb3e7a0 Support option -plugin-opt=dwo_dir=
Summary:
This adds support to option -plugin-opt=dwo_dir=${DIR}. This option is used to specify the directory to store the .dwo files when LTO and debug fission is used
at the same time.

Reviewers: ruiu, espindola, pcc

Reviewed By: pcc

Subscribers: eraman, dexonsmith, mehdi_amini, emaste, arichardson, steven_wu, llvm-commits

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

llvm-svn: 337195
2018-07-16 17:55:48 +00:00
George Rimar 484aabc818 [ELF] - Eliminate ObjFile<ELFT>::getLineInfo. NFC.
Flow is the same, but a bit shorter after this change.

llvm-svn: 337183
2018-07-16 15:29:35 +00:00
George Rimar e420cd8d05 [ELF] - Cover ObjFile<ELFT>::getLineInfo() with a test.
There was no test for the first `return`.

llvm-svn: 337182
2018-07-16 15:27:53 +00:00
Nico Weber 6c414a31ae attempt to get test/COFF/driver.test passing on sanitizer-x86_64-linux-fast; cf r337092
llvm-svn: 337093
2018-07-14 11:47:23 +00:00
Nico Weber c421fe5ef4 lld-link: Add /lib to Options.td so that it appears in lld-link's help output.
https://reviews.llvm.org/D49319

llvm-svn: 337086
2018-07-14 04:07:51 +00:00
George Rimar d55ec633e6 [ELF] - Simplify code. NFC.
Just use getDataAs for taking sections contents.

llvm-svn: 336892
2018-07-12 08:33:02 +00:00
George Rimar d31c478f99 [ELF] - Eliminate dead code. NFC.
Code is dead because caller of the isDuplicateArmExidxSex
(https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L1446)

explicitly does not pass sentinel. So no reason to check it.

llvm-svn: 336891
2018-07-12 08:12:08 +00:00
Zachary Turner e2ce2a5c86 [coff] remove_dots from /PDBPATH but not /PDBALTPATH.
This more closely matches the behavior of link.exe, and also
simplifies the code slightly.

llvm-svn: 336882
2018-07-12 03:22:39 +00:00
Zachary Turner bf9abccacd [coff] Remove dots in path pointing to PDB file.
Some Microsoft tools (e.g. new versions of WPA) fail when the
COFF Debug Directory contains a path to the PDB that contains
dots, such as D:\foo\./bar.pdb.  Remove dots before writing this
path.

This fixes pr38126.

llvm-svn: 336873
2018-07-12 00:44:15 +00:00
Yi Kong a2125b12ec Also search BitcodeFiles for exclude-lib symbols
Archives created with ThinLTO are bitcodes, they also need to be searched for excluded symbols.

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

llvm-svn: 336826
2018-07-11 17:45:28 +00:00
George Rimar bdaffd6c6b [ELF] - Simplify code. NFC.
This looks a bit simpler IMO.

llvm-svn: 336815
2018-07-11 15:23:33 +00:00
George Rimar 1aa8f39dc0 [ELF] - Simplify. NFCI.
It does not look possible to end up with empty Sections
at this place. And this knowledge allows simplifying the code.

llvm-svn: 336814
2018-07-11 15:18:23 +00:00
George Rimar cb17fdbe3c [ELF] - Add classof() member for ARMExidxSentinelSection.
Or code uses constructions like isa<ARMExidxSentinelSection>:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L1428
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L2944

That is confusing, because without ARMExidxSentinelSection::classof()
these lines are equal to isa<SyntheticSection> and the code does not really do
the same what it expected to. I found no good way to break it though, but it is not nice.

Patch adds ARMExidxSentinelSection::classof().

llvm-svn: 336813
2018-07-11 15:11:13 +00:00
Igor Kudrin 4f48b3ef90 [ELF] Update addends in non-allocatable sections for REL targets when creating a relocatable output.
This fixes PR37735.

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

llvm-svn: 336799
2018-07-11 12:52:04 +00:00
George Rimar fd6af6dc98 [ELF] - Report proper error message about mixing bitcode files.
If we have 2 bitcode inputs for different targets, LLD would
print "<internal>" instead of the name of one of the files.

The patch adds a test and fixes this issue.

llvm-svn: 336794
2018-07-11 12:32:00 +00:00
Rui Ueyama eca0e633d1 Remove dead code.
llvm-svn: 336791
2018-07-11 11:52:13 +00:00
Rui Ueyama d29c039119 Parallelize GdbIndexSection's symbol table creation.
Since .gdb_index sections contain all known symbols, they can be very large.
One of my executables has a .gdb_index section of 1350 GiB. Uniquifying
symbols by name takes 3.77 seconds on my machine. This patch parallelize it.

  Time to call createSymbols() with 8.4 million unique symbols:

  Without this patch: 3773 ms
  Parallelism = 1:    4374 ms
  Parallelism = 2:    2628 ms
  Parallelism = 16:    837 ms

As you can see above, this algorithm is a bit more inefficient
than the non-parallelized version, but even with dual-core, it is
faster than that, so I think it is overall a win.

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

llvm-svn: 336790
2018-07-11 11:37:10 +00:00
Rui Ueyama f51c853cf1 Remove a workaround for an old GCC bug.
This workaround is for GCC 5.4.1. Without this workaround, lld will
produce larger .gdb_index sections for object files compiled with the
buggy version of the compiler.

Since it is not for correctness, and it affects only debug builds (since
you are generating .gdb_index sections), perhaps the hack shouldn't have been
added in the first place. At least, I think it is time to remove this hack.

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

llvm-svn: 336788
2018-07-11 10:52:00 +00:00
Rui Ueyama f3731d4e9c Refactor GdbIndexSection. NFC.
This patch merges createGdbIndex function and GdbIndexSection's
constructor into a single static member function of the class.

This patch also change how we keep CU vectors. Previously, CuVector
and GdbSymbols were parallel arrays, but there's no reason to choose that
design. Now, CuVector is a member of GdbSymbol class.

A lot of members are removed from GdbIndexSection. Previously, it has
members that need to be kept in sync over several phases. I belive the new
design is less error-prone, and the new code is much easier to read
than before.

llvm-svn: 336743
2018-07-10 23:48:27 +00:00
Simon Atanasyan 64fb2901e5 [ELF][MIPS] Add mote tests on MipsArchTree routines, fix typos in error messages
This fix add more test cases for routines check MIPS ELF header flags and
flags from .MIPS.abiflags sections. The tests use yaml2obj for object
files generation because not all combinations of flags can be produced
by LLVM tools.

llvm-svn: 336704
2018-07-10 16:51:17 +00:00
Rui Ueyama 2b9b85f2bf Initialize a variable properly to fix buildbots.
llvm-svn: 336700
2018-07-10 16:26:15 +00:00
Rui Ueyama 09b373845a Make a struct type declaration private. NFC.
llvm-svn: 336690
2018-07-10 15:57:25 +00:00
Rui Ueyama bee192f6b0 Simplify. NFC.
llvm-svn: 336686
2018-07-10 15:15:56 +00:00
Rui Ueyama 3467fac091 Rename a variable for consistency. NFC.
llvm-svn: 336674
2018-07-10 14:03:39 +00:00
Rui Ueyama 7f112ea26d Reduce memory usage when creating .gdb_index. NFC.
.gdb_index sections can be very large. When you are compiling
multi-gibibyte executables, they can be larger than 1 GiB. The previous
implementation of .gdb_index seems to consume too much memory.

This patch reduces memory consumption by eliminating temporary objects.
In one experiment, memory consumption of GdbIndexSection class is
reduced from 962 MiB to 228 MiB when creating a .gdb_index of 1350 GiB.

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

llvm-svn: 336672
2018-07-10 13:49:13 +00:00
George Rimar 92108de572 [ELF] - Add a test for readCallGraph() code.
This is to test the following untested line:
https://github.com/llvm-mirror/lld/blob/master/ELF/Driver.cpp#L643

llvm-svn: 336670
2018-07-10 13:42:21 +00:00
Martin Storsjo 474be005db [COFF] Store import symbol pointers as pointers to the base class
Future symbol insertions can potentially change the type of these
symbols - keep pointers to the base class to reflect this, and
use dynamic casts to inspect them before using as the subclass
type.

This fixes crashes that were possible before, by touching these
symbols that now are populated as e.g. a DefinedRegular, via
the old pointers with DefinedImportThunk type.

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

llvm-svn: 336652
2018-07-10 10:40:11 +00:00
George Rimar bc6702a424 [ELF] - Improve call graph pasing error reporting.
This adds a file name to the error message,
adds a missing test case and refactors code a bit. 

llvm-svn: 336651
2018-07-10 10:28:55 +00:00
George Rimar 20b92c4d0d [ELF] - Report call graph profile file names in error messages.
We did not report file names for some reason.

llvm-svn: 336650
2018-07-10 10:16:48 +00:00
Rui Ueyama 2a3036fb1d Report an error for an extremely large .gdb_index section.
I believe the only way to test this functionality is to create extremely
large object files and attempt to create a .gdb_index that is greater
than 4 GiB. But I think that's too much for most environments and buildbots,
so I'm commiting this without a test that actually triggers the new
error condition.

llvm-svn: 336631
2018-07-10 01:22:25 +00:00
Rui Ueyama a9e169edff Fix a bug for packed relocations.
Previously, we didn't create multiple consecutive bitmaps.
Added a test to catch this bug too.

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

llvm-svn: 336620
2018-07-09 23:54:24 +00:00
Rui Ueyama 703c872a4a Simplify RelrSection<ELFT>::updateAllocSize.
This patch also speeds it up by making some constants compile-time
constants. Other than that, NFC.

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

llvm-svn: 336614
2018-07-09 22:29:57 +00:00
Rui Ueyama 3e730b8ae6 Fix direct calls to __wrap_sym when it is relocated.
Patch by Matthew Koontz!

Before, direct calls to __wrap_sym would not map to valid PLT entries,
so they would crash at runtime. This change maps such calls to the same
PLT entry as calls to sym that are then wrapped.

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

llvm-svn: 336609
2018-07-09 22:03:05 +00:00
Rui Ueyama 45192b3746 Factor out code to parse -pack-dyn-relocs. NFC.
llvm-svn: 336599
2018-07-09 20:22:28 +00:00
Rui Ueyama 11479daf2f lld: add experimental support for SHT_RELR sections.
Patch by Rahul Chaudhry!

This change adds experimental support for SHT_RELR sections, proposed
here: https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg

Pass '--pack-dyn-relocs=relr' to enable generation of SHT_RELR section
and DT_RELR, DT_RELRSZ, and DT_RELRENT dynamic tags.

Definitions for the new ELF section type and dynamic array tags, as well
as the encoding used in the new section are all under discussion and are
subject to change. Use with caution!

Pass '--use-android-relr-tags' with '--pack-dyn-relocs=relr' to use
SHT_ANDROID_RELR section type instead of SHT_RELR, as well as
DT_ANDROID_RELR* dynamic tags instead of DT_RELR*. The generated
section contents are identical.

'--pack-dyn-relocs=android+relr --use-android-relr-tags' enables both
'--pack-dyn-relocs=android' and '--pack-dyn-relocs=relr': lld will
encode the relative relocations in a SHT_ANDROID_RELR section, and pack
the rest of the dynamic relocations in a SHT_ANDROID_REL(A) section.

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

llvm-svn: 336594
2018-07-09 20:08:55 +00:00
Zaara Syeda 75c348a097 [PPC64] Add TLS local dynamic to local exec relaxation
This patch adds the target call back relaxTlsLdToLe to support TLS relaxation
from local dynamic to local exec model.

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

llvm-svn: 336559
2018-07-09 16:35:51 +00:00
Zachary Turner 648bebdc67 [PDB] One more fix for hasing GSI records.
The reference implementation uses a case-insensitive string
comparison for strings of equal length.  This will cause the
string "tEo" to compare less than "VUo".  However we were using
a case sensitive comparison, which would generate the opposite
outcome.  Switch to a case insensitive comparison.  Also, when
one of the strings contains non-ascii characters, fallback to
a straight memcmp.

The only way to really test this is with a DIA test.  Before this
patch, the test will fail (but succeed if link.exe is used instead
of lld-link).  After the patch, it succeeds even with lld-link.

llvm-svn: 336464
2018-07-06 21:01:42 +00:00
George Rimar 475dc96901 [ELF] - Add test for empty version in a symbol name.
This covers the following line which was untested:
https://github.com/llvm-mirror/lld/blob/master/ELF/Symbols.cpp#L170

llvm-svn: 336443
2018-07-06 15:03:53 +00:00
George Rimar e5cd32b702 [ELF] - Remove dead code #2.
'Pos' is never can be 0 here.

llvm-svn: 336436
2018-07-06 13:30:50 +00:00
George Rimar 92bd49e874 [ELF] - Remove dead code. NFC.
'Pos' can never be 0.

llvm-svn: 336435
2018-07-06 13:23:49 +00:00
Hans Wennborg b09e004cde Relax filechecks in r336405 tests
They were failing in Chromium's packaging builds with:

  C:\b\rr\tmphqfaff\w\src\third_party\llvm\tools\lld\test\COFF\pdb-globals-dia-vfunc-collision2.test:24:8:
  error: expected string not found in input
  CHECK: func [0x00001060+ 0 - 0x0000106c-12 | sizeof= 12] (FPO) virtual int __cdecl A132()
         ^
  <stdin>:8:11: note: scanning from here
   struct S [sizeof = 8] {
            ^
  <stdin>:9:2: note: possible intended match here
   func [0x00001060+ 0 - 0x0000106c-12 | sizeof= 12] (FPO) virtual int __cdecl S::A132()
   ^

Maybe due to different DIA versions.

llvm-svn: 336424
2018-07-06 08:44:08 +00:00
Hans Wennborg bf7caf4232 dos2unix
llvm-svn: 336423
2018-07-06 08:44:04 +00:00
Simon Atanasyan 78c46bdf52 [ELF][MIPS] Simplify `checkFlags` routine and inline `rejectMicroMips64`. NFC
llvm-svn: 336414
2018-07-06 05:50:46 +00:00
Simon Atanasyan 0905b953da [ELF][MIPS] Remove support for linking microMIPS 64-bit code
Remove support for linking microMIPS 64-bit code because this kind of
ISA is rarely used and unsupported by LLVM.

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

llvm-svn: 336413
2018-07-06 05:50:41 +00:00
Zachary Turner 457cc34e48 [llvm-pdbutil] Dump more info about globals.
We add an option to dump the entire global / public symbol record
stream.  Previously we would dump globals or publics, but not both.
And when we did dump them, we would always dump them in the order
they were referenced by the corresponding hash streams, not in
the order they were serialized in.  This patch adds a lower level
mode that just dumps the whole stream in serialization order.

Additionally, when dumping global-extras, we now dump the hash
bitmap as well as the record offset instead of dumping all zeros
for the offsets.

llvm-svn: 336407
2018-07-06 02:59:25 +00:00
Zachary Turner 1f200adfa7 [PDB] Sort globals symbols by name in GSI hash buckets.
It seems like the debugger first computes a symbol's bucket,
and then does a binary search of entries in the bucket using the
symbol's name in order to find it.  If the bucket entries are not
in sorted order, this obviously won't work.  After this patch a
couple of simple test cases show that we generate an exactly
identical GSI hash stream, which is very nice.

llvm-svn: 336405
2018-07-06 02:33:58 +00:00
Rui Ueyama a8db71f06f Remove redundnat call of makeArrayRef(). NFC.
llvm-svn: 336378
2018-07-05 17:14:33 +00:00
Rui Ueyama 5ba7266761 Simplify PPC64::calcEFlags().
In this file we only have to handle the v2 ABI, so what we need to do
is to just make sure that all object files have v2 or unspecified version
number.

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

llvm-svn: 336372
2018-07-05 16:58:42 +00:00
Rui Ueyama 53ec0a075d Make a test more robust.
Reported by Chris Jackson.

llvm-svn: 336366
2018-07-05 16:03:20 +00:00
George Rimar 061af9aafa [ELF] - Add test case for checking PT_INTERP behavior.
When PT_INTERP is specified in PHDRS command, it should be created.
(if other conditions met)

We had no test for the folowing line:
https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L1108
And for this header itself.

Patch fixes that.

llvm-svn: 336359
2018-07-05 15:01:44 +00:00
George Rimar 732a1e52b9 [ELF] - Eliminate dead "if". NFC.
We call switchTo() from assignAddresses() for switching to Aether,
and from assignOffsets().

First calls assignOffsets() one by one for each output section.
(https://github.com/llvm-mirror/lld/blob/master/ELF/LinkerScript.cpp#L1045)

That I believe means the condition removed in this patch is dead.

llvm-svn: 336356
2018-07-05 14:27:36 +00:00
George Rimar ccf0db9974 [ELF] - Convert excessive dyn_cast -> cast. NFC.
Currently, there are only OutputSection and SymbolAssignment
commands possible at the first level under SECTIONS tag.

Hence, dyn_cast was excessive.

llvm-svn: 336354
2018-07-05 14:09:47 +00:00
George Rimar d87b1eed8e [ELF] - Test we are able to assign version to symbols that are not "_Z*"
This is to test the following line of the code:
https://github.com/llvm-mirror/lld/blob/master/ELF/SymbolTable.cpp#L681

If symbol does not start from _Z prefix and we have extern "C++",
we do not call demangler and use its name as is.

llvm-svn: 336353
2018-07-05 14:01:54 +00:00
George Rimar 8ac85d9a11 [ELF] - Check we do not assign version to undefined symbol when using extern C++.
This tests the following 'continue' line in getDemangledSyms():
https://github.com/llvm-mirror/lld/blob/master/ELF/SymbolTable.cpp#L677

llvm-svn: 336349
2018-07-05 13:39:39 +00:00
George Rimar 2d55b36aac [ELF] - Add test to check we don't crash when tracing reserved symbol.
This is to test the following line of code:
https://github.com/llvm-mirror/lld/blob/master/ELF/SymbolTable.cpp#L601

Without that line linker would crash.

llvm-svn: 336345
2018-07-05 12:48:29 +00:00
George Rimar 889a161b4f [ELF] - Test LLD creates empty .imports file.
This covers the following code line with a test:
https://github.com/llvm-mirror/lld/blob/master/ELF/LTO.cpp#L213

After that, coverage of LTO.cpp is 100%.

llvm-svn: 336342
2018-07-05 12:23:37 +00:00
George Rimar 72ceddab7b [ELF] - Add test to check we produce an error if unable to write an empty index file.
Test case ensures lld generates an error if unable to
write an empty index file for lazy object file that is not added to link.

This covers the following line with a test:
https://github.com/llvm-mirror/lld/blob/master/ELF/LTO.cpp#L206

llvm-svn: 336340
2018-07-05 12:12:30 +00:00
George Rimar 046fa610e0 [ELF] - Remove dead code. NFC.
I think code is dead, because the only way to see
Path as empty seems would be if replaceThinLTOSuffix()
replaced some prefix with empty prefix (making the result
Path empty).

But it is impossible to pass the empty prefix,
we would file in driver:
https://github.com/llvm-mirror/lld/blob/master/ELF/Driver.cpp#L669

llvm-svn: 336338
2018-07-05 11:58:04 +00:00
George Rimar 9b99abcf99 [ELF] - Advance position in a memory region when change the Dot.
This is https://bugs.llvm.org//show_bug.cgi?id=37836

Previously LLD could assign to Dot or set the address
for the section with address expression but did not advance
the position in a memory region.

Patch fixes the issue.

llvm-svn: 336335
2018-07-05 10:44:17 +00:00
George Rimar 6a7c7f3915 [ELF] - Simplify. NFC.
Currently, there are only OutputSection and SymbolAssignment
commands possible at the first level under SECTIONS tag.

So, shouldSkip() contained dead "return true".

Patch simplifies the code.

llvm-svn: 336282
2018-07-04 15:05:21 +00:00
George Rimar 0fc47bea90 [ELF] - Extend edata-etext.s test case.
We did not have a test that would test that
_etext address is equal to etext, _end == end and _edata == edata.

Because of that, the following line was never
executed when running our tests:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L928

Patch fixes that.

llvm-svn: 336280
2018-07-04 14:47:19 +00:00
George Rimar aef7413962 [ELF] - Cover handling of DW_AT_external with test.
The following check was uncovered with tests:
https://github.com/llvm-mirror/lld/blob/master/ELF/InputFiles.cpp#L159

Patch adds test to cover it.

llvm-svn: 336273
2018-07-04 14:04:59 +00:00
George Rimar 6906f4ec9c [ELF] - LTO: add test for createEmptyIndex.
We have a following comment for createEmptyIndex caller code:

// If LazyObjFile has not been added to link, emit empty index files.
// This is needed because this is what GNU gold plugin does and we have a
// distributed build system that depends on that behavior.
  
Though createEmptyIndex() itself
(https://github.com/llvm-mirror/lld/blob/master/ELF/LTO.cpp#L202)
is never called in our test cases. 

Patch adds a test.

llvm-svn: 336270
2018-07-04 13:36:45 +00:00
George Rimar 514ac22d8f [ELF] - Add a test case for relocation pointing to deduplicated COMDAT.
ELF spec doesn't allow a relocation to point to a deduplicated
COMDAT section. Unfortunately this happens in practice (e.g. .eh_frame)

We have a code in MarkLive.cpp for that and it was uncovered by any test case:
https://github.com/llvm-mirror/lld/blob/master/ELF/MarkLive.cpp#L199

Patch adds a test.

llvm-svn: 336259
2018-07-04 10:38:12 +00:00
Simon Atanasyan 91d190199d [ELF][MIPS] Use llvm-mc to generate test case input file. NFC
llvm-svn: 336201
2018-07-03 14:39:27 +00:00
George Rimar b5d6e76bb7 [ELF] - Add a comment. NFC.
Minor follow up for r336197
"[ELF] - Add support for '||' and '&&' in linker scripts."

llvm-svn: 336199
2018-07-03 14:16:19 +00:00
George Rimar a50054829d [ELF] - Add support for '||' and '&&' in linker scripts.
This is https://bugs.llvm.org//show_bug.cgi?id=37976,
we had no support, but seems someone faced it.

llvm-svn: 336197
2018-07-03 14:02:52 +00:00
James Henderson b427d4eced [ELF] Don't create empty output section for unreferenced PROVIDEs
LLD removes empty output sections otherwise specified in the linker
script. Prior to this change however, if section descriptions included
ANY kind of symbol assignment, then the consequent output section would
not be removed, even if the assignment was marked with PROVIDE and not
actually triggered (i.e. the symbol was never referenced). This change
modifies the isDiscarable function to ignore such directives when
determining whether a section should be discarded, in keeping with
bfd's behaviour. Symbol assignments that do result in a symbol
definition will continue to result in a kept section (this is not
actually the same as bfd's behaviour, but it is simpler, and probably
makes more sense).

Reviewed By: grimar

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

llvm-svn: 336184
2018-07-03 09:23:25 +00:00
Peter Smith 13a7b37ad4 [ELF][AArch64] Add test case for load/store exclusive instructions [NFC]
The AArch64 -fix-cortex-a53-843419 is missing a test case for the load and
store exclusive instructions. This was leading to a function not being
covered in the codebase. This change adds two new instruction sequences to
be recognised as an instance of the erratum, one with a load exclusive the
other with a store exclusive.

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

llvm-svn: 336181
2018-07-03 08:53:41 +00:00
George Rimar 8bcab86955 [ELF] - Revert mips-tls-64-pic-local-variable.s changed in r336129.
This restores the original comment in the test case.

llvm-svn: 336180
2018-07-03 08:34:55 +00:00
George Rimar 34d2333c07 [ELF] - Revert huge-temporary-file.s changed in r336129
Comment in the test case says that:

## This inputs previously created a 4gb temporarily file under 32 bit
## configuration. Issue was fixed. There is no clean way to check that from here.
## This testcase added for documentation purposes.

The intention of the test was to create such huge file
in case if our code will be broken again.
And currently it documents we do not create huge outputs.

r336129 changed -o to /dev/null and broke the intentions of the test case.

llvm-svn: 336179
2018-07-03 08:30:55 +00:00
Sam Clegg b2144058a6 [LTO] Errors in LLVM backend should manifest as lld errors
Differential Revision: https://reviews.llvm.org/D48812

llvm-svn: 336143
2018-07-02 21:01:43 +00:00
Fangrui Song 841ae5ab1e [ELF] Fix other tests after r336129
llvm-svn: 336136
2018-07-02 19:17:03 +00:00
Fangrui Song 36e021490d [ELF] Fix just-symbols*.s after r336129
llvm-svn: 336135
2018-07-02 19:12:10 +00:00
Fangrui Song 40a9f2251b [ELF] Replace unused output filenames with /dev/null in tests
Post commit review at rLLD335992

llvm-svn: 336129
2018-07-02 17:48:23 +00:00
Sam Clegg 92c10492de [WebAssembly] Set threadmodel during LTO
Subscribers: dschuff, mehdi_amini, inglorion, jgravelle-google, aheejin, sunfish, steven_wu, llvm-commits

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

llvm-svn: 336118
2018-07-02 16:27:50 +00:00
George Rimar 03b0a4856f [ELF] - Cleanup error reporting code and cover with the test. NFC.
We have the following code that is uncovered with the test:
https://github.com/llvm-mirror/lld/blob/master/ELF/Target.cpp#L95

This patch:
1) Removes "!IS" check. Because at that point of execution
(we are reolving the relocations during writing output)
we should only have InputSection type of the sections in the vector.
(because we already converted MergeInputSection in mergeSections()
and combined EhInputSections in combineEhFrameSections()).

2) Covers the "!IS->getParent()" with the test.

llvm-svn: 336106
2018-07-02 14:13:11 +00:00
George Rimar 2757df7933 [ELF] - Remove dead code. NFC.
It duplicated the default implementation.

llvm-svn: 336093
2018-07-02 11:10:08 +00:00
George Rimar 90d057d75e [ELF] - Change dyn_cast to cast. NFC.
This is followup for r335958.

Thanks to Rui for noticing.

llvm-svn: 336082
2018-07-02 08:26:20 +00:00
Zachary Turner d3fe59833f Fix test after S_PROCREF change.
Since the names are being hashed correctly now, enumerating them
returns them in a different order.  Update the test to reflect
that.

llvm-svn: 336027
2018-06-29 22:41:16 +00:00
Fangrui Song c61b568e2d [ELF] Set -o because current directory may not be writable during a test
llvm-svn: 335992
2018-06-29 17:07:22 +00:00
Filipe Cabecinhas 17f3f7ae6b [lld] Address post-commit review of r335848
llvm-svn: 335985
2018-06-29 15:34:36 +00:00
George Rimar 0751a0307a [ELF] - Linker script: add tests for checking malformed numbers parsing.
Previoulsy we had no test that covered malfolmed numbers
with 'H', 'K' and 'M' suffixes, so the following lines
were uncovered:

https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L996
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L1003
https://github.com/llvm-mirror/lld/blob/master/ELF/ScriptParser.cpp#L1008

Patch fixes that.

llvm-svn: 335979
2018-06-29 14:29:44 +00:00
George Rimar f9e1dc0023 [ELF] - Eliminate dead code from shouldKeepInSymtab. NFC.
shouldKeepInSymtab is called from copyLocalSymbols:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L574

The pre-condition is that symbol should be Defined:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L572

And its section is Live:
https://github.com/llvm-mirror/lld/blob/master/ELF/Writer.cpp#L548

InputSection::Discarded section can never be Live. And hence I believe
check I removed in this patch is excessive.

llvm-svn: 335973
2018-06-29 13:34:05 +00:00
George Rimar 2f7e39c7d5 [ELF] - EhFrame.cpp: cover personality encoding handling code with the test cases.
CIEs augmentation string can have 'P' character,
what means the next byte is the personality encoding, a DW_EH_PE_xxx value.
This is followed by a pointer to the personality function.

We had the support of the different encodings earlier, but had no test cases.

This change adds coverage of DW_EH_PE_absptr/DW_EH_PE_signed/DW_EH_PE_udata2/DW_EH_PE_sdata2 and
DW_EH_PE_udata8/DW_EH_PE_sdata8 cases for place below:
https://github.com/llvm-mirror/lld/blob/master/ELF/EhFrame.cpp#L123

llvm-svn: 335969
2018-06-29 12:19:35 +00:00