Commit Graph

9035 Commits

Author SHA1 Message Date
Rafael Espindola be28c2e4a5 Add --gc-sections to a test.
This shows that the logic in --gc-sections is a bit more precise than
what can be easily done in LTO.

llvm-svn: 309234
2017-07-26 23:47:24 +00:00
Rafael Espindola 4b075bb218 Make __start_sec __end_sec handling more precise.
With this we only ask LTO to keep a C named section if there is a
__start_ or __end symbol.

This is not as strict as lld's --gc-sections, but is as good as we can
get without having a far more detailed ir summary.

llvm-svn: 309232
2017-07-26 23:39:10 +00:00
Nico Weber 268f89d540 lld: /manifestuac:no shouldn't disable /manifestdependency:
Matches link.exe
https://reviews.llvm.org/D35872

llvm-svn: 309231
2017-07-26 23:38:10 +00:00
Rui Ueyama e1b48e099c Rename ObjectFile ObjFile for COFF as well.
llvm-svn: 309228
2017-07-26 23:05:24 +00:00
Rafael Espindola 6c4f5b41a3 Fix the name of the section end symbol.
It is __stop_<sec>, not __end_<sec>.

llvm-svn: 309225
2017-07-26 22:52:53 +00:00
Rui Ueyama 709fb2bb10 Rename ObjectFile -> ObjFile.
Rename it because it was too easy to conflict with llvm::object::ObjectFile
which broke buildbots several times.

llvm-svn: 309199
2017-07-26 22:13:32 +00:00
Meador Inge b0e6229742 [ELF, LinkerScript] Memory region name parsing fix
This patch fixes a small issue with respect to how memory region names
are parsed on output section descriptions.  For example, consider:

  .text : { *(.text) } > rom

That can also be written like:

  .text : { *(.text) } >rom

The latter form is accepted by GNU LD and is fairly common.

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

llvm-svn: 309191
2017-07-26 21:51:09 +00:00
Rui Ueyama 3e96f1167c Attempt to fix buildbots.
llvm-svn: 309188
2017-07-26 21:37:11 +00:00
Rui Ueyama 23f64d229b Remove unnecessary namespace specifier.
I believe this compiles fine on all platforms, even on Windows.

llvm-svn: 309182
2017-07-26 21:24:01 +00:00
Martin Storsjo 38608c0975 [COFF, ARM64] Handle ADRP immediate offsets in relocations
Also handle overflow correctly in LDR/STR relocations. Even if the
offset range of a 8 byte LDR instruction is 15 bit (even if the immediate
itself is 12 bit) due to a 3 bit shift, only include up to 12 bits of offset
after doing the relocation, by limiting the range of the immediate by the
number of shifted bits.

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

llvm-svn: 309175
2017-07-26 20:51:47 +00:00
Rafael Espindola aaa8e433ad Try to fix the windows build.
llvm-svn: 309162
2017-07-26 19:57:40 +00:00
Rafael Espindola b4b485370c Try to fix the windows build.
llvm-svn: 309161
2017-07-26 19:39:40 +00:00
Rafael Espindola bf991405de Try to fix the windows build.
llvm-svn: 309160
2017-07-26 19:37:58 +00:00
Rafael Espindola a5e8dd35b0 Simplify. NFC.
llvm-svn: 309153
2017-07-26 18:47:49 +00:00
Rafael Espindola 244ef98161 Detemplate SymbolTable.
NFC, just makes it easier to access from non templated code.

llvm-svn: 309152
2017-07-26 18:42:48 +00:00
George Rimar d5948f3a9a [ELF] - Ignore --warn-once option.
Was discussed in D35797 thread.

llvm-svn: 309096
2017-07-26 10:25:49 +00:00
George Rimar 84941ef158 [ELF] - Change way how we handle --noinhibit-exec
Previously we handled this option implicitly, only
for infering unresolved symbols handling policy.

ld man says: "--noinhibit-exec Retain the executable
output file whenever it is still usable",
and we may want to handle other cases too.

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

llvm-svn: 309091
2017-07-26 09:46:59 +00:00
George Rimar 6977ec6899 [ELF] - Print options aliases in --help
This is PR30422,
previously LLD did not render all option aliases in --help.
With this patch it will.

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

llvm-svn: 309089
2017-07-26 09:21:10 +00:00
Rui Ueyama 8109789a33 Simplify ignored options.
Since the flag is ignored anyway, it doesn't matter whether
it is an alias or not.

llvm-svn: 309055
2017-07-25 23:32:05 +00:00
Rafael Espindola cb83c8c85f Simplify. NFC.
llvm-svn: 309053
2017-07-25 23:23:40 +00:00
Rafael Espindola d4fbe4fe82 Reduce templating. NFC.
llvm-svn: 309051
2017-07-25 23:15:35 +00:00
Rafael Espindola affe7209c0 LTO: Handle sections with valid C names.
These can be referenced with __start_/__stop_ symbols. I will try to make
this more precise in a followup patch.

llvm-svn: 309048
2017-07-25 22:51:05 +00:00
Martin Storsjo 82eaf6cb50 [COFF] Add support for delay loading DLLs on ARM
Differential Revision: https://reviews.llvm.org/D35768

llvm-svn: 309017
2017-07-25 20:00:37 +00:00
Nico Weber 578363ac08 Attempt to fix lld tests on Windows after 308998.
The test used /manifestinput: without /manifest:embed, which isn't actually
supported.  Just remove this part of the test for now; if it's important to
check this the llvm-readobj part should be extended to check this.

llvm-svn: 309002
2017-07-25 18:39:38 +00:00
Nico Weber a7a2c44e70 lld: only write .manifest files if /manifest is passed, PR33925
Also emit an error if /manifestinput: is used without /manifest:embed.
Increases compatibility with link.exe

https://reviews.llvm.org/D35842

llvm-svn: 308998
2017-07-25 18:08:03 +00:00
George Rimar 4c351c6540 [ELF] - Fix init_fini_priority.s test.
Previously .init_array/.fini_array sections
were not unique and we had 3 .init_array sections +
3 .fini_array input sections passed to linker,
instead of 5 + 5.

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

llvm-svn: 308958
2017-07-25 09:26:35 +00:00
George Rimar f694d33f4c [ELF] - Fix calculation of memory region offset.
This is PR33714.

Previously for each input section offset of memory region
was incremented on a size of output section.

That resulted in a wrong error message saying about
overflow. Patch fixes that.

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

llvm-svn: 308955
2017-07-25 08:29:29 +00:00
Martin Storsjo 405b5bcc36 [COFF] Correctly set the thumb bit in DLL export addresses
The same adjustment is already done for the entry point in
Writer.cpp and for relocations that point to executable code
in Chunks.cpp.

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

llvm-svn: 308953
2017-07-25 06:10:44 +00:00
Martin Storsjo 25712667cb [COFF] Add a test for producing DLLs and import libraries for ARM64
This is a test for LLVM SVN r308951.

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

llvm-svn: 308952
2017-07-25 06:08:25 +00:00
Rafael Espindola dc49af9d32 Make a function static. NFC.
llvm-svn: 308939
2017-07-24 23:55:33 +00:00
Tom Stellard 1d70d75f46 Fix ObjCPass on big-endian host
Summary:
This fixes test/mach-o/objc-image-info-pass-output.yaml on
big-endian hosts.

Reviewers: lhames, kledzik, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 308935
2017-07-24 23:13:31 +00:00
Dmitry Mikulin 97d6a80895 If user requested section alignment is greater than MaxPageSize, propagate it to segment headers correctly.
Differential Revision: https://reviews.llvm.org/D35813

llvm-svn: 308930
2017-07-24 21:27:02 +00:00
Davide Italiano 0a26c5738d [ELF] Fix a typo introduced in r308915.
Thanks to Rafael for finding it in a post-commit review.

llvm-svn: 308921
2017-07-24 20:18:16 +00:00
Davide Italiano 957f1206e9 [LTO] Make sure symbol ordering is honoured also for data.
Follow-up to r308915 suggested by Rafael and Peter.

llvm-svn: 308920
2017-07-24 20:15:07 +00:00
Davide Italiano 4deb97c377 [ELF] Fix a couple of typos in a test.
llvm-svn: 308916
2017-07-24 19:42:13 +00:00
Davide Italiano 1f4e29c71d [LTO] Make sure symbol ordering is honoured.
We do this emitting a section for every function when LTO is used.
Fixes PR33888.

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

