Commit Graph

3293 Commits

Author SHA1 Message Date
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