Commit Graph

10392 Commits

Author SHA1 Message Date
Rui Ueyama ba32e739b2 Remove GnuHashTableSection::getShift2().
Choosing a Shift2 value based on wordsize is cargo-culted from gold.
Assuming that djb hash is a good hash function, choosing bits [4,9]
shouldn't be any worse or better than choosing bits [5,10]. We shouldn't
have copied that behavior that we can't justify in the first place.

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

llvm-svn: 327921
2018-03-19 23:04:13 +00:00
Rui Ueyama 048a669b92 allow-multiple-definitions should completely suppress errors instead of making them warnings.
We found that when you pass --allow-multiple-definitions or `-z muldefs`
to GNU linkers, they don't complain about duplicate symbols at all. They
don't even print out warnings on it. We emit warnings in that case.
If you pass --fatal-warnings, that difference results in a link failure.

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

llvm-svn: 327920
2018-03-19 23:04:04 +00:00
Zachary Turner a21558897b Revert "Support embedding natvis files in PDBs."
This is causing a test failure on a certain bot, so I'm removing
this temporarily until we can figure out the source of the error.

llvm-svn: 327903
2018-03-19 20:41:59 +00:00
Zachary Turner de53aaf132 Support embedding natvis files in PDBs.
Natvis is a debug language supported by Visual Studio for
specifying custom visualizers.  The /NATVIS option is an
undocumented link.exe flag which will take a .natvis file
and "inject" it into the PDB.  This way, you can ship the
debug visualizers for a program along with the PDB, which
is very useful for postmortem debugging.

This is implemented by adding a new "named stream" to the
PDB with a special name of /src/files/<natvis file name>
and simply copying the contents of the xml into this file.

Additionally, we need to emit a single stream named
/src/headerblock which contains a hash table of embedded
files to records describing them.

This patch adds this functionality, including the /NATVIS
option to lld-link.

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

llvm-svn: 327895
2018-03-19 19:53:51 +00:00
Zaara Syeda 52ed6eb8d9 [ELF] Add basic support for PPC LE
This patch adds changes to start supporting the Power 64-Bit ELF V2 ABI.
This includes:
- Changing the ElfSym::GlobalOffsetTable to be named .TOC.
- Creating a GotHeader so the first entry in the .got is .TOC.
- Setting the e_flags to be 1 for ELF V1 and 2 for ELF V2

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

llvm-svn: 327871
2018-03-19 17:40:14 +00:00
Peter Smith 3d044f57d4 [ELF] Recommit 327248 with Arm using the .got for _GLOBAL_OFFSET_TABLE_
This is the same as 327248 except Arm defining _GLOBAL_OFFSET_TABLE_ to
be the base of the .got section as some existing code is relying upon it.

For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be at
the start of the .got.plt section so that _GLOBAL_OFFSET_TABLE_[0] =
reserved value that is by convention the address of the dynamic section.
Previously we had defined _GLOBAL_OFFSET_TABLE_ as either the start or end
of the .got section with the intention that the .got.plt section would
follow the .got. However this does not always hold with the current
default section ordering so _GLOBAL_OFFSET_TABLE_[0] may not be consistent
with the reserved first entry of the .got.plt.

X86, X86_64 and AArch64 will use the .got.plt. Arm, Mips and Power use .got

Fixes PR36555

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

llvm-svn: 327823
2018-03-19 06:52:51 +00:00
Shoaib Meenai 290f26fefd [COFF] Clarify comment. NFC
Reid pointed out the string table for supporting long section names is a
BFD extension and the comments should reflect that. Explicitly spell out
link.exe's and binutil's behavior around section names and the rationale
for LLD's behavior.

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

llvm-svn: 327736
2018-03-16 20:20:01 +00:00
Peter Collingbourne 5c902845e5 Revert r327248, "For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be at"
This change broke ARM code that expects to be able to add
_GLOBAL_OFFSET_TABLE_ to the result of an R_ARM_REL32.

I will provide a reproducer on llvm-commits.