llvm-svn: 308915
2017-07-24 19:38:13 +00:00
Rafael Espindola fae04ae44c Handle a section being more aligned than a page size.
llvm-svn: 308812
2017-07-22 00:17:57 +00:00
Rafael Espindola ca5740d95a Don't crash on an empty section with an ALIGN.
llvm-svn: 308809
2017-07-22 00:00:51 +00:00
Rui Ueyama 8940102671 Fix a test breakage caused by r308752.
llvm-svn: 308775
2017-07-21 20:15:46 +00:00
George Rimar 4f37d57547 [ELF] - Introduce multiclass Eq helper for Options.td
Eq helper allows to define `XXX` and `XXX=` options forms easily.
Patch adds testcases for few aliases.

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

llvm-svn: 308752
2017-07-21 16:27:26 +00:00
Igor Kudrin 7d2b15a7ab [ELF] Avoid data race in ObjectFile<ELFT>::getDILineInfo().
Differential Revision: https://reviews.llvm.org/D35537

llvm-svn: 308728
2017-07-21 11:26:08 +00:00
Petr Hosek 8b591f592b [ELF] Remove processNonSectionCommands
This method is no longer being used anywhere.

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

llvm-svn: 308706
2017-07-21 01:02:30 +00:00
Petr Hosek 039fb8c296 [ELF] Align the value if needed when computing the expression
Also add the test cases for the addition and subtraction both for
the relative and absolute case.

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

llvm-svn: 308692
2017-07-20 23:11:47 +00:00
Kevin Enderby b4c351dfd1 lld matching change for llvm change r308690 to add error handling to
the dyld compact export entries in libObject.

llvm-svn: 308691
2017-07-20 23:09:19 +00:00
Rui Ueyama 800cd3ec40 Add a missing tool dependency.
This dependency was introduced in r308681.

llvm-svn: 308686
2017-07-20 22:39:31 +00:00
Rafael Espindola 2bd185bcde Fix symbol type with icf.
We were not looking at Repl and so thinking there was no output
section associated with the merged symbol. Because of that it was
produced as absolute.

This was found by an internal round of testing.

llvm-svn: 308681
2017-07-20 21:55:40 +00:00
Rui Ueyama bc2c9e0278 Do not strip SHF_GROUP in elf::decompressAndMergeSections().
SHF_GROUP flag should have been removed when the control reaches here
because InputSectionBase turns the flag off. So this code should be
redundant.

llvm-svn: 308680
2017-07-20 21:42:30 +00:00
Rui Ueyama 875ae82b0b Add the --chroot option for --reproduce.
Summary:
If the linker is invoked with `--chroot /foo` and `/bar/baz.o`, it
tries to read the file from `/foo/bar/baz.o`. This feature is useful
when you are dealing with files created by the --reproduce option.

Reviewers: grimar

Subscribers: llvm-commits, emaste

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

llvm-svn: 308646
2017-07-20 18:17:55 +00:00
Rafael Espindola 4b1008af73 Add test from pr33173.
It was fixed by r308544.

llvm-svn: 308634
2017-07-20 17:14:52 +00:00
Martin Storsjo 5ae7649a4e [COFF] Support 128 bit SIMD/FP ldr/str in IMAGE_REL_ARM64_PAGEOFFSET_12L
Also extend the tests for IMAGE_REL_ARM64_PAGEOFFSET_12L to test
all 8/16/32/64 bit GPR and 8/16/32/64/128 SIMD/FP bit ldr/str variants,
and a ldr with an existing offset.

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

llvm-svn: 308631
2017-07-20 16:48:33 +00:00
Martin Storsjo dd62dffbcb [COFF] Minor tweaks to ARM64 relocation code. NFC.
Fix issues found in existing code, while reviewing other changes.

Change the data type of a variable to uint32_t, to avoid potential issues
with signedness in shifts.

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

llvm-svn: 308586
2017-07-20 05:49:58 +00:00
Martin Storsjo b3c97b9623 [COFF] Align import address chunks to the pointer size
This fixes cases on ARM64 when importing from more than one DLL,
in case the imports from the first DLL ended up unaligned.

When fixing up a IMAGE_REL_ARM64_PAGEOFFSET_12L, which shifts the
offset by the load/store size, check that the shift doesn't discard
any bits. (This would also detect if the import address chunks were
unaligned.)

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

llvm-svn: 308585
2017-07-20 05:49:54 +00:00
Rafael Espindola 8b1afd59c3 Speed up gdb index creation.
With that in place we can use lld's own infrastructure for the low
level detail of dwarf parsing.

With this we don't decompress sections twice, we don't scan all
realocations and even with this simplistic implementation linking
clang with gdb index goes from 34.09 seconds to 20.80 seconds.

llvm-svn: 308544
2017-07-19 22:27:35 +00:00
Rui Ueyama 0deaacb95a Call StringRef::contains only once for each StringRef.
llvm-svn: 308529
2017-07-19 21:49:01 +00:00
Rui Ueyama 12234f8093 Use StringRef::contains().
llvm-svn: 308526
2017-07-19 21:40:26 +00:00
Rui Ueyama 7eaf3d4b31 Fix one more occurrence of getOption().getID().
llvm-svn: 308523
2017-07-19 21:06:46 +00:00
Rui Ueyama 38b0f4a1f2 Handle option aliases in a better way.
In this way, we don't need to know which options have aliases.

llvm-svn: 308519
2017-07-19 20:30:04 +00:00
Rafael Espindola aca2afcc55 Don't depend on these symbols being implicitly global.
This might change in llvm-mc and it is nice to be explicit in a test.

llvm-svn: 308506
2017-07-19 18:24:38 +00:00
Reid Kleckner d91ca7666f [PDB] Emit TPI and IPI hashes
llvm-svn: 308497
2017-07-19 17:26:07 +00:00
Rafael Espindola 3ddf2110d5 Bring back r307364.
In addition this includes a change to prefer symbols with a default
version @@ over unversioned symbols.

Original commit message:

[ELF] - Handle symbols with default version early.

This fixes last testcase provided in PR28414.
In short issue is next: when we had X@@Version symbol in object A,
we did not resolve it to X early. Then when in another object B
we had reference to undefined X, symbol X from archive was fetched.
Since both archive and object A contains another symbol Z, duplicate
symbol definition was triggered as a result.

Correct behavior is to use X@@Version from object A instead and do not fetch
any symbols from archive.

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

llvm-svn: 308492
2017-07-19 16:45:05 +00:00
Hans Wennborg 884e84533d Clear release notes for 6.0.0
llvm-svn: 308475
2017-07-19 14:09:52 +00:00
Hans Wennborg 7e9b4784a6 Bump docs version to 6.0
llvm-svn: 308463
2017-07-19 13:47:08 +00:00
Saleem Abdulrasool 2334adeb02 test: remove duplicated test
This test is folded into implib-name.  Don't bother with the racy test.
The use of %T results in left-overs from previous tests which write out
the same import library as this test.

llvm-svn: 308409
2017-07-19 02:39:00 +00:00
Saleem Abdulrasool ace2fa7da4 COFF: improve link conformance for import names
Improve the link conformance for the import name embedded into the
import library.  This requires the associated change to the LLVM portion
for the DEF file parser.  The import file generation embeds a different
name based on whether the driver is invoked as "link" or "lib".
Furthermore, the LIBRARY keyword in the DEF file influences the import
name.  The behaviour can be summarised according to the following table:

      | LIBRARY w/ ext |   LIBRARY w/o ext   | no LIBRARY
 -----+----------------+---------------------+------------------
 LINK | {value}        | {value}.{.dll/.exe} | {output name}
  LIB | {value}        | {value}.dll         | {output name}.dll

llvm-svn: 308407
2017-07-19 02:01:27 +00:00
Rafael Espindola 2b84fa418b Make the test more precise.
The real issue was the missing explicit versions.

llvm-svn: 308391
2017-07-18 23:26:16 +00:00
Rafael Espindola 483506562c Add a test for PR33820.
This would have found the issue.

llvm-svn: 308389
2017-07-18 22:52:44 +00:00
Saleem Abdulrasool 08c83ea0f3 test: add COFF test for library extension handling
Ensure that an extension other than .dll, .exe is preserved as per the
behaviour of link.

