Commit Graph

8783 Commits

Author SHA1 Message Date
Rui Ueyama e8a3be4693 Fix -Wpessimizing-move.
llvm-svn: 306323
2017-06-26 19:52:01 +00:00
Rui Ueyama 921d43fbb2 Add trap instructions for ARM and MIPS.
This patch fills holes in executable sections with 0xd4 (ARM) or
0xef (MIPS). These trap instructions were suggested by Theo de Raadt.

llvm-svn: 306322
2017-06-26 19:45:53 +00:00
Paul Robinson a22c98c030 Tweak to match change in LLVM API, in r306315.
llvm-svn: 306316
2017-06-26 18:43:26 +00:00
Eric Beckmann 2a81089116 Replace trivial use of external rc.exe by writing our own .res file.
This patch removes the dependency on the external rc.exe tool by writing
a simple .res file using our own library. In this patch I also added an
explicit definition for the .res file magic.  Furthermore, I added a
unittest for embeded manifests and fixed a bug exposed by the test.

llvm-svn: 306311
2017-06-26 17:43:30 +00:00
Rui Ueyama 82143d3fbb Move `assert` upwards so that it fails early if it fails.
llvm-svn: 306308
2017-06-26 17:11:36 +00:00
Rui Ueyama 71fab2f03b Remove confusing `return`.
`addInputSec` returns void. Even though it is syntactically correct,
the use of `return` here is just confusing.

llvm-svn: 306307
2017-06-26 16:52:16 +00:00
Reid Kleckner eb8c0f9d51 [COFF] Fix SECREL and SECTION relocations against common symbols
Summary:
They do the obvious thing: provide the section index of .bss and the
offset of the symbol in .bss.

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 306304
2017-06-26 16:45:36 +00:00
Reid Kleckner 892d2a5767 Add .yaml as an lld test suffix
Over time we've started to add inputs and test cases using the .yaml
extension, which seems to be preferred over the .objtxt extension that
we were using initially. One nice thing about using .yaml is that it
triggers existing editor highlighting and formatting support.

Fix two pdb*.yaml test cases that I added that weren't being run as part
of check-lld.

llvm-svn: 306303
2017-06-26 16:42:44 +00:00
Rui Ueyama fb02869b74 Remove a stale comment.
llvm-svn: 306295
2017-06-26 15:51:28 +00:00
Reid Kleckner 502d4ce2e4 [COFF] Improve synthetic symbol handling
Summary:
The main change is that we can have SECREL and SECTION relocations
against ___safe_se_handler_table, which is important for handling the
debug info in the MSVCRT.

Previously we were using DefinedRelative for __safe_se_handler_table and
__ImageBase, and after we implement CFGuard, we plan to extend it to
handle __guard_fids_table, __guard_longjmp_table, and more.  However,
DefinedRelative is really only suitable for implementing __ImageBase,
because it lacks a Chunk, which you need in order to figure out the
output section index and output section offset when resolving SECREl and
SECTION relocations.

This change renames DefinedRelative to DefinedSynthetic and gives it a
Chunk. One wart is that __ImageBase doesn't have a chunk. It points to
the PE header, effectively. We could split DefinedRelative and
DefinedSynthetic if we think that's cleaner and creates fewer special
cases.

I also added safeseh.s, which checks that we don't emit a safe seh table
entries pointing to garbage collected handlers and that we don't emit a
table at all when there are no handlers.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: inglorion, pcc, llvm-commits, aprantl

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

llvm-svn: 306293
2017-06-26 15:39:52 +00:00
Rui Ueyama 92c3781959 Add GlobalOffsetTable to ElfSym. NFC.
Most "reserved" symbols are in ElfSym and it looks like there's no
reason to not do the same thing for _GLOBAL_OFFSET_TABLE_. This should
help https://reviews.llvm.org/D34618 too.

llvm-svn: 306292
2017-06-26 15:11:24 +00:00
Peter Smith 113a59e7db [ELF] Define _GLOBAL_OFFSET_TABLE_ symbol relative to .got
On many architectures gcc and clang will recognize _GLOBAL_OFFSET_TABLE_ - .
and produce a relocation that can be processed without needing to know the
value of _GLOBAL_OFFSET_TABLE_. This is not always the case; for example ARM
gcc produces R_ARM_BASE_PREL but clang produces the more general
R_ARM_REL32 to _GLOBAL_OFFSET_TABLE_. To evaluate this relocation
correctly _GLOBAL_OFFSET_TABLE_ must be defined to be the either the base of
the GOT or end of the GOT dependent on architecture..

If/when llvm-mc is changed to recognize _GLOBAL_OFFSET_TABLE_ - . this
change will not be necessary for new objects. However there may still be
old objects and versions of clang.

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

llvm-svn: 306282
2017-06-26 10:22:17 +00:00
Anton Korobeynikov 5875b7d3d7 Test commit
llvm-svn: 306225
2017-06-24 21:16:41 +00:00
Petar Jovanovic 661102a339 [mips] update expected output in test/ELF/mips-plt-r6.s
r306095 in LLVM has changed register positions for instruction aui.
This change updates the test that checks for aui.

llvm-svn: 306173
2017-06-23 22:30:28 +00:00
Reid Kleckner 5a7eca5223 Silence -Wunused-variable warning
llvm-svn: 306135
2017-06-23 18:22:29 +00:00
Peter Collingbourne 36d43dd958 Add parens for python3.
llvm-svn: 306128
2017-06-23 17:11:50 +00:00
Peter Collingbourne 8d29223386 Add a ThinLTO cache policy for controlling the maximum cache size in bytes.
This is useful when an upper limit on the cache size needs to be
controlled independently of the amount of the amount of free space.

One use case is a machine with a large number of cache directories
(e.g. a buildbot slave hosting a large number of independent build
jobs). By imposing an upper size limit on each cache directory,
users can more easily estimate the server's capacity.

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

llvm-svn: 306126
2017-06-23 17:05:03 +00:00
Reid Kleckner 8456411e3b [COFF] Fix SECTION and SECREL relocation handling for absolute symbols
Summary:
For SECTION relocations against absolute symbols, MSVC emits the largest
output section index plus one. I've implemented that by threading a
global variable through DefinedAbsolute that is filled in by the Writer.
A more library-oriented approach would be to thread the Writer through
Chunk::writeTo and SectionChunk::applyRel*, but Rui seems to prefer
doing it this way.

