Commit Graph

3759 Commits

Author SHA1 Message Date
Rui Ueyama 04ec69aa9e COFF: Use ErrorOr::operator* instead of ErrorOr::get.
This patch is to make COFF coding style consistent with ELF. NFC.

llvm-svn: 245282
2015-08-18 09:18:15 +00:00
Rui Ueyama 570752c7ac Do not use unique pointers. NFC.
These unique pointers have the exact same lifetime as automatic
variables, so use automatic variables instead.

llvm-svn: 245281
2015-08-18 09:13:25 +00:00
Rui Ueyama 95b781d863 COFF: Do not handle __NULL_IMPORT_DESCRIPTOR differently than the other symbols.
__NULL_IMPORT_DESCRIPTOR is a symbol used by MSVC liner to construct
the import descriptor table. We do not use the symbol. Previously,
we had code to skip that symbol. That code does not actually do
anything meaningful because no one is referencing the symbol, the
symbol would naturally be ignored. This patch stops recognizing
the symbol.

llvm-svn: 245280
2015-08-18 09:06:41 +00:00
Rui Ueyama 0081f91853 Create lld-link symlink on "make/ninja/whatever install".
llvm-svn: 245266
2015-08-18 04:24:46 +00:00
Rui Ueyama 7171c82194 COFF: Allow forward reference for weak externals
Previously, weak external symbols could reference only symbols that
appeared before them. Although that covers almost all use cases
of weak externals, there are object files out there which contains
weak externals that have forward references.

This patch supports such weak externals.

llvm-svn: 245258
2015-08-17 23:35:43 +00:00
Rui Ueyama 27716bb9d9 COFF: Fix a broken test.
This test couldn't be run more than once because lib.exe does not work
if the files already exist.

llvm-svn: 245214
2015-08-17 11:06:21 +00:00
Rui Ueyama d157088adb COFF: Fix the order of the DLL import entry.
There are some DLLs whose initializers depends on other DLLs'
initializers. The initialization order matters for them.

MSVC linker uses the order of the libraries from the command line.
LLD used ASCII-betical order. So they were incompatible.
This patch makes LLD compatible with MSVC.

llvm-svn: 245201
2015-08-17 08:30:31 +00:00
Rui Ueyama e73e418bb4 COFF: Simplify Writer::createImportTables.
A short import library has up to two symbols, so we don't have
to do a for-loop and type dispatch in createImportTables.

llvm-svn: 245200
2015-08-17 07:27:45 +00:00
Rafael Espindola 1bd885aba4 ELF: Also record the type of undefined symbols.
Tested with a weak undefined. Testing with a plain undefined will have to wait
for support for -shared.

llvm-svn: 245069
2015-08-14 16:46:28 +00:00
Rafael Espindola bd481b8f89 Fix the build with gcc.
llvm-svn: 245060
2015-08-14 15:20:34 +00:00
Rafael Espindola c44d17ad45 Add the type of the symbols to the symbol table.
For now only defined symbols are covered. I will add undefined ones in the
next patch.

llvm-svn: 245057
2015-08-14 15:10:49 +00:00
Rafael Espindola 457c940835 Delete dead code.
llvm-svn: 245056
2015-08-14 14:58:57 +00:00
Rafael Espindola 4c3aa0f228 Delete unused forward declarations.
llvm-svn: 245055
2015-08-14 14:51:11 +00:00
Rafael Espindola 3bf356ee9c Remove unused default values.
llvm-svn: 245053
2015-08-14 14:38:44 +00:00
Rafael Espindola beee25e484 Make these headers as being c++.
llvm-svn: 245050
2015-08-14 14:12:54 +00:00
Rafael Espindola 383c323d4d ELF: Set the correct symbol binding.
llvm-svn: 245049
2015-08-14 13:52:36 +00:00
Rafael Espindola 62b81b875a Start populating the symbol table.
With this patch only the name is set. I will set the other fields shortly.

For now the table doesn't include local symbols. This is equivalent to using
--discard-all with gnu ld. This is OK for now since the symbols are not
needed for execution and for testing symbol resolution we only need the
global symbols.

llvm-svn: 245044
2015-08-14 13:07:05 +00:00
Rui Ueyama 8050d32b13 ELF2: Rename a function to make it the same as the COFF's counterpart.
llvm-svn: 245030
2015-08-14 05:17:30 +00:00
Peter Collingbourne 526ff15546 COFF: Introduce flag /opt:lldlto=N for controlling LTO optimization level.
Differential Revision: http://reviews.llvm.org/D12024

llvm-svn: 245027
2015-08-14 04:47:07 +00:00
Rafael Espindola 5c546a1437 COFF: In chunks, store the offset from the start of the output section. NFC.
This is more convenient than the offset from the start of the file as we
don't have to worry about it changing when we move the output section.

This is a port of r245008 from ELF.

llvm-svn: 245018
2015-08-14 03:30:59 +00:00
Rafael Espindola f763ca3c9c ELF: Create a symbol table.
For now it is empty. I will add the symbols in a followup patch.

llvm-svn: 245008
2015-08-14 02:42:20 +00:00
Rafael Espindola 83b0dc6392 ELF: Drop the Chunk base class.
With OutputSection being a virtual interface, each concrete OutputSection
handles only one type of chunk and we don't need a base Chunk class.

So for we have a class that handles input sections and one that handles
the string table, but this extends naturally for other outputs (symbol table,
merging of SHF_MERGE sections, etc.).