llvm-svn: 308386
2017-07-18 22:25:07 +00:00
Rafael Espindola a4148c6eed Fix REQUIRES line.
llvm-svn: 308385
2017-07-18 22:14:26 +00:00
Rafael Espindola afbb7be6d5 Fix a crash.
This is PR33821.

What we really want to check in here is if the output section was
created, not if the command was empty.

llvm-svn: 308382
2017-07-18 21:46:27 +00:00
Rui Ueyama ede4c7ecbc Fix errors in r308335 and add "REQUIRES: x86" to one more file.
llvm-svn: 308339
2017-07-18 18:51:43 +00:00
Jon Chesterfield e0ca2ff070 [LLD] Mark a number of x86 only tests to require x86
Noticed while testing for an out of tree target. There are probably more tests that should be so marked.
I'm not sure who owns these tests so I've added a few names I recognise from the recent history.

With advice from probinson, ruiu, rafael and dramatically improved by davidb. Thank you all!

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

llvm-svn: 308335
2017-07-18 18:40:50 +00:00
Shoaib Meenai 9a61a791ac [COFF] Accept discarded relocations in DWARF debug sections
DWARF debug sections can also contain relocations against symbols in
discared segments. LLD should accept such relocations.

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

llvm-svn: 308315
2017-07-18 15:11:05 +00:00
George Rimar b939d32f53 [ELF] - Fix member name: alignment -> Alignment. NFC.
llvm-svn: 308300
2017-07-18 11:59:19 +00:00
George Rimar 67c60727ce [ELF] - Apply clang-format. NFC.
llvm-svn: 308297
2017-07-18 11:55:35 +00:00
Reid Kleckner f8522d81c3 Fix pdb-type-server-simple test on non-Windows
Assume that the LF_TYPESERVER2 record contains Windows-style paths.  In
any case, 'sys::path::filename(Path, Style::windows)' will work on
Unix-style paths.

llvm-svn: 308241
2017-07-18 00:33:53 +00:00
Rui Ueyama 0e0369e535 Revert r307364: [ELF] - Handle symbols with default version early.
This reverts commit r307364 because that change is likely to have
caused https://bugs.llvm.org/show_bug.cgi?id=33820.

llvm-svn: 308239
2017-07-18 00:33:14 +00:00
Reid Kleckner 651db91c2d [PDB] Merge in types and items from type servers (/Zi)
Summary:
Object files compiled with /Zi emit type information into a type server
PDB. The .debug$S section will contain a single TypeServer2Record with
the absolute path and GUID of the type server. LLD needs to load the
type server PDB and merge all types and items it finds in it into the
destination PDB.

Depends on D35495

Reviewers: ruiu, inglorion

Subscribers: zturner, llvm-commits

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

llvm-svn: 308235
2017-07-18 00:21:25 +00:00
Reid Kleckner 67653ee086 [codeview] Fix YAML for LF_TYPESERVER2 by hoisting PDB_UniqueId
Summary:
We were treating the GUIDs in TypeServer2Record as strings, and the
non-ASCII bytes in the GUID would not round-trip through YAML.

We already had the PDB_UniqueId type portably represent a Windows GUID,
but we need to hoist that up to the DebugInfo/CodeView library so that
we can use it in the TypeServer2Record as well as in PDB parsing code.

Reviewers: inglorion, amccarth

Subscribers: llvm-commits, hiraditya

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

llvm-svn: 308234
2017-07-17 23:59:44 +00:00
Rui Ueyama 8d8916d1dd Fix tests for .ctors/.dtors.
They are supposed to contain pointers, so .byte wasn't quite right.

llvm-svn: 308214
2017-07-17 20:42:52 +00:00
Reid Kleckner a842cd75e2 [codeview] Remove TypeServerHandler and PDBTypeServerHandler
Summary:
Instead of wiring these through the CVTypeVisitor interface, clients
should inspect the CVTypeArray before visiting it and potentially load
up the type server's TPI stream if they need it.

No tests relied on this functionality because LLD was the only client.

Reviewers: ruiu

Subscribers: mgorny, hiraditya, zturner, llvm-commits

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

llvm-svn: 308212
2017-07-17 20:28:06 +00:00
Shoaib Meenai e1d7776c53 [ELF] Use stable_sort for compareByFilePosition
The comment at the top of compareByFilePosition indicates that it relies
on stable_sort to preserve the order of synthetic sections. We were
using sort instead of stable_sort, however, leading to incorrect
synthetic section ordering.

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

llvm-svn: 308207
2017-07-17 19:42:19 +00:00
Peter Smith a49442f323 [ELF] Introduce target specific inBranchRange() function
In preparation for range extension thunks introduce a function that will
check whether a branch identified by a relocation type at a source address
can reach a destination.

For targets where range extension thunks are not supported the function will
return true as it is not expected that branches are out of range. An
implementation has been provided for ARM.

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

llvm-svn: 308188
2017-07-17 16:54:29 +00:00
George Rimar dae8495faf [ELF] - Stop listing version-script= form as ignored option.
Funny but we list it as ignored for about 1.5 years atm,
though LLD started to support version script really long time ago.

llvm-svn: 308170
2017-07-17 10:15:15 +00:00
George Rimar f525c928cf [ELF] - Implement filter library support (-F / --filter)
This is PR33766.

-F name
--filter=name
When creating an ELF shared object, set the internal DT_FILTER field to the specified name. This tells the dynamic linker that the symbol table of the shared object which is being created should be used as a filter on the symbol table of the shared object name.

