Commit Graph

10902 Commits

Author SHA1 Message Date
Peter Smith 796fb999b3 [ELF] Do not error for missing version when symbol has local version.
If a symbol with an undefined version in a DSO is not going to be
exported into the dynamic symbol table then do not give an error message
for the missing version. This can happen with the --exclude-libs option
which implicitly gives all symbols in a static library the local version.
This matches the behavior of ld.gold and is exploited by the Bionic
dynamic linker on Arm.

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

llvm-svn: 332224
2018-05-14 10:13:56 +00:00
Peter Collingbourne 107f55005b COFF: ICF a section and its associated sections as a unit.
This is needed to avoid merging two functions with identical
instructions but different xdata. It also reduces binary size by
deduplicating identical pdata sections.

Fixes PR35337.

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

llvm-svn: 332169
2018-05-12 02:12:40 +00:00
Peter Collingbourne d25dfe9bda COFF: Add a flag for disabling string tail merging.
We discovered (crbug.com/838449#c24) that string tail merging can
negatively affect compressed binary size, so provide a flag to turn
it off for users who care more about compressed size than uncompressed
size.

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

llvm-svn: 332149
2018-05-11 22:21:36 +00:00
Rumeet Dhindsa ebb7f5c71a Update input file in test
llvm-svn: 332139
2018-05-11 20:50:27 +00:00
Rumeet Dhindsa 2ef385e150 Update test to not check for output file
Differential Revision: https://reviews.llvm.org/D46771

llvm-svn: 332134
2018-05-11 20:28:45 +00:00
Rumeet Dhindsa 304d0d5560 Splitting thinlto.ll test file and renaming other test files.
Differential Revision: https://reviews.llvm.org/D46731

llvm-svn: 332128
2018-05-11 19:37:08 +00:00
Sean Fertile c12f051112 [PPC64] isRelExpr should return true for the PPC Call Exprs.
Both R_PPC_CALL and R_PPC_CALL_PLT Exprs map to the R_PPC64_REL24 relocation
which has the form Sym + addend - P.

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

llvm-svn: 332127
2018-05-11 19:31:19 +00:00
Martin Storsjo 5fb6437012 [MachO] Don't write test files to /tmp, remove them afterwards.
This matches what is done in MachONormalizedFileBinaryWriterTests.cpp
already.

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

llvm-svn: 332114
2018-05-11 18:19:02 +00:00
George Rimar 4c9ae67bb7 [ELF] - Revert of: r332038, r332054, r332060, r332061, r332062, r332063
This reverts "Mitigate relocation overflow [part 1 of 2]." and the following commits which
were trying to fix the bots.

At the moment of r332082, bots are still failing and we need to find the reason of test case breakages first of all.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/17042/steps/test/logs/stdio
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/29845/steps/test/logs/stdio

llvm-svn: 332085
2018-05-11 08:11:25 +00:00
Fangrui Song a119322c1d [ELF] Fix test
llvm-svn: 332063
2018-05-10 23:57:38 +00:00
Fangrui Song fa0700a978 [ELF] Fix tests after rL332038
llvm-svn: 332062
2018-05-10 23:55:41 +00:00
Fangrui Song c638db5913 [ELF] --warn-backref: don't report backref to weak symbols.
Summary:
Suppose we visit symbols in this order:

1. weak definition of foo in a lazy object
2. reference of foo
3 (optional). definition of foo

bfd/gold allows 123 but not 12.

Current --warn-backrefs implementation will report both cases as a backward reference. With this change, both 123 (intended) and 12 (unintended) are allowed. The usage of weak definitions usually imply there are also global definitions, so the trade-off is justified.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 332061
2018-05-10 23:53:05 +00:00
Fangrui Song f6f7e0940a [ELF] Fix two tests after D45788
llvm-svn: 332060
2018-05-10 23:51:37 +00:00
Peter Collingbourne b6c5a3045b COFF: Allow ICF on vtable sections.
Differential Revision: https://reviews.llvm.org/D46734

llvm-svn: 332059
2018-05-10 23:31:58 +00:00
Han Shen b3f2172ce4 Fix test cases failure caused by revision 332038.
The previous CL changes the order of output sections, which causes address changes in test cases.

Review: https://reviews.llvm.org/D46730
llvm-svn: 332054
2018-05-10 22:32:39 +00:00
Han Shen 6c0881c3cd Mitigate relocation overflow [part 1 of 2].
This CL is to mitigate R_X86_64_PC32 relocation overflow problems for huge binaries that has near 4G allocated sections.

By examining those binaries, there're 2 issues contributes to the problem:
1). huge ".dynsym" and ".dynstr" stands in the way between .rodata and .text
2). _init_array_start/end are placed at 0 if no ".init_array" presents, this causes .text relocation against them become more prone to overflow.

This CL addresses 1st problem (the 2nd will be addressed in another CL.) by assigning a smaller sortrank to .dynsym and .dynstr thus they no longer stand in between.

llvm-svn: 332038
2018-05-10 20:44:42 +00:00
Peter Collingbourne e28faed768 COFF: Don't create unnecessary thunks.
A thunk is only needed if a relocation points to the undecorated
import name.

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

llvm-svn: 332019
2018-05-10 19:01:28 +00:00
Sam Clegg 668447677a [WebAssembly] Add a flag to control merging data segments
Merging data segments produces smaller code sizes because each segment
has some boilerplate. Therefore, merging data segments is generally the
right approach, especially with wasm where binaries are typically
delivered over the network.

However, when analyzing wasm binaries, it can be helpful to get a
conservative picture of which functions are using which data
segments[0]. Perhaps there is a large data segment that you didn't
expect to be included in the wasm, introduced by some library you're
using, and you'd like to know which library it was. In this scenario,
merging data segments only makes the analysis worse.

Alternatively, perhaps you will remove some dead functions by-hand[1]
that can't be statically proven dead by the compiler or lld, and
removing these functions might make some data garbage collect-able, and
you'd like to run `--gc-sections` again so that this now-unused data can
be collected. If the segments were originally merged, then a single use
of the merged data segment will entrench all of the data.

[0] https://github.com/rustwasm/twiggy
[1] https://github.com/fitzgen/wasm-snip

Patch by Nick Fitzgerald!

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

llvm-svn: 332013
2018-05-10 18:23:51 +00:00
Nico Weber cac2b3349e lld-link: Add --color-diagnostics(={always,never,auto})?, --no-color-diagnostics flags.
This is most useful when using lld-link on a non-Win host (but it might become
useful on Windows too if lld also grows a fansi-escape-codes flag).

Also make the help for --color-diagnostic mention the valid values in ELF and
wasm, and print the flag name with two dashes in diags, since the one-dash form
is seen as a list of many one-letter flags in some contexts.

https://reviews.llvm.org/D46693

llvm-svn: 332012
2018-05-10 18:19:02 +00:00
Sam Clegg d6beb320b4 [WebAssembly] Simplify writing of exports section. NFC.
Differential Revision: https://reviews.llvm.org/D43963

llvm-svn: 332011
2018-05-10 18:10:34 +00:00
Sam Clegg 262e09018b [WebAssembly] Remove final -wasm component of target triple. NFC.
This has been the default for a while now.

llvm-svn: 332009
2018-05-10 17:59:41 +00:00
Simon Atanasyan d9802236d5 [ELF][MIPS] Add test case to check some microMIPS R6 relocations. NFC
llvm-svn: 331995
2018-05-10 15:56:27 +00:00
Simon Atanasyan dd995bd790 [ELF][MIPS] Add test case to check N32 ABI PLT generation. NFC
llvm-svn: 331994
2018-05-10 15:56:22 +00:00
George Rimar 6b3801824c [ELF] - Improve the test cases for notes sections.
A minor clean up and improvement for our tests for notes sections.

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

llvm-svn: 331980
2018-05-10 13:45:34 +00:00
Ed Maste 6556aa6848 [ELF] Omit PT_NOTE for SHT_NOTE without SHF_ALLOC
A non-alloc note section should not have a PT_NOTE program header.

Found while linking ghc (Haskell compiler) with lld on FreeBSD.
ghc emits a .debug-ghc-link-info note section (as the name suggests, it
contains link information) as a SHT_NOTE section without SHF_ALLOC set.

For this case ld.bfd does not emit a PT_NOTE segment for the
.debug-ghc-link-info section.  lld previously emitted a PT_NOTE with
p_vaddr = 0 and FreeBSD's rtld segfaulted when trying to parse a note at
address 0.

llvm.org/pr37361

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

llvm-svn: 331973
2018-05-10 11:12:18 +00:00
James Henderson d621037788 [ELF] Rework debug line parsing to use llvm::Error and callbacks (LLD-side)
Reviewed by: ruiu, grimar, espindola

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

Summary:
r331971 changes the debug line parser interface to report LLVM errors in an
interface that different executables can use, rather than always being printed
directly as warnings to stderr. This change allows LLD to make use of the new
interface and call its own warning methods to report problems.

llvm-svn: 331972
2018-05-10 10:52:21 +00:00
Martin Storsjo 5c84d442f5 [COFF] Fix dangling StringRefs from SVN 331900
llvm-svn: 331912
2018-05-09 19:07:10 +00:00
Martin Storsjo 0ca06f7950 [COFF] Allow specifying export forwarding in a def file
Previously this was only supported when specified on the command line
or in directives.

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

llvm-svn: 331900
2018-05-09 18:19:41 +00:00
Benjamin Kramer 9a85470a57 [wasm] Update test for variables->retainedNodes rename.
This fixes the test after LLVM r331841.

