Commit Graph

3426 Commits

Author SHA1 Message Date
Simon Atanasyan 6df6c75b61 [Mips] Support R_MIPS_PC16 relocation handling
llvm-svn: 239677
2015-06-13 14:48:14 +00:00
Simon Atanasyan 3d13c7dc67 [Mips] Use standard relocations R_MIPS_HI16/LO16 instead of custom variants
No functional changes.

llvm-svn: 239676
2015-06-13 14:48:04 +00:00
Rafael Espindola 9bd82e9952 Update for llvm api change.
llvm-svn: 239671
2015-06-13 12:50:13 +00:00
Davide Italiano d106ab263a [COFF] Spell the namespace correctly.
llvm-svn: 239641
2015-06-12 21:37:55 +00:00
Simon Atanasyan 5f54812cb0 [Mips] Handle TLS relocations in -static linking mode
llvm-svn: 239615
2015-06-12 16:13:14 +00:00
Simon Atanasyan d5296b206b [Mips] Define _gpxxx symbols in both static/dynamic linking modes
llvm-svn: 239614
2015-06-12 16:13:00 +00:00
Simon Atanasyan 01cde9cf5a [Mips] Setup EI_ABIVERSION flag
- Set EI_ABIVERSION to '1' in case of non-PIC executable.
- Set EI_ABIVERSION to '3' in case of using FP64/FP64A floating point ABI.

llvm-svn: 239613
2015-06-12 16:12:50 +00:00
Peter Collingbourne 1b6fd1f5fd COFF: Symbol resolution for common and comdat symbols defined in bitcode.
In the case where either a bitcode file and a regular file or two bitcode
files export a common or comdat symbol with the same name, the linker needs
to pick one of them following COFF semantics. This patch implements a design
for resolving such symbols that pushes most of the work onto either LLD's
regular mechanism for resolving common or comdat symbols or the IR linker's
mechanism for doing the same.

We modify SymbolBody::compare to always prefer non-bitcode symbols, so that
during the initial phase of symbol resolution, the symbol table always contains
a regular symbol in any case where we need to choose between a regular and
a bitcode symbol. In SymbolTable::addCombinedLTOObject, we force export
any bitcode symbols that were initially pre-empted by a regular symbol,
and later use SymbolBody::compare to choose between the regular symbol in
the symbol table and the regular symbol from the combined LTO object file.

This design seems to be sound, so long as the resolution mechanism is defined
to be commutative and associative modulo arbitrary choices between symbols
(which seems to be the case for COFF).

Differential Revision: http://reviews.llvm.org/D10329

llvm-svn: 239563
2015-06-11 21:49:54 +00:00
Rui Ueyama 8b33f59bfd COFF: De-virtualize and inline garbage collector functions.
isRoot, isLive and markLive functions are called very frequently.
Previously, they were virtual functions. This patch make them
non-virtual.

Also this patch checks chunk liveness before calling its mark().
Previously, we did that at beginning of markLive(), so the virtual
function would return immediately if it's live. That was inefficient.

llvm-svn: 239458
2015-06-10 04:21:47 +00:00
Peter Collingbourne bd1cb792d3 COFF: Implement /lib using LibDriver.
Differential Revision: http://reviews.llvm.org/D10347

llvm-svn: 239436
2015-06-09 21:52:48 +00:00
Rui Ueyama efba7812cc COFF: Split SymbolTable::addCombinedLTOObject. NFC.
llvm-svn: 239418
2015-06-09 17:52:17 +00:00
Rui Ueyama 0e77d227f8 COFF: Update comment.
llvm-svn: 239413
2015-06-09 16:52:56 +00:00
Peter Collingbourne 73b75e3d0c COFF: Handle references from LTO object to lazy symbols correctly.
The code generator may create references to runtime library symbols such as
__chkstk which were not visible via LTOModule. Handle these cases by loading
the object file from the library, but abort if we end up having loaded any
bitcode objects.

Because loading the object file may have introduced new undefined references,
call reportRemainingUndefines again to detect and report them.

Differential Revision: http://reviews.llvm.org/D10332

llvm-svn: 239386
2015-06-09 04:29:54 +00:00
Peter Collingbourne d9e4e98cce COFF: Allow the combined LTO object to define new symbols.
The LLVM code generator can sometimes synthesize symbols, such as SSE
constants, that are not visible via the LTOModule interface. Allow such
symbols so long as they have definitions.

Differential Revision: http://reviews.llvm.org/D10331

llvm-svn: 239385
2015-06-09 02:53:09 +00:00
Peter Collingbourne df637ea289 COFF: Skip internal symbols in bitcode files.
Differential Revision: http://reviews.llvm.org/D10319

