Commit Graph

2757 Commits

Author SHA1 Message Date
George Rimar bcba39ab9c [ELF] - Check that .dynsym is present in DSO if SHT_GNU_versym section is.
When we have SHT_GNU_versym section, it is should be associated with symbol table
section. Usually (and in out implementation) it is .dynsym.
In case when .dynsym is absent (due to broken object for example), 
lld crashes in parseVerdefs() when accesses null pointer:

Versym = reinterpret_cast<const Elf_Versym *>(this->ELFObj.base() +
                                              VersymSec->sh_offset) +
         this->Symtab->sh_info;

DIfferential revision: https://reviews.llvm.org/D25553

llvm-svn: 285796
2016-11-02 10:16:25 +00:00
Rui Ueyama a959393a15 Add strings to .dynstr early.
Previously, we added strings from DynamicSection::finalize().
It was a bit tricky because finalize() is supposed to fix the final
size of the section, but adding new strings would change the size of
.dynstr section. So there was a dependency between finalize functions
of .dynamic and .dynstr.

However, I noticed that we can elimiante the dependency by simply
add strings early; we don't have to do that in finalize() but can do
from DynamicSection's ctor.

This patch defines a new function, DynamicSection::addEntries, to
add .dynamic entries that doesn't depend on other sections.

llvm-svn: 285784
2016-11-02 02:18:01 +00:00
Rafael Espindola e036907c59 Update for llvm change.
We no longer use the section names in this test.

llvm-svn: 285754
2016-11-01 21:34:26 +00:00
Rui Ueyama 5fc84a1828 Remove string table offsets from tests.
<N> where "foo (<N>)" is the offset of string "foo" in the string table.

llvm-svn: 285751
2016-11-01 21:26:28 +00:00
Rafael Espindola 4a2055bef9 Update for llvm change.
llvm-svn: 285739
2016-11-01 20:25:27 +00:00
Davide Italiano 1da3a52d11 [ELF/GC] Fix pending references to garbage collected sections.
The example reported in PR30793 shows a case where gc reclaims
a SHF_TLS section, but it doesn't reclaim the section containing
the debug info for it.
This is expected, as we do not reclaim non-alloc sections
during the garbage collection phase (and this is not going to
change anytime soon, at least this is what I gathered last I
talked with Rafael about it).
So, we end up with a pending reference, thinking that the input
was invalid (which is not true, as it's GC that removed the
SHT_TLS section, and therefore didn't create the PT_TLS *segment*
for it). In cases like this, just assign a VA of zero at relocation
time instead of error'ing out (this is what gold does as well, FWIW).

Differential Revision:  https://reviews.llvm.org/D26201

llvm-svn: 285735
2016-11-01 20:11:01 +00:00
Rui Ueyama 035c4f14e0 Implement R_PPC_ADDR32.
Patch from Jack Andersen.

llvm-svn: 285720
2016-11-01 18:30:28 +00:00
Rui Ueyama 7fd5c84f46 Implement R_PPC_REL24 and R_PPC_REL32 relocations.
This enables LLD to relocate PC-relative R_PPC_REL32 and
R_PPC_REL24 types (as used in bl instructions).

Patch from Jack Andersen!

llvm-svn: 285719
2016-11-01 18:30:26 +00:00
Eugene Leviant 282251a226 Convert BuildIdSection to input section
Differential revision: https://reviews.llvm.org/D25627

llvm-svn: 285682
2016-11-01 09:49:24 +00:00
Eugene Leviant c4681203e1 Allow fetching source line, when multiple "AX" sections present
Differential revision: https://reviews.llvm.org/D26070

llvm-svn: 285680
2016-11-01 09:17:50 +00:00
Rafael Espindola b0de56b59d The expr '.' is not absolute.
With this patch we keep track of the fact that . is a position in the
file and therefore not absolute. This allow us to compute relative
relocations that involve symbol that are defined in linker scripts
with '.'.

This fixes https://llvm.org/bugs/show_bug.cgi?id=30406

There is still more work to track absoluteness over the various
expressions, but this should unblock linking the EFI bootloader.

llvm-svn: 285641
2016-10-31 21:36:23 +00:00
Rui Ueyama 20df4ecf4f Re-commit r285607: Emit Section Map stream."
Removed some test fields that overspecified test conditions.

llvm-svn: 285638
2016-10-31 21:09:21 +00:00
Reid Kleckner 240cbabc6b Revert "Add a space to work around a Windows CPython / MSys quoting bug"
This reverts commit r284768.

After LLVM r285237, the lit shell interpreter works around this bug for
us.