MSVC rejects SECREL relocations against absolute symbols, but only when
the relocation is in a real output section. When the relocation is in a
CodeView debug info section destined for the PDB, it seems that this
relocation error is suppressed, and absolute symbols become zeros in the
object file. This is easily implemented by checking the input section
from which we're applying relocations.

This should fix errors about __safe_se_handler_table and
__guard_fids_table when linking the CRT and generating a PDB.

Reviewers: ruiu

Subscribers: aprantl, llvm-commits

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

llvm-svn: 306071
2017-06-22 23:33:04 +00:00
Zachary Turner 7df69958f8 [llvm-pdbutil] Rename "raw" to "dump".
Now you run llvm-pdbutil dump <options>.  This is a followup
after having renamed the tool, whereas before raw was obviously
just the style of dumping, whereas now "dump" is the action to
perform with the "util".

llvm-svn: 306055
2017-06-22 20:57:39 +00:00
Rui Ueyama 4402a39981 Keep the original symbol name when renamed.
Previously, when symbol A is renamed B, both A and B end up having
the same name. This is because name is a symbol's attribute, and
we memcpy symbols for symbol renaming.

This pathc saves the original symbol name and restore it after memcpy
to keep the original name.

This patch shouldn't change program's meaning, but names in symbol
tables make more sense than before.

llvm-svn: 306036
2017-06-22 17:30:19 +00:00
Igor Kudrin 393563a0ce [ELF] Add an apostrophe after a file name when reporting discarded sections.
Differential Revision: https://reviews.llvm.org/D34442

llvm-svn: 305983
2017-06-22 04:07:58 +00:00
Peter Collingbourne bac3570d53 ELF: Don't dereference Repl in MarkLive. NFCI.
This is unnecessary because --gc-sections runs before ICF.

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

llvm-svn: 305954
2017-06-21 21:29:51 +00:00
Reid Kleckner d0e6e24a53 [PDB] Add symbols to the PDB
Summary:
The main complexity in adding symbol records is that we need to
"relocate" all the type indices. Type indices do not have anything like
relocations, an opaque data structure describing where to find existing
type indices for fixups. The linker just has to "know" where the type
references are in the symbol records. I added an overload of
`discoverTypeIndices` that works on symbol records, and it seems to be
able to link the standard library.

Reviewers: zturner, ruiu

Subscribers: llvm-commits, hiraditya

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

llvm-svn: 305933
2017-06-21 17:25:56 +00:00
Rui Ueyama 28ea8c7ad7 [COFF] Set MajorLinkerVersion to 14 instead of 0.
This works around a strange interaction with Authenticode signatures,
in which a signed PE executable with {Major,Minor}LinkerVersion = 0.0
fails to validate on Windows 7 (but is OK on Windows 10). Setting the
linker version to 14.0 (which is what VS2015 outputs) makes it work
again.

Patch by Simon Tatham <simon.tatham@arm.com>.

llvm-svn: 305929
2017-06-21 16:42:08 +00:00
Rui Ueyama d1f8b8162b Implement the --exclude-libs option.
The --exclude-libs option is not a popular option, but at least some
programs in Android depend on it, so it's worth to support it.

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

llvm-svn: 305920
2017-06-21 15:36:24 +00:00
Rui Ueyama d2ccdbfa61 Remove redundant namespace specifier.
llvm-svn: 305877
2017-06-21 03:05:08 +00:00
Rui Ueyama 2f740f74bb Define __guard_{iat,longjmp}_{count,table} symbols.
VC2017 contains these new symbols as undefined symobls. They are used
for /guard:cf. Since we do not support the control flow guard, but we
want to at least ignore these symbols so that we can link against VS2017
libraries.

Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=727193.

llvm-svn: 305876
2017-06-21 02:26:19 +00:00
Rui Ueyama f076b97a80 Improve error messages.
llvm-svn: 305868
2017-06-20 23:11:28 +00:00
Reid Kleckner 91ef9de643 [codeview] YAMLize all section offsets and indices in symbol records
We forgot to serialize these because llvm-readobj didn't dump them. They
are typically all zeros in an object file. The linker fills them in with
relocations before adding them to the PDB. Now we can properly round
trip these symbols through pdb2yaml -> yaml2pdb.

I made these fields optional with a zero default so that we can elide
them from our test cases.

llvm-svn: 305857
2017-06-20 21:19:22 +00:00
Sam Clegg 7859216b28 Fix argument numbersing in OPTION macro
The option numbers in the macro were off by one which
leads to some confusion.  There are actually 12 arguments
to this macro.

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

llvm-svn: 305823
2017-06-20 19:17:58 +00:00
Reid Kleckner f5bb738f75 [PDB] Don't emit debug info associated with dead chunks
Summary:
Previously we didn't add debug info chunks to the SparseChunks array, so
they didn't participate in section GC. Now we do.

Reviewers: ruiu

Subscribers: aprantl, llvm-commits

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

llvm-svn: 305811
2017-06-20 17:14:09 +00:00
Yuka Takahashi ba5d4af490 [GSoC] Flag value completion for clang
This is patch for GSoC project, bash-completion for clang.

To use this on bash, please run `source clang/utils/bash-autocomplete.sh`.
bash-autocomplete.sh is code for bash-completion.

In this patch, Options.td was mainly changed in order to add value class
in Options.inc.

llvm-svn: 305805
2017-06-20 16:31:31 +00:00
Rafael Espindola 9c0395e39e Prefer -Ttext over linker script values.
I found this while trying to build u-boot. It uses -Ttext in
combination with linker scripts.

My first reaction was to change the linker scripts to have the correct
value, but I found that it is actually quite convenient to have -Ttext
take precedence.

By having just

.text : { *(.text) }

In the script, they can define the text address in a single Makefile
and pass it to ld with -Ttext and for the C code with
-DFoo=value. Doing the same with linker scripts would require them to
be generated during the build.

llvm-svn: 305766
2017-06-20 01:51:50 +00:00
Kevin Enderby 2a833e0123 Fix lld test that was causing llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast
to fail due to change in llvm trunk r305744.

llvm-svn: 305747
2017-06-19 21:48:29 +00:00
Konstantin Zhuravlyov f3e3629f3d LLD: Move ELF/Mips.cpp to ELF/Arch/MipsArchTree.cpp
Differential Revision: https://reviews.llvm.org/D34358

