Commit Graph

2732 Commits

Author SHA1 Message Date
Rui Ueyama 251b0e268b COFF: Remove the old COFF linker and make link an alias to link2.
It's time to remove old COFF linker because the new one is now complete.

llvm-svn: 244226
2015-08-06 16:19:35 +00:00
Rafael Espindola b835ae8e4a Port the error functions from ELF to COFF.
This has a few advantages

* Less C++ code (about 300 lines less).
* Less machine code (about 14 KB of text on a linux x86_64 build).
* It is more debugger friendly. Just set a breakpoint on the exit function and
  you get the complete lld stack trace of when the error was found.
* It is a more robust API. The errors are handled early and we don't get a
  std::error_code hot potato being passed around.
* In most cases the error function in a better position to print diagnostics
  (it has more context).

llvm-svn: 244215
2015-08-06 14:58:50 +00:00
Simon Atanasyan 7a400d9af4 [Mips] Implement definition of the DT_MIPS_RLD_MAP_REL dynamic tag
llvm-svn: 243835
2015-08-01 14:53:49 +00:00
Simon Atanasyan 98a857140b [Mips] Implement definition of DT_MIPS_RLD_MAP dynamic tag, .rld_map section, and __RLD_MAP symbol
llvm-svn: 243626
2015-07-30 07:45:55 +00:00
Simon Atanasyan 9191a84392 [Mips] Define _DYNAMIC_LINKING symbol if output is a is dynamically linked executable file
llvm-svn: 243211
2015-07-25 10:18:52 +00:00
Simon Atanasyan 8e24577100 [Mips] Remove redundant separate functions to calculate relocations. Do
that inline.

No functional changes.

llvm-svn: 243210
2015-07-25 10:18:44 +00:00
Simon Atanasyan 4504791890 [Mips] Remove duplicated code by joining the same functions
llvm-svn: 243209
2015-07-25 10:18:39 +00:00
Simon Atanasyan 3b6ea7ab4a [Mips] Do not sign-extend addends read from RELA relocation records
llvm-svn: 243208
2015-07-25 10:18:33 +00:00
Michael J. Spencer 84487f1174 [ELF2] Add a new ELF linker based on the new PE/COFF linker.
Differential Revision: http://reviews.llvm.org/D11188

llvm-svn: 243161
2015-07-24 21:03:07 +00:00
Rui Ueyama 8abca7e729 Fix -Wextra-semi.
Patch from Eugene.Zelenko!

llvm-svn: 243060
2015-07-23 23:03:55 +00:00
Rafael Espindola 5871bf30ac Use the getSymbol with an explicit symbol table. NFC.
llvm-svn: 243014
2015-07-23 13:41:25 +00:00
Denis Protivensky f84acb959b [LinkerScript] Fix case when setting custom NONE segment
llvm-svn: 243006
2015-07-23 11:46:59 +00:00
Denis Protivensky cdc1246750 [ELF] Apply segments from linker scripts
Put sections to segments according to linker scripts if available.
Rework the code of TargetLayout::assignSectionsToSegments so it operates
on the given list of segments, which can be either read from linker scripts
or constructed as before.
Handle NONE segments defined in linker scripts by putting corresponding sections
to PT_NULL segment.
Consider flags set for segments through linker scripts.

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

llvm-svn: 243002
2015-07-23 10:34:30 +00:00
Simon Atanasyan b6d60a69c0 [ELF] Protect write access to the ELFLinkingContext::_cidentSections by a mutex
The _cidentSections container is filled during files parsing so we need to
serialize a concurrent access to it.

llvm-svn: 242885
2015-07-22 10:32:19 +00:00
Rafael Espindola 1cb8a19bcb Don't assume ELFFile iterates over the program headers.
It will stop doing so shortly.

llvm-svn: 242832
2015-07-21 20:46:21 +00:00
Rafael Espindola 5f95fa31b3 Drop last use of getDynamicSymbolName.
llvm-svn: 242820
2015-07-21 18:15:32 +00:00
Rafael Espindola 16154afb06 Keep track of which string table is associated with a symbol table.
This removes the last uses of getStaticSymbolName in lld.