llvm-svn: 285629
2016-10-31 20:13:41 +00:00
Rafael Espindola 2f831dcafd Delay computation of IsAbsolute.
We parse linker scripts very early, but whether an expression is
absolute or not can depend on a symbol defined in a .o. Given that, we
have to delay the computation of IsAbsolute. We can do that by storing
an AST when parsing or by also making IsAbsolute a function like we do
for the expression value. This patch implements the second option.

llvm-svn: 285628
2016-10-31 19:56:37 +00:00
Rafael Espindola 63b4a37ef5 Simple numeric constants are absolute.
llvm-svn: 285621
2016-10-31 18:56:02 +00:00
Rui Ueyama e7b54c2ea5 Revert r285607: Emit Section Map stream.
That change broke buildbots.

llvm-svn: 285618
2016-10-31 18:50:13 +00:00
Rafael Espindola a0aaa8a0a3 Mark a few more expressions as absolute.
llvm-svn: 285611
2016-10-31 18:20:34 +00:00
Rafael Espindola f661393ad6 Move IsAbsolute from SymbolAssignment to Expr.
And as a token of the new feature, make ALIGNOF always absolute.

This is a step in making it possible to have non absolute symbols out
of output sections.

llvm-svn: 285608
2016-10-31 17:43:38 +00:00
Rui Ueyama 86a1ef388b Emit Section Map stream.
This is how we use DbiStreamBuilder::addSectionMap.

Differential Revision: https://reviews.llvm.org/D26113

llvm-svn: 285607
2016-10-31 17:40:40 +00:00
Rafael Espindola 3dabfc6b0d Correctly merge visibility of linkerscript created symbols.
llvm-svn: 285567
2016-10-31 13:14:53 +00:00
Rafael Espindola d598c8103a Be less aggressive at relaxing got access in this case.
This fixes pr30803 by not relaxing that particular access. We could
also let adjustRelaxExpr know that the target is absolute so that it
uses R_RELAX_GOT_PC_NOPIC, but it is not clear if it is worth it.

llvm-svn: 285317
2016-10-27 17:28:56 +00:00
Rafael Espindola 7cc713adcb Store OSABI in Config.
This allows us to set a value for it based on -m.

llvm-svn: 285294
2016-10-27 14:00:51 +00:00
Peter Smith 17cd3752b8 [ELF] Synthetic symbol definitions for ARM static linking
When static linking in ARM (like Mips) __tls_get_addr is defined by
the library so we should not define it as a synthetic.
    
We also need to add __exidx_start and __exidx_end for the .ARM.exidx
section as the static libc library startup code is expecting them to
be defined by the default linker script for static linking on ARM.

Differential revision: https://reviews.llvm.org/D25978

llvm-svn: 285279
2016-10-27 10:28:53 +00:00
Rafael Espindola cb09daab0a Call _exit.
As the state of lld gets more complicated, shutting down gets more
expensive.

In a normal lld run we can just call _exit immediately after renaming
the temporary output file. We still want the ability to run a full
shutdown since that is useful for detecting memory leaks.

This patch adds a --full-shutdown flag and changes lit to use it.

llvm-svn: 285224
2016-10-26 18:59:00 +00:00
Eugene Leviant b380b24e6e [ELF] Better error reporting for undefined symbols
This patch make lld show following details for undefined symbol errors:
- file (line)
- file (function name)
- file (section name + offset)

Differential revision: https://reviews.llvm.org/D25826