llvm-svn: 244972
2015-08-13 22:21:37 +00:00
Rafael Espindola ebd2108215 Make OutputSection virtual and use that for creating the string table.
We were creating the string table in a completely ad hoc way. Now the
string table is an output section and gets its output offset set just like
any other section.

This opens the way for other linker created sections like the symbol table.

llvm-svn: 244969
2015-08-13 22:14:37 +00:00
Rafael Espindola 2db634d8f1 Correctly align output sections.
They don't need to be aligned to page boundaries. Only segments need that.

llvm-svn: 244942
2015-08-13 20:24:18 +00:00
Rafael Espindola 0160a281c2 Record the alignment of the output sections.
llvm-svn: 244941
2015-08-13 20:13:39 +00:00
Rafael Espindola 5d83ccd55b Make getSectionName non virtual. NFC.
llvm-svn: 244939
2015-08-13 19:18:30 +00:00
Rafael Espindola ea133eaa39 Delete dead code.
llvm-svn: 244938
2015-08-13 19:00:23 +00:00
Rafael Espindola a175eb6ca6 Template OutputSection only over Is64Bit.
This is a bit more c++ code, but:
* It is less machine code: lld's text is 44688 bytes smaller.
* It should be a bit more efficient in the non native endian case.
* It should be a bit more efficient on architectures with slow unaligned access.

llvm-svn: 244934
2015-08-13 18:37:23 +00:00
Rafael Espindola 184d94e009 Define trivial methods inline. NFC.
llvm-svn: 244930
2015-08-13 18:25:47 +00:00
Rafael Espindola 64e888ba5f Set the file offset of zero sized sections.
There is no reason not to do it and this matches what gold and bfd ld do.

llvm-svn: 244929
2015-08-13 18:23:43 +00:00
Rafael Espindola 29e8d343e4 Rename addSectionChunk to addChunk now that it can handle any Chunk.
llvm-svn: 244919
2015-08-13 17:35:13 +00:00
Rafael Espindola 375a508234 Pass the type and flags to the OutputSection constructor. NFC.
This will allow further cleanups.

llvm-svn: 244918
2015-08-13 17:32:30 +00:00
Rafael Espindola a7471795ae Take name, type and flags in consideration when concatenating sections.
This is mandated by the ELF spec.

llvm-svn: 244911
2015-08-13 17:04:50 +00:00
Rafael Espindola 674b5d570f Store the offset in the output section, no in the file.
That is the value that is stable as the we layout the output sections.

llvm-svn: 244904
2015-08-13 15:54:36 +00:00
Rafael Espindola ef1ac01c2e Don't give an address to sections that are not allocated.
llvm-svn: 244900
2015-08-13 15:31:17 +00:00
Rafael Espindola abad6186c3 Place SHF_ALLOC sections first in the output.
Having them in the middle of the file complicates the creation of segments.

llvm-svn: 244898
2015-08-13 15:23:46 +00:00
Rafael Espindola 25f51850a4 Delete dead code.
llvm-svn: 244896
2015-08-13 14:48:49 +00:00
Rafael Espindola cde251370a Include non-alloca sections in the link.
llvm-svn: 244895
2015-08-13 14:45:44 +00:00
Rafael Espindola f0461ba985 Update for llvm api change.
llvm-svn: 244856
2015-08-13 01:07:08 +00:00
Rafael Espindola bdc8f2fb83 Update for llvm api change.
llvm-svn: 244849
2015-08-13 00:31:46 +00:00
Rafael Espindola 40dfae36fc This test needs lib.exe.
llvm-svn: 244844
2015-08-13 00:03:47 +00:00
David Blaikie a3191ef66b Wdeprecated: Remove unnecessary user-defined dtor that was getting in the way of the default ops (copy construction, assignment, etc)
llvm-svn: 244836
2015-08-12 23:26:58 +00:00
Rafael Espindola 372889a8e6 Fix an use of uninitialized.
Should fix some tests on windows.

llvm-svn: 244834
2015-08-12 23:25:42 +00:00
Denis Protivensky 90512d5440 [ELF] Remove TargetLayout::getCustomSegments methods
llvm-svn: 244747
2015-08-12 13:27:27 +00:00
Denis Protivensky 0c8beb1c95 [LinkerScript] Process program header in PHDRS command
Add PT_PHDR segment depending on its availability in linker script's
PHDRS command, fallback if no linker script is given.
Handle FILEHDR, PHDRS and FLAGS attributes of program header.

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

llvm-svn: 244743
2015-08-12 12:31:35 +00:00
Rafael Espindola 91009b3856 Fix the alignment of the section headers.
Thanks a lot to Rui for noticing it.

llvm-svn: 244711
2015-08-12 01:45:28 +00:00
Rafael Espindola 6b83b90b6a ELF: Create a string table.
For now only the sections are in it, but it already makes the output easier
to read and test.

llvm-svn: 244702
2015-08-12 00:00:24 +00:00
Rui Ueyama 4f89fdad9f ELF2: Make Defined{Regular,Weak} ctors look the same as other SymbolBody ctors.
llvm-svn: 244701
2015-08-11 23:37:25 +00:00
Rafael Espindola 021834046f Template ELF's OutputSection.
This removes what I think is the last hard coded ELF64 structure.

llvm-svn: 244700
2015-08-11 23:34:29 +00:00
Rafael Espindola 52a0f1e8c6 Move more code that is local to Writer.cpp to an anonymous namespace.
llvm-svn: 244697
2015-08-11 23:22:24 +00:00