llvm-svn: 242816
2015-07-21 18:00:39 +00:00
Simon Atanasyan b1600f2eee [Mips] Fix addend writing for R_MIPS_REL32 relocation
llvm-svn: 242760
2015-07-21 05:54:30 +00:00
Simon Atanasyan f9db71eaec [Mips] Handle R_MIPS_JALR relocation to omptimize jalr/jr instructions
llvm-svn: 242759
2015-07-21 05:54:22 +00:00
Rafael Espindola d285d3fbb7 Update for llvm api change.
llvm-svn: 242701
2015-07-20 20:08:04 +00:00
Rafael Espindola 9170a17377 Update for llvm api change.
llvm-svn: 242216
2015-07-14 22:19:09 +00:00
Adhemerval Zanella 4d0d1babfc [ELF/AArch64] Fix export TLS dynamic symbol
This patch fixes the TLS dynamic variable exportation from .got.plt segments,
created by General-dynamic relocations (TLSDESC).  Current code only export
symbols in dynamic table from .got sections.

llvm-svn: 242142
2015-07-14 13:25:32 +00:00
Michael J. Spencer bae540e945 Revert ELF port. Posting to mailing list.
llvm-svn: 242118
2015-07-14 04:49:48 +00:00
Rafael Auler 2c4af3ead7 [LinkerScript] Don't create unnecessarily large segments
When using a linker script expression to change the address of a section, even
if the new address is more than a page of distance from the old address, lld
may put everything in the same segment, forcing it to be unnecessarily large.
This patch changes the logic in Segment::assignVirtualAddress() and
Segment::assignFileOffsets() to allow the segment to be sliced into two or more
if it detects a linker script expression that changes a section address.

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

llvm-svn: 242096
2015-07-14 00:34:43 +00:00
Rafael Auler a4917f74eb [LinkerScript] Fix bug in Segment::assignVirtualAddress()
When calculating the start address and size of a segment, lld mistakenly
attributed the start address of the last segment slice to the whole segment
when it should consider the start address of the first slice. In this case, in a
multi-slice segment, Segment::assignVirtualAddress() will return a wrong
segment start address to TargetLayout::assignVirtualAddress(). The effect of
this miscalculation is to allocate some program headers in unnecessarily far
away addresses. This commit fixes this.

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

llvm-svn: 242089
2015-07-13 23:52:58 +00:00
Michael J. Spencer 8a4145411f Initial ELF port.
This is a direct port of the new PE/COFF linker to ELF.

It can take a single object file and generate a valid executable that executes at the first byte in the text section.

llvm-svn: 242088
2015-07-13 23:48:06 +00:00
Simon Atanasyan b34a080701 [Mips] Support MIPS big-endian 32/64-bits targets
llvm-svn: 242014
2015-07-13 09:11:35 +00:00
Nico Weber d08eca0181 elf: Make error output from AtomSection<ELFT>::write() deterministic.
The function uses parallel_for() and then writes error messages from the
parallel loop's body.  This produces nondetermistic error messages.  Instead,
copy error messages to a vector and sort it by the atom's file offsets before
printing all error messages after the parallel_for().  This results in a few
string copies, but only in the error case.  (And passing tests seem more
important than performance.)

This makes tests elf/AArch64/rel-prel16-overflow.test and
elf/AArch64/rel-prel32-overflow.test pass on Windows: Both tests check that
atom error messages are emitted in a certain order, and on Windows they
happened to be emitted in a different order before this patch.

llvm-svn: 241988
2015-07-12 04:45:35 +00:00
Rafael Espindola dbb40ab8b7 Update for upcoming llvm change.
llvm-svn: 241746
2015-07-08 22:14:36 +00:00
Davide Italiano 5a2acd1e1e Fix undefined behaviour exposed by the new -Wshift-negative-value warning.
llvm-svn: 241530
2015-07-07 00:02:59 +00:00
Adhemerval Zanella c0ad64543b [ELF/AArch64] Set correct loader name in linking context
This patch reimplements ELFLinkingContext::getDefaultInterpreter for aarch64
with correct loader name. It is required to exclude the loader from DT_NEEDED
in shared library creation.

llvm-svn: 241371
2015-07-03 21:24:36 +00:00
Adhemerval Zanella fdb4d6346a [ELF/AArch64] Set correct loader name in linking context
This patch reimplements ELFLinkingContext::getDefaultInterpreter for aarch64
with correct loader name.  It is required to exclude the loader from DT_NEEDED
in shared library creation.