If you later link a program against this filter object, then, when you run the program, the dynamic linker will see the DT_FILTER field. The dynamic linker will resolve symbols according to the symbol table of the filter object as usual, but it will actually link to the definitions found in the shared object name. Thus the filter object can be used to select a subset of the symbols provided by the object name.
(https://linux.die.net/man/1/ld).

Shared Objects as Filters:
https://docs.oracle.com/cd/E19683-01/817-3677/chapter4-31738/index.html

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

llvm-svn: 308167
2017-07-17 09:43:18 +00:00
Reid Kleckner af88a910fd [CodeView] Dump BuildInfoSym and ProcSym type indices
I need to print the type index in hex so that I can match it in
FileCheck for a test I'm writing.

llvm-svn: 308107
2017-07-15 18:10:39 +00:00
Rafael Espindola 3eb2bb1a28 Avoid using OutputSections::Sections.
This code runs after clearOutputSections.

llvm-svn: 308066
2017-07-14 22:26:16 +00:00
Rafael Espindola 72385ba53a Pass OutputSectionCommand to getOSThunkSec. NFC.
llvm-svn: 308057
2017-07-14 21:37:10 +00:00
Rafael Espindola e8b087c7e4 Pass OutputSectionCommand to forEachExecInputSection's callback.
NFC, just makes the OutputSectionCommand available.

llvm-svn: 308056
2017-07-14 21:33:14 +00:00
George Rimar b444efb939 [ELF] - Update testcases after LLVM update. (D35351)
llvm-svn: 308034
2017-07-14 16:00:34 +00:00
George Rimar 638e8a405d [ELF] - Remove dependency on precompiled inputs from -gdb-index testcases.
Previously we used precompiled objects in gdb-index.s and
debug-gnu-pubnames.s testcases. We can avoid that.

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

llvm-svn: 308005
2017-07-14 08:26:44 +00:00
Igor Kudrin 202a9f6817 [ELF] Fix writing the content of the .got section in a wrong place.
In filling the .got sections, InputSection::OutSecOff was added twice
when finding the position to apply a relocation: first time in
InputSection::writeTo() and then in SectionBase::getOffset().

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

llvm-svn: 308003
2017-07-14 08:10:45 +00:00
Shoaib Meenai e7ecbbcd62 [lld] Update Windows support docs
The /appcontainer flag was added in r299728, and the lib.exe dependency
for creating import libraries was removed in r275242. Update the docs
accordingly.

The PDB support also needs updating, but I'll leave that for someone
who's more familiar with the current status (probably rnk).

llvm-svn: 307998
2017-07-14 04:05:39 +00:00
Peter Collingbourne b069a36f27 ELF: Exclude dead symbols from -Map output.
This was previously erroring out if one of the dead symbols was a
TLS symbol and we were able to discard all TLS sections.

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

llvm-svn: 307984
2017-07-14 00:31:56 +00:00
Peter Collingbourne 3e2abdef02 ELF: Reword a somewhat misleading error message.
PT_TLS is a type of program header, so we wouldn't expect to see
one in an object file. This error should probably be referring to
the fact that we didn't see a section with the flag SHF_TLS, which
would normally cause us to create a PT_TLS program header.

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

llvm-svn: 307983
2017-07-14 00:22:46 +00:00
Reid Kleckner 0faf6d7beb [PDB] Put LLD's PDB writing code in a class NFC
Summary:
We've accumulated about five or so data structures that are widely
referenced:
- PDBBuilder
- Type table
- Id table
- PDB string table
- Type server handler

I'm about to rewrite type server handling, and I need a new class in LLD
where I can put its state. By creating a new PDBLinker class, I hope to
put it there next.

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 307979
2017-07-14 00:14:58 +00:00
Rui Ueyama 1e77ad1456 Move feature-specific functions out of Strings.cpp.
Functions declared in Strings.h should provide generic string operations
for the linker, but some of them are too specific to some features. This
patch moves them to the location where they are used.

llvm-svn: 307949
2017-07-13 20:30:35 +00:00
Reid Kleckner 3b8acb2c5a [COFF] Bounds check relocations
Summary:
This would have caught the invalid object file I used in my test case in
r307726. The OOB was only caught by ASan later, which is slow and
doesn't work on some platforms. LLD should do some basic input
validation itself. This check isn't perfect, so relocations can reach
OOB by up to seven bytes, but it's better than what we had and probably
cheap.

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 307948
2017-07-13 20:29:59 +00:00
Reid Kleckner 6597c28d76 [PDB] Fix type server handling for archives
Summary:
This fixes type indices for SDK or CRT static archives. Previously we'd
try to look next to the archive object file path, which would not exist
on the local machine.

Also error out if we can't resolve a type server record. Hypothetically
we can recover from this error by discarding debug info for this object,
but that is not yet implemented.

Reviewers: ruiu, amccarth

Subscribers: aprantl, hiraditya, llvm-commits

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

llvm-svn: 307946
2017-07-13 20:12:23 +00:00
Rafael Espindola 300b38678c Refactor gdb index creation.
I have a patch to let DwarfContext defer to lld for getting section
contents and relocations.

That is a pretty big performance improvement.

This is just a refactoring to make that easier to do.

This change makes the *creation* of gdb index a dedicated step and
makes that templated. That is so that we can uses Elf_Rel in the code.

llvm-svn: 307867
2017-07-12 23:56:53 +00:00
Reid Kleckner 03b5baf480 Re-land "[PDB] Use a more appropriate message for a fatal error"
This re-commits r307726 with valid line table relocations.

llvm-svn: 307829
2017-07-12 18:49:43 +00:00
Adrian McCarthy a6c21919d0 Temporary fix to green up the build bots on behalf of zturner who's on vacation.
llvm-svn: 307823
2017-07-12 18:10:02 +00:00
Rafael Espindola d3fc0c91e3 Bring back InVersionScript.
We were producing bogus warnings without it.

llvm-svn: 307820
2017-07-12 17:49:17 +00:00
George Rimar 8c804d9746 [ELF] - Allow moving location counter backward in some cases.
Patch removes restriction about moving location counter
backwards outside of output sections declarations.

That may be useful for some apps relying on such scripts, 
known example is linux kernel.

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

llvm-svn: 307794
2017-07-12 14:50:25 +00:00
George Rimar 3e8a461bdf [ELF] - Give a symbol version extracted from name a priority over version set by script.
This fixes PR33712.

Imagine following script and code:

VER1 { global: foo; local: *; };
VER2 { global: foo; };

.global bar
bar:
.symver bar, foo@VER1

.global zed
zed:
.symver zed, foo@@VER2

We add foo@@VER2 as foo to symbol table, because have to resolve references to
foo for default symbols.
Later we are trying to assign symbol versions from script. For that we are searching for 'foo'
again. Here it is placed under VER1 and VER2 at the same time, we find it twice and trying to
set version again both times, hence LLD shows a warning.
Though sample code is correct: we have 2 different versions of foo.

Patch gives a symbol version extracted from name a priority over version set by script.

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

llvm-svn: 307792
2017-07-12 13:54:42 +00:00
George Rimar d92e1286ed [ELF] - Fix handling of weak symbols from static library when using version script.
When version script was used, binding opf undefined weak symbols sometimes
was calculated as STB_LOCAL, making them non-preemtible what
broke correct relocations handling logic for them.

Fixes PR33738.

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

llvm-svn: 307767
2017-07-12 11:09:46 +00:00
Vitaly Buka e970c2b706 Revert "[PDB] Use a more appropriate message for a fatal error"
Revert "[PDB] Tweak bad type index error handling"

check-lld with asan detects use-after-poison.

This reverts commits r307733 and r307726.

llvm-svn: 307752
2017-07-12 04:34:17 +00:00
Rui Ueyama 106179a257 Remove redundant newline.
llvm-svn: 307750
2017-07-12 01:43:01 +00:00
Reid Kleckner 992263c14e [PDB] Use a more appropriate message for a fatal error
llvm-svn: 307733
2017-07-11 23:44:51 +00:00
Rafael Espindola a69df6f843 Update now that the llvm-mc bug is fixed.
llvm-svn: 307728
2017-07-11 22:56:51 +00:00
Reid Kleckner 2bf9ab2d62 [PDB] Tweak bad type index error handling
Translate invalid type indices to a sentinel value instead of skipping
the record. Skipping records isn't a good recovery method, because we
can skip a scope open or close record, which will confuse the scope
management code.

We currently have lots of invalid type indices on Microsoft-provided
standard libraries, because the LF_TYPESERVER2 records contain absolute
paths that are only valid on their build servers. Our type server
handlers need to look at other things (GUIDs) to find these type server
PDBs.

llvm-svn: 307726
2017-07-11 22:37:50 +00:00
Rui Ueyama 9a1898768f Remove unnecessary local variable.
llvm-svn: 307703
2017-07-11 20:33:04 +00:00
Rafael Espindola da8a47ab01 Delete redundant InVersionScript field.
Thanks to Rui for the suggestion.

llvm-svn: 307690
2017-07-11 18:59:45 +00:00
George Rimar 4a9cfc8267 [ELF] - Fix functionality treating IFunc definitions in DSOs as functions.
It was intially implemented in D19517 but then broken.
Patch fixes PR33707, testcase is based on PR's case.

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

llvm-svn: 307652
2017-07-11 11:40:59 +00:00
Peter Smith c1ace40bf9 [ELF] Add comment to explain LinkerScript::CurAddressState [NFC]
r307367 via D34345 split out the temporary address state used within
processCommands() and assignAddresses(). Due to the way that getSymbolValue
is used by the ScriptParser there is no way of giving the current
OutputSection to getSymbolValue() without somehow accessing the created
addressState. The suggestion was that by making a pointer that would go out
of scope we would find out by ASAN/MSAN or a crash if someone had misused
currentAddressState.

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

llvm-svn: 307637
2017-07-11 09:28:27 +00:00
Martin Storsjo 2779165d8c [COFF] Add initial support for some ARM64 relocations and import thunks
This is enough to link a working hello world executable, with
a call to an imported function, a string constant passed to
the imported function, and loads from a global variable.

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

llvm-svn: 307629
2017-07-11 07:22:44 +00:00
Zachary Turner 7eaf1d96ad [lld/pdb] Create an empty public symbol record stream.
This is part of the continuing effort to increase parity between
LLD and MSVC PDBs.  link still doesn't like our PDBs, so the most
obvious thing to check was whether adding an empty publics stream
would get it to do something else.  It still fails in the same way
but at least this removes one more variable from the equation.
The next logical step would be to try creating an empty globals
stream.

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

llvm-svn: 307598
2017-07-10 22:40:20 +00:00
Zachary Turner 77f23b9c21 Fix pdb-linker-module test on linux.
lld-link is apparently a symlink to lld.  Our pdb writing code
uses llvm::sys::fs::getMainExecutable() and writes that value
into the PDB, which will resolve symlinks etc.  But what we
really want is the exact value of argv[0], which matches what
the MS linker does.  Fix this by just writing argv[0] instead
of calling getMainExecutable.

llvm-svn: 307592
2017-07-10 21:09:11 +00:00
Zachary Turner 6708e0b45e [lld/pdb] Add some basic linker module symbols.
Differential Revision: https://reviews.llvm.org/D35152

llvm-svn: 307590
2017-07-10 21:01:37 +00:00
Zachary Turner a9d944fd6f Resubmit "Add pdb-diff test."
This was originally reverted because of two issues.
  1) Printing ANSI color escape codes even when outputting to
     a file
  2) Module name comparisons were failing when comparing a PDB
     generated on one machine to a PDB generated on another
     machine.