llvm-svn: 331862
2018-05-09 10:09:23 +00:00
Martin Storsjo 97379ff6b2 [COFF] Improve correctness of def parsing for GNU features
The operator == used for exporting a function with a different
name in the DLL compared to the name in the import library
(which is useful for adding linker level aliases for function
in the import library) is a feature distinct and different from
the operator = used for exporting a function with a different
name (both in import library and DLL) than in the implementation
producing the DLL.

When creating an import library using dlltool, from a def file that
contains forwards (Func = OtherDll.Func), this shouldn't affect the
produced import library, which should still behave just as if it
was a normal exported function.

This clears a lot of confusion and subtle misunderstandings, and
avoids a parameter that was used to avoid creating weak aliases
when invoked from lld. (This parameter was added previously due to
the existing conflation of the two features.)

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

llvm-svn: 331860
2018-05-09 09:22:03 +00:00
Simon Atanasyan d62b3e8f5d [ELF][MIPS] Add test case to cover LA25 r6 thunks generation. NFC
llvm-svn: 331851
2018-05-09 06:51:58 +00:00
Sean Fertile 49914cc807 [PPC64] Add lazy symbol resolution stubs.
Adds support for .glink resolver stubs from the example implementation in the V2
ABI (Section 4.2.5.3. Procedure Linkage Table). The stubs are written to the
PltSection, and the sections are renamed to match the PPC64 ABI:
    .got.plt --> .plt    Type = SHT_NOBITS
    .plt     --> .glink

And adds the DT_PPC64_GLINK dynamic tag to the dynamic section when the plt is
not empty.

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

llvm-svn: 331840
2018-05-09 02:07:53 +00:00
Sriraman Tallam 8244c9c489 Fix test by adding -triple=x86_64-unknown-linux
llvm-svn: 331828
2018-05-09 00:20:45 +00:00
Sriraman Tallam be01d2e3de New option -z keep-text-section-prefix to keep text sections with prefixes separate.
Separate output sections for selected text section prefixes to enable TLB optimizations and for readablilty.

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

llvm-svn: 331823
2018-05-08 23:19:50 +00:00
Rumeet Dhindsa b5b7d6e19c Add support for LTO plugin option obj-path
Differential Revision: https://reviews.llvm.org/D46598

llvm-svn: 331817
2018-05-08 22:37:57 +00:00
Rumeet Dhindsa 1888326b2d Update ThinLTO Indexing logic
Instead of writing empty index for file, this patch tracks the state of files in ObjectToIndexFileState. If the files are not indexed , only then we emit the empty files

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

llvm-svn: 331803
2018-05-08 20:12:07 +00:00
Rui Ueyama d31b54b3c1 Refactor BitcodeCompiler::add(). NFC.
This change makes it explicit that the main loop iterates over a
parallel array, Syms and ObjSyms.

llvm-svn: 331780
2018-05-08 17:50:54 +00:00
Rui Ueyama 2f9fa42892 Fix a bug that a copy of a large vector was created. NFC.
llvm-svn: 331779
2018-05-08 17:50:43 +00:00
Simon Atanasyan 610e621c99 [ELF][MIPS] Fix test case in attempt to restore Windows build-bot. NFC
llvm-svn: 331774
2018-05-08 16:11:40 +00:00
Simon Atanasyan 0560050668 [ELF][MIPS] Fix calculation of GP relative relocations in case of relocatable output
Some MIPS relocations depend on "gp" value. By default, this value has
0x7ff0 offset from a .got section. But relocatable files produced by a
compiler or a linker might redefine this default value and we have to
use it for a calculation of the relocation result. When we generate EXE
or DSO it's trivial. Generating a relocatable output is more difficult
case because the linker does calculate relocations in this case and
cannot store individual "gp" values used by each input object file.
As a workaround we add the "gp" value to the relocation addend.

This fixes https://llvm.org/pr31149

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

llvm-svn: 331772
2018-05-08 15:34:06 +00:00
Peter Smith 24d906630b [LLD][ELF][AArch64] Increase test coverage of AArch64ErrataFix [NFC]
In the recognise test convert some ST1 multiple structure to ST1 single
structure to test the isST1SingleOpcode() function.

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

llvm-svn: 331752
2018-05-08 09:36:24 +00:00
Peter Smith f6ed9dd41d [LLD][ELF] Add test cases to improve code coverage of Thunks [NFC]
Add two test cases to improve the code coverage of ThunkSection creation
when there are no existing ThunkSections in range. There are two test
cases, one where a new section can be created and another to trigger the
"InputSection too large for range extension thunk" error message. A recent
code coverage report showed that this section of code wasn't covered by a
test case.

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

llvm-svn: 331751
2018-05-08 09:26:06 +00:00
Fangrui Song 95851515d7 Add a CIE with length 0 unconditionally.
Summary: This is not technically required, but glibc unwind-dw2-fde.c classify_object_over_fdes expects there is a CIE record length 0 as a terminator.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 331708
2018-05-08 01:19:16 +00:00
Rui Ueyama cdf8d06426 Rename a local variable whose scope is very narrow. NFC.
llvm-svn: 331703
2018-05-07 23:43:48 +00:00
Rui Ueyama ac403ef7f0 Improve error message for --plugin-opt=thinlto-prefix-replace.
llvm-svn: 331700
2018-05-07 23:24:25 +00:00
Rui Ueyama d432f216d1 Rename Config::ThinLTOIndexOnlyObjectFiles -> Config::ThinLTOIndexOnlyArg.
llvm-svn: 331699
2018-05-07 23:24:16 +00:00
Rui Ueyama 397dffd81b Split BitcodeCompiler::init() into two functions. NFC.
Previously, code to initialize Backend and code to initialize Conf are
intermingled in init(), though they don't depend on each other.

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

llvm-svn: 331698
2018-05-07 23:24:07 +00:00
Rumeet Dhindsa 4fb5119215 Add support for thinlto option ( thinlto-emit-imports-files) to emit import files for thinlink.
Differential Revision: https://reviews.llvm.org/D46400

llvm-svn: 331696
2018-05-07 23:14:12 +00:00
Rui Ueyama 554adb2e97 Do not call exit() directly from lld.
Our promise is that as long as there's no fatal error (i.e. broken
file is given to the linker), our main function returns to the caller.
So we can't use exit() in the regular code path.

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

llvm-svn: 331690
2018-05-07 22:11:34 +00:00
Rui Ueyama d54f1c2fed Refactor ThinLTO-related code in BitcodeCompiler.cpp. NFC.
Summary: Refactor ThinLTO-related code in BitcodeCompiler.cpp. NFC.

Reviewers: rdhindsa, espindola

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

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

llvm-svn: 331689
2018-05-07 22:11:24 +00:00
Rumeet Dhindsa d48f236a7e Add test to ensure lld writes linked files to linked objects file for ThinLTO Indexing Only option.
Differential Revision: https://reviews.llvm.org/D46542

llvm-svn: 331671
2018-05-07 20:28:02 +00:00
Rui Ueyama f64f345e1b Do not pass Config members to simplify function signature. NFC.
llvm-svn: 331658
2018-05-07 17:59:52 +00:00
Rui Ueyama 4454b3d1eb Parse --thinlto-prefix-replace early so that we don't need to parse it later. NFC.
llvm-svn: 331657
2018-05-07 17:59:43 +00:00
Rui Ueyama e4ba06eda6 Use StringRef instead of `const std::string &`. NFC.
llvm-svn: 331656
2018-05-07 17:59:34 +00:00
Rui Ueyama 66a9f257b6 Refactor BitcodeCompiler::createLTO. NFC.
llvm-svn: 331655
2018-05-07 17:46:28 +00:00
Roman Lebedev 7cb6896732 ELF Thunks: fix build error: missing 'overrides'
llvm-svn: 331608
2018-05-06 19:50:04 +00:00
Sean Fertile d2e887d2f6 [PPC64] Emit plt call stubs to the text section rather then the plt section.
On PowerPC calls to functions through the plt must be done through a call stub
that is responsible for:
1) Saving the toc pointer to the stack.
2) Loading the target functions address from the plt into both r12 and the
   count register.
3) Indirectly branching to the target function.

Previously we have been emitting these call stubs to the .plt section, however
the .plt section should be reserved for the lazy symbol resolution stubs. This
patch moves the call stubs to the text section by moving the implementation from
writePlt to the thunk framework.

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

llvm-svn: 331607
2018-05-06 19:13:29 +00:00
Andrea Di Biagio 25c1a2f0d1 Fix -Wunused-variable warning introduced at r331566.
llvm-svn: 331589
2018-05-05 10:53:31 +00:00
Sam Clegg 752494bfe3 [WebAssembly] Check function signatures by default
But only produce a warning (for now) unless --fatal-warnings
is passed.

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

llvm-svn: 331574
2018-05-05 01:23:07 +00:00
Sam Clegg 60609c9f12 Add llvm-dwarfdump tool_patterns
Differential Revision: https://reviews.llvm.org/D46481

llvm-svn: 331572
2018-05-05 00:32:26 +00:00
Sam Clegg c1953144ac [WebAssembly] Only perform sanity checking of relocation targets in debug builds
Also:
- Reduce the error to a warning so that debug and release
  versions can still link the same inputs.
- Add another check to verify the input LEB is padded to 5 bytes

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

llvm-svn: 331571
2018-05-05 00:18:43 +00:00
Sam Clegg d177ab2a5f [WebAssembly] Add support for debug (DWARF) sections
Specifically add support for custom sections that contain
relocations, and for the two new relocation types needed
by DWARF sections.

See: https://reviews.llvm.org/D44184

Patch by Yury Delendik!

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

llvm-svn: 331566
2018-05-04 23:14:42 +00:00
Simon Atanasyan b6211d9084 [ELF][MIPS] Reorganize isMipsPIC routine. NFC
llvm-svn: 331555
2018-05-04 20:48:53 +00:00
Simon Atanasyan 86a1219d30 [ELF][MIPS] Add STO_MIPS_MICROMIPS flag to symbols point to microMIPS PLT records
llvm-svn: 331554
2018-05-04 20:48:47 +00:00
Peter Collingbourne e5ad31d376 Object: The default alignment of a section without alignment flags is 16.
Differential Revision: https://reviews.llvm.org/D46420