llvm-svn: 239338
2015-06-08 20:21:28 +00:00
Rui Ueyama 57fe78d339 COFF: Read symbol names lazily.
This change seems to make the linker about 10% faster.
Reading symbol name is not very cheap because it needs strlen()
on the string table. We were wasting time on reading non-external
symbol names that would never be used by the linker.

llvm-svn: 239332
2015-06-08 19:43:59 +00:00
Rui Ueyama f533d3e09d COFF: Avoid callign stable_sort.
MSVC profiler reported that this stable_sort takes 7% time
when self-linking. As a result, createSection was taking 10% time.
Now createSection takes 3%. This small change actually makes
the linker a bit but perceptibly faster.

llvm-svn: 239292
2015-06-08 08:26:28 +00:00
Rui Ueyama 7d80640f25 COFF: Use the empty string as the current directory instead of ".".
This is NFC but makes log message a bit nicer because it doesn't
append .\ (or ./ on Unix) to files in the current directory.

llvm-svn: 239290
2015-06-08 06:13:12 +00:00
Rui Ueyama eeae5ddbe2 COFF: Add more log messages.
llvm-svn: 239289
2015-06-08 06:00:10 +00:00
Rui Ueyama 5b2588ae8c COFF: Print out log messages to stdout.
llvm-svn: 239288
2015-06-08 05:43:50 +00:00
Rui Ueyama 80141a4bcd COFF: Check for auxiliary symbol's type.
We forgot to check for auxiliary symbol's type. So we sometimes read
garbage as associative section definitions.

Associative sections are considered as not live themselves by the
garbage collector because they are live only when associaited sections
are live.