I attempted to fix #2 by adding command line options which let
you specify prefixes to strip from the beginning of embedded
paths, which effectively lets us specify a path to "base" each
PDB from and only compare the parts under the base.  But this is
tricky because PDB paths always use Windows path syntax, even
when they are created on non-Windows hosts.  A problem still
existed when constructing the prefix to strip, where we were
accidentally using a host-specific path separator instead of
a Windows path separator.

This resubmission fixes the issue on Linux (and I have verified
that the test now passes on Linux).

llvm-svn: 307571
2017-07-10 19:16:49 +00:00
Zachary Turner ba3836bc78 Revert "Build fixes for pdb-diff test."
This reverts commit 180af3fdbdb17ec35b45ec1f925fd743b28d37e1.

This is still breaking due to linux-specific path differences.

llvm-svn: 307559
2017-07-10 17:32:47 +00:00
Zachary Turner 6da7a3058e Fix pdb-diff test.
A test was checked in on Friday that worked by checking in an
object file and PDB generated locally by MSVC, and then having
the test run lld-link on the object file and diffing LLD's PDB
against the checked in PDB.

This failed because part of the diffing algorithm involves
determining if two modules are the same, and if so drilling into
the module and diffing individual fields of the module.  The
only thing we can use to make this determination though is the
"name" of the module, which is a path to where the module (obj
file) was read from on the machine where it was linked.  This
fails for obvious reasons when comparing a PDB generated on one
machine to a PDB on another machine.

The fix employed here is to add two command line options to the
diff subcommand, which allow the user to specify a "binary root
path".  The bin root path, if specified, is stripped from the
beginning of any embedded PDB paths.  The test is updated to
specify the user's local test output directory for the left
PDB, and is hardcoded to the location where the original PDB
was created for the right PDB.  This way all the equivalence
comparisons should succeed.

llvm-svn: 307555
2017-07-10 16:52:15 +00:00
Eric Beckmann c8dba240b1 Revert "Revert "Revert "Revert "Switch external cvtres.exe for llvm's own resource library.""""
This reverts commit 147f45ff24456aea59575fa4ac16c8fa554df46a.

Revert "Revert "Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file.""""

This reverts commit 61a90a67ed54a1f0dfeab457b65abffa129569e4.

The patches were intially reverted because they were causing a failure
on CrWinClangLLD.  Unfortunately, this was done haphazardly and didn't
compile, so the revert was reverted again quickly to fix this.  One that
was done, the revert of the revert was itself reverted.  This allowed me
to finally fix the actual bug in r307452.  This patch re-enables the
code path that had originally been causing the bug, now that it (should)
be fixed.

llvm-svn: 307460
2017-07-08 03:06:10 +00:00
Zachary Turner 41f6a453e4 Delete the pdb diff test.
This is failing on Linux for unknown reasons, so I need to
get the bots green while I investigate.

llvm-svn: 307459
2017-07-08 02:54:19 +00:00
Eric Beckmann 7c865f004b Add name offset flags, for parity with cvtres.exe.
Summary:
The original cvtres.exe sets the high bit when an identifier offset
points to a string.  Even though this is not mentioned in the spec, and
in fact does not seem to cause errors with most cases, for some reason
this causes a failure in Chromium where the new resource file is not
verified as a new version.  This patch sets this high bit flag, and also
adds a test case to check that the output of our library is always
identical to original cvtres.

Reviewers: zturner, ruiu

Subscribers: llvm-commits, hiraditya

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

llvm-svn: 307452
2017-07-07 23:23:53 +00:00
Zachary Turner 3a11fdf8ce [PDB] More changes to bring lld PDBs to parity with MSVC.
1) Don't write a /src/headerblock stream.  This appears to be
   written conditionally by MSVC, but it's not clear what the
   condition is.  For now, just remove it since we dont' know
   what it is anyway and the particular pdb we've checked in
   for the test doesn't have one.
2) Write a valid timestamp for the PDB file signature.  This
   leads to non-reproducible builds, but it matches the default
   behavior of link, so it should be out default as well.  If
   we need reproducibility, we should add a separate command
   line option for it that is off by default.
3) Write an empty FPO stream.  MSVC seems to always write an
   FPO stream.  This change makes the stream directory match
   up, although we still need to make the contents of the FPO
   stream match.

llvm-svn: 307436
2017-07-07 20:25:39 +00:00
Zachary Turner fe71c546e7 [llvm-pdbutil] Fix build.
Some platforms require an explicit specialization of std::hash
for PdbRaw_FeaturesSig.  Also a test involving case sensitivity
needed to be fixed.  For now that particular check just accepts
any path even if they're completely different.  Long term we
should output paths in the correct case to match MSVC.

llvm-svn: 307426
2017-07-07 19:00:06 +00:00
Zachary Turner 448dea419c Use windows path syntax when writing PDB module name.
Without this we would just append whatever the user
wrote on the command line, so if we're in C:\foo
and we run lld-link bar/baz.obj, we would write
C:\foo\bar/baz.obj in various places in the PDB.
MSVC linker does not do this, so we shouldn't either.
This fixes some differences in the diff test, so we
update the test as well.

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

llvm-svn: 307423
2017-07-07 18:46:14 +00:00
Zachary Turner c1e93e5fa4 Fix some differences between lld and MSVC generated PDBs.
A couple of things were different about our generated PDBs.

1) We were outputting the wrong Version on the PDB Stream.
   The version we were setting was newer than what MSVC is setting.
   It's not clear what the implications are, but we change LLD
   to use PdbImplVC70, as MSVC does.
2) For the optional debug stream indices in the DBI Stream, we
   were outputting 0 to mean "the stream is not present".  MSVC
   outputs uint16_t(-1), which is the "correct" way to specify
   that a stream is not present.  So we fix that as well.
3) We were setting the PDB Stream signature to 0.  This is supposed
   to be the result of calling time(nullptr).  Although this leads
   to non-deterministic builds, a better way to solve that is by
   having a command line option explicitly for generating a
   reproducible build, and have the default behavior of lld-link
   match the default behavior of link.

To test this, I'm making use of the new and improved `pdb diff`
sub command.  To make it suitable for writing tests against, I had
to modify the diff subcommand slightly to print less verbose output.
Previously it would always print | <column> | <value1> | <value2> |
which is quite verbose, and the values are fragile.  All we really
want to know is "did we produce the same value as link?"  So I added
command line options to print a single character representing the
result status (different, identical, equivalent), and another to
hide the value display.  Note that just inspecting the diff output
used to write the test, you can see some things that are obviously
wrong.  That is just reflective of the fact that this is the state
of affairs today, not that we're asserting that this is "correct".
We can use this as a starting point to discover differences, fix
them, and update the test.

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

llvm-svn: 307422
2017-07-07 18:45:56 +00:00
Davide Italiano 6687318bab [LTO] Add a test for ThinLTO + --defsym.
We also get this right since r307303.

llvm-svn: 307412
2017-07-07 16:40:19 +00:00
Davide Italiano 406d8707f0 [LTO] Add a test for ThinLTO + --wrap.
We should get this right after r307303.

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

llvm-svn: 307410
2017-07-07 16:33:01 +00:00
Tom Stellard a6b7efc7e3 [MachO] Add missing byte-swaps when reading dyld_info
Summary:
This fixes the following tests on big-endian hosts:

lld :: mach-o/dylib-install-names.yaml
lld :: mach-o/force_load-dylib.yaml
lld :: mach-o/lib-search-paths.yaml
lld :: mach-o/upward-dylib-load-command.yaml

Reviewers: lhames, kledzik, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 307405
2017-07-07 15:20:17 +00:00
Peter Smith 96f813d1a0 [ELF] Add call to assignAddresses() before createThunks() [NFC]
In preparation for the addition of rangeThunks() calculate the addresses
of all the inputSections so that ThunkSections can be inserted at the right
place.

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

llvm-svn: 307373
2017-07-07 10:03:37 +00:00
George Rimar 1b51b7fc7f [ELF] - Fail the link if something happens on DWARF parsing stage of -gdb-index building
This is relative to PR33173,

Previously if something wrong happened on DWARF parsers side during parsing
object for building gdb index (like was in PR: unsupported relocation) 
then LLD continued and finished the link. DWARF parsers sure showed error
message on their side, but that is all.

Patch changes behavior to fail the link in this case and show more
detailed message.

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

llvm-svn: 307370
2017-07-07 09:18:05 +00:00
Peter Smith 906e9a1898 [ELF] Extract temporary state used in assignAddresses()
The assignAddresses() function accumulates state in the LinkerScript that
prevents it from being called multiple times. This change moves the state
into a separate structure AddressState that is created at the start of the
function and disposed of at the end.

CurAddressState is used rather than passing a reference to the state as a
parameter to the functions used by assignAddresses(). This is because the
getSymbolValue function needs to be executed in the context of AddressState
but it is stored in ScriptParser when AddressState is not available.

The AddressState is also used in a limited context by processCommands()

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

llvm-svn: 307367
2017-07-07 09:11:27 +00:00
George Rimar 85e9216e8c [ELF] - Handle symbols with default version early.
This fixes last testcase provided in PR28414.
In short issue is next: when we had X@@Version symbol in object A,
we did not resolve it to X early. Then when in another object B
we had reference to undefined X, symbol X from archive was fetched.
Since both archive and object A contains another symbol Z, duplicate
symbol definition was triggered as a result.

Correct behavior is to use X@@Version from object A instead and do not fetch
any symbols from archive.

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

llvm-svn: 307364
2017-07-07 08:29:51 +00:00
Zachary Turner cea99709c4 Fix lld tests after r307356.
llvm-svn: 307360
2017-07-07 05:41:25 +00:00
Zachary Turner 6c4bfba8f3 [PDB] Teach libpdb to write DBI Stream ECNames.
Based strictly on the name, this seems to have something to do
width edit & continue.  The goal of this patch has nothing to do
with supporting edit and continue though.  msvc link.exe writes
very basic information into this area even when *not* compiling
with support for E&C, and so the goal here is to bring lld-link
to parity.  Since we cannot know what assumptions standard tools
make about the content of PDB files, we need to be as close as
possible.

This ECNames data structure is a standard PDB string hash table.
link.exe puts a single string into this hash table, which is the
full path to the PDB file on disk.  It then references this string
from the module descriptor for the compiler generated `* Linker *`
module.

With this patch, lld-link will generate the exact same sequence of
bytes as MSVC link for this subsection for a given object file
input (as reported by `llvm-pdbutil bytes -ec`).

llvm-svn: 307356
2017-07-07 05:04:36 +00:00
David L. Jones d4053fb2ec Change remaining references to lit.util.capture to use subprocess.check_output.
Summary:
The capture() function was removed in r306625. This should fix PGO breakages
reported by Michael Zolotukhin.

Reviewers: mzolotukhin

Subscribers: sanjoy, llvm-commits

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

llvm-svn: 307320
2017-07-06 21:46:47 +00:00
Reid Kleckner ffa5180f39 Fix pdb-scopes.test
llvm-svn: 307280
2017-07-06 16:41:15 +00:00
Rafael Espindola 055312465b Remove redundant argument. NFC.
llvm-svn: 307279
2017-07-06 16:40:44 +00:00
Reid Kleckner 3f85192930 [PDB] Fill in "Parent" and "End" fields of scope-like symbol records
Summary:
There are a variety of records that open scopes: function scopes, block
scopes, and inlined call site scopes. These symbol records contain
Parent and End fields with the offsets of other symbol records. The End
field contains the offset of the matching S_END or S_INLINESITE_END
record. The Parent field contains the offset of the parent record, or 0
if this is a top-level scope (i.e. a function).

With this change, `llvm-pdbutil pretty -all` no longer crashes on PDBs
produced by LLD. I haven't tried a real debugger yet.

Reviewers: zturner, ruiu

Subscribers: llvm-commits

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

llvm-svn: 307278
2017-07-06 16:39:32 +00:00
Eric Beckmann f6090b620e Revert "Revert "Revert "Switch external cvtres.exe for llvm's own resource library."""
This reverts commit ae21ee0b6cacbc1efaf4d42502e71da2f0eb45c3.