llvm-svn: 305742
2017-06-19 21:03:57 +00:00
Eric Beckmann ddcfbf7d0a Have writeCOFFWriter return Expected<unique_ptr>.
Summary: Have writeCOFFWriter return Expected<unique_ptr> instead of requiring being passed an uninitialized unique_ptr.

Reviewers: zturner, ruiu

Subscribers: hiraditya, llvm-commits

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

llvm-svn: 305730
2017-06-19 18:49:05 +00:00
Rui Ueyama 10ae4ca564 Fix build breakage.
llvm-svn: 305726
2017-06-19 18:04:34 +00:00
Rui Ueyama 02e5d2a6cb Fix a threading bug.
llvm-svn: 305718
2017-06-19 17:47:04 +00:00
Reid Kleckner adea0ce7ca Fix build and PDB test on Linux
llvm-svn: 305716
2017-06-19 17:27:31 +00:00
Rui Ueyama 86360d6902 Replace CRLF with LF.
llvm-svn: 305714
2017-06-19 17:23:04 +00:00
Reid Kleckner 44cdb10964 [PDB] Start emitting source file and line information
Summary:
This is a first step towards getting line info to show up in VS and
windbg. So far, only llvm-pdbutil can parse the PDBs that we produce.
cvdump doesn't like something about our file checksum tables. I'll have
to dig into that next.

This patch adds a new DebugSubsectionRecordBuilder which takes bytes
directly from some other producer, such as a linker, and sticks it into
the PDB. Line tables only need to be relocated. No data needs to be
rewritten.

File checksums and string tables, on the other hand, need to be re-done.

Reviewers: zturner, ruiu

Subscribers: llvm-commits, hiraditya

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

llvm-svn: 305713
2017-06-19 17:21:45 +00:00
Andrew Ng 6e9f98c198 [LLD][LinkerScript] Add support for segment NONE.
This patch adds support for segment NONE in linker scripts which enables the
specification that a section should not be assigned to any segment.

Note that GNU ld does not disallow the definition of a segment named NONE, which
if defined, effectively overrides the behaviour described above. This feature
has been copied.

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

llvm-svn: 305700
2017-06-19 15:28:58 +00:00
James Henderson 38e67e8212 [ELF] Emit only one error if -z max-page-size without value
In r305364, Rui changed the mechanism that parses -z option values slightly.
This caused a bug, as demonstrated by this test, which now fails:

---
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t -z max-page-size

.global _start
_start:
  nop
---

Before, the link succeeded and set the max-page-size to the target default.

After we get the following two error messages:
"invalid max-page-size: "
"max-page-size: value isn't a power of 2"

The latter error is because an uninitialised variable ends up being passed back
to getMaxPageSize).

This change ensures we only get the first error.

Reviewers: ruiu

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

llvm-svn: 305679
2017-06-19 11:05:15 +00:00
Peter Smith 9873c4b509 [ELF] make default for get{ARM,AArch64}UndefinedRelativeWeakVA unreachable
The get{ARM,AArch64}UndefinedRelativeWeakVA() functions should only be
called for PC-relative relocations. Complete the supported pc-relative
relocations in the switch statement and make the default case unreachable.

The R_ARM_TARGET relocation can be evaluated as R_ARM_REL32 but it is only
used in the context of exception tables, and is never output with respect
to a weak reference so it does not appear in the switch statement.
    
Differential Revision: https://reviews.llvm.org/D34138

llvm-svn: 305673
2017-06-19 09:43:43 +00:00
Eric Beckmann 9e19d790a6 Update documentation to reflection disuse of external cvtres.
Subscribers: llvm-commits

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

llvm-svn: 305631
2017-06-17 02:26:27 +00:00
Rafael Espindola 4f1fca270a Error when discarding .dynstr.
We would crash before.

llvm-svn: 305615
2017-06-16 23:53:36 +00:00
Rafael Espindola 656cc20f5b Error when discarding .dynsym.
We would crash instead before.

llvm-svn: 305614
2017-06-16 23:50:09 +00:00
Rafael Espindola 2af64b0bf8 Error on trying to discard .dynamic.
We would crash instead before.

llvm-svn: 305613
2017-06-16 23:45:35 +00:00
Zachary Turner 7ba50b7151 Remove /dumppdb option from LLD.
This option is no longer needed.

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

llvm-svn: 305610
2017-06-16 23:41:44 +00:00
Rui Ueyama e6d8c1cb38 Update a comment.
llvm-svn: 305601
2017-06-16 22:45:13 +00:00
Eric Beckmann d135e8c039 Switch external cvtres.exe for llvm's own resource library.
In this patch, I flip the switch in DriverUtils from using the external
cvtres.exe tool to using the Windows Resource library in llvm.

I also fixed a bug where .rsrc sections were marked as discardable
memory and therefore were placed in the wrong order in the final PE.

Furthermore, I modified WindowsResource to write the coff directly to a
memory buffer instead of to file, also had it use the machine types
already declared in COFF.h instead creating my own enum.

Finally, I flipped the switch to allow all unit tests that had
previously run only on windows due to a winres dependency to run
cross-platform.

Reviewers: zturner, ruiu

Subscribers: llvm-commits, hiraditya

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

llvm-svn: 305592
2017-06-16 21:13:24 +00:00
Reid Kleckner f8b992dd08 Give associative-comdat lld test a triple
llvm-svn: 305585
2017-06-16 20:51:42 +00:00
Reid Kleckner 79ac99b3e8 [COFF] Drop unused comdat sections when GC is turned off
Summary:
Adds a "Discarded" bool to SectionChunk to indicate if the section was
discarded by COMDAT deduplication. The Writer still just checks
`isLive()`.

Fixes PR33446

Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 305582
2017-06-16 20:47:19 +00:00
Rui Ueyama e145bc22fd Do not use make<> to allocate TargetInfo. NFC.
llvm-svn: 305577
2017-06-16 20:15:03 +00:00
Rui Ueyama c9fefaac67 Add comments for AVR support.
AVR support is somewhat exotic as generated ELF executables are not
directly consumed but objcopy'ed to write it to on-chip flush memory.
This comment describes it for those why a full-fledged ELF linker is
used to link programs for the 8-bit microcontroller.