By reading more data (or garbage) as associative section definitions,
we treated more sections as non-GC-roots, that caused the linker to
discard too many sections by mistake. That caused another mysterious
bug (such as some global constructors don't run at all for some reason.)

llvm-svn: 239287
2015-06-08 05:00:42 +00:00
Rui Ueyama f811472b4c COFF: Simplify InputFile class.
Now that all InputFile subclasses have MemoryBufferRefs and
provides the same set of functions. Implement that in the base class.

llvm-svn: 239281
2015-06-08 03:27:57 +00:00
Rui Ueyama 9cf1abb8d4 COFF: Set non-1 alignment to common chunks.
I don't know what the right thing to do here, but at least 1 does
not seem like a correct value. If we do not align common chunks at
all, a small program which calls puts() from global dtors crashes
mysteriously in a kernel32's function.

I believe the crash was caused by symbols overlapping each other,
and my guess is that alignment has something to do with that, but
I am not 100% sure. Needs investigating.

llvm-svn: 239280
2015-06-08 03:17:07 +00:00
Rui Ueyama b4f791b510 COFF: Fix memory leak.
llvm-svn: 239272
2015-06-08 00:09:25 +00:00
Rui Ueyama a6cd6c0cd8 COFF: Fix typo.
This change doesn't change its functionality since the value
passed here is converted to uint16_t immediately.

llvm-svn: 239271
2015-06-07 23:10:50 +00:00
Rui Ueyama aace577e3e COFF: Simplify. NFC.
llvm-svn: 239270
2015-06-07 23:02:50 +00:00
Rui Ueyama b51f67a175 COFF: Use llvm:🆑:ExpandReponseFiles.
llvm-svn: 239269
2015-06-07 23:00:29 +00:00
Rui Ueyama 0c35b38fd2 COFF: Add a glossary to README.
llvm-svn: 239268
2015-06-07 22:42:52 +00:00
Rui Ueyama c6b87363a1 COFF: Use named constants instead of sizeof().
llvm-svn: 239267
2015-06-07 22:00:28 +00:00
Rui Ueyama b3aa5e71a0 COFF: Remove dead code.
/include'ed symbols are already added to Config->GCRoots.
Marking symbols twice doesn't have any effect.

llvm-svn: 239266
2015-06-07 21:58:34 +00:00
Rui Ueyama 94df713199 COFF: Make local variables local.
llvm-svn: 239244
2015-06-07 03:55:28 +00:00
Rui Ueyama e2cbfeae5c COFF: Add /opt:noref option.
This option disables dead-stripping.

llvm-svn: 239243
2015-06-07 03:17:42 +00:00
Rui Ueyama 115d7c1036 COFF: Support resonpse files.
llvm-svn: 239242
2015-06-07 02:55:19 +00:00
Rui Ueyama 4b22fa7437 COFF: Move Windows-specific code from Chunk.{cpp,h} to DLL.{cpp,h}.
llvm-svn: 239239
2015-06-07 01:15:04 +00:00
Rui Ueyama ad66098c20 COFF: Fix default output file path.
Default output filename is the same as the first object file's
name with its extension replaced with ".exe".

llvm-svn: 239238
2015-06-07 00:20:32 +00:00
Rui Ueyama 4a9fbbca9f COFF: Add comments and move main function to the top. NFC.
llvm-svn: 239237
2015-06-06 23:32:08 +00:00
Rui Ueyama cc608e4f35 COFF: Rename writeHeader -> writeHeaderTo.
Chunk has writeTo function which takes uint8_t *Buf.
writeHeaderTo feels more consistent with that because this member
function also takes uint8_t *Buf.

llvm-svn: 239236
2015-06-06 23:19:38 +00:00
Rui Ueyama 929d8c52b1 COFF: Inline a constant that is used only once.
llvm-svn: 239235
2015-06-06 23:19:36 +00:00
Rui Ueyama e56f9c0883 Remove redundant `using namespace`.
llvm-svn: 239234
2015-06-06 23:11:39 +00:00
Rui Ueyama 55168c9f70 COFF: Add .didat section.
llvm-svn: 239233
2015-06-06 23:07:01 +00:00
Rui Ueyama 458df98869 COFF: Update comments.
llvm-svn: 239232
2015-06-06 22:56:55 +00:00
Rui Ueyama c6ea057d7f COFF: Move .idata constructor from Writer to Chunk.
Previously, half of the constructor for .idata contents was in Chunks.cpp
and the rest was in Writer.cpp. This patch moves the latter to Chunks.cpp.
Now IdataContents class manages everything for .idata section.

llvm-svn: 239230
2015-06-06 22:46:15 +00:00
Simon Atanasyan 253fd15977 [Mips] Factor out some bit manipulation code into separate routines
No functional changes.

llvm-svn: 239226
2015-06-06 17:26:35 +00:00
Simon Atanasyan c859644f67 [Mips] Check symbol alignment for some MIPS relocations.
llvm-svn: 239225
2015-06-06 17:26:28 +00:00
Simon Atanasyan 439af8550e [Mips] Perform an overflow checking for relocations results
llvm-svn: 239224
2015-06-06 17:26:18 +00:00
Simon Atanasyan 26b1c4584d [Mips] Rearrange relocation related cases in the `switch` operator
No functional changes.

llvm-svn: 239223
2015-06-06 17:26:09 +00:00
Simon Atanasyan e801f43655 [Mips] Use signed/unsigned types in relocation calculations consistently
No functional changes.

llvm-svn: 239222
2015-06-06 17:26:04 +00:00
Simon Atanasyan 6d19105c1d [Mips] Handle all grouped relocations in a uniform way
No functional changes.

llvm-svn: 239221
2015-06-06 17:25:58 +00:00
Rui Ueyama 743afa0736 COFF: Merge Chunk::applyRelocations with Chunk::writeTo.
In this design, Chunk is the only thing that knows how to write
its contents to output file as well as how to apply relocations
there. The writer shouldn't know about the details.

llvm-svn: 239216
2015-06-06 04:07:39 +00:00
Peter Collingbourne ace2f091fd COFF: Read linker directives from bitcode files.
Differential Revision: http://reviews.llvm.org/D10285

llvm-svn: 239212
2015-06-06 02:00:45 +00:00
Simon Atanasyan 24945e6745 [Mips] Add test to check jal -> jalx conversion
No functional changes.

llvm-svn: 239180
2015-06-05 18:26:44 +00:00
Simon Atanasyan 6eadaf1921 [Mips] Add test to check relocation result shifting in case of N64 ABI
llvm-svn: 239179
2015-06-05 18:26:38 +00:00
Simon Atanasyan efad3402f0 [Mips] Fix rel-gprel16.test test case
This test case uses too large GP0 value. Now the test is correct. Later
we need to implement overflow checking to catch such cases.

llvm-svn: 239178
2015-06-05 18:26:33 +00:00
Simon Atanasyan 1a58aca55f [Mips] Fix hilo16-9-micro.test test case
This test case uses too large addends in relocations. Now the test is correct.
Later we need to implement overflow checking to catch such cases.

llvm-svn: 239177
2015-06-05 18:26:25 +00:00
Rui Ueyama 8854d8a6f1 COFF: Add /failifmismatch option.
llvm-svn: 239073
2015-06-04 19:21:24 +00:00
Rui Ueyama 2ba7908cf9 Add comments.
llvm-svn: 239072
2015-06-04 19:21:22 +00:00
Rafael Espindola 010ce27c0c Fix the test to use the correct size.
For some reason llvm's r239045 made lld propagate data_1's size. This indicates
a bug somewhere in lld.

I hesitated between changing the test or just checking in a .o produced with
the old llvm-mc. Since the size is now correct, it seemed better to update the
test.

llvm-svn: 239067
2015-06-04 18:49:12 +00:00
Rui Ueyama eb262ce4b6 COFF: /include'd symbols must be preserved.
Not only entry point symbol but also symbols specified by /include
option must be preserved, as they will never be dead-stripped.

http://reviews.llvm.org/D10220

llvm-svn: 239005
2015-06-04 02:12:16 +00:00
Adhemerval Zanella c694b40590 [ELF/AArch64] Fix build issue on MSVC
This patch fixes a build issue from r238981.

llvm-svn: 238986
2015-06-03 22:47:41 +00:00
Adhemerval Zanella 9f0c63bfdf [ELF/AArch64] Fix TLS initial executable relocation
This patch fixes the TLS initial executable for AArch64.  Current
implementation have two issues: 1. does not generate dynamic
R_AARCH64_TLS_TPREL64 relocation for the external module symbols,
and 2. does not export the TLS initial executable symbol in dynamic
symbol table.

The fix follows the MIPS strategy to add a arch-specific GOTSection
class to keep track of TLS symbols required to be place in dynamic
symbol table. It also overrides the buildDynamicSymbolTable for
ExecutableWrite class to add the symbols.

It also adds some refactoring on AArch64RelocationPass.cpp based on ARM
backend.

llvm-svn: 238981
2015-06-03 21:44:03 +00:00
Adhemerval Zanella 4bcc13d988 [ELF/AArch64] Fix correct TCB aligment calculation
This patch fixes the TLS local relocations alignment done by @238258.
As pointed out, the TLS size should not be considered, but rather the
TCB size based on maximum output segment alignment.  Although it has
not shown in the TLS simple cases for test-suite, more comprehensible
tests with more local TLS variable showed wrong relocations values
being generated.

The local TLS testcase is expanded to add more tls variable (both
exported and static) initialized or not.

llvm-svn: 238960
2015-06-03 20:39:30 +00:00
Rui Ueyama 2d7627198f Fix typo.
llvm-svn: 238937
2015-06-03 16:50:41 +00:00
Rui Ueyama bda72a4af4 COFF: Change OutputSections' type from vector<unique_ptr<T>> to vector<T*>.
This is mainly for readability. OutputSection objects are still owned
by the writer using SpecificBumpPtrAllocator.

llvm-svn: 238936
2015-06-03 16:44:00 +00:00
Rui Ueyama 652052b82c COFF: Update README.
Avoid saying this is based on sections because it's not very accurate.
That we don't split section into smaller chunks of data does not mean
that the linker is built on top of that.
In reality, most part of the code do not care about underlying data,
so they are neither based on "atoms" nor sections.
The symbol table only cares about symbol names and their types.
The writer handles list of chunks, which look like just blobs,
and the writer doesn't care what those chunks are backed by.
The only thing that interact with sections is SectionChunk, which is
abstracted away as one type of Chunk.

llvm-svn: 238902
2015-06-03 05:39:13 +00:00
Rui Ueyama 07e661f8cd COFF: SymbolTable to manage symbols using BumpPtrAllocator.
llvm-svn: 238901
2015-06-03 05:39:12 +00:00
Rafael Espindola 3df0533b00 Update for LLVM api change.
llvm-svn: 238825
2015-06-02 12:05:36 +00:00
Denis Protivensky dad8aa8241 [Mips] Fix enumeral vs. non-enumeral warning in ternary. NFC
That's a weird gcc's complain.

llvm-svn: 238812
2015-06-02 09:22:38 +00:00
Rui Ueyama 1db1ef9ab4 Use reinterpret_cast instead of const_cast and C-style cast.
llvm-svn: 238786
2015-06-01 21:49:21 +00:00
Rui Ueyama 81b030cbf6 COFF: Remove BitcodeFile::BitcodeFile(StringRef Filename).
In r238690, I made all files have only MemoryBufferRefs. This change
is to do the same thing for the bitcode file reader. Also updated
a few variable names to match with other code.

llvm-svn: 238782
2015-06-01 21:19:43 +00:00
Rui Ueyama fd99e01b91 COFF: Support import-by-ordinal DLL imports.
Symbols exported by DLLs can be imported not by name but by
small number or ordinal. Usually, symbols have both ordinals
and names, and in that case ordinals are called "hints" and
used by the loader as hints.

However, symbols can have only ordinals. They are called
import-by-ordinal symbols. You need to manage ordinals by hand
so that they will never change if you choose to use the feature.
But it's supposed to make dynamic linking faster because
it needs no string comparison. Not sure if that claim still
stands in year 2015, though. Anyways, the feature exists,
and this patch implements that.

llvm-svn: 238780
2015-06-01 21:05:27 +00:00
Rui Ueyama c2abdd9152 COFF: Use Chunk instead of its derived classes.
I'm adding ordinal-only (nameless) imports to the import table.
The chunk for that type is going to be different from LookupChunk.
Without this change, we cannot add objects of the new type to the
vectors.

llvm-svn: 238779
2015-06-01 21:05:24 +00:00
Peter Collingbourne 60c1616613 COFF: Initial implementation of link-time optimization.
This implementation is known to work in very simple cases (see new test case).

Differential Revision: http://reviews.llvm.org/D10115

llvm-svn: 238777
2015-06-01 20:10:10 +00:00
Denis Protivensky 6833690402 COFF: Fix warnings found by gcc
llvm-svn: 238734
2015-06-01 09:26:32 +00:00
Denis Protivensky 1c43df7481 COFF: Better noexcept specification with LLVM_NOEXCEPT
This is a follow-on to r238732

llvm-svn: 238733
2015-06-01 09:08:11 +00:00
Denis Protivensky c44223ed96 COFF: Add noexcept to std::error_category::name
This fixes build error with gcc.

llvm-svn: 238732
2015-06-01 08:12:44 +00:00
Rui Ueyama 5b25edddfe COFF: Fix the import table Hint/Name field.
llvm-svn: 238719
2015-06-01 03:55:04 +00:00
Rui Ueyama 68216c680d Fix comments.
llvm-svn: 238718
2015-06-01 03:55:02 +00:00
Rui Ueyama 78aefcb238 COFF: Fix /include. Included symbols are GC-roots.
llvm-svn: 238717
2015-06-01 03:42:54 +00:00
Rui Ueyama 8fd9fb9857 COFF: Define an error category for the linker.
Instead of returning non-categorized errors, return categorized errors.
All uses of make_dynamic_error_code are removed.

Because we don't have error reporting mechanism, I just chose to print out
error messages to stderr, and then return an error object. Not sure if
that's the right thing to do, but at least it seems practical.

http://reviews.llvm.org/D10129

llvm-svn: 238714
2015-06-01 02:58:15 +00:00
Rui Ueyama 360bace8eb COFF: Add /alternatename option.
Previously, this feature was implemented using a special type of
undefined symbol, in addition to an intricate way to make the resolver
read a virtual file containing that renaming symbols.

Now the feature is directly handled by the symbol table.
The symbol table has a function, rename(), to rename symbols, whose
definition is 4 lines long. Symbol renaming is naturally modeled using
Symbol and SymbolBody.

llvm-svn: 238696
2015-05-31 22:31:31 +00:00
Rui Ueyama 711cd2d7c8 COFF: Detect file type by file magic.
llvm-svn: 238691
2015-05-31 21:17:10 +00:00
Rui Ueyama d7c2f5847a COFF: Make the Driver own all MemoryBuffers. NFC.
Previously, a MemoryBuffer of a file was owned by each InputFile object.
This patch makes the Driver own all of them. InputFiles now have only
MemoryBufferRefs. This change simplifies ownership managment
(particularly for ObjectFile -- the object owned a MemoryBuffer only when
it's not created from an archive file, because in that case a parent
archive file owned the entire buffer. Now it owns nothing unconditionally.)

llvm-svn: 238690
2015-05-31 21:04:56 +00:00
Simon Atanasyan faa8bfdd1a [Mips] Add a couple of MipsAbiInfoHandler functions to check linked code type
No functional changes.

llvm-svn: 238689
2015-05-31 20:37:22 +00:00
Simon Atanasyan 2944e4a43d [Mips] Do not put the .reginfo section into the separate segment
The .reginfo should not belong to the separate segment if there is
a .MIPS.abiflags section.

llvm-svn: 238688
2015-05-31 20:37:13 +00:00
Simon Atanasyan c140b41c39 [Mips] Sort segments so PT_MIPS_ABIFLAGS goes right after the PT_INTERP
llvm-svn: 238687
2015-05-31 20:36:58 +00:00
Simon Atanasyan c90c425735 [Mips] Reading, merging and writing .MIPS.abiflags section
http://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking

llvm-svn: 238686
2015-05-31 20:36:43 +00:00
Simon Atanasyan 3eec407a53 [Mips] Delete MipsReginfo structure. Use the Elf_Mips_RegInfo instead.
llvm-svn: 238685
2015-05-31 20:36:21 +00:00
Simon Atanasyan 70e21bc83d [Mips] Collect all ABI related info in the single MipsAbiInfoHandler class
New MipsAbiInfoHandler merges and hold both ELF header flags
and registries usage masks. In the future commits it will manage some
additional information.

llvm-svn: 238684
2015-05-31 20:36:11 +00:00
Rui Ueyama f4784cce54 COFF: /libpath should not take precedence over the current directory.
llvm-svn: 238683
2015-05-31 20:20:37 +00:00
Rui Ueyama 0613747e1a COFF: Add /libpath option.
llvm-svn: 238682
2015-05-31 20:10:11 +00:00
Rui Ueyama e042fa9aa5 COFF: Add /include option.
It does not involve notions of virtual archives or virtual files,
nor store a list of undefined symbols somewhere else to consume them later.
We did that before. In this patch, undefined symbols are just added to
the symbol table, which now can be done in very few lines of code.

llvm-svn: 238681
2015-05-31 19:55:40 +00:00
Rui Ueyama d21b00bd7c COFF: Add /nodefaultlib option.
llvm-svn: 238679
2015-05-31 19:17:14 +00:00
Rui Ueyama 54b71daec4 COFF: Refactor functions to find files from search paths.
llvm-svn: 238678
2015-05-31 19:17:12 +00:00
Rui Ueyama a9cbbf885f COFF: Create LinkerDriver class.
Previously the main linker routine is just a non-member function.
We store some context information to the Config object.
This patch makes it belong to Driver.

llvm-svn: 238677
2015-05-31 19:17:09 +00:00
Rui Ueyama 80b5689d91 COFF: Use range-based for loop.
llvm-svn: 238675
2015-05-31 16:10:50 +00:00
Rui Ueyama aa47cf9dae COFF: Remove redundant options from tests.
llvm-svn: 238670
2015-05-31 04:21:30 +00:00
Rui Ueyama d68ff34ad2 Fix unsafe memory access.
llvm-svn: 238669
2015-05-31 03:57:30 +00:00
Rui Ueyama 3ee0fe4c2c COFF: Implement subsystem inference.
llvm-svn: 238668
2015-05-31 03:55:46 +00:00
Rui Ueyama 5cff68599d COFF: Infer entry symbol name if /entry is not given.
`main` is not the only main function in Windows. You can choose one
from these four -- {w,}{WinMain,main}. There are four different entry
point functions for them, {w,}{WinMain,main}CRTStartup, respectively.
The linker needs to choose the right one depending on which `main`
function is defined.

llvm-svn: 238667
2015-05-31 03:34:08 +00:00
Rui Ueyama e00d651071 Use initializer instead of memset to zero out.
llvm-svn: 238662
2015-05-30 19:28:58 +00:00
Rui Ueyama bfb4aa1791 COFF: Support long section name.
Section names were truncated to 8 bytes because the section table's
name field is 8 byte long. This patch creates the string table to
store long names.

llvm-svn: 238661
2015-05-30 19:09:50 +00:00
Peter Collingbourne 246ccc5f51 COFF: Move machine type auto-detection to SymbolTable.
The new mechanism is less code, and fixes the case where all inputs
are archives.

Differential Revision: http://reviews.llvm.org/D10136

llvm-svn: 238618
2015-05-29 21:47:36 +00:00
Rui Ueyama 15cc47ee81 COFF: Add /subsystem option.
llvm-svn: 238571
2015-05-29 16:34:31 +00:00
Rui Ueyama b9dcdb5fc9 COFF: Add /version option.
llvm-svn: 238570
2015-05-29 16:28:29 +00:00
Rui Ueyama c377e9aefe COFF: Add /heap option.
llvm-svn: 238569
2015-05-29 16:23:40 +00:00
Rui Ueyama b41b7e5a69 Add /stack option.
llvm-svn: 238568
2015-05-29 16:21:11 +00:00
Rui Ueyama 804a8b6361 COFF: Add /base option.
llvm-svn: 238567
2015-05-29 16:18:15 +00:00
Rui Ueyama 5c726433d2 COFF: Add /help option.
llvm-svn: 238565
2015-05-29 16:11:52 +00:00
Rui Ueyama 3d3e6fba6e COFF: Add /machine option.
llvm-svn: 238564
2015-05-29 16:06:00 +00:00
Rui Ueyama 7c4fcdd559 COFF: Move Windows-specific function under Windows-specific marker.
llvm-svn: 238563
2015-05-29 15:49:09 +00:00
Rui Ueyama c9bfe32010 COFF: Fill imort table HintName field.
Currently we set the field to zero, but as per the spec, we should
set numbers we read from import library files. The loader uses the
values as starting offsets for binary search when looking up imported
symbols from DLL.

llvm-svn: 238562
2015-05-29 15:45:35 +00:00
Rui Ueyama 322b2c413d COFF: Return an error_code directly.
llvm-svn: 238486
2015-05-28 20:39:29 +00:00
Rui Ueyama 3500f6667a COFF: Split Driver.cpp to Driver.cpp and DriverUtils.cpp. NFC.
The previous implementation's driver file is cluttered by lots of
small functions, and it was hard to find important functions.
Make a separate file to prevent that issue.

llvm-svn: 238482
2015-05-28 20:30:06 +00:00
Rui Ueyama d52824d361 Rename InputFile::Name -> InputFile::Filename.
Other local variables shadowed the member variable.
Rename to make that a bit longer.

llvm-svn: 238478
2015-05-28 20:16:25 +00:00
Rui Ueyama 9aefa0c6b9 Fix non-debug build.
llvm-svn: 238474
2015-05-28 20:04:51 +00:00
Rui Ueyama d6fefba447 COFF: Teach Chunk to write to a mmap'ed output file.
Previously Writer directly handles writes to a file.
Chunks needed to give Writer a continuous chunk of memory.
That was inefficent if you construct data in chunks because
it would require two memory copies (one to construct a chunk
and the other is to write that to a file).

This patch teaches chunk to write directly to a file.
From readability point of view, this is also good because
you no longer have to call hasData() before calling getData().

llvm-svn: 238464
2015-05-28 19:45:43 +00:00
Rui Ueyama 411c636081 COFF: Add a new PE/COFF port.
This is an initial patch for a section-based COFF linker.

The patch has 2300 lines of code including comments and blank lines.
Before diving into details, you want to start from reading README
because it should give you an overview of the design.

All important things are written in the README file, so I write
summary here.

- The linker is already able to self-link on Windows.

- It's significantly faster than the existing implementation.
  The existing one takes 5 seconds to link LLD on my machine,
  while the new one only takes 1.2 seconds, even though the new
  one is not multi-threaded yet. (And a proof-of-concept multi-
  threaded version was able to link it in 0.5 seconds.)

- It uses much less memory (250MB vs. 2GB virtual memory space
  to self-host).

- IMHO the new code is much simpler and easier to read than
  the existing PE/COFF port.

http://reviews.llvm.org/D10036

llvm-svn: 238458
2015-05-28 19:09:30 +00:00
Michael J. Spencer 42a738198b Fix unused variable warnings.
llvm-svn: 238384
2015-05-28 00:29:56 +00:00
Michael J. Spencer cc0554d057 Add PHDR and FILL parsing.
llvm-svn: 238383
2015-05-28 00:14:58 +00:00
Simon Atanasyan 06eccbea9d [Mips] Move member function definitions to cpp files
No functional changes.

llvm-svn: 238310
2015-05-27 11:56:15 +00:00
Simon Atanasyan bb399f3d57 [ELF][Mips] Do not merge ELF flags in the `isCompatible` routine
We do not need to merge ELF flags from DSO. But `isCompatible` is called
for all input files. So this change move ELF flags merging into the
MipsELFFile class.

llvm-svn: 238304
2015-05-27 08:45:31 +00:00
Simon Atanasyan 256f2cadfe [Mips] Factor out look up of Elf_Mips_RegInfo structure into the separate function
No functional changes.

llvm-svn: 238303
2015-05-27 08:45:21 +00:00
Adhemerval Zanella f3c1c065aa [ELF/AArch64] Fix local TLS relocations
This patch fixes the R_AARCH64_TLSLE_ADD_TPREL_HI12 and R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
handling by using the correct offset by using the target layout along with
aarch64 alignments requirements.

It fixes the TLS test-suite SingleSource failures for aarch64:

* SingleSource/UnitTests/Threads/2010-12-08-tls.execution_time
* SingleSource/UnitTests/Threads/tls.execution_time

llvm-svn: 238258
2015-05-26 21:49:39 +00:00
Denis Protivensky 499292dede [ARM] Fix enum type cast in switch
It caused warning in clang assuming the default
branch would never be reached with the given
switch key type.

llvm-svn: 238194
2015-05-26 11:13:09 +00:00
Denis Protivensky 02fc0b1d64 [ARM] Move out .ARM.exidx related things to ARM backend
llvm-svn: 238191
2015-05-26 10:26:15 +00:00
Simon Atanasyan b48abf5dac [Mips] Use structures declared in the llvm/Object/ELFTypes.h
No functional changes.

llvm-svn: 238189
2015-05-26 08:48:33 +00:00
Simon Atanasyan e62aa7457f [Mips] Add Elf_Mips_Options::getRegInfoDesc() function to retrieve an ODK_REGINFO descriptor
No functional changes.

llvm-svn: 238176
2015-05-26 06:05:07 +00:00
Simon Atanasyan e09faec16e [Mips] Make the code shorter - use LLVM_ELF_IMPORT_TYPES_ELFT macro
No functional changes.

llvm-svn: 238175
2015-05-26 06:05:01 +00:00
Davide Italiano 683703ea6d [ELF] Add support for -z origin/now options.
Differential Revision:	http://reviews.llvm.org/D9963

llvm-svn: 238169
2015-05-26 01:57:32 +00:00
Simon Atanasyan 0b22359858 [ELF] Fix lld when no unique sections is used
Original patch of Shankar Easwaran with additional test case.
The yaml2obj does not allow to create an object file with non-unique
sections names so the fix uses a binary input object file in the test
case.

llvm-svn: 238115
2015-05-24 16:19:27 +00:00
Lang Hames 825e258fc3 [lld] Manage atom ordinals in the File class rather than using a static counter.
This is a cleaner fix for the race-condition bug that was originally papered
over by r237857.

llvm-svn: 238072
2015-05-22 23:56:44 +00:00
Simon Atanasyan b2f6afb30a [Mips] Cleanup and reformat test cases, add more checkings
No functional changes.

llvm-svn: 238050
2015-05-22 21:08:37 +00:00
Benjamin Kramer ebcc0dcad1 Remove redundant std::move on functions that return a unique_ptr.
llvm-svn: 238034
2015-05-22 17:52:04 +00:00
Benjamin Kramer 91d8cfd698 [ELF] Remove redundant unique_ptr moves found by -Wpessimizing-move.
llvm-svn: 238030
2015-05-22 16:01:21 +00:00
Benjamin Kramer fc99f3d43f [ELF] Fix shared CMake build.
llvm-svn: 238029
2015-05-22 16:01:12 +00:00
Denis Protivensky f2c22f4ff8 [ARM] report_fatal_error for not implemented functionality
llvm-svn: 238017
2015-05-22 12:39:05 +00:00
Denis Protivensky 575f7d4f1c [ARM] Ability to add GOT and PLTGOT entries for same symbol
These two serve different purpose:
PLTGOT entries are (usually) lazily resolved and serve as trampolines
to correctly call dynamically linked functions. They often have
R_*_JUMP_SLOT dynamic relocation type used.
Simple GOT entries hold other things, one of them may be
R_*_GLOB_DAT to correctly reference global and static data. This
is also used to hold dynamically linked function's address.

To properly handle cases when shared object's function is called
and at the same time its address is taken, we need to be able to have
both GOT and PLTGOT entries bearing different dynamic relocation types
for the same symbol.

llvm-svn: 238015
2015-05-22 11:23:39 +00:00
Denis Protivensky 214122cffc [ARM] Implement R_ARM_GLOB_DAT for GOT entries
This is used when referencing global or static data in shared
objects. This is also used when function's address is taken and
function call is made indirectly.

llvm-svn: 238014
2015-05-22 11:00:31 +00:00
Lang Hames ff4b13c538 [lld] Make the MachO -stack_size default '0', add a test case.
Addresses some review comments for r237841.

llvm-svn: 237979
2015-05-22 00:25:34 +00:00
Davide Italiano 339191fcfa [ELF] Simplify dynamic table entry creation.
Differential Revision:	http://reviews.llvm.org/D9921
Reviewed by:  atanasyan

llvm-svn: 237973
2015-05-21 23:44:19 +00:00
Denis Protivensky af1c9dd513 [ARM] Add dynamic symbols to the dynamic library writer
llvm-svn: 237898
2015-05-21 12:52:00 +00:00
Denis Protivensky eb273b6b28 [ARM] Remove useless file with writer's instantiation stub
llvm-svn: 237896
2015-05-21 12:31:15 +00:00
Denis Protivensky db2b179b1e [ARM] Remove unused field in executable writer
llvm-svn: 237892
2015-05-21 11:50:54 +00:00
Denis Protivensky ad52e44e98 [ARM] Move out common Writer functionality to ARMELFWriter
llvm-svn: 237891
2015-05-21 11:16:40 +00:00
Denis Protivensky 30e40be080 [ELF] Move start/end atom method assignment to OutputELFWriter. NFC
llvm-svn: 237886
2015-05-21 10:11:27 +00:00
Denis Protivensky e6651618a8 [ARM] Remove unused fields in dynamic library writer
llvm-svn: 237883
2015-05-21 09:52:21 +00:00
Denis Protivensky 2db1a03b07 [ARM] Add skeleton implementation of DSO linking
llvm-svn: 237881
2015-05-21 09:28:25 +00:00
Lang Hames b103c0321f [LLD] Make lastOrdinal atomic to avoid race conditions.
No test case: We don't have a good way to test race conditions.

llvm-svn: 237857
2015-05-20 23:44:37 +00:00
Lang Hames 2a10996706 [LLD] Fix an out-of-order-initialization bug that was introduced in r237841 by
moving a field in MachOLinkingContext.

llvm-svn: 237847
2015-05-20 22:35:20 +00:00
Lang Hames d48be84032 [LLD] Revert r237842 - it went in without a proper commit message.
llvm-svn: 237846
2015-05-20 22:33:34 +00:00