The initial revert was done in order to prevent ongoing errors on
chromium bots such as CrWinClangLLD.  However, this was done haphazardly
and I didn't realize there were test and compilation failures, so this
revert was reverted.  Now that those have been fixed, we can revert the
revert of the revert.

llvm-svn: 307227
2017-07-05 23:46:06 +00:00
Eric Beckmann 81979b038f Revert "Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file."""
This reverts commit 5fecbbbe5049665d86834cf69d8f75db4f392308.

The initial revert was done in order to prevent ongoing errors on
chromium bots such as CrWinClangLLD.  However, this was done haphazardly
and I didn't realize there were test and compilation failures, so this
revert was reverted.  Now that those have been fixed, we can revert the
revert of the revert.

llvm-svn: 307226
2017-07-05 23:45:50 +00:00
Rafael Espindola 2126334e08 Move fabricateDefaultCommands earlier.
It is now just after the OutputSections are created, which is as early
as it can possibly go.

llvm-svn: 307225
2017-07-05 23:36:24 +00:00
Rafael Espindola a4c15c1339 Remove dummy cast.
llvm-svn: 307220
2017-07-05 23:16:38 +00:00
Rafael Espindola 4cc0cd6556 Use Entry::SecSize in a couple of cases.
This avoids having to compute relocation section sizes early, removing
the last use of assignOffsets.

llvm-svn: 307219
2017-07-05 23:06:59 +00:00
Rafael Espindola 9f9e99be20 Simplify. NFC.
llvm-svn: 307217
2017-07-05 22:30:04 +00:00
Rafael Espindola cf7347379f Remove a function that is now trivial.
llvm-svn: 307214
2017-07-05 22:25:38 +00:00
Rafael Espindola 7016a14702 Using existing variable. NFC.
llvm-svn: 307211
2017-07-05 22:15:58 +00:00
Rafael Espindola cfeb9ae073 Remove two dummy casts. NFC.
llvm-svn: 307209
2017-07-05 22:07:20 +00:00
Eric Beckmann 1d50926e71 Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file.""
This reverts commit 8c8dce3b8f15d6ebaefc35ce88f15a85c8cdbd6e.

llvm-svn: 307191
2017-07-05 19:04:48 +00:00
Eric Beckmann 0eafa581a3 Revert "Revert "Switch external cvtres.exe for llvm's own resource library.""
This reverts commit 165e578e47f1cd38191120aad23a9020fb5476dd.

Forgot to run tests on this.

llvm-svn: 307190
2017-07-05 19:04:33 +00:00
Eric Beckmann 36793a0ecf Revert "Switch external cvtres.exe for llvm's own resource library."
This reverts commit 600d52c278e123dd08bee24c1f00932b55add8de.

This patch still seems to break CrWinClangLLD, reverting until I can
find root problem.

llvm-svn: 307189
2017-07-05 18:59:16 +00:00
Eric Beckmann 8cc9fd31e6 Revert "Replace trivial use of external rc.exe by writing our own .res file."
This patch still seems to break CrWinClangLLD, reverting this once more
until I can discover root problem.

This reverts commit 3dbbc8ce43be50ffde2b1c655c6d3a25796fe78b.

llvm-svn: 307188
2017-07-05 18:59:01 +00:00
Rafael Espindola d7faa9165f Merge createOrphanCommands into addOrphanSections.
This is a bit simpler and avoids a walk over OutputSections.

llvm-svn: 307178
2017-07-05 17:50:43 +00:00
David Blaikie 15309044ba Use LoadedObjectInfoHelper to simplify/delegate the implementation of 'clone'
llvm-svn: 307167
2017-07-05 15:24:42 +00:00
Sean Eveson d54759b236 [ELF] Fix nullptr dereference when creating an error message for a synthetic section.
Differential Revision: https://reviews.llvm.org/D34752