llvm-svn: 305567
2017-06-16 17:53:26 +00:00
Rui Ueyama 21c0a9ceeb Split Target.cpp into small files.
Target.cpp contains code for all the targets that LLD supports. It was
simple and easy, but as the number of supported targets increased,
it got messy.

This patch splits the file into per-target files under ELF/arch directory.

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

llvm-svn: 305565
2017-06-16 17:32:43 +00:00
Peter Smith 3298027951 [ELF] Enable createThunks to be called more than once.
In preparation for supporting range extension thunks we now continually
call createThunks() until no more thunks are added. This requires us to
record the thunks we add on each pass and only merge the new ones into the
OutputSection. We also need to check if a Relocation is targeting a thunk
to prevent us from infinitely creating more thunks.
    
Differential Revision: https://reviews.llvm.org/D34034

llvm-svn: 305555
2017-06-16 13:10:08 +00:00
Zachary Turner 56ed9deafc Remove some non-determinstic numbers from pdb test.
llvm-svn: 305520
2017-06-15 22:41:45 +00:00
Zachary Turner 93f986a7dc Fix pdb embedded paths.
Obviously the paths are going to be machine dependent, so
don't try to match them in the test.

llvm-svn: 305518
2017-06-15 22:30:00 +00:00
Zachary Turner 6305545527 Resubmit "[llvm-pdbutil] rewrite the "raw" output style."
This resubmits commit c0c249e9f2ef83e1d1e5f166b50673d92f3579d7.

It was broken due to some weird template issues, which have
since been fixed.

llvm-svn: 305517
2017-06-15 22:24:24 +00:00
Rafael Espindola c54b1c8b4d Try to fix MSVC build.
llvm-svn: 305514
2017-06-15 22:03:06 +00:00
Rafael Espindola 383971d2a7 Move clearOutputSections before sortSections.
This is probably the main patch left in unifying our intermediary
representation.

It moves the creation of default commands before section sorting. This
has the nice effect that we now have one location where we decide
where an orphan section should be placed.

Before this patch sortSections would decide the relative location of
orphan sections to other sections, but it was up to placeOrphanSection
to decide on the exact location.

We now only sort sections we created since the linker script is
already in the correct order.

llvm-svn: 305512
2017-06-15 21:51:01 +00:00
Zachary Turner da504b794c Revert "[llvm-pdbutil] rewrite the "raw" output style."
This reverts commit 83ea17ebf2106859a51fbc2a86031b44d33696ad.

This is failing due to some strange template problems, so reverting
until it can be straightened out.

llvm-svn: 305505
2017-06-15 20:55:51 +00:00
Saleem Abdulrasool bc7ff7027e COFF: add support for lib mode usage
When link is invoked with `/def:` and no input files, it behaves as if
`lib.exe` was invoked.  Emulate this behaviour, generating the import
library from the def file that was passed.  Because there is no input to
actually generate the dll, we simply process the def file early and exit
once we have created the import library.

llvm-svn: 305502
2017-06-15 20:39:58 +00:00
Zachary Turner b560fdf3b8 [llvm-pdbutil] rewrite the "raw" output style.
After some internal discussions, we agreed that the raw output style had
outlived its usefulness. It was originally created before we had even
thought of dumping to YAML, and it was intended to give us some insight
into the internals of a PDB file. Now we have YAML mode which does
almost exactly this but is more powerful in that it can round-trip back
to a PDB, which the raw mode could not do. So the raw mode had become
purely a maintenance burden.

One option was to just delete it. However, its original goal was to be
as readable as possible while staying close to the "metal" - i.e.
presenting the output in a way that maps directly to the underlying file
format. We don't actually need that last requirement anymore since it's
covered by the yaml mode, so we could repurpose "raw" mode to actually
just be as readable as possible.

This patch implements about 80% of the functionality previously in raw
mode, but in a completely different style that is more akin to what
cvdump outputs. Records are very compressed, often times appearing on
just one line. One nice thing about this is that it makes full record
matching easier, because you can grep for indices, names, and leaf types
on a single line often.

See the tests for some examples of what the new output looks like.

Note that this patch actually regresses the functionality of raw mode in
a few areas, but only because the patch was already unreasonably large
and going 100% would have been even worse. Specifically, this patch is
missing:

The ability to dump module debug subsections (checksums, lines, etc)
The ability to dump section headers
Aside from that everything is here. While goign through the tests fixing
them all up, I found many duplicate tests. They've been deleted. In
subsequent patches I will go through and re-add the missing
functionality.

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

llvm-svn: 305495
2017-06-15 19:34:41 +00:00
Petr Hosek 40f2866a67 [ELF] Mark symbols referenced from linker script as live
This is necessary to ensure that sections containing symbols referenced
from linker scripts (e.g. in data commands) don't get GC'd.

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

llvm-svn: 305452
2017-06-15 05:34:31 +00:00
Leslie Zhai 49ba795d15 [ELF] Initial migration of AVR target
Reviewers: ruiu, rafael, grimar, atanasyan, psmith, dylanmckay

Reviewed By: ruiu, rafael, grimar, dylanmckay

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

llvm-svn: 305444
2017-06-15 02:27:50 +00:00
Rui Ueyama 2aecdde512 Inline a small function. NFC.
llvm-svn: 305428
2017-06-14 23:37:37 +00:00
Zachary Turner a207f6476b Remove lld toStringRef function.
I added the same function in llvm, so this is causing an
ambiguous symbol.

llvm-svn: 305412
2017-06-14 20:20:11 +00:00
Rui Ueyama 0e2753897e Fix documentation.
We do not actually accept .rc files. We only accept .res files.

Pointed out by Eric Beckmann.

llvm-svn: 305406
2017-06-14 18:18:20 +00:00
Zachary Turner a8cfc29c9a Resubmit "[codeview] Make obj2yaml/yaml2obj support .debug$S..."
This was originally reverted because of some non-deterministic
failures on certain buildbots.  Luckily ASAN eventually caught
this as a stack-use-after-scope, so the fix is included in
this patch.

llvm-svn: 305393
2017-06-14 15:59:27 +00:00
Eugene Leviant ad270ec314 [ELF] Add armelf emulation mode
Differential revision: https://reviews.llvm.org/D34140

llvm-svn: 305375
2017-06-14 08:25:38 +00:00
Yuka Takahashi 1f1378dcbc Use getLastArgValue instead of getString
Summary: I found that getString defined in the LLD's Driver.cpp is
exactly the same as Arg::getLastArgValue defined in
llvm/Option/ArgLIst.h. This patch removes that local function and use
the function that the Arg class provides.