llvm-svn: 327688
2018-03-16 01:01:44 +00:00
Rui Ueyama aa92fca83c Fix linker script operator precedence.
"&" should have higher priority than "|" [1]. Previously, they had
the same priority.

[1] https://sourceware.org/binutils/docs/ld/Operators.html

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

llvm-svn: 327684
2018-03-15 23:12:33 +00:00
Peter Collingbourne f1a11f87a0 COFF: Implement string tail merging.
In COFF, duplicate string literals are merged by placing them in a
comdat whose leader symbol name contains a specific prefix followed
by the hash and partial contents of the string literal. This gives
us an easy way to identify sections containing string literals in
the linker: check for leader symbol names with the given prefix.

Any sections that are identified in this way as containing string
literals may be tail merged. We do so using the StringTableBuilder
class, which is also used to tail merge string literals in the ELF
linker. Tail merging is enabled only if ICF is enabled, as this
provides a signal as to whether the user cares about binary size.

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

llvm-svn: 327668
2018-03-15 21:14:02 +00:00
Peter Collingbourne 435b099115 COFF: Move assignment of section RVAs to assignAddresses(). NFCI.
This makes the design a little more similar to the ELF linker and
should allow for features such as ARM range extension thunks to be
implemented more easily.

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

llvm-svn: 327667
2018-03-15 21:13:46 +00:00
Rui Ueyama 8e53917a26 Add a comment about ELF spec and the symbol table's sh_info.
llvm-svn: 327645
2018-03-15 17:10:50 +00:00
George Rimar 211e94d666 [ELF] - Fix build bot after rL327612.
Missed this one.

llvm-svn: 327616
2018-03-15 09:40:25 +00:00
George Rimar 76f1c78dea [ELF] - Simplify test case. NFCI.
llvm-svn: 327614
2018-03-15 09:26:08 +00:00
George Rimar 61a1f50b39 [ELF] - Fix build bot after rL327612.
Error was: 
error: field 'Size' will be initialized after field 'CommandString' [-Werror,-Wreorder]

llvm-svn: 327613
2018-03-15 09:24:51 +00:00
George Rimar 84bcabcb86 [ELF] - Show data and assignment commands in the map file.
Patch teaches LLD to print BYTE/SHORT/LONG/QUAD and
location move commands to the map file.

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

llvm-svn: 327612
2018-03-15 09:16:40 +00:00
Rumeet Dhindsa 14c3a871be Update Error Message
Summary: Updates error message  for dynamic relocation attempt for read only segments.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, javed.absar, arichardson, llvm-commits

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

llvm-svn: 327584
2018-03-14 22:05:12 +00:00
Nicholas Wilson ca5cc20e51 [WebAssembly] Fix -Werror=extra failure due to enum in ternary
llvm-svn: 327579
2018-03-14 21:43:04 +00:00
Rui Ueyama a5c1ed340f [ELF] Add .eh_frame pieces to map file
This patch is a simplified version of https://reviews.llvm.org/D42960
written by Andrew Ng.

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

llvm-svn: 327574
2018-03-14 21:18:18 +00:00
Reid Kleckner 19454f1a9d [COFF] Fix LLD COFF tests as a follow-up to r327563
I definitely didn't run the tests before committing :(

Most of these tests failed because the LLD map file output changed,
moving the functions from the main text section to a new per-function
section.

ICF also started to fire in a few cases, leading to new layouts.

llvm-svn: 327571
2018-03-14 20:41:39 +00:00
Martin Storsjo af841d113c [test] Fix a temp filename in a test from SVN r327561. NFC.
An earlier file name accidentally slipped through into the committed
version.

llvm-svn: 327567
2018-03-14 20:31:31 +00:00
Rui Ueyama db46a62e2b Implement --cref.
This is an option to print out a table of symbols and filenames.
The output format of this option is the same as GNU, so that it can be
processed by the same scripts as before after migrating from GNU to lld.

This option is mildly useful; we can live without it. But it is pretty
convenient sometimes, and it can be implemented in 50 lines of code, so
I think lld should support this option.

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