llvm-svn: 307162
2017-07-05 14:55:43 +00:00
Peter Smith 283b9f2de3 [ELF] Fix Windows build error
Attempt to fix Windows buildbots From 307131 Replaced return {ET, false};
with return std::make_pair(ET, false);

llvm-svn: 307137
2017-07-05 10:15:46 +00:00
Peter Smith fa23764278 [ELF] Allow multiple thunks to be added for a symbol.
This change permits there to be more than one thunk to be associated with
a symbol. For interworking thunks we only require one thunk, but range
extension thunks may require more than one.

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

llvm-svn: 307136
2017-07-05 09:53:33 +00:00
Peter Smith 7d66e849fc [ELF] Introduce Thunk reuse compatibility
On ARM the interworking thunks are only produced for branch instructions
that can't be changed into a blx instruction so only Thumb callers would
call Thumb thunks and only ARM callers would call ARM thunks. With range
extension thunks branch and link instructions may need a Thunk. These
instructions can be rewritten as a blx and can use either ARM or Thumb
thunks.

We introduce an isCompatibleWith() function so that a caller can check if
an existing Thunk is compatible before reusing it.

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

llvm-svn: 307132
2017-07-05 09:36:03 +00:00
Peter Smith 5aedebff38 [ELF] Extract allocateHeaders() from assignAddresses()
The allocateHeaders() function is called at the end of assignAddresses(), it
decides whether the ELF header and program header table can be allocated to
a PT_LOAD program header. As the function alters state, it prevents
assignAddresses() from being called multiple times.

This change splits out the call to allocateHeaders() from assignAddresses()
this will permit assignAddresses() to be called while processing range
extension thunks without trying to allocateHeaders().

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

llvm-svn: 307131
2017-07-05 09:12:54 +00:00
Rafael Espindola cf00d4374e Fix PR33635.
This is a semantic revert of r306036.

We have to change the names, otherwise dynamic relocations will point
to the wrong name.

llvm-svn: 307110
2017-07-05 00:43:18 +00:00
Rafael Espindola 9b3f657d21 Move clearOutputSections earlier. NFC.
This is finally getting to the point where output sections are
constructed.

createOrphanCommands and fabricateDefaultCommands are moved out so
they can be merged with existing code in followup commits.

llvm-svn: 307107
2017-07-04 21:05:26 +00:00
Rafael Espindola d48b208833 Move clearOutputSections earlier. NFC.
Now addSectionSymbols operates on the linker script.

llvm-svn: 307102
2017-07-04 19:08:40 +00:00
Rafael Espindola b691545721 Move clearOutputSections earlier. NFC.
Now all of finalizeSections works on the linker script.

llvm-svn: 307101
2017-07-04 19:05:03 +00:00
Rafael Espindola 1eb3a0fa83 Move clearOutputSections earlier. NFC.
Now addPredefinedSections operates only on the linker script.

llvm-svn: 307100
2017-07-04 18:26:21 +00:00
Tom Stellard c17a04c6c8 ELF: Only unlink regular files
Summary:
If the output file is a character file (e.g. /dev/null) unlinking it could
potentially destabilize the user's system.  For example,
unlinking causes `lld %input -o /dev/null` to replace /dev/null with a
regular file, which will lead to unexpected behavior in other programs
that read from /dev/null, and worse than expected peformance for
programs that write to /dev/null.

This makes it possible to run the test-release.sh script as root.
Prior to this patch, the ELF/basic.s test would replace
/dev/null with a regular file, which would cause crashes in llvm
test-suite programs that piped /dev/null to stdin.

For example, if you run the test-relase.sh script as root,

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, llvm-commits

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

llvm-svn: 307092
2017-07-04 16:03:34 +00:00
Rafael Espindola 909899cc47 Improve error message.
Before we would sometimes not mention that the relocation was in a ro
area before.

llvm-svn: 307089
2017-07-04 15:53:57 +00:00
Simon Atanasyan 2e5c46cbac [ELF] Do not use `this` to access members of non-template class. NFC
llvm-svn: 307083
2017-07-04 15:04:30 +00:00
Rafael Espindola aec6287f5d Make the test more strict.
We now don't produce "has undefined version" errors when producing
binaries even when there is a linker script.

llvm-svn: 307082
2017-07-04 14:59:28 +00:00
George Rimar 4d2f976208 [ELF] - Resolve references properly when using .symver directive
This is PR28414. 
Previously LLD was unable to link following:
(failed with undefined symbol bar)

Version script:
SOME_VERSION { global: *; };

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
  jmp bar
Manual has next description:

.symver name, name2@@nodename
In this case, the symbol name must exist and be defined within the file being assembled. It is similar to name2@nodename. 
The difference is name2@@nodename will also be used to resolve references to name2 by the linker
https://sourceware.org/binutils/docs/as/Symver.html

Patch implements that. If we have name@@ver symbol and name is undefined, name@@ver is used to resolve references to name.
If name is defined then multiple definition error is emited, that is consistent with what bfd do.

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

llvm-svn: 307077
2017-07-04 13:19:13 +00:00
George Rimar a951d5c40b [ELF] - Use llvm::find_if instead std::find_if where possible. NFC.
Two more places.

llvm-svn: 307076
2017-07-04 13:10:37 +00:00
Rafael Espindola 43ee36040d fix msvc build
llvm-svn: 307044
2017-07-03 17:32:09 +00:00
Rafael Espindola c080ff64dc Move clearOutputSections earlier.
Now removeUnusedSyntheticSections operates entirely on the linker
script.

llvm-svn: 307043
2017-07-03 16:54:39 +00:00
Rafael Espindola bd9682a1ad Add a test for a recent regression.
llvm-svn: 307041
2017-07-03 16:49:17 +00:00
George Rimar d971e7030e [ELF] - Simplify allocateHeaders(). NFC.
* Return type changed to void, because it was unused.
* std::find_if -> llvm::find_if

llvm-svn: 307039
2017-07-03 16:05:51 +00:00
Petr Hosek 52db9a4fe6 [ELF] Remove unused synthetic sections from script commands
Script commands are processed before unused synthetic sections are
removed. Therefore, if a linker script matches one of these sections
it'll get emitted as an empty output section because the logic for
removing unused synthetic sections ignores script commands which
could have already matched and captured one of these sections. This
patch fixes that by also removing the unused synthetic sections from
the script commands.

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

llvm-svn: 307037
2017-07-03 15:49:25 +00:00
George Rimar bd4943e2ca [ELF] - Remove use of precomipled binary for invalid-relocation-x64.test
Since yaml2obj is now able to parse integer values as relocation types,
there is no need to keep hex edited elf object for this test,
we can produce it on fly, just like this patch do.

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

llvm-svn: 307032
2017-07-03 15:24:50 +00:00
Andrew Ng a020d3487e [LLD][LinkerScript] Allow non-alloc sections to be assigned to segments.
This patch makes changes to allow sections without the SHF_ALLOC bit to be
assigned to segments in a linker script.

The assignment of output sections to segments is performed in
LinkerScript::createPhdrs. Previously, this function would bail as soon as it
encountered an output section which did not have the SHF_ALLOC bit set, thus
preventing any output section without SHF_ALLOC from being assigned to a
segment.

This restriction has now been removed from LinkerScript::createPhdrs and instead
a check for SHF_ALLOC has been added to LinkerScript::adjustSectionsAfterSorting
to not propagate program headers to sections without SHF_ALLOC which matches the
behaviour of bfd linker scripts.

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

llvm-svn: 307013
2017-07-03 10:11:25 +00:00
Rui Ueyama 80cbc776cb Revert r306813: "[ELF] - Resolve references properly when using .symver directive"
This reverts commit r306813 because it broke linking of the
FreeBSD base system.

llvm-svn: 306996
2017-07-03 03:26:07 +00:00
Martin Storsjo 94fce50950 [COFF] Add initial support for linking ARM64 binaries
A plain empty entry point function that returns 0 seems to produce
a binary that loads and runs fine in wine.

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

llvm-svn: 306963
2017-07-01 20:29:27 +00:00
Eric Beckmann 602afcf7e9 Revert "Revert "Replace trivial use of external rc.exe by writing our own .res file.""
Summary:
This reverts commit 51931072a7c9a52540baf76fc30ef391d2529a2f.

This revert was originally done because the integrations of the new
WindowsResource library into LLD was causing error in chromium, due to
bugs in how resource sections were handled.  These bugs were fixed,
meaning that the features may be reintegrated.