llvm-svn: 331538
2018-05-04 16:45:57 +00:00
Zaara Syeda edc7a8c1e5 [PPC64] Remove support for ELF V1 ABI in LLD - buildbot fix
Fix buildbot error, failure to build with msvc due to error C2446
Use switch instead of ternary operator.

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

llvm-svn: 331534
2018-05-04 16:04:04 +00:00
Zaara Syeda f61b0733a8 [PPC64] Remove support for ELF V1 ABI in LLD
The current support for V1 ABI in LLD is incomplete.
This patch removes V1 ABI support and changes the default behavior to V2 ABI,
issuing an error when using the V1 ABI. It also updates the testcases to V2
and removes any V1 specific tests.

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

llvm-svn: 331529
2018-05-04 15:09:49 +00:00
Peter Smith 2689d9f4f0 [ELF][AArch64] Add aarch64_elf64_le_vec emulation
Android AOSP has started specifying -m aarch64_elf64_le_vec as supported
by gold and BFD. This is a simple change to add the emulation so that LLD
doesn't immediately error when used as a linker in an AOSP build.

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

llvm-svn: 331521
2018-05-04 14:28:29 +00:00
Peter Smith 9c116180a4 [ELF][AArch64] Add REQUIRES aarch64 to test [NFC]
Forgot to add REQUIRES aarch64 to the test I recently added for D46255.

llvm-svn: 331513
2018-05-04 09:10:18 +00:00
Peter Smith e72d3d32bb [ELF][AArch64] Implement the AArch64 TLSLD_LDST_LO12 family of relocs
Implement the following relocations for AArch64:
R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC

These are specified in ELF for the 64-bit Arm Architecture.

Fixes pr36727

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

llvm-svn: 331511
2018-05-04 08:53:34 +00:00
Martin Storsjo cc80776eff [COFF] Implement the remaining ARM64 relocations
Now only IMAGE_REL_ARM64_ABSOLUTE and IMAGE_REL_ARM64_TOKEN
are unhandled.

Also add range checks for the existing BRANCH26 relocation.

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

llvm-svn: 331505
2018-05-04 06:06:27 +00:00
Rumeet Dhindsa 9c2af27f80 Added ThinLTO test to verify that index files are not generated if thinlto-index-only is not enabled.
Differential Revision: https://reviews.llvm.org/D46405

llvm-svn: 331478
2018-05-03 20:13:38 +00:00
Simon Atanasyan bc4da23133 [ELF][MIPS] Check that a section has a valid reference to a file in the isMipsPIC routine
llvm-svn: 331470
2018-05-03 17:33:10 +00:00
Sam Clegg a0f095ebd7 [WebAssembly] Add --stack-first option which places the shadow stack at start of linear memory
Fixes https://bugs.llvm.org/show_bug.cgi?id=37181

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

llvm-svn: 331467
2018-05-03 17:21:53 +00:00
Peter Smith 2e54353b86 [LLD][AArch64] Simplify relocations sharing same encoding [NFC]
The code to encode the result in relocateOne for the relocations:
R_AARCH64_LD64_GOT_LO12_NC
R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
R_AARCH64_TLSDESC_LD64_LO12

is equivalent to that for R_AARCH64_LDST64_ABS_LO12_NC. This is described
in the ABI as "Set the LD/ST immediate field bits [11:3] of X. No overflow
check; check that X&7 =0.
    
Differential Revision: https://reviews.llvm.org/D46247

llvm-svn: 331452
2018-05-03 12:59:52 +00:00
David Zarzycki f161de4e7d [CMake] Fix BUILD_SHARED_LIBS regression due to r331405
llvm-svn: 331444
2018-05-03 10:03:45 +00:00
Rumeet Dhindsa 437f66d06d Update Error Message
https://reviews.llvm.org/D46375

llvm-svn: 331426
2018-05-03 01:54:14 +00:00
Rumeet Dhindsa b082a8790c Updated ThinLTO test to not include forward or backward slash for testing
Differential Revision: https://reviews.llvm.org/D46372

llvm-svn: 331419
2018-05-03 00:28:51 +00:00
Rumeet Dhindsa d366e36bbf Added support for ThinLTO plugin options : thinlto-index-only and thinlto-prefix-replace
Differential Revision: https://reviews.llvm.org/D46034

llvm-svn: 331405
2018-05-02 21:40:07 +00:00
Zaara Syeda 116c0424da Fix warning: result of 32-bit shift implicitly converted to 64 bits - NFC
Fix warning caused by rL331046.

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

llvm-svn: 331181
2018-04-30 14:37:28 +00:00
Ed Maste 59c4962c1d Add -warn-backrefs (r329636) to lld's man page
llvm-svn: 331133
2018-04-29 02:18:48 +00:00
Fangrui Song 8c07d06da9 Migrate from std::pointer_to_unary_function as it is removed in C++17
llvm-svn: 331097
2018-04-28 00:12:02 +00:00
Rafael Espindola bd4d2acb11 Don't create a temporary DenseMap for each input .eh_frame.
These maps are small, but we are creating an destroying one for each
input .eh_frame.

This patch reduces the total memory allocation from 765.54MB to
749.19MB. The peak is still the same: 563.7MB.

llvm-svn: 331075
2018-04-27 20:19:28 +00:00
Rafael Espindola f1652d4c60 Split .eh_frame sections in parellel.
We can now split them in the same spot we split merge sections.

llvm-svn: 331064
2018-04-27 18:17:36 +00:00
Rafael Espindola 9bf1006278 Split merge sections early.
Now that getSectionPiece is fast (uses a hash) it is probably OK to
split merge sections early.

The reason I want to do this is to split eh_frame sections in the same
place.

This does mean that we have to decompress early. Given that the only
compressed sections are debug info, I don't think we are missing much.

It is a small improvement: 0.5% on the geometric mean.

llvm-svn: 331058
2018-04-27 16:29:57 +00:00
Zaara Syeda 82dd99e08e [PPC64] Add offset to local entry point when calling functions without plt
PPC64 V2 ABI describes two entry points to a function. The global entry point
sets up the TOC base pointer. When calling a local function, the call should
branch to the local entry point rather than the global entry point.
Section 3.4.1 describes using the 3 most significant bits of the st_other
field to find out how many instructions there are between the local and global
entry point. This patch adds the correct offset required to branch to the local
entry point of a function.

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

llvm-svn: 331046
2018-04-27 15:41:19 +00:00
Rui Ueyama 50bf643cfb Do not set RequiresNullTerminator. NFC.
When reading object files, we don't need '\0' at end of each file.

llvm-svn: 331045
2018-04-27 15:32:04 +00:00
Fangrui Song 1f3e2b2966 [ELF] Fix typo. NFC
llvm-svn: 331018
2018-04-27 05:50:40 +00:00
Shoaib Meenai 1b1f97ac60 [ELF] Clarify help wording for --symbol-ordering-file
The input file for this option should contain a list of symbols, not a
list of sections, so explicitly refer to ordering symbols (but keep the
reference to laying out sections, since that's how the option must
operate). Referring to the file itself as the "symbol ordering file" is
consistent with --warn-symbol-ordering and less ambiguous than "symbol
file" (albeit slightly redundant).

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

llvm-svn: 331000
2018-04-26 22:25:04 +00:00
Roman Lebedev d338222a8c [LLD][WASM] Handle WASM_SYMBOL_TYPE_SECTION in toString().
Fixes build. If this is not the desired solution, please revert.
WasmSymbolType was changed in rL330982 / D44184

llvm-svn: 330984
2018-04-26 20:00:11 +00:00
Rafael Espindola 40f46bc3e6 Delete unused variable.
llvm-svn: 330978
2018-04-26 19:21:07 +00:00
Sam Clegg 2b8b179867 [WebAssembly] Add version to linking section (to match llvm-side change)
Differential Revision: https://reviews.llvm.org/D46070

llvm-svn: 330971
2018-04-26 18:17:21 +00:00
Rafael Espindola ab44b923f5 Add a comment. NFC.
llvm-svn: 330967
2018-04-26 18:03:04 +00:00
Rafael Espindola ab0cce5f1f Replace SharedSymbols with Defined when creating copy relocations.
This is slightly simpler to read IMHO. Now if a symbol has a position
in the file, it is Defined.

The main motivation is that with this a SharedSymbol doesn't need a
section, which reduces the size of SymbolUnion.

With this the peak allocation when linking chromium goes from 568.1 to
564.2 MB.

llvm-svn: 330966
2018-04-26 17:58:58 +00:00
Rafael Espindola 06cb7c8773 Simplify processRelocAux.
It returns a different Expr only in the case of creating a function
symbol pointing to its plt entry. We can just add a call to
addPltEntry to avoid that and return void.

With this patch further simplifications of how we handle copy
relocations are possible.

llvm-svn: 330960
2018-04-26 17:22:44 +00:00
Rafael Espindola f4a9d56a9a Delete GotPltIndex.
It was always an offset of PltIndex.

This doesn't reduce the size of the structures, but makes it easier to
do so in a followup patch.

llvm-svn: 330953
2018-04-26 16:09:30 +00:00
Rafael Espindola faa3b8a554 Add a test. NFC.
This would have fund a bug in a patch I am working on.