llvm-svn: 327565
2018-03-14 20:29:45 +00:00
Reid Kleckner 8364901f24 [COFF] Enable per-function and data sections in LTO
Summary: This allows post-LTO symbol reordering and ICF.

Reviewers: inglorion

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 327563
2018-03-14 20:25:41 +00:00
Martin Storsjo fb36e6e82c [MinGW] Add support for the GNU ld flag --kill-at
llvm-svn: 327562
2018-03-14 20:17:24 +00:00
Martin Storsjo 5351891b55 [COFF] Add support for the GNU ld flag --kill-at
GNU ld has got a number of different flags for adjusting how to
behave around stdcall functions. The --kill-at flag strips the
trailing sdcall suffix from exported functions (which otherwise
is included by default in MinGW setups).

This also strips it from the corresponding import library though.
That makes it hard to link to such an import library from code
that calls the functions - but this matches what GNU ld does with
this flag. Therefore, this flag is probably not sensibly used
together with import libraries, but probably mostly when creating
some sort of plugin, or if creating the import library separately
with dlltool.

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

llvm-svn: 327561
2018-03-14 20:17:16 +00:00
Reid Kleckner 36f678b48a [wasm] Fix wasm lld test on Windows, where the executable name ends in .exe
llvm-svn: 327560
2018-03-14 19:49:57 +00:00
Reid Kleckner 850b610cc5 [COFF] Add integration test for LTO + /guard:cf
This tests that LLVM emits the relocations that /guard:cf needs to
identify address taken.

This was PR36624, which was fixed in r327557.

llvm-svn: 327559
2018-03-14 19:49:28 +00:00
Rui Ueyama 4e6b822cdc Separate sentences to clarify a comment.
llvm-svn: 327555
2018-03-14 19:01:00 +00:00
Rafael Espindola e2cc92ce28 Error instead of producing broken binary.
This "fixes" PR36678 by just producing an error when we find a case
where we would produce an plt entry that used ebx but ebx would not be
set.

llvm-svn: 327542
2018-03-14 18:08:33 +00:00
Rafael Espindola 74acdfa691 Reduce code duplication a bit.
The code for computing the offset of an entry in the plt is simple,
but it was duplicated in quite a few places.

llvm-svn: 327536
2018-03-14 17:41:34 +00:00
Nicholas Wilson 3e3f5fb3a3 [WebAssembly] Use DenseMapInfo traits from LLVM repo. NFC
Differential Revision: https://reviews.llvm.org/D44150

llvm-svn: 327527
2018-03-14 15:58:16 +00:00
Nicholas Wilson c4d9aa1b5f [WebAssembly] Avoid COMDAT hashmap lookup for each symbol. NFC
This reduces the number of lookups to one per COMDAT group, rather than
one per symbol in a COMDAT group.

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

llvm-svn: 327523
2018-03-14 15:45:11 +00:00
Nicholas Wilson 2eb39c137f [WebAssembly] Add missing implementation for --initial/max-memory args
Previously, Config->InitialMemory/MaxMemory were hooked up to some
commandline args but had no effect at all.

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

llvm-svn: 327508
2018-03-14 13:53:58 +00:00
Nicholas Wilson a06a355095 [WebAssembly] Replace varargs debugPrint with standard log call
Differential Revision: https://reviews.llvm.org/D44441

llvm-svn: 327507
2018-03-14 13:50:20 +00:00
Pavel Labath fe9922f8af Fix build broken by llvm r327486
llvm::DWARFFormParams moved to llvm::dwarf::FormParams.

llvm-svn: 327489
2018-03-14 09:57:52 +00:00
George Rimar 2ab9362bf5 [ELF] - Never create .gnu_hash with NBuckets == 0.
Currently, we can end up with NBuckets==0 and android loader
does not like it (PR36537).

Seems we can go with a minimal amount of changes here for simplicity
and be consistent with gold and so just always use >= 1 value for NBuckets.

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

llvm-svn: 327481
2018-03-14 08:52:39 +00:00
George Rimar 271ed6eb0d [ELF] - Convert overlapping-sections.s testcase to x86 and cleanup.
Patch do the following changes:

* Test case was converted from MIPS to x86.

* Removed part of the test checking we are able to produce a valid output.
  Since we do that already in other tests, this one's intention should be
  only to check we are still able to report overlaps and/or produce
  broken output with overlaps.

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

llvm-svn: 327480
2018-03-14 07:44:23 +00:00
Sam Clegg 37fbfc6815 [WebAssembly] Fix expected contents of relocations with addends
This fixes issues found on the wasm waterfall related to relocations
with addends. Undefined symbols, even those with addends should
always have a provisional value of zero. At least this is what llvm
emits (and I believe this is true for ELF too).

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

llvm-svn: 327468
2018-03-14 00:53:34 +00:00
George Rimar b9f4b70f20 [ELF} - Fix build bots.
llvm-svn: 327419
2018-03-13 16:23:48 +00:00
George Rimar b7288836ca [ELF] - Fix mistype in comment. NFC.
llvm-svn: 327417
2018-03-13 16:11:02 +00:00
George Rimar f95e7c6f7a [ELF] - Rename test cases to *.test.
This is a follow-up for r327410.

llvm-svn: 327416
2018-03-13 16:02:45 +00:00
George Rimar cfd2c97008 [ELF] - Represent tests as linker scripts instead of asm.
This follows recently started direction and sometimes
allows to fully get rid from `echo` calls.

I'll rename changed files to *.test in a follow-up.

llvm-svn: 327410
2018-03-13 15:47:14 +00:00
Nicholas Wilson 531769b9f9 [WebAssembly] Demangle symbol names for use by the browser debugger
Differential Revision: https://reviews.llvm.org/D44316

llvm-svn: 327392
2018-03-13 13:30:04 +00:00
Nicholas Wilson 88d9ffc973 [WebAssembly] Use helper macro from ELF/Options.td to tidy. NFC
Differential Revision: https://reviews.llvm.org/D44394

llvm-svn: 327391
2018-03-13 13:16:15 +00:00
Nicholas Wilson 08cff61572 [WebAssembly] Add missing --demangle arg
Previously, Config->Demangle was uninitialised (not hooked up to
commandline handling)

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

llvm-svn: 327390
2018-03-13 13:12:03 +00:00
George Rimar 796684b451 [ELF] - Implement INSERT BEFORE.
This finishes PR35877.

INSERT BEFORE used similar to INSERT AFTER,
it inserts sections before the given target section.

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

llvm-svn: 327378
2018-03-13 09:18:11 +00:00
George Rimar ebc1d1fdde [ELF] - Fix wrong "REQUIRES" in test.
Its a follow up for r327374 to fix BB.

llvm-svn: 327377
2018-03-13 08:50:36 +00:00
George Rimar 2313086726 [ELF] - Restrict section offsets that exceeds file size.
This is part of PR36515.

With some linkerscripts it is possible to get file offset overlaps
and overflows. Currently LLD checks overlaps in checkNoOverlappingSections().
And also we allow broken output with --no-inhibit-exec.
Problem is that sometimes final offset of sections is completely broken
and we calculate output file size wrong and might crash.

Patch implements check to verify that there is no output section
which offset exceeds file size.

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

llvm-svn: 327376
2018-03-13 08:47:17 +00:00
George Rimar afbf90aef9 [ELF] - Drop special flags for empty output sections.
This fixes PR36598.

LLD currently crashes when we have empty output section
with SHF_LINK_ORDER flag. This might happen if we place an 
empty synthetic section in the linker script, but keep output
section alive with the use of additional symbol, for example.

The patch fixes the issue by dropping all special flags
for empty sections.

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

llvm-svn: 327374
2018-03-13 08:32:56 +00:00
Rafael Espindola 33a2836307 Use PLT relocations in test.
Currently lld creates plain plt entries when a R_386_PC32 resolves to
a symbol in a shared library. That is a bug (PR36678). Don't depend on
that behavior on this test.

llvm-svn: 327357
2018-03-13 01:41:49 +00:00