Commit Graph

3751 Commits

Author SHA1 Message Date
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
Rafael Espindola 5211c2a1a0 Delete dead code.
llvm-svn: 244696
2015-08-11 23:19:06 +00:00
Rafael Espindola 98f6bd09e4 Be a bit more consistent about using uintX_t for offsets and sizes. NFC.
llvm-svn: 244694
2015-08-11 23:14:13 +00:00
Rui Ueyama fa071e13aa COFF: Align sections to 512-byte boundaries on disk.
Sections must start at page boundaries in memory, but they
can be aligned to sector boundaries (512-bytes) on disk.
We aligned them to 4096-byte boundaries even on disk, so we
wasted disk space a bit.

llvm-svn: 244691
2015-08-11 23:09:00 +00:00
Rui Ueyama 880632c458 ELF2: Remove unused global variable.
A global variable "Driver" is to re-entry to the driver to parse a
.drectve section. Because the need is COFF-specific, we don't need
this variable for ELF.

llvm-svn: 244680
2015-08-11 21:45:55 +00:00
Reid Kleckner f7b85e0ce2 Fix mismatched sign comparison
llvm-svn: 244653
2015-08-11 20:06:51 +00:00
Rafael Espindola 76e24ea955 Add support for weak undefined symbols.
llvm-svn: 244640
2015-08-11 17:57:05 +00:00
Rafael Espindola 791e9f9c59 Remove unused templating.
llvm-svn: 244639
2015-08-11 17:51:57 +00:00
Rafael Espindola b13df6582a Add support for weak symbols.
llvm-svn: 244636
2015-08-11 17:33:02 +00:00