llvm-svn: 330925
2018-04-26 06:10:18 +00:00
Rui Ueyama b774c3c0e5 Simplify. NFC.
llvm-svn: 330892
2018-04-26 01:38:29 +00:00
Bob Haarman 947647d0c1 [COFF] more informative "broken object file" diagnostics
Summary:
When a symbol refers to a special section or a section that doesn't
exist, lld would fatal with "broken object file". This change gives a
different message for each scenario, and includes the name of the
file, name of the symbol, and the section being referred to.

Reviewers: pcc, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 330883
2018-04-25 23:33:19 +00:00
Rui Ueyama 5fcebff485 Remove unused features from StringRefZ and move it to Symbols.h.
Differential Revision: https://reviews.llvm.org/D46087

llvm-svn: 330879
2018-04-25 22:34:21 +00:00
Rafael Espindola 1eeb26293d Pack symbols a bit more.
Before this patch:

Symbol 56
Defined 80
Undefined 56
SharedSymbol 88
LazyArchive 72
LazyObject 56

With this patch

Symbol 48
Defined 72
Undefined 48
SharedSymbol 80
LazyArchive 64
LazyObject 48

The result is that peak allocation when linking chromium (according to
heaptrack) goes from 578 to 568 MB.

llvm-svn: 330874
2018-04-25 21:44:37 +00:00
Rafael Espindola 047f857642 Also demote lazy symbols.
This is not a big simplification right now, but the special cases for
lazy symbols have been a common source of bugs in the past.

llvm-svn: 330869
2018-04-25 20:46:08 +00:00
Hans Wennborg 03ca8f4fd0 [COFF] Don't set the tsaware bit on DLLs
It doesn't apply to DLLs, and link.exe doesn't set it.

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

llvm-svn: 330868
2018-04-25 20:32:00 +00:00
George Rimar d30a78b3fe [ELF] - Eliminate the AssertCommand.
Currently, LLD supports ASSERT as a separate command.

We support two forms now.