llvm-svn: 285186
2016-10-26 11:07:09 +00:00
Peter Collingbourne 0fab40b915 ELF: Simplify handling of *_start/*_end symbols.
We were previously using the (static) addSynthetic function to create
*_start/*_end symbols. This function was doing almost the same thing as
addOptionalSynthetic, except that it would also create the symbol in the
case where it is unreferenced. Because the symbol has hidden visibility,
creating it in that case would have no effect other than adding another
entry to the static symbol table. Remove addSynthetic and change callers to
use addOptionalSynthetic instead.

Differential Revision: https://reviews.llvm.org/D25545

llvm-svn: 285021
2016-10-24 20:46:21 +00:00
Rui Ueyama fe4c9f96c6 Use FileCheck's -strict-whitespace option instead of sed.
llvm-svn: 284846
2016-10-21 17:50:26 +00:00
Peter Smith 580ba95b16 [ELF] Add sh_link field to .ARM.exidx sections for relocatable links
When doing a relocatable link the .ARM.exidx sections with the
SHF_LINK_ORDER flag set need to set the sh_link field to the executable
section they describe. We find the appropriate OutputSection by
following the sh_link field of the .ARM.exidx InputSections.
    
The getOutputSectionName() function rules make sure that when there are
multiple .ARM.exidx InputSections in an OutputSection they all have the
same sh_link field.

Differential revision: https://reviews.llvm.org/D25825

llvm-svn: 284820
2016-10-21 11:25:33 +00:00
Simon Atanasyan bed04bf1df [ELF][MIPS] Put local GOT entries accessed via a 16-bit index first
Some MIPS relocations used to access GOT entries are able to manipulate
16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle
32-bit indexes. 16-bit relocations are generated by default. The 32-bit
relocations are generated by -mxgot flag passed to compiler. Usually
these relocation are not mixed in the same code but files like crt*.o
contain 16-bit relocations so even if all "user's" code compiled with
-mxgot flag a few 16-bit relocations might come to the linking phase.

Now LLD does not differentiate local GOT entries accessed via a 16-bit
and 32-bit indexes. That might lead to relocation's overflow if 16-bit
entries are allocated to far from the beginning of the GOT.

The patch introduces new "part" of MIPS GOT dedicated to the local GOT
entries accessed by 32-bit relocations. That allows to put local GOT
entries accessed via a 16-bit index first and escape relocation's overflow.

Differential revision: https://reviews.llvm.org/D25833

llvm-svn: 284809
2016-10-21 07:22:30 +00:00
Rui Ueyama 94dff2c0af llvm-dwarfdump is now used in a test, so add a depedency on the tool.
llvm-svn: 284776
2016-10-20 20:50:00 +00:00
Reid Kleckner 613c00db88 Add a space to work around a Windows CPython / MSys quoting bug
Summary:
The rules for quoting the command line that a subprocess receives are
user space conventions implemented by the C runtime. Python's quoting
rules are implemented here:
c30098c8c6/Lib/subprocess.py (L725)

The result is that the final command line C string computed by Python is
'echo \"'. Mingw doesn't appear to interpret that backslash as escaping
the quote because it is not already inside a quoted region. As a result,
our echo command prints a single backslash instead of a quote.

The whole issue can be sidestepped by adding a space a forcing Python to
put the argument to echo in double quotes.

Reviewers: inglorion, ruiu

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25841

llvm-svn: 284768
2016-10-20 20:02:24 +00:00
Konstantin Zhuravlyov b625d17db8 [AMDGPU] Handle R_AMDGPU_ABS64 relocation
This is needed for the following case (OpenCL example):
  __global int Var = 0; 
  __global int* Ptr[] = {&Var}; 
  ...

Differential Revision: https://reviews.llvm.org/D25815

llvm-svn: 284764
2016-10-20 18:34:58 +00:00
Peter Smith b663f1b407 [ELF] Add REQUIRES: arm to test to fix buildbot without ARM backend.
llvm-svn: 284711
2016-10-20 10:16:13 +00:00
Peter Smith d648603415 [ELF] Allow relative exceptions relocations in shared libraries
The R_ARM_PREL31 and R_ARM_NONE relocations should not be faulted in
shared libraries. In the case of R_ARM_NONE, we have moved the TLS
relaxation hint instruction to R_TLSDESC_CALL so that R_HINT can be used
without side-effects. In the case of R_ARM_PREL31 we permit it to be used
against PLT entries as the personality routines are imported when used in
shared libraries.

Differential Revision: https://reviews.llvm.org/D25721

llvm-svn: 284710
2016-10-20 09:59:26 +00:00
Eugene Leviant db35fdf70f Don't include PHDRs if linker script doesn't want them
This script below shouldn't include file and program headers
to PT_LOAD segment, because it doesn't have PHDRS and FILEHDR
attributes:

PHDRS { all PT_LOAD; }
SECTIONS { /* list of sections here */ }

Differential revision: https://reviews.llvm.org/D25774

llvm-svn: 284709
2016-10-20 09:39:09 +00:00
George Rimar 58fa5243cc [ELF] - Partial support of --gdb-index command line option (Part 1).
In this patch partial gdb_index section is created. 
For costructing the .gdb_index section 6 steps should be performed (details are in
SplitDebugInfo.cpp file header), this patch do first 3:

Creates proper section header.
Fills list of compilation units.
Types CU list area is not supposed to be supported, so it is ignored and therefore
can be treated as implemented either.

Differential revision: https://reviews.llvm.org/D24706