Reviewers: ruiu

Subscribers: emaste, llvm-commits

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

llvm-svn: 305374
2017-06-14 08:01:26 +00:00
Zachary Turner 0085dce221 Revert "[codeview] Make obj2yaml/yaml2obj support .debug$S..."
This is causing failures on linux bots with an invalid stream
read.  It doesn't repro in any configuration on Windows, so
reverting until I have a chance to investigate on Linux.

llvm-svn: 305371
2017-06-14 06:24:24 +00:00
Zachary Turner a3da4467fa [codeview] Make obj2yaml/yaml2obj support .debug$S/T sections.
This allows us to use yaml2obj and obj2yaml to round-trip CodeView
symbol and type information without having to manually specify the bytes
of the section. This makes for much easier to maintain tests. See the
tests under lld/COFF in this patch for example. Before they just said
SectionData: <blob> whereas now we can use meaningful record
descriptions. Note that it still supports the SectionData yaml field,
which could be useful for initializing a section to invalid bytes for
testing, for example.

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

llvm-svn: 305366
2017-06-14 05:31:00 +00:00
Rui Ueyama d3a4a3e3e4 Use StringRef::split instead of StringRef::find and StringRef::substr.
Summary: Pointed out by Yuka Takahashi.

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

llvm-svn: 305364
2017-06-14 04:02:40 +00:00
Rafael Espindola e86fddd651 Simplify. NFC.
llvm-svn: 305341
2017-06-13 23:54:34 +00:00
Rafael Espindola f51c80559c Make OutputSections and OutputSectionCommands globals.
This is similar to what we do for InputSections and makes them easier
to access.

llvm-svn: 305337
2017-06-13 23:26:31 +00:00
Rafael Espindola cdf813bbd1 Move clearOutputSections earlier. NFC.
llvm-svn: 305333
2017-06-13 22:36:20 +00:00
Rafael Espindola dece28087e Set non alloc section address to 0 earlier.
Currently we do layout as if non alloc sections had an actual address
and then set it to zero. This produces a few odd results where a
symbol has an address that is inconsistent with the section address.

The simplest way to fix it is probably to just set the address earlier.

The behavior of bfd seems to be similar, but it only sets the non
alloc section address is missing from the linker script or if the
script has an explicit " : 0" setting the address of the output
section (which the default script does).

llvm-svn: 305323
2017-06-13 20:57:43 +00:00
Sam Clegg be373670ec Add llvm-pdbutil tool_patterns in lit.cfg
This means that 'llvm-pdbutil' in test commands will resolve
to the absolute path to the tool, in line with what happens
already for other tools.

This works either way because the bin directory is also
prepended to the PATH.  I'm not sure why both methods are
used.

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

llvm-svn: 305297
2017-06-13 15:53:53 +00:00
Reid Kleckner 8cbdd0c0f2 [PDB] Add a module descriptor for every object file
Summary:
Expose the module descriptor index and fill it in for section
contributions.

Reviewers: zturner

Subscribers: llvm-commits, ruiu, hiraditya

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

llvm-svn: 305296
2017-06-13 15:49:13 +00:00
Reid Kleckner 41ff570657 [lld] Add .s to the test suffix list for all lld ports
We have two .s test files in lld/test/COFF that weren't being run as
part of check-lld. They both pass locally for me.

llvm-svn: 305295
2017-06-13 15:39:49 +00:00
Zachary Turner fa18b2f68c Fix broken LLD test.
llvm-svn: 305260
2017-06-13 00:30:09 +00:00
Rafael Espindola 4c4becf83c Also check section address in test.
This shows an oddity of this output. While the section address is 0,
the the symbol address is computed as if the section was allocatable.

llvm-svn: 305250
2017-06-12 23:22:00 +00:00
Zachary Turner 68ea80d0a7 Slightly better fix for dealing with no-id-stream PDBs.
The last fix required the user to manually add the required
feature.  This caused an LLD test to fail because I failed to
update LLD.  In practice we can hide this logic so it can just
be transparently added when we write the PDB.

llvm-svn: 305236
2017-06-12 21:46:51 +00:00
Peter Collingbourne 89061b2224 IR: Replace the "Linker Options" module flag with "llvm.linker.options" named metadata.
The new metadata is easier to manipulate than module flags.

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

llvm-svn: 305227
2017-06-12 20:10:48 +00:00
Rui Ueyama f9f69548a9 Allow the GNU gold-style nonstandard SHT_GROUP section.
The ELF standard defines that the SHT_GROUP section as follows:

 - its sh_link has the symbol index, and
 - the symbol name is used to uniquify section groups.

Object files created by GNU gold does not seem to comply with the
standard. They have this additional rule:

 - if the symbol has no name and a STT_SECTION symbol, a section
   name is used instead of a symbol name.

If we don't do anything for this, the linker fails with a mysterious
error message if input files are generated by gas. It is unfortunate
but I think we need to support it.

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

llvm-svn: 305218
2017-06-12 18:46:33 +00:00
Rafael Espindola f846ce259a Fix weak symbols on arm and aarch64.
Given

.weak target
 .global _start
_start:
 b target

The intention is that the branch goes to the instruction after the
branch, effectively turning it on a nop.  The branch adds the runtime
PC, but we were adding it statically too.

I noticed the oddity by inspection, but llvm-objdump seems to agree,
since it now prints things like:

b       #-4 <_start+0x4>

llvm-svn: 305212
2017-06-12 18:05:01 +00:00
Peter Collingbourne bfd5113ca1 ELF: Teach ICF about relocations referring to merge input sections.
Relocations referring to merge sections are considered equal if they
resolve to the same offset in the same output section.

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

llvm-svn: 305177
2017-06-12 00:05:54 +00:00
Peter Collingbourne dc7936eced ELF: Move section merging before ICF. NFCI.
Differential Revision: https://reviews.llvm.org/D34093

llvm-svn: 305176
2017-06-12 00:00:51 +00:00
Rafael Espindola 7ff9329b7c Move clearOutputSections before createPhdrs. NFC.
llvm-svn: 305156
2017-06-10 22:12:32 +00:00
Galina Kistanova 0c10465a57 Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.
llvm-svn: 305145
2017-06-10 08:06:17 +00:00
Rafael Espindola 07c8741644 Relax the overflow checking of R_386_PC16.
Currently the freebsd early boot code fails to link. The issue reduces
to 16 bit code at position 0x7000 wanting to jump to position
0x9000. That is represented in the .o file as a relocation with no
symbol and an addend of 0x9000 - 2 (The -2 is because i386 uses the ip
after the current instruction for jumps).