Assign expression-form: . = ASSERT(0x100)
(old GNU ld required it and some scripts in the wild are still using
something like . = ASSERT((_end - _text <= (512 * 1024 * 1024)), "kernel image bigger than KERNEL_IMAGE_SIZE");

Nowadays above is not a mandatory form and command-like form is commonly used:
ASSERT(<expr>, "text);

The return value of the ASSERT is Dot. That was implemented in D30171.
It looks like (2) is just a short version of (1) then.

GNU ld does *not* list ASSERT as a SECTIONS command:
https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS

Given above we probably can change ASSERT to be an assignment to Dot. 
That makes the rest of the code much simpler. Patch do that.

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

llvm-svn: 330814
2018-04-25 11:16:31 +00:00
Rafael Espindola 61376d9bed Bring r329960 back.
The fix is to copy Used when replacing the symbol.

Original message:

Do not keep shared symbols created from garbage-collected eliminated DSOs.

If all references to a DSO happen to be weak, and if the DSO is
specified with --as-needed, the DSO is not added to DT_NEEDED.
If that happens, we also need to eliminate shared symbols created
from the DSO. Otherwise, they become dangling references that point
to non-exsitent DSO.

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

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

llvm-svn: 330788
2018-04-25 00:29:13 +00:00
Bob Haarman 8832f88996 [COFF] create MemoryBuffers without requiring NUL terminators
Summary:
In a number of places in the COFF linker, we were calling
MemoryBuffer::getFile() with default parameters. This causes LLVM to
NUL-terminate the buffers, which can prevent them from being memory
mapped. Since we operate on binary and do not use NUL as an indicator
of the end of the file content, this change causes us to not require
the NUL terminator anymore.

Reviewers: ruiu, pcc

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 330786
2018-04-24 23:16:39 +00:00
Rui Ueyama ffa650a183 Style fix.
llvm-svn: 330785
2018-04-24 23:09:57 +00:00
Rafael Espindola a8d0b87f50 Add a test. NFC.
This would have found the issue in r329960.

llvm-svn: 330784
2018-04-24 23:03:58 +00:00
Sam Clegg 1bfdabacfe [WebAssembly] Match llvm-side change to reloc section header
Differential Revision: https://reviews.llvm.org/D45795

llvm-svn: 330750
2018-04-24 18:11:47 +00:00
George Rimar de83cbf37e [ELF] - Never use std::sort.
It turns out we should not use the std::sort anymore.
r327219 added a new wrapper llvm::sort (D39245).
When EXPENSIVE_CHECKS is defined, it shuffles the
input container and that helps to find non-deterministic
ordering.

Patch changes code to use llvm::sort and std::stable_sort
instead of std::sort

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

llvm-svn: 330702
2018-04-24 09:55:39 +00:00
George Rimar 19f9b814dd [ELF] - Refactor lazy symbol duplicated code.
Our code for LazyObject and LazyArchive duplicates.

This patch extracts the common part to remove
the duplication.

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

llvm-svn: 330701
2018-04-24 09:41:56 +00:00
Zachary Turner d6fce2e9db [COFF] Alias /DEBUG:FULL to /DEBUG
With MSVC linker, /DEBUG is an alias of /DEBUG:FASTLINK, and if
you don't want /DEBUG:FASTLINK you have to explicitly specify
/DEBUG:FULL.

LLD doesn't support /DEBUG:FASTLINK, and so our standard /DEBUG
option is what MSVC calls /DEBUG:FULL.  To provide command line
compatibility with MSVC, we should also support /DEBUG:FULL, and
since it's the same as what LLD already does for /DEBUG, just
alias it.

llvm-svn: 330647
2018-04-23 20:54:08 +00:00
Rui Ueyama d134d2e509 Remove duplicate "error:" from an error message.
This patch also simplifies the code a bit which wasn't committed in
https://reviews.llvm.org/r330600.

llvm-svn: 330644
2018-04-23 20:34:35 +00:00
Zaara Syeda 25b488b0ea [PPC64] Fix toc restore nops offset for V2 ABI
The PPC64 V2 ABI restores the toc base by loading from an offset of 24 from r1.
This patch fixes the offset and updates the testcases from V1 to V2. It also
issues an error when a nop is missing after a call to an external function.

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

llvm-svn: 330600
2018-04-23 15:01:24 +00:00
George Rimar 97df22f110 [ELF] - Simplify. NFC.
llvm-svn: 330597
2018-04-23 14:41:49 +00:00
Fangrui Song c8ac0a6f97 [ELF] Swap argument names: use Old to refer to original symbol and New for incoming one
Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 330491
2018-04-20 22:50:15 +00:00
Bob Haarman 8679a7ecea Fix nullptr passed to memcpy in lld/COFF/Chunks.cpp
Summary:
ubsan found that we sometimes pass nullptr to memcpy in
SectionChunk::writeTo(). This change adds a check that avoids that.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 330490
2018-04-20 22:16:09 +00:00
Peter Collingbourne c8f5c05d41 COFF: Document /pdbaltpath.
llvm-svn: 330488
2018-04-20 22:11:28 +00:00
Peter Collingbourne 9106b2becd Use /pdbaltpath to avoid a path length dependency.
llvm-svn: 330485
2018-04-20 21:54:55 +00:00
Peter Collingbourne 3d636edc56 COFF: Merge .xdata into .rdata by default.
Differential Revision: https://reviews.llvm.org/D45804

llvm-svn: 330484
2018-04-20 21:32:37 +00:00
Peter Collingbourne 326f419335 COFF: Merge .bss into .data by default.
Differential Revision: https://reviews.llvm.org/D45803

llvm-svn: 330483
2018-04-20 21:30:36 +00:00
Rui Ueyama 88fe5c9557 Add -z {combreloc,copyreloc,noexecstack,lazy,relro,text}.
Differential Revision: https://reviews.llvm.org/D45902

llvm-svn: 330482
2018-04-20 21:24:08 +00:00
Peter Collingbourne 71c7de5b77 COFF: Preserve section type when processing /section flag.
It turns out that we were dropping this before.

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

llvm-svn: 330481
2018-04-20 21:23:16 +00:00
Peter Collingbourne 381b3d8aa3 COFF: Use (name, output characteristics) as a key when grouping input sections into output sections.
This is what link.exe does and lets us avoid needing to worry about
merging output characteristics while adding input sections to output
sections.

With this change we can't process /merge in the same way as before
because sections with different output characteristics can still
be merged into one another. So this change moves the processing of
/merge to just before we assign addresses. In the case where there
are multiple output sections with the same name, link.exe only merges
the first section with the source name into the first section with
the target name, and we do the same.

At the same time I also implemented transitive merging (which means
that /merge:.c=.b /merge:.b=.a merges both .c and .b into .a).

This isn't quite enough though because link.exe has a special case for
.CRT in 32-bit mode: it processes sections whose output characteristics
are DATA | R | W as though the output characteristics were DATA | R
(so that they get merged into things like constructor lists in the
expected way). Chromium has a few such sections, and it turns out
that those sections were causing the problem that resulted in r318699
(merge .xdata into .rdata) being reverted: because of the previous
permission merging semantics, the .CRT sections were causing the entire
.rdata section to become writable, which caused the SEH runtime to
crash because it apparently requires .xdata to be read-only. This
change also implements the same special case.

This should unblock being able to merge .xdata into .rdata by default,
as well as .bss into .data, both of which will be done in followups.

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

llvm-svn: 330479
2018-04-20 21:10:33 +00:00
Sterling Augustine 7026d3bac4 Under some scenarios, the current directory isn't writable
during a test. Set the output path to avoid that problem.

llvm-svn: 330464
2018-04-20 18:45:24 +00:00
Zachary Turner 041eb6fef6 [LLD/PDB] Remove improper assert.
It's possible to have an empty object file, for example if you
just compile an empty .c file.  This file won't have any sections
so asserting that a file has chunks is definitely wrong.

llvm-svn: 330461
2018-04-20 18:36:51 +00:00
Zachary Turner 194be871b9 [LLD/PDB] Emit first section contribution for DBI Module Descriptor.
Part of the DBI stream is a list of variable length structures
describing each module that contributes to the final executable.

One member of this structure is a section contribution entry that
describes the first section contribution in the output file for
the given module.

We have been leaving this structure unpopulated until now, so with
this patch it is now filled out correctly.

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

llvm-svn: 330457
2018-04-20 18:00:46 +00:00
Nicholas Wilson 358af38d37 [WebAssembly] Implement -print-gc-sections, to better test GC of globals
Differential Revision: https://reviews.llvm.org/D44311

llvm-svn: 330456
2018-04-20 17:28:12 +00:00
Nicholas Wilson a1e299f58b [WebAssembly] Implement GC for imports
Differential Revision: https://reviews.llvm.org/D44313

llvm-svn: 330454
2018-04-20 17:18:06 +00:00
Nicholas Wilson 6c7fe30a1c [WebAssembly] Implement --print-gc-sections for synthetic functions
Enables cleaning up confusion between which name variables are mangled
and which are unmangled, and --print-gc-sections then excersises and
tests that.

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

llvm-svn: 330449
2018-04-20 17:09:18 +00:00
Fangrui Song 2416d7fcb2 [ELF] --warn-backrefs: use the same GroupId for object files in the same --{start,end}-lib
Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 330443
2018-04-20 16:33:01 +00:00
Rafael Espindola a59aacf52b Fix trap instruction on pp64.
The test was passing on a big endian host, but just because od with x4
was compensating for it.

llvm-svn: 330386
2018-04-20 01:21:24 +00:00
Fangrui Song b72daf00f4 [ELF] Increase NextGroupId with --end-group
Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 330379
2018-04-19 23:23:23 +00:00
Sam Clegg 0dbe57e752 [WebAssembly] Fix bug where reloc addends were written as unsigned
Relocation addends can be negative so should be written as
signed LEBs. This bug meant that writing value between 64
and 128 would be incorrectly interpreted as negative by the
object file readers.

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

llvm-svn: 330374
2018-04-19 22:48:03 +00:00
Rafael Espindola 991c1cd5f7 Add a test. NFC.
We have relatively few tests on the contents of non alloc
sections. This one would have found a bug in a patch I am working on.

llvm-svn: 330369
2018-04-19 21:58:28 +00:00
Peter Collingbourne be084eca5b COFF: Remove OutputSection::getPermissions() and getCharacteristics().
All callers can just access the header directly.

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

llvm-svn: 330367
2018-04-19 21:48:37 +00:00
Peter Collingbourne fa322abee9 COFF: Rename Chunk::getPermissions to getOutputCharacteristics.
In an upcoming change I will need to make a distinction between section
type (code, data, bss) and permissions. The term that I use for both
of these things is "output characteristics".

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

llvm-svn: 330361
2018-04-19 20:03:24 +00:00
Rafael Espindola 4809e2c11d Define InputSection::getOffset inline.
This is much simpler than the other section types and there are many
places where the section type is statically know.

llvm-svn: 330350
2018-04-19 18:00:46 +00:00
Rafael Espindola f4d6e8caea Simplify Repl handling.
Now that we don't ICF synthetic sections, we can go back to the old
logic on whose responsibility it is to check Repl.

The idea is that Sec->something() will not check Repl. It is the
responsibility of the caller to find the correct Sec.

llvm-svn: 330346
2018-04-19 17:26:50 +00:00
Rafael Espindola aded409325 Simplify getOffset for synthetic sections.
We had a single symbol using -1 with a synthetic section. It is
simpler to just update its value.

This is not a big will by itself, but will allow having a simple
getOffset for InputSeciton.

llvm-svn: 330340
2018-04-19 16:54:30 +00:00
Rafael Espindola 6275a7aa39 Rename MergeInputSection::getOffset.
Unlike the getOffset in the base class, this one computes the offset
in the parent synthetic section, not the final output section.

llvm-svn: 330339
2018-04-19 16:05:07 +00:00
Rafael Espindola 9c680301b0 Simplify. NFC.
Using getOffset is here was a bit of an overkill. This is being
written and has relocations. This implies it is a .eh_frame or regular
section.

llvm-svn: 330307
2018-04-19 03:51:26 +00:00
Rafael Espindola 719fcd08c6 Don't call getOffset twice. NFC.
Just a bit faster.

llvm-svn: 330306
2018-04-19 02:24:28 +00:00
Reid Kleckner 8f1a28f190 [COFF] Mark images with no exception handlers for /safeseh
Summary:
DLLs and executables with no exception handlers need to be marked with
IMAGE_DLL_CHARACTERISTICS_NO_SEH, even if they have a load config.

Discovered here when building Chromium with LLD on Windows:
https://crbug.com/833951

Reviewers: ruiu, mstorsjo

Subscribers: llvm-commits

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

llvm-svn: 330300
2018-04-18 22:37:10 +00:00
Peter Collingbourne 3108802f16 COFF: Friendlier undefined symbol errors.
Summary:
This change does three things:
- Try to find the file and line number of an undefined symbol
  reference by reading codeview debug info.
- Try to find the name of the function or global variable with the
  undefined symbol reference by searching the object file's symbol
  table.
- Prints the information in the same style as the ELF linker.

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

llvm-svn: 330235
2018-04-17 23:32:33 +00:00
Michael J. Spencer b842725c1d [ELF] Add profile guided section layout
This adds profile guided layout using the Call-Chain Clustering (C³) heuristic
from https://research.fb.com/wp-content/uploads/2017/01/cgo2017-hfsort-final1.pdf .

RFC: [llvm-dev] [RFC] Profile guided section layout
     http://lists.llvm.org/pipermail/llvm-dev/2017-June/114178.html

Pass `--call-graph-ordering-file <file>` to read a call graph profile where each
line has the format:

    <from symbol> <to symbol> <call count>

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

llvm-svn: 330234
2018-04-17 23:30:05 +00:00
Peter Collingbourne 66f1c9a858 Reland r330223, "COFF: Merge .idata, .didat and .edata into .rdata by default.", which was reverted in r330228.
In this reland I removed an unnecessary use of /debug in the test
delayimports32.test and used the /pdbaltpath flag in the test
pdb-publics-import.test, both of which avoid embedding absolute PDB
paths in executables which could affect later RVAs.

Original commit message:
> COFF: Merge .idata, .didat and .edata into .rdata by default.
>
> This saves a little space and matches what link.exe does.
>
> Tested using the chromium Windows trybots:
> https://chromium-review.googlesource.com/c/chromium/src/+/1014784

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

llvm-svn: 330233
2018-04-17 23:28:52 +00:00
Peter Collingbourne 94aa62e48a COFF: Implement /pdbaltpath flag.
I needed to revert r330223 because we were embedding an absolute PDB
path in the .rdata section, which ended up being laid out before the
.idata section and affecting its RVAs. This flag will let us control
the embedded path.

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

llvm-svn: 330232
2018-04-17 23:28:38 +00:00
Peter Collingbourne 1254f3e77c Revert r330223, "COFF: Merge .idata, .didat and .edata into .rdata by default."
Seems to have uncovered some sort of non-determinism on the bots.

llvm-svn: 330228
2018-04-17 22:16:39 +00:00
Peter Collingbourne 09e0e2e656 COFF: Merge .idata, .didat and .edata into .rdata by default.
This saves a little space and matches what link.exe does.

Tested using the chromium Windows trybots:
https://chromium-review.googlesource.com/c/chromium/src/+/1014784

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

llvm-svn: 330223
2018-04-17 21:44:31 +00:00
Peter Collingbourne 7c26663f58 llvm-pdbutil: Fix an off-by-one error.
Differential Revision: https://reviews.llvm.org/D45740

llvm-svn: 330222
2018-04-17 21:44:17 +00:00
Zachary Turner bee6c22414 [llvm-pdbutil] Dump first section contribution for each module.
The DBI stream contains a list of module descriptors.  At the
beginning of each descriptor is a structure representing the first
section contribution in the output file for that module.  LLD
currently doesn't fill out this structure at all, but link.exe
does.  So as a precursor to emitting this data in LLD, we first
need a way to dump it so that it can be checked.

This patch adds support for the dumping, and verifies via a test
that LLD emits bogus information.

llvm-svn: 330208
2018-04-17 20:06:43 +00:00
Peter Collingbourne 2f6d00612d COFF: Make SectionChunk::Relocs field an ArrayRef. NFCI.
Differential Revision: https://reviews.llvm.org/D45714

llvm-svn: 330172
2018-04-17 01:54:34 +00:00
Reid Kleckner 9c86a31307 Revert r329960 "Do not keep shared symbols created from garbage-collected eliminated DSOs."
This is causing large numbers of Chromium test executables to crash on
shutdown. The relevant symbol seems to be __cxa_finalize, which gets
removed from the dynamic symbol table for some of the support libraries.

llvm-svn: 330164
2018-04-16 22:45:23 +00:00
Zachary Turner d8d97de514 [PDB] Correctly use the target machine when writing DBI stream.
Using Config->is64() will treat ARM64 as Amd64, which is incorrect.
Furthermore, there are more esoteric architectures that could
theoretically be encountered.  Just set it directly to the machine
type, which we already know anyway.

llvm-svn: 330157
2018-04-16 20:42:06 +00:00
Zachary Turner e3fe669855 Resubmit "Fix some incorrect fields in our generated PDBs."
This fixes the failing tests.  They simply hadn't been updated
to match the new output resulting from this patch.

llvm-svn: 330145
2018-04-16 18:17:13 +00:00
Zachary Turner 52c80e3860 Revert "Fix some incorrect fields in our generated PDBs."
There are a couple of failing tests which slipped under my radar
so I'm reverting this while I attempt to fix.

llvm-svn: 330133
2018-04-16 16:55:41 +00:00
Zachary Turner 1b06cc7817 Fix some incorrect fields in our generated PDBs.
Most of these are pretty trivial and obvious. Setting the toolchain
version to 14.11 is perhaps a little questionable, but we've been bitten
in the past where one of our version fields sidn't match MSVC's, and I
definitely don't want to go through that diagnosis again as it was
pretty time consuming and hard to track down.

I found all of these by using llvm-pdbutil export to dump the dbi and
pdb streams to a file, then using fc followed by llvm-pdbutil explain to
explain the mismatched bytes.

There are still some more, these are just the low hanging fruit.

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

llvm-svn: 330130
2018-04-16 16:27:49 +00:00
Rui Ueyama 197194b6c9 Define InitLLVM to do common initialization all at once.
We have a few functions that virtually all command wants to run on
process startup/shutdown. This patch adds InitLLVM class to do that
all at once, so that we don't need to copy-n-paste boilerplate code
to each llvm command's main() function.

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

llvm-svn: 330046
2018-04-13 18:26:06 +00:00
Rafael Espindola ea2c78369c Reduce code duplication.
getVA was already implemented in the base class.

llvm-svn: 330036
2018-04-13 16:07:27 +00:00
Simon Atanasyan 1ba194212a [ELF][MIPS] Support linking of PIE for MIPS
MIPS ABI requires creation of the MIPS_RLD_MAP dynamic tag for non-PIE
executables only and MIPS_RLD_MAP_REL tag for both PIE and non-PIE
executables. The patch skips definition of the MIPS_RLD_MAP for PIE
files and defines MIPS_RLD_MAP_REL.

The MIPS_RLD_MAP_REL tag stores the offset to the .rld_map section
relative to the address of the tag itself.

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

llvm-svn: 329996
2018-04-13 08:15:01 +00:00
Rui Ueyama 039d248778 Do not keep shared symbols created from garbage-collected eliminated DSOs.
If all references to a DSO happen to be weak, and if the DSO is
specified with --as-needed, the DSO is not added to DT_NEEDED.
If that happens, we also need to eliminate shared symbols created
from the DSO. Otherwise, they become dangling references that point
to non-exsitent DSO.

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

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

llvm-svn: 329960
2018-04-12 21:57:04 +00:00
Sam Clegg 225c4697b4 [WebAssembly] Match llvm change to custom section size
Summary:
The content of custome sections no longer includes the
name itself.

See: https://reviews.llvm.org/D45579

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

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

llvm-svn: 329948
2018-04-12 20:31:35 +00:00
Sam Clegg d11b6edfc8 Remove references to old SymbolBody class
Differential Revision: https://reviews.llvm.org/D45400

llvm-svn: 329846
2018-04-11 19:52:53 +00:00
David Blaikie ad191189f0 Rename to match an LLVM change
llvm-svn: 329841
2018-04-11 18:49:41 +00:00
George Rimar c552619fc1 [ELF] - Reorder local symbols.
This fixes PR36716 (https://bugs.llvm.org/show_bug.cgi?id=36716),

Patch sorts local symbols to match the
following order: file1, local1, hidden1, file2, local2, hidden2 ...

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

llvm-svn: 329787
2018-04-11 09:24:27 +00:00
George Rimar 9f0b8e8025 [ELF] - Simplify. NFC.
llvm-svn: 329785
2018-04-11 09:03:02 +00:00
Rafael Espindola 262589db70 Don't warn on ICFed symbols, warn on synthetic ones.
Based on a patch for the ICF warning by Rui.

llvm-svn: 329757
2018-04-10 21:13:52 +00:00
Sam Clegg 80ba43872e [WebAssembly] Add support for custom sections
Copy user-defined custom sections into the output, concatenating
sections with the same name.

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

llvm-svn: 329717
2018-04-10 16:12:49 +00:00
Nico Weber fb64730005 s/LLVM_ON_WIN32/_WIN32/, lld
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in             
HandleLLVMOptions.cmake, which is where _WIN32 defined too.  Just use the        
default macro instead of a reinvented one.                                       
                                                                                 
See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev.   
No intended behavior change. 

llvm-svn: 329696
2018-04-10 13:15:21 +00:00
George Rimar e160473823 [ELF] - Do not crash when trying to order --defsym/linker script symbols.
Currently, we crash because File is null for
such symbols.

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

llvm-svn: 329678
2018-04-10 09:44:44 +00:00
Rui Ueyama e4ba9044ad Add a test for nested --start-group.
llvm-svn: 329642
2018-04-09 23:30:21 +00:00
Rui Ueyama 1d92aa7380 Add --warn-backrefs to maintain compatibility with other linkers
I'm proposing a new command line flag, --warn-backrefs in this patch.
The flag and the feature proposed below don't exist in GNU linkers
nor the current lld.

--warn-backrefs is an option to detect reverse or cyclic dependencies
between static archives, and it can be used to keep your program
compatible with GNU linkers after you switch to lld. I'll explain the
feature and why you may find it useful below.

lld's symbol resolution semantics is more relaxed than traditional
Unix linkers. Therefore,

  ld.lld foo.a bar.o

succeeds even if bar.o contains an undefined symbol that have to be
resolved by some object file in foo.a. Traditional Unix linkers
don't allow this kind of backward reference, as they visit each
file only once from left to right in the command line while
resolving all undefined symbol at the moment of visiting.

In the above case, since there's no undefined symbol when a linker
visits foo.a, no files are pulled out from foo.a, and because the
linker forgets about foo.a after visiting, it can't resolve
undefined symbols that could have been resolved otherwise.

That lld accepts more relaxed form means (besides it makes more
sense) that you can accidentally write a command line or a build
file that works only with lld, even if you have a plan to
distribute it to wider users who may be using GNU linkers.  With
--check-library-dependency, you can detect a library order that
doesn't work with other Unix linkers.

The option is also useful to detect cyclic dependencies between
static archives. Again, lld accepts

  ld.lld foo.a bar.a

even if foo.a and bar.a depend on each other. With --warn-backrefs
it is handled as an error.

Here is how the option works. We assign a group ID to each file. A
file with a smaller group ID can pull out object files from an
archive file with an equal or greater group ID. Otherwise, it is a
reverse dependency and an error.

A file outside --{start,end}-group gets a fresh ID when
instantiated. All files within the same --{start,end}-group get the
same group ID. E.g.

  ld.lld A B --start-group C D --end-group E

A and B form group 0, C, D and their member object files form group
1, and E forms group 2. I think that you can see how this group
assignment rule simulates the traditional linker's semantics.

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

llvm-svn: 329636
2018-04-09 23:05:48 +00:00
Peter Collingbourne bdfa127c3e COFF: Remove dead code. NFCI.
Differential Revision: https://reviews.llvm.org/D45423

llvm-svn: 329609
2018-04-09 19:46:00 +00:00
Rumeet Dhindsa 682a417e51 Added support for LTO options: sample_profile, new_pass_manager and debug_pass_manager
Differential Revision: https://reviews.llvm.org/D45275

llvm-svn: 329598
2018-04-09 17:56:07 +00:00
George Rimar aeb7e305b8 [ELF] - Simplify test case. NFC.
llvm-svn: 329563
2018-04-09 13:13:36 +00:00
George Rimar 0029f21482 [ELF] - Stop setting OutSecOff too early.
Currently LLD sets OutSecOff in addSection for input sections.
That is a fake offset (just a rude approximation to remember the order), 
used for sorting SHF_LINK_ORDER sections
(see resolveShfLinkOrder, compareByFilePosition).

There are 2 problems with such approach:

1. We currently change and reuse Size field as a value assigned. Changing size is
not good because leads to bugs. Currently, SIZEOF(.bss) for empty .bss returns 2
because we add two empty synthetic sections and increase size twice by 1. 
(See PR37011: https://bugs.llvm.org/show_bug.cgi?id=37011)

2. Such approach simply does not work when --symbol-ordering-file is involved,
because processing of the ordering file might break the initial section order.

This fixes PR37011.

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

llvm-svn: 329560
2018-04-09 13:01:50 +00:00
George Rimar 9bc20fff4a [ELF] - Fix cref.s test case.
The intention of -gc-sections flag was to check
that discarded is not in the output. It should be
specified in the executable command line invocation
and also, the symbol must be global as local symbols
are anyways not printed.

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

llvm-svn: 329559
2018-04-09 12:45:29 +00:00
George Rimar 7bf92be676 [ELF] - Allow LLD to produce file symbols.
This is for PR36716 and
this enables emitting STT_FILE symbols.

Output size affect is minor:
lld binary size changes from 52,883,408 to 52,949,400
clang binary size changes from 83,136,456 to 83,219,600

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

llvm-svn: 329557
2018-04-09 11:43:52 +00:00
Aaron Smith c3b5515e51 [tests] Fix format-binary-non-ascii.s to work with Python 3 on Windows
Some platforms interpret the pound sign as one character. Platforms that use 
Python 2.x actually interpret it as two characters because in the Python 2.x 
version of lit, the string used for the file name is a byte string and the pound 
sign is two bytes.

Patch by Stella Stamenova!

llvm-svn: 329472
2018-04-07 00:55:26 +00:00
Peter Collingbourne 4902508934 COFF: Process /merge flag as we create output sections.
With this we can merge builtin sections.

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

llvm-svn: 329471
2018-04-07 00:46:55 +00:00
Rafael Espindola b4d3dfefb7 Avoid some temporary allocations.
Some system libraries have a lot of versioned symbols. When linking
scylla this brings the number of malloc calls from 49154 to 37944.

llvm-svn: 329453
2018-04-06 20:53:06 +00:00
Benjamin Kramer d726d04f45 [ELF] Don't write to the source directory in test.
llvm-svn: 329384
2018-04-06 10:05:47 +00:00
Rafael Espindola 3bd98b1031 Change which file we print when a symbol cannot be ordered.
Currently there are a few odd things about the warning about symbols
that cannot be ordered. This patch fixes:

* When there is an undefined symbol that resolves to a shared file, we
  were printing the location of the undefined reference.

* If there are multiple comdats, we were reporting them all.

llvm-svn: 329371
2018-04-06 03:36:19 +00:00
Peter Collingbourne f2c0f39b91 COFF: Create output sections early. NFCI.
With this, all output sections are created in one place. This will make
it simpler to implement merging of builtin sections.

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

llvm-svn: 329370
2018-04-06 03:25:49 +00:00
Rafael Espindola 9b6a65b144 Don't ignore addend when a SHF_MERGE section is dead.
This is similar to r329219, but for the entire section. Like r329219 I
don't expect this to have any real impact, it is just more consistent
and simpler.

llvm-svn: 329367
2018-04-06 01:10:33 +00:00
Rui Ueyama 96ba8befa9 [WebAssembly] Remove StackPointerGlobal member variable from the driver.
Since InputGlobal makes a copy of a given object, we can use a temporary
object allocated on the stack here.

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

llvm-svn: 329337
2018-04-05 19:37:48 +00:00
Rui Ueyama ac95bb1d52 [WebAssembly] Remove another trivial accessor.
Differential Revision: https://reviews.llvm.org/D43725

llvm-svn: 329336
2018-04-05 19:37:31 +00:00
Fangrui Song c43eff6208 [ELF] Add CHECK to test/ELF/undef-start.s
llvm-svn: 329333
2018-04-05 19:20:33 +00:00
Rui Ueyama 4e150c4c88 Make "Size" column in the map file one characters shorter.
Previously, "size" column is 9 characters long which is too long
at least for 32-bit (because at maximum it needs 8 columns). This
patch make it one column shorter than before. That's also a reasonable
default for 64-bit.

llvm-svn: 329317
2018-04-05 17:20:18 +00:00
Rui Ueyama 16a130bc78 Fix column size in the map file.
Size can be narrow, but LMA should be the same width as VMA.

llvm-svn: 329312
2018-04-05 16:45:37 +00:00
Rafael Espindola 5f8e77afb5 Initialize OutputOff to zero.
We have a dedicated Live bit, so we don't need a special value and we
were not accounting for in at least one place.

llvm-svn: 329307
2018-04-05 15:56:04 +00:00
Eugene Leviant 57225ac179 [ELF] Don't add NOLOAD sections to segment
Differential revision: https://reviews.llvm.org/D45264

llvm-svn: 329281
2018-04-05 13:23:59 +00:00
George Rimar f9936e1fc9 [ELF] - Eliminate Target::isPicRel method.
As was mentioned in comments for D45158,
isPicRel's name does not make much sense,
because what this method does is checks if
we need to create the dynamic relocation or not.

Instead of renaming it to something different,
we can 'isPicRel' completely.

We can reuse the getDynRel method.
They are logically very close, getDynRel can just return
R_*_NONE in case no dynamic relocation should be produced
and that would simplify things and avoid functionality
correlation/duplication with 'isPicRel'.

The patch does this change.

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

llvm-svn: 329275
2018-04-05 12:07:20 +00:00
George Rimar e88b76a989 [ELF] - Reveal more information in -Map file about assignments.
Currently, LLD print symbol assignment commands to the map file,
but it does not do that for assignments that are outside of the section
descriptions. Such assignments can affect the layout though.

The patch implements the following:

* Teaches LLD to print symbol assignments outside of section declaration.
* Teaches LLD to print PROVIDE/HIDDEN/PROVIDE hidden commands.

In case when symbol is not provided, nothing will be printed.

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

llvm-svn: 329272
2018-04-05 11:25:58 +00:00
George Rimar ee01b1d390 [ELF] - Print LMA in a -Map file.
Currently, LLD prints VA, but not LMA in a map file.
It seems can be useful to print both to reveal layout
details and patch implements it.

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

llvm-svn: 329271
2018-04-05 10:51:06 +00:00
Rafael Espindola 7bd45502fe Initialize OffsetMap earlier.
Now that getSectionPiece uses OffsetMap, it is advantageous to
initialize it earlier.

llvm-svn: 329242
2018-04-05 00:01:57 +00:00
Rui Ueyama 5a9529f4a2 Do not show alignment 0 because that is equivalent to 1.
Differential Revision: https://reviews.llvm.org/D44991

llvm-svn: 329233
2018-04-04 21:25:37 +00:00
Peter Collingbourne 05f0bae318 COFF: Sort non-discardable sections at the same time as other sections. NFC.
This makes the sort order a little clearer.

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

llvm-svn: 329227
2018-04-04 20:30:37 +00:00
Hans Wennborg 2a6943ca14 Fix the test some more after r329221
llvm-svn: 329224
2018-04-04 19:55:45 +00:00
Hans Wennborg e6cf0a3d9f Fix test after r329221
It seems I accidentally overspecified the section size in my previous
commit, whereas it was previously carefully left out.

llvm-svn: 329222
2018-04-04 19:36:27 +00:00
Hans Wennborg 9a9fc78744 COFF: Layout sections in the same order as link.exe
One place where this seems to matter is to make sure the .rsrc section comes
after .text. The Win32 UpdateResource() function can change the contents of
.rsrc. It will move the sections that come after, but if .text gets moved, the
entry point header will not get updated and the executable breaks. This was
found by a test in Chromium.

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

llvm-svn: 329221
2018-04-04 19:15:55 +00:00
Rafael Espindola f7c5a10e55 Don't ignore addend in getOffset.
We were ignoring the addend if the piece was dead. I don't expect this
to make a difference in any real world situations, but it is simpler
anyway.

llvm-svn: 329219
2018-04-04 19:13:30 +00:00
George Rimar 785a79133b [ELF] - X86_64: Use white list for relocations checked by isPicRel.
isPicRel is used to check if we want to create the dynamic relocations.
Not all of the dynamic relocations we create are passing through this
check, but those that are, probably better be whitelisted.

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

llvm-svn: 329203
2018-04-04 15:21:21 +00:00
George Rimar 55d717805b [ELF] - Use early return. NFC.
llvm-svn: 329180
2018-04-04 12:36:21 +00:00
George Rimar 4d2740c6ed [ELF] - Cleanup. NFCI.
Rename field, added comments.

This is splitted from the D44894. 
Requested to be committed as independent cleanup.

llvm-svn: 329162
2018-04-04 09:39:05 +00:00
George Rimar 94e148c830 [ELF] - Rename checkSectionOverlap() to checkSections(). NFC.
Renaming was requested in post commit review for D43820.

llvm-svn: 329159
2018-04-04 09:24:31 +00:00
George Rimar 4f98e0bc03 [ELF] - Revert r329060 "Simplify createFiles. NFCI."
Was requested during post commit review.

llvm-svn: 329155
2018-04-04 08:13:28 +00:00
Rui Ueyama 20b3423715 Fix manifestinput-error.test on Windows 10.
Patch by Alexandre Ganea.

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

llvm-svn: 329132
2018-04-03 23:12:28 +00:00
Rui Ueyama 90f13ed0e4 Return early. NFC.
llvm-svn: 329126
2018-04-03 22:39:12 +00:00
Rui Ueyama d35b839c3f Merge two `if`s and add a few blank lines. NFC.
llvm-svn: 329125
2018-04-03 22:39:04 +00:00
Rui Ueyama 265dbe4666 Inline a small test file.
llvm-svn: 329124
2018-04-03 22:38:56 +00:00
Rafael Espindola 6cd7af51e1 Inline initOffsetMap.
In the lld perf builder r328686 had a negative impact in
stalled-cycles-frontend. Somehow that stat is not showing on my
machine, but the attached patch shows an improvement on cache-misses,
which is probably a reasonable proxy.

My working theory is that given a large input the pieces vector is out
of cache by the time initOffsetMap runs.

Both finalizeContents implementation have a convenient location for
initializing the OffsetMap, so this seems the best solution.

llvm-svn: 329117
2018-04-03 21:38:18 +00:00
Rui Ueyama c6bf37d56d Instead of using std::copy, clear the vector first and add new elements. NFC.
Differential Revision: https://reviews.llvm.org/D45227

llvm-svn: 329107
2018-04-03 20:08:45 +00:00
Peter Collingbourne bca630bd61 ELF: Use a vector of pairs to sort sections ordered using --symbol-ordering-file.
This improved performance by 0.5-1% linking Chromium for Android.

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

llvm-svn: 329106
2018-04-03 19:45:10 +00:00
Rui Ueyama 61b67abe89 Fix buildbots.
r329092 broke buildbots.

llvm-svn: 329103
2018-04-03 18:59:31 +00:00
Rafael Espindola 03d7a1bc46 Add a test for an issue fixed in r329092.
We were setting IsUsedInRegularObj in lazy symbols only used from IR.

llvm-svn: 329101
2018-04-03 18:35:46 +00:00
Rui Ueyama cc013f62c1 Make fetchIfLazy only fetch an object file. NFC.
Previously, fetchIfLazy did more than the name says. Now, setting
to UsedInRegularObj is moved to another function.

llvm-svn: 329092
2018-04-03 18:01:18 +00:00
Bob Haarman 8c63bafdd3 [lld] fix data race in ELF/ICF.cpp
Summary:
r328610 fixed a data race in the COFF linker. This change makes a
similar fix to the ELF linker.

Reviewers: ruiu, pcc, rnk

Reviewed By: ruiu

Subscribers: emaste, llvm-commits, arichardson

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

llvm-svn: 329088
2018-04-03 17:27:39 +00:00
George Rimar 1ef746ba21 [ELF] - Eliminate Lazy class.
Patch removes Lazy class which
is just an excessive layer.

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

llvm-svn: 329086
2018-04-03 17:16:52 +00:00
George Rimar 1fc9f39bd5 [ELF] - Check that output sections fit in address space.
Added checks to test that we do not produce
output where VA of sections overruns the address
space available.

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

llvm-svn: 329063
2018-04-03 12:39:28 +00:00
George Rimar 8fcd04b786 [ELF] - Fix the comment. NFC.
llvm-svn: 329062
2018-04-03 12:28:53 +00:00
George Rimar bc1d58a6b1 [ELF] - Relax checks for R_386_8/R_386_16 relocations.
This fixes PR36927.

The issue is next. Imagine we have -Ttext 0x7c and code below.

.code16
.global _start
_start:
movb $_start+0x83,%ah

So we have R_386_8 relocation and _start at 0x7C.
Addend is 0x83 == 131. We will sign extend it to 0xffffffffffffff83.

Now, 0xffffffffffffff83 + 0x7c gives us 0xFFFFFFFFFFFFFFFF.
Techically 0x83 + 0x7c == 0xFF, we do not exceed 1 byte value, but
currently LLD errors out, because we use checkUInt<8>.

Let's try to use checkInt<8> now and the following code to see if it can help (no):
main.s:
.byte foo

input.s:
.globl foo
.hidden foo
foo = 0xff

Here, foo is 0xFF. And addend is 0x0. Final value is 0x00000000000000FF.
Again, it fits one byte well, but with checkInt<8>,
we would error out it, so we can't use it.

What we want to do is to check that the result fits 1 byte well.
Patch changes the check to checkIntUInt to fix the issue.

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

llvm-svn: 329061
2018-04-03 12:19:04 +00:00
George Rimar bfbeecdc5d [ELF] - Simplify createFiles. NFCI.
Groups paired options together.

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

llvm-svn: 329060
2018-04-03 12:06:29 +00:00
George Rimar c6735c23d2 [ELF] - X86_64: don't allow 8/16 bit dynamic relocations.
Having 8/16 bits dynamic relocations is incorrect.

Both gold and bfd (built from latest sources) disallow
that too.

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

llvm-svn: 329059
2018-04-03 11:58:23 +00:00
George Rimar 624e163f53 [ELF] - Remove dead declaration. NFC.
llvm-svn: 329058
2018-04-03 10:40:39 +00:00
Rafael Espindola 95f8d303ab Use OffsetMap in getSectionPiece.
OffsetMap maps to a SectionPiece index, but we were not taking
advantage of that in getSectionPiece.

With this patch both getOffset and getSectionPiece use OffsetMap and
the binary search is moved to findSectionPiece.

llvm-svn: 329044
2018-04-03 04:06:14 +00:00
Rui Ueyama 24a47201fd Merge LazyArchive::fetch() and ArchiveFile::getMember(). NFC.
They are to pull out an object file for a symbol, but for a historical
reason the code is written in two separate functions. This patch
merges them.

llvm-svn: 329039
2018-04-03 02:06:57 +00:00
Rui Ueyama 7d6131a898 Inline two trivial functions that are called only once. NFC.
llvm-svn: 329034
2018-04-02 23:58:50 +00:00
Rafael Espindola 3e7d6fc2c6 Define TrapInst for ppc64.
This is nice for testing since it is the first TrapInst whose bytes
are not all the same.

llvm-svn: 329014
2018-04-02 21:11:13 +00:00
Sean Fertile 227d4399bf [PPC64] Minor changes for Plt relocations.
The Plt relative relocations are R_PPC64_JMP_SLOT in the V2 abi, and we only
reserve 2 double words instead of 3 at the start of the array of PLT entries for
lazy linking.

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

llvm-svn: 329006
2018-04-02 19:47:21 +00:00
Sean Fertile af95629deb [PPC64] Write plt stubs for ElfV2 abi
Add the default version of a plt stub for the V2 Elf abi.

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

llvm-svn: 329004
2018-04-02 19:17:12 +00:00
Sean Fertile 6bf3fe124e [PPC] Add a test for toc-relative access on ppc64le.
Adds a simple test for accessing a local global variable in the ElfV2 abi.
Checks that the toc base used is the expected offset from the .TOC. symbol,
and that the offsets for the global are calculated relative to the toc base.

llvm-svn: 328982
2018-04-02 15:42:07 +00:00
George Rimar 5b31b6f12d [ELF] - cref.s: check that we print symbols from archives. NFCI.
This is consistent with bfd and we already supported it,
though test did not contain the explicit check.

llvm-svn: 328967
2018-04-02 11:28:44 +00:00
Fangrui Song ef61d85fc9 [ELF] Simplify read32. NFC
llvm-svn: 328908
2018-03-30 23:13:00 +00:00
Peter Collingbourne 5ea6d50af1 ELF: Place ordered sections in the middle of the unordered section list on targets with limited-range branches.
It generally does not matter much where we place sections ordered
by --symbol-ordering-file relative to other sections. But if the
ordered sections are hot (which is the case already for some users
of --symbol-ordering-file, and is increasingly more likely to be
the case once profile-guided section layout lands) and the target
has limited-range branches, it is beneficial to place the ordered
sections in the middle of the output section in order to decrease
the likelihood that a range extension thunk will be required to call
a hot function from a cold function or vice versa.

That is what this patch does. After D44966 it reduces the size of
Chromium for Android's .text section by 60KB.

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

llvm-svn: 328905
2018-03-30 21:36:54 +00:00
Rumeet Dhindsa 7588a8e89d Initialize Elf Header to zero to ensure that bytes not assigned any value later on are initialized properly.
Differential Revision: https://reviews.llvm.org/D44986

llvm-svn: 328902
2018-03-30 20:49:34 +00:00
Peter Collingbourne 5e3ee94562 ELF: Try to create last thunk section at ThunkSectionSpacing bytes before the end.
Now that we have the ability to create short thunks, it is beneficial
for thunk sections to be surrounded by ThunkSectionSpacing bytes
of code on both sides in order to increase the likelihood that the
distance from the thunk to the target will be sufficiently small to
allow for the creation of a short thunk. This is currently the case
for most thunks that we create, except for the last one, which could,
depending on the size of the output section, potentially appear near
the end and therefore have a relatively small amount of code after it.

This patch moves the last thunk section to ThunkSectionSpacing bytes
before the end of the output section, as long as the section is larger
than 2*ThunkSectionSpacing bytes. It reduces the size of Chromium
for Android's .text section by 32KB.

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

llvm-svn: 328889
2018-03-30 18:32:24 +00:00
Rui Ueyama 5f8c3e85aa Fix Windows buildbots.
llvm-svn: 328882
2018-03-30 17:49:51 +00:00
Rui Ueyama 5aab635e10 Improve error message for an unknown --plugin-opt.
Before:

  $ ld.lld --plugin-opt=-foo
  ld.lld: --Unknown command line argument '-abc'

After:

  $ ld.lld --plugin-opt=-foo
  ld.lld: --plugin-opt: ld.lld --Unknown command line argument '-abc'

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

llvm-svn: 328880
2018-03-30 17:22:44 +00:00
Nico Weber a764379458 [lld-link] Add comment explaining that /FIXED behavior is correct despite contradicting MSDN.
Also add a test for /FIXED.
https://reviews.llvm.org/D45087

llvm-svn: 328879
2018-03-30 17:17:04 +00:00
Nico Weber 0945ad6643 [lld-link] Let /PROFILE imply /OPT:REF /OPT:NOICF /INCREMENTAL:NO /FIXED:NO
/FIXED:NO is always the default, so that part needs no work.

Also test the interaction of /ORDER: with /INCREMENTAL.

https://reviews.llvm.org/D45091

llvm-svn: 328877
2018-03-30 17:14:50 +00:00
Rui Ueyama 0961218c10 [WebAssembly] Error if both --export-table and --import-table are specified.
Differential Revision: https://reviews.llvm.org/D45001

llvm-svn: 328873
2018-03-30 16:06:14 +00:00
Nico Weber 8ee3b06f82 Simplify test more.
llvm-svn: 328863
2018-03-30 13:48:11 +00:00
Nico Weber 4fb8799f74 Simplify test.
As of rL215127, FileCheck has an -allow-empty flag,
so this could be used instead of writing a dummy line.
But it looks like the log is never empty now, so not
even that is needed.

llvm-svn: 328862
2018-03-30 13:44:15 +00:00
Rui Ueyama 5a67a6ec4a Re-implement --just-symbols as a regular object file.
I tried a few different designs to find a way to implement it without
too much hassle and settled down with this. Unlike before, object files
given as arguments for --just-symbols are handled as object files, with
an exception that their section tables are handled as if they were all
null.

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

llvm-svn: 328852
2018-03-30 01:15:36 +00:00
Peter Collingbourne 4653b0021e Add missing REQUIRES: arm.
llvm-svn: 328847
2018-03-29 23:08:32 +00:00
Peter Collingbourne 015d30c807 ELF: Add support for short thunks on ARM.
A short thunk uses a direct branch (b or b.w) instruction, and is used
when the target has the same thumbness as the thunk and is within
direct branch range (32MB for ARM, 16MB for Thumb-2). Reduces the
size of Chromium for Android's .text section by around 160KB.

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

llvm-svn: 328846
2018-03-29 22:43:52 +00:00
Rui Ueyama f001ead490 Do not use template for check{Int,UInt,IntUInt,Alignment}.
Template is just unnecessary.

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

llvm-svn: 328843
2018-03-29 22:40:52 +00:00
Peter Collingbourne c5391ce51e ELF: Allow thunks to change size. NFCI.
Differential Revision: https://reviews.llvm.org/D44962

llvm-svn: 328841
2018-03-29 22:32:13 +00:00