Subscribers: hiraditya, llvm-commits

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

llvm-svn: 306941
2017-07-01 03:59:54 +00:00
Zachary Turner af8c75a8c0 [llvm-pdbutil] Output the symbol offset when dumping.
Type records have a unique type index, but symbol records do
not.  Instead, symbol records refer to other symbol records
by referencing their offset in the symbol stream.  In a sense
this is the analogue of the TypeIndex, but we are not printing
it in the dumper.  Printing it not only gives us more useful
information when manually investigating the contents of a PDB,
but also allows us to write better tests by enabling us to
verify that fields that reference other symbol records do
so correctly.

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

llvm-svn: 306890
2017-06-30 21:35:00 +00:00
Richard Smith 4451cb63fb Fix ODR violations due to abuse of LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR
This is a short-term fix for PR33650 aimed to get the modules build bots green again.

Remove all the places where we use the LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR
macros to try to locally specialize a global template for a global type. That's
not how C++ works.

Instead, we now centrally define how to format vectors of fundamental types and
of string (std::string and StringRef). We use flow formatting for the former
cases, since that's the obvious right thing to do; in the latter case, it's
less clear what the right choice is, but flow formatting is really bad for some
cases (due to very long strings), so we pick block formatting. (Many of the
cases that were using flow formatting for strings are improved by this change.)

Other than the flow -> block formatting change for some vectors of strings,
this should result in no functionality change.

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

Corresponding LLVM change is r306878.

llvm-svn: 306880
2017-06-30 20:57:21 +00:00
Eric Beckmann 5de7361097 Tighten up tests for .rsrc section emission.
Summary:
There have been bugs with the WindowsResource library, such as incorrect
symbols for addresses.  Directly checking the .rsrc in the final PE will
help ensure this doesn't happen again.

Subscribers: llvm-commits

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

llvm-svn: 306854
2017-06-30 18:22:11 +00:00
George Rimar aad84e2ee2 [ELF] - Resolve references properly when using .symver directive
This is PR28414. 
Previously LLD was unable to link following:
(failed with undefined symbol bar)

```
Version script:
SOME_VERSION { global: *; };

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
  jmp bar
```

Manual has next description:
//
.symver name, name2@@nodename
In this case, the symbol name must exist and be defined within the file being assembled. It is similar to name2@nodename. 
**The difference is name2@@nodename will also be used to resolve references to name2 by the linker**
https://sourceware.org/binutils/docs/as/Symver.html
//

Patch implements that. If we have name@@ver symbol and name is undefined, 
name@@ver is used to resolve references to name.

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

llvm-svn: 306813
2017-06-30 10:19:54 +00:00
Martin Storsjo e24f434eb2 Update a test case after LLVM r306794
llvm-svn: 306796
2017-06-30 07:02:59 +00:00
Sam Clegg c090962255 Remove unused declarations
Differential Revision: https://reviews.llvm.org/D34852

llvm-svn: 306772
2017-06-30 00:34:35 +00:00
Paul Robinson c60318af24 Tweak to match change in LLVM API, in r306699
llvm-svn: 306700
2017-06-29 16:52:29 +00:00
Eric Beckmann d40dd64ff0 Revert "Replace trivial use of external rc.exe by writing our own .res file."
This reverts commit d4c7e9fc63c10dbab0c30186ef8575474a704496.

This is done in order to address the failure of CrWinClangLLD etc. bots.
These throw an error of "side-by-side configuration is incorrect" during
compilation, which sounds suspiciously related to these manifest
changes.

Revert "Switch external cvtres.exe for llvm's own resource library."

This reverts commit 71fe8ef283a9dab9a3f21432c98466cbc23990d1.

llvm-svn: 306618
2017-06-29 00:17:26 +00:00
Rafael Espindola b04290569c Delete comparison with GlobalOffsetTable.
Now that _GLOBAL_OFFSET_TABLE_ is defined, we can just use R_PC for it
if needed.

llvm-svn: 306614
2017-06-28 23:19:32 +00:00
Rafael Espindola 85de6786ab Fix indentation.
llvm-svn: 306609
2017-06-28 22:44:11 +00:00
Rui Ueyama b2269ec4d3 Move copy function from Symbol to SymbolBody.
We could have add this function either Symbol or SymbolBody. I added it
to Symbol at first. But I noticed that if I've added it to SymbolBody,
we could've removed SymbolBody::setName(). So I'll do that in this patch.

llvm-svn: 306590
2017-06-28 19:43:02 +00:00
Rui Ueyama 8e11b6d94b Define Symbol::copyBody function.
This patch adds a utility function to Symbol. This function should
be useful in https://reviews.llvm.org/D33680 too.

llvm-svn: 306587
2017-06-28 19:28:49 +00:00
Reid Kleckner a1001b8f38 [COFF] Allow debug info to relocate against discarded symbols
Summary:
In order to do this without switching on the symbol kind multiple times,
I created Defined::getChunkAndOffset and use that instead of
SymbolBody::getRVA in the inner relocation loop.

Now we get the symbol's chunk before switching over relocation types, so
we can test if it has been discarded outside the inner relocation type
switch. This also simplifies application of section relative
relocations. Previously we would switch on symbol kind to compute the
RVA, then the relocation type, and then the symbol kind again to get the
output section so we could subtract that from the symbol RVA. Now we
*always* have an OutputSection, so applying SECREL and SECTION
relocations isn't as much of a special case.

I'm still not quite happy with the cleanliness of this code. I'm not
sure what offsets and bases we should be using during the relocation
processing loop: VA, RVA, or OutputSectionOffset.

Reviewers: ruiu, pcc

Reviewed By: ruiu

Subscribers: majnemer, inglorion, llvm-commits, aprantl

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

llvm-svn: 306566
2017-06-28 17:06:35 +00:00
Rui Ueyama 0cc1483562 Add basic 64-bit SPARC support
Add support for the most common SPARC relocations.
Make DT_PLTGOT point to the PLT on SPARC.
Mark the PLT as executable on SPARC.

This adds a basic test that creates a SPARV9 executable
that invokes the exit system call on OpenBSD.

Patch by Mark Kettenis.

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

llvm-svn: 306565
2017-06-28 17:05:39 +00:00
George Rimar e0b43df32e [ELF] - Do not crash when LLD synthesizes output sections with BYTE commands and -r
This is PR33596. Previously LLD would crash
because BYTE command synthesized output section,
but it was not assigned to Sec member of OutputSectionCommand.

Behaviour of -script and -r combination is not well defined,
but it seems after this change LLD naturally inherits behavior of
GNU linkers - creates output section requested in script and does not
crash anymore.

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

llvm-svn: 306527
2017-06-28 09:59:34 +00:00
George Rimar dbe843d602 [ELF] - Do not set st_size field of SHT_UNDEF symbols.
This fixes PR33598.

Size field for undefined symbols is not significant.
Setting it to fixed value, like zero, may be useful though.

For example when we have 2 DSO's, like in this PR, if lower level DSO may
change slightly (in part of some symbol's st_size)  and higher-level DSO is
rebuilt, then tools that monitoring checksum of high level DSO file can notice
it and trigger cascade of some other unnecessary actions. 
If we set st_size to zero, that can be avoided.

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

llvm-svn: 306526
2017-06-28 09:51:33 +00:00
Peter Smith 691ff76662 [ELF] Consolidate .ARM.extab.* sections into .ARM.extab
When -ffunction-sections and ARM C++ exceptions are used each .text.suffix
section will have at least one .ARM.exidx.suffix section and may have an
additional .ARM.extab.suffix section if the unwinding instructions are too
large to inline into the .ARM.exidx table entry. For a large program without
a linker script this can lead to a large number of section header table
entries that can increase the size of the ELF file.

This change introduces a default rule for .ARM.extab.* to be placed in
a single output section called .ARM.extab . This follows the behavior of
ld.gold and ld.bfd.

fixes pr33407

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

llvm-svn: 306522
2017-06-28 09:12:38 +00:00
Rafael Espindola 36f2edb6fd Check the produced file instead of stderr.
It is somewhat pointless to check that a specific error is not
produced. That is already checked by the ld.lld exit value.

Instead make the test a bit stronger by checking that the output file
has the expected symbol and section.

llvm-svn: 306496
2017-06-28 01:46:31 +00:00