llvm-svn: 284708
2016-10-20 09:19:48 +00:00
George Rimar 6912147094 [ELF] - Testcase checking that we do not crash on invalid sh_info in SHT_GROUP sections. NFC.
Fix was landed as r284702 "[Object/ELF] - Check index argument in getSymbol()."

Patch contains LLD testcase only.

llvm-svn: 284703
2016-10-20 08:22:54 +00:00
Rui Ueyama d7c4454fb2 Fix error message for unknown -format argument.
-format=<foo>, -format <foo> and -b <foo> are all the same.
Previous code was intended to produce an error message with the
same spelling as given from the command line, but it actually
always printed out this string: "unknown -format= value:".
This is probably more confusing than "unknown -format value:".
So I changed the message.

llvm-svn: 284693
2016-10-20 04:47:45 +00:00
Rui Ueyama 8da7aa0894 Allow linker-script-defined entry symbols.
Previously, we were checking the existence of an entry symbol
too early. It was done before the linker script processor creates
symbols defined in scripts. Fixes bug 30743.

llvm-svn: 284676
2016-10-20 00:07:36 +00:00
Rui Ueyama 7c1381a099 Read an expression in the form of "ABSOLUTE(<expr>) op <expr> ...".
Fixes bug 30741.

llvm-svn: 284662
2016-10-19 23:11:21 +00:00
Rui Ueyama 90d12f44b7 Avoid using grep command in a test.
This test is failing on FreeBSD bots. This is an attempt to fix it
by not using grep command.

llvm-svn: 284645
2016-10-19 21:07:29 +00:00
Rui Ueyama 22646a80f4 Include ARGV[0] in error messages.
This is what other linkers and clang driver do.

Differential Revision: https://reviews.llvm.org/D25780

llvm-svn: 284634
2016-10-19 20:05:43 +00:00
Rui Ueyama 8088ebe499 Remove ending "." from an error message.
Other error messages don't end with ".".

llvm-svn: 284625
2016-10-19 18:09:52 +00:00
Eugene Leviant ce30b1c78e [ELF] Choose default segment when it is not specified
Linker scripts may specify PHDRS, but not specify section to
segment assignments, i.e:

PHDRS { seg PT_LOAD; }
SECTIONS { 
  .sec1 {} : seg
  .sec2 {} 
}

In such case linker should still choose some segment for .sec2 section.
This patch will add .sec2 to previously opened segments (seg) or to the 
very first PT_LOAD segment, if no section-to-segment assignments has been
made

Differential revision: https://reviews.llvm.org/D24795

llvm-svn: 284600
2016-10-19 15:04:49 +00:00
Rafael Espindola 2adccee13f Don't gc non-alloca non-string pieces.
We were already doing it for strings. This matches the behavior of
bfd and gold.

llvm-svn: 284598
2016-10-19 14:50:26 +00:00
Eugene Leviant 74c1b6c548 [ELF] Add "error" and "warning" prefixes to linker messages
Differential revision: https://reviews.llvm.org/D25729

llvm-svn: 284575
2016-10-19 09:35:19 +00:00
George Rimar 9f578ceed7 [ELF] - Update testcases after llvm change.
llvm-svn: 284474
2016-10-18 11:11:03 +00:00
George Rimar 95dd718c98 [ELF] - Linkerscript: accept integer values for PHDRS types.
Both gold and ld accepts integers instead of named constants
for PHDRS.
Patch adds support for that.

Differential revision: https://reviews.llvm.org/D25549

llvm-svn: 284470
2016-10-18 10:49:50 +00:00
Peter Smith 9bbd4e27a9 [ELF] Support for R_ARM_TARGET2 relocation
The R_ARM_TARGET2 relocation is used in ARM exception tables to encode
a data dependency that will only be dereferenced by code in the
run-time support library. In a similar way to R_ARM_TARGET1 the
handling of the relocation is target specific, it maps to one of
R_ARM_ABS32, R_ARM_REL32 or R_ARM_GOT_PREL. The choice depends on the 
run-time library. R_ARM_GOT_PREL is used for linux and BSD,
R_ARM_ABS32 and R_ARM_REL32 are used for bare-metal.

The command line option --target2=<target> can be used to select the
relocation used for R_ARM_TARGET2. The default is R_ARM_GOT_PREL.

Differential revision: https://reviews.llvm.org/D25684

llvm-svn: 284404
2016-10-17 18:12:24 +00:00
George Rimar c3c4f46d07 [ELF] - Add support for -nopie
This is https://llvm.org/bugs/show_bug.cgi?id=30696,

Differential revision: https://reviews.llvm.org/D25676

llvm-svn: 284388
2016-10-17 14:42:11 +00:00