llvm-svn: 241370
2015-07-03 21:21:39 +00:00
Rafael Espindola ec57b8b9f8 Use getDynamicSymbolName/getStaticSymbolName instead of a constant argument.
llvm-svn: 241346
2015-07-03 12:50:54 +00:00
Simon Atanasyan 47a2eafd5c [Mips] Factor out symbol type checking (PIC/non-PIC) into the separate function
No functional changes.

llvm-svn: 241342
2015-07-03 11:36:55 +00:00
Simon Atanasyan a87c17a201 [ELF] Define __start_XXX/__stop_XXX symbols where XXX is a section name
This is GNU ELF linker extension used particularly by LibC code.
If input object files contain section named XXX, and the XXX is a valid C
identifier, and there are undefined or weak symbols __start_XXX/__stop_XXX,
linker should define __start_XXX/__stop_XXX symbols point to the begin/end
of the XXX section correspondingly.

For example, without support of this extension statically linked executables
for X86_64 and Mips (maybe other) targets do not flush IO buffers at the end
of executing.

llvm-svn: 241341
2015-07-03 11:25:37 +00:00
Rafael Espindola cd55286893 Update for llvm changes.
llvm-svn: 241298
2015-07-02 20:55:28 +00:00
Simon Atanasyan b28f504226 [ELF] Remove dead code. NFC
llvm-svn: 241274
2015-07-02 15:04:08 +00:00
Simon Atanasyan 0d38933235 [ELF] Make OutputSection::memSize `const` member function. NFC
llvm-svn: 241194
2015-07-01 21:44:55 +00:00
Adhemerval Zanella dbd75b7fa0 [ELF/AArch64] Initial General-dynamic TLS support
This patch adds initial general-dynamic TLS support for AArch64.  Currently
no optimization is done to realx for more performance-wise models (initial-exec
or local-exec).  This patch also only currently handles correctly executable
generation, although priliminary DSO support through PLT specific creation
is also added.

With this change clang/llvm bootstrap with lld is possible in static configuration
(some DSO creation fails due missing Linker script support, not AArch64 specific),
although make check also shows some issues.

llvm-svn: 241192
2015-07-01 21:35:39 +00:00
Rafael Espindola a5ee9fdea2 Update for llvm api change.
llvm-svn: 241157
2015-07-01 12:56:33 +00:00
Rafael Espindola 1acc30e970 Use copy init instead of direct init.
llvm-svn: 241089
2015-06-30 18:04:46 +00:00
Rafael Espindola 29efdd4a21 Update for llvm change.
llvm-svn: 241075
2015-06-30 15:34:00 +00:00
Rafael Espindola bff864a596 Update for llvm api change.
llvm-svn: 240997
2015-06-29 21:26:07 +00:00
Rafael Espindola fdeb19ff33 Update for llvm api change.
llvm-svn: 240951
2015-06-29 14:39:30 +00:00
Rafael Espindola 4d24127ae0 Update for llvm change.
llvm-svn: 240940
2015-06-29 12:38:35 +00:00
Rafael Espindola bb50727e94 Update for llvm changes.
llvm-svn: 240781
2015-06-26 13:19:38 +00:00
Simon Atanasyan 253125af03 [Mips] Reject R_MIPS_CALL16 against local symbols
llvm-svn: 240765
2015-06-26 07:25:20 +00:00
Simon Atanasyan 52db6aefcc [Mips] Use helper functions to determine relocations purpose
That allows to remove duplicated long switch/case statements.

No functional changes.

llvm-svn: 240764
2015-06-26 07:25:12 +00:00
Simon Atanasyan b7bcff8796 [Mips] Create LA25 stubs for all branch relocations
llvm-svn: 240763
2015-06-26 07:25:06 +00:00
Adhemerval Zanella 3ebea27d66 [ELF] Fix .init_array initialization
Some compilers may not add the section symbol in '.symtab' for the
.init_array and 'ldd' just ignore it.  It results in global constructor
not being called in final executable.

This patch add both '.init_array' and '.fini_array' to be added in
Atom graph generation even when the section contains no symbol.  An
already existing testcase is modified to check for such scenario.

The issue fixes the llvm test-suite regressions for both Single
and MultiSource files.

llvm-svn: 240570
2015-06-24 19:26:00 +00:00