If the addend is interpreted as signed (it should), it is -28674. In a
32 bit architecture, that is the address 0xffff8ffe. To get there from
0x7000 we have to add 4294909950 (too big) or subtract 57346 (too
small). We then produce an error.

What lld is missing is the fact that at runtime this will actually be
a 16 bit architecture and adding 0x1ffe produces 0x8ffe which is the
correct result in 16 bits (-28674).

Since we have a 16 bit addend and a 16 bit PC, the relocation can move
the PC to any 16 bit address and that is the only thing we really need
to check: if the address we are pointing to fits in 16 bits. This is
unfortunately hard to do since we have to delay subtracting the PC and
if we want to do that outside of Target.cpp, we have to move the
overflow check out too.  An incomplete patch that tries to do that is
at https://reviews.llvm.org/D34070

This patch instead just relaxes the check. Since the value we have is
the destination minus the PC and the PC is 16 bits, it should fit in
17 bits if the destination fits in 16 too.

bfd had a similar issue for some time and got a similar fix:
https://sourceware.org/ml/binutils/2005-08/msg00001.html

llvm-svn: 305135
2017-06-10 01:56:58 +00:00
Rui Ueyama 1c837b5fb1 [ICF] Ignore SHF_GROUP flag when comparing two sections.
SHF_GROUP bit doesn't make sense in executables or DSOs, so linkers are
expected to remove that bit from section flags. We did that when we create
output sections.

This patch is to do that earlier than before. Now the flag is dropped when
we instantiate input section objects.

This change improves ICF. Previously, two sections that differ only in
SHF_GROUP flag were not merged, because when the control reached ICF,
the flag was still there. Now the flag is dropped before reaching to ICF,
so the difference is ignored naturally.

This issue was found by pcc.

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

llvm-svn: 305134
2017-06-10 00:38:55 +00:00
Rui Ueyama d97265f792 Simplify. NFC.
llvm-svn: 305112
2017-06-09 21:09:08 +00:00
Zachary Turner bd336e44d8 Rename llvm-pdbdump -> llvm-pdbutil.
This is to reflect the evolving nature of the tool as being
useful for more than just dumping PDBs, as it can do many other
things.

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

llvm-svn: 305106
2017-06-09 20:46:17 +00:00
Rafael Espindola d2a1b944bc Don't check the raw bits in tests.
It is not needed since we have the disassemble.

llvm-svn: 305096
2017-06-09 18:07:34 +00:00
George Rimar adaba7aeaa [ELF] - Simplify gdb-index-empty.s
Just simplifies existent test.

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

llvm-svn: 305073
2017-06-09 13:30:36 +00:00
George Rimar af845f26e6 [ELF] - Fix build bot.
llvm-svn: 305071
2017-06-09 12:58:13 +00:00
George Rimar 1840901a2f [ELF] - Allow producing -r output if only empty archive is given.
This is used by linux kernel build system.

(https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt "3.2 Built-in object goals")

It has for example next configuration for linking built-in.o files:
drivers-y	:= $(patsubst %/, %/built-in.o, $(drivers-y))
drivers-$(CONFIG_PCI)		+= arch/ia64/pci/
...
drivers-$(CONFIG_OPROFILE)	+= arch/ia64/oprofile/

Im most simple case all CONFIG_* options are off. That means linker is called with empty input archive, 
emulation option and no inputs and expected to generate some relocatable output. 
ld.bfd is able to do that, we dont.

Patch allows to support this case.

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

llvm-svn: 305069
2017-06-09 12:26:57 +00:00
Peter Smith 28285576cb [ELF] Be more precise about Thumb state bit in ARM thunks
The symbols generated for Thunks have type STT_FUNC, to permit a thunk to
be reused via a blx instruction the Thumb bit (0) needs to be set properly.

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

llvm-svn: 305065
2017-06-09 09:51:51 +00:00
George Rimar b4b7b74b5a [ELF] - Fix build bot.
SyntheticSections.cpp:1773:29: error: chosen constructor is explicit in copy-initialization
        CuVectors.push_back({});
                            ^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/set:428:14: note: constructor declared here
    explicit set(const value_compare& __comp = value_compare())
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/vector:702:59: note: passing argument to parameter '__x' here
    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);

llvm-svn: 305054
2017-06-09 04:48:56 +00:00
Rui Ueyama f08b38cbe1 Simplify. NFC.
llvm-svn: 305048
2017-06-09 03:19:08 +00:00
Rui Ueyama a1ba859ad3 Simplify. NFC.
llvm-svn: 305047
2017-06-09 02:42:20 +00:00
Rafael Espindola 6b901217dc Fix filename.
It was passing locally because of a leftover file.

llvm-svn: 305042
2017-06-09 00:56:09 +00:00
Rafael Espindola 85c607ea56 Add a test for R_386_PC16 range checking.
llvm-svn: 305040
2017-06-09 00:48:55 +00:00
Rui Ueyama 67aea737f3 Use check() to report an error.
llvm-svn: 305033
2017-06-08 23:43:44 +00:00
Rui Ueyama 38a2841665 Use LLVM_FALLTHROUGH.
llvm-svn: 305010
2017-06-08 20:16:21 +00:00
Rui Ueyama 3271d3704a Fix a bug in output section directive.
Previously, it couldn't parse

  SECTIONS .text (0x1000) : { *(.text) }

because "(" was interpreted as the begining of the "(NOLOAD)" directive.

llvm-svn: 305006
2017-06-08 19:47:16 +00:00
Rafael Espindola e76231b647 Move fabricateDefaultCommands earlier.
This then requires delaying a call to getHeaderSize.

llvm-svn: 304961
2017-06-08 04:17:04 +00:00
Rafael Espindola 7204620d32 Use OutputSectionCommands in assignOffsets.
This allows moving clearOutputSections earlier.

llvm-svn: 304952
2017-06-07 23:08:55 +00:00
Rafael Espindola f2c41271ca Delete dead code.
The real offsets are computed in assignAddresses and we compute the
special cases we need earlier after this.

llvm-svn: 304950
2017-06-07 22:57:52 +00:00
Rafael Espindola fa6fcff2e3 Move clearOutputSections earlier. NFC.
llvm-svn: 304948
2017-06-07 22:27:51 +00:00
Rafael Espindola 2356c9ffae Convert an use of OutputSections to OutputSectionCommands.
This allows moving clearOutputSections a bit earlier.

llvm-svn: 304947
2017-06-07 22:23:01 +00:00
Sam Clegg c1e7a0dde5 Add BinaryFormat to lld libraries
Without this, when building with shared BUILD_SHARED_LIBS=ON
I get errors such as:

lib/Core/Reader.cpp:40: error: undefined reference to
'llvm::identify_magic(llvm::StringRef)'

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

llvm-svn: 304932
2017-06-07 18:06:11 +00:00
George Rimar 8666562e89 [ELF] - Make implementation of .gdb index to be more natural for futher paralleling.
This patch reimplements .gdb_index in more natural way,
that makes proccess of switching to multithreaded index building to
be trivial. 

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

llvm-svn: 304927
2017-06-07 16:59:11 +00:00
George Rimar fbb0463f39 [ELF] - Linkerscript: implement NOLOAD section type.
This is PR32351

Each output section may have a type. The type is a keyword in parentheses.
(https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type)
This patch support only one type, it is NOLOAD.
If output section has such type, we force it to be SHT_NOBITS. 

More details are available on a review page.

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

llvm-svn: 304925
2017-06-07 16:31:08 +00:00
Rafael Espindola 66d98495b0 Delete dead function.
llvm-svn: 304914
2017-06-07 14:24:32 +00:00
George Rimar 0641b8b4d3 [ELF] - Simplify readAddressArea() implementation.
Approach significantly simplifies LLD .gdb_index code and makes it much faster.
Also it should resolve issues, like D33176 tries to address once and forever in a clean way.

LLC binary linking without patch and without --gdb-index: 1,599241063
LLC binary linking without patch and with --gdb-index: 6,064316262
LLC binary linking with patch and with --gdb-index: 4,116792104

Time spent for building gdbindex changes from (6,064316262 - 1,599241063 == 4,465075199)
to (4,116792104- 1,599241063 == 2,517551041).
That is 2,517551041/4,465075199 = 0,564 or about 44% speedup.

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

llvm-svn: 304895
2017-06-07 10:52:02 +00:00
Peter Smith 8e791463ef [ELF] Convert Thunks to use InputSectionDescriptions
Thunks are now generated per InputSectionDescription instead of per
OutputSection. This allows created ThunkSections to be inserted directly
into InputSectionDescription.

Changes in this patch:
- Loop over InputSectionDescriptions to find relocations to Thunks
- Generate a ThunkSection per InputSectionDescription
- Remove synchronize() as we no longer need it
- Move fabricateDefaultCommands() before createThunks

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

llvm-svn: 304887
2017-06-07 09:35:14 +00:00
George Rimar 990c9cb2bf [ELF] - Do not merge relocation sections by name when using --emit-relocs.
Previously we would merge relocation sections by name.
That did not work in some cases, like testcase shows.

Patch implements logic to merge relocation sections if their target
sections were merged into the same output section.

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

llvm-svn: 304886
2017-06-07 09:20:35 +00:00
George Rimar 41c7ab4a3d [ELF] - Linkerscript: improved error reporting.
When linking linux kernel LLD currently reports next errors:

ld: error: unable to evaluate expression: input section .head.text has no output section assigned
ld: error: At least one side of the expression must be absolute
ld: error: At least one side of the expression must be absolute

That does not provide file/line information and overall looks unclear. 
Patch adds location information to ExprValue and that allows
to provide more clear error messages.

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

llvm-svn: 304881
2017-06-07 08:54:43 +00:00
Galina Kistanova 1cbc801dd6 Removed the redundant comment. NFC.
llvm-svn: 304874
2017-06-07 06:52:58 +00:00
Galina Kistanova 91d62c9a56 Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.
llvm-svn: 304873
2017-06-07 06:46:38 +00:00
Zachary Turner 264b5d9e88 Move Object format code to lib/BinaryFormat.
This creates a new library called BinaryFormat that has all of
the headers from llvm/Support containing structure and layout
definitions for various types of binary formats like dwarf, coff,
elf, etc as well as the code for identifying a file from its
magic.

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

llvm-svn: 304864
2017-06-07 03:48:56 +00:00
Rafael Espindola d57c58d75d Move clearOutputSections earlier. NFC.
This now just requires not calling assignOffsets after it.

llvm-svn: 304861
2017-06-07 02:31:19 +00:00
Rafael Espindola 189860c317 Use assignAddresses with -r.
Before this patch in -r we compute the OutputSection sizes early in
the various calls to assignOffsets. With this change we can remove
most of those calls.

llvm-svn: 304860
2017-06-07 02:24:08 +00:00
Rafael Espindola 658a0c74ec Avoid using OutputSection::Sections. NFC.
We now used the InputSectionDescriptions in
OutputSectionCommand::finalize. This will allow moving
clearOutputSections earlier.

llvm-svn: 304827
2017-06-06 20:13:19 +00:00
Rafael Espindola 8c284acf14 Move finalize to OutputSectionCommands. NFC.
This removes a mapping from OutputSection to OutputSectionCommand and
is another step in moving clearOutputSections earlier.

llvm-svn: 304821
2017-06-06 19:40:01 +00:00
Rafael Espindola 13f412f6a2 Convert a use of OutputSections. NFC.
llvm-svn: 304820
2017-06-06 19:29:36 +00:00
Rafael Espindola 0e454a9837 Define __executable_start.
This is defined by both bfd and gold and used by the android libc.

llvm-svn: 304803
2017-06-06 16:18:48 +00:00
Peter Smith 8a2e00e631 [ELF] Refactor CreateThunks to extract the iteration through InputSections.
In preparation for inserting Thunks into InputSectionDescription::Sections
extract the loop that finds InputSections that may have calls that need
Thunks. This isn't much benefit now but this will be useful when we have to
extract the InputSectionDescriptions::Sections from the script.

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

llvm-svn: 304783
2017-06-06 10:06:48 +00:00
Peter Smith 8f7565b6f2 [ELF] Refactor ThunkCreator to not key on OutputSection for Thunks
In preparation for inserting Thunks into InputSectionDescriptions this
simple change associates added Thunks with a vector of InputSections instead
of an OutputSection. As of now we are just using OutputSection::Sections.

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

llvm-svn: 304782
2017-06-06 09:42:44 +00:00
George Rimar 1124001c68 [ELF] - Early return from writeTo() if section is SHT_NOBITS. NFCi.
That addresses port commit comments for https://reviews.llvm.org/D33646

llvm-svn: 304777
2017-06-06 07:46:28 +00:00
George Rimar 8cde9a7e77 [ELF] - Allow multiple comdats when producing relocatable output.
Previously LLD would fail for case when there are multiple comdats and -r.

That happened because it merged all ".group" (SHT_GROUP) sections into single
output, producing broken result. Such sections may have similar name, alignment and flags
and other properties. We need to produce separate output section for each such input one.

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

llvm-svn: 304769
2017-06-06 06:38:32 +00:00
Rafael Espindola a6fef0e5db Move clearOutputSections earlier.
This moves clearOutputSections and OutputSectionCommands creation as
early as possible without changing other code.

llvm-svn: 304751
2017-06-05 23:43:49 +00:00
Konstantin Zhuravlyov 4c882d90aa AMDGPU/LLD: Remove deprecated and unused elf definitions from tests
Differential Revision: https://reviews.llvm.org/D33691

llvm-svn: 304734
2017-06-05 20:57:17 +00:00
Petr Hosek 7953e62f2e [ELF] Define __dso_handle symbol if needed
Traditionally, it has been defined in crtbegin.o, which is typically
provided by libgcc or as part of the C library on some systems. However,
but there's no principled reason for it to be there. We optionaly
define this symbol, which can be used on platforms that don't provide
__dso_handle in crtbegin.o or which don't use crtbegin.o at all.

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

llvm-svn: 304732
2017-06-05 20:42:34 +00:00
Dmitry Mikulin db3b87b2c0 Symbols re-defined with -wrap and -defsym need to be excluded from inter-
procedural optimizations to prevent dropping symbols and allow the linker
to process re-directs.

PR33145: --wrap doesn't work with lto.
Differential Revision: https://reviews.llvm.org/D33621

llvm-svn: 304719
2017-06-05 16:24:25 +00:00
George Rimar 60a0ea161e [ELF] - Make LLD remove gnu-lib compression prefix (".z") after decompression when using -r
This is PR33289.

Previously LLD leaved section naming as is and that lead to wrong result,
because we decompress sections when using -r,
and hence should remove ".z" prefix.

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

llvm-svn: 304711
2017-06-05 12:49:21 +00:00
Peter Smith 43e852fb79 [ELF] SHF_LINK_ORDER should sort based on InputSectionDescriptions
This change alters the sorting for OutputSections with the SHF_LINK_ORDER
flag in OutputSection::finalize() to use the InputSectionDescription
representation and not the OutputSection::Sections representation.

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

llvm-svn: 304700
2017-06-05 08:51:15 +00:00
Rafael Espindola c7c42f6ae0 Convert another OutputSections use.
This allows moving clearOutputSections a bit earlier.

llvm-svn: 304654
2017-06-03 06:51:22 +00:00
Reid Kleckner c2eaccb0af Revert "Merge IAT and ILT."
This reverts r303374. It breaks Chrome's IAT patching code:
http://crbug.com/729077

llvm-svn: 304584
2017-06-02 18:49:38 +00:00
Reid Kleckner 146eb7a65f Re-land "COFF: migrate def parser from LLD to LLVM"
This reverts commit r304561 and re-lands r303490 & co.

The fix was to use "SymbolName" when translating LLD's internal export
list to lib/Object's short export struct. The SymbolName reflects the
actual symbol name, which may include fastcall and stdcall mangling bits
not included in the /EXPORT or .def file EXPORTS name:

@@ -434,8 +434,7 @@ std::vector<COFFShortExport> createCOFFShortExportFromConfig() {
   std::vector<COFFShortExport> Exports;
   for (Export &E1 : Config->Exports) {
     COFFShortExport E2;
-    E2.Name = E1.Name;
+    // Use SymbolName, which will have any stdcall or fastcall qualifiers.
+    E2.Name = E1.SymbolName;
     E2.ExtName = E1.ExtName;
     E2.Ordinal = E1.Ordinal;
     E2.Noname = E1.Noname;

llvm-svn: 304573
2017-06-02 17:53:06 +00:00
Reid Kleckner 5a1ed789e1 Add test case for LLD/COFF for stdcall exports in .def files
The .def file parser changes I reverted broke this test case, and
exported "__imp__foo" instead of "__imp__foo@8". This was
http://crbug.com/728726.

llvm-svn: 304572
2017-06-02 17:48:06 +00:00
Reid Kleckner d249e4a188 Revert "COFF: migrate def parser from LLD to LLVM"
This reverts commits r303490, r303491, r303493, and r303494.

This caused http://crbug.com/728726. Essentially, exporting stdcall
functions doesn't appear to work after this change. Reduced test case
soon.

llvm-svn: 304561
2017-06-02 16:26:24 +00:00
George Rimar 6a0644b24b [ELF] - Following commit for r304531 to fix BB.
Not sure why I did not faced that locally earlier, 
llvm-readobj did not have -s flag for 2/3 tests.

llvm-svn: 304539
2017-06-02 10:38:45 +00:00
George Rimar ef84219d21 [ELF] - Assign SHF_INFO_LINK flag to REL[A] sections.
Spec says: (http://www.sco.com/developers/gabi/latest/ch4.sheader.html)

sh_info
This member holds extra information, whose interpretation depends on the section type.
If the sh_flags field for this section header includes the attribute SHF_INFO_LINK, 
then this member represents a section header table index.

SHF_INFO_LINK
The sh_info field of this section header holds a section header table index.

Since sh_info for SHT_REL[A] sections should contain the section header index of the
section to which the relocation applies, this is
consistent with spec to put this flag. Behavior matches both bfd and gold as well.

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

llvm-svn: 304531
2017-06-02 09:17:45 +00:00
Rafael Espindola 0f7dc0e2d0 Run fabricateDefaultCommands before fixSectionAlignments.
This allows us to remove the PageAlign field. It will also allow
moving fabricateDefaultCommands earlier.

llvm-svn: 304513
2017-06-02 01:37:58 +00:00