Commit Graph

6536 Commits

Author SHA1 Message Date
Petr Hosek 14cd5c2405 [ELF] Allow arbitrary code alignment in .eh_frame
According to the specification, CIE code alignment factor is an
arbitrary unsigned LEB128 encoded value.

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

llvm-svn: 277105
2016-07-29 04:41:38 +00:00
Rui Ueyama 09d4f177fc Remove dependency to SymbolTable from CommonInputSection.
llvm-svn: 277103
2016-07-29 03:39:44 +00:00
Rui Ueyama 3de0a3308b Rename DoLayout -> HasContents. NFC.
llvm-svn: 277102
2016-07-29 03:31:09 +00:00
Rui Ueyama 174e0a16f9 Simplify. readAssignment never returns a nullptr.
llvm-svn: 277090
2016-07-29 00:29:25 +00:00
George Rimar f586ff7ec9 [ELF] - Removed excessive check. NFC.
Thanks to Rui Ueyama who noticed that.

llvm-svn: 277062
2016-07-28 22:15:44 +00:00
George Rimar 352eac37a1 [ELF] - Attempt to fix BB after 277042.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/17294
Change:
std::make_unique -> llvm::make_unique

llvm-svn: 277059
2016-07-28 22:10:50 +00:00
George Rimar 8c16d52893 [ELF] - Cosmetic change. NFC.
peek()[0] == '*' changed to peek().startswith("*")

llvm-svn: 277043
2016-07-28 22:01:56 +00:00
George Rimar 0659800ef0 [ELF] - Linkerscript: implemented filename specification.
Scripts can contain something like:
KEEP (*crtbegin.o(.ctors))

What means that "*crtbegin.o" is a wildcard of file to take the sections from.
This is some kind of opposite to EXCLUDE_FILE and used in FreeBSD script:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l122

Patch implements this.

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

llvm-svn: 277042
2016-07-28 21:51:30 +00:00
George Rimar 30835ea47a [ELF] - Linkerscript: implemented += operator.
Sometimes += is used to move the location counter.
Example from the wild is:

.dbg_excpt _DBG_EXCPT_ADDR (NOLOAD) :
{
  . += (DEFINED (_DEBUGGER) ? 0x8 : 0x0);
https://github.com/chipKIT32/pic32-Arduino-USB-Bootloader-original/blob/master/boot-linkerscript.ld

Patch implements it and opens way for others type of assignments (-= *= etc), though I think only += is
actual to support.

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

llvm-svn: 277035
2016-07-28 21:08:56 +00:00
Rui Ueyama ad10c3d8d4 Make CommonInputSection singleton class.
All other singleton instances are accessible globally.
CommonInputSection shouldn't be an exception.

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

llvm-svn: 277034
2016-07-28 21:05:04 +00:00
Eugene Leviant 3e6b027705 [ELF] Allows setting section for common symbols in linker script
llvm-svn: 277023
2016-07-28 19:24:13 +00:00
Rafael Espindola 1415cb9cbe Trying to fix this test on windows.
llvm-svn: 277022
2016-07-28 19:18:22 +00:00
Rafael Espindola 54c145ce0e Add support for SEGMENT_START.
This is a bit of an odd feature. It is normally used in

. = SEGMENT_START(seg, val);

In bfd it evaluates to val or to the value of the corresponding
-T<seg>-segment. Note that the -T<seg>-segment in bfd doesn't actually
change the segment address, just the value this evaluates too,
including in the default linker script.

In gold the -T<seg>-segment options do change the segment address and
seeing this expressions in linker scripts disables the options.

For new this just always evaluates the expression to val.

llvm-svn: 277014
2016-07-28 18:16:24 +00:00
Lang Hames 1b81e75a60 [lld][MachO] Fix bugs in the debug-syms test case.
The previous run line depended on libSystem.dylib being present, which it's not
on non-darwin platforms. The new run line uses libSystem.yaml instead.

llvm-svn: 276999
2016-07-28 16:56:26 +00:00
George Rimar 03fc010e10 [ELF] - Linkerscript: ignore SORT(CONSTRUCTORS)
Some scripts can contain SORT(CONSTRUCTORS) expression:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l152

for ELF it just a nop:
"When linking object file formats which do not support arbitrary sections, such as ECOFF and XCOFF, the linker will automatically recognize C++ global constructors and destructors by name. For these object file formats, the CONSTRUCTORS command tells the linker to place constructor information in the output section where the CONSTRUCTORS command appears. The CONSTRUCTORS command is ignored for other object file formats."
(http://www.sourceware.org/binutils/docs-2.10/ld_3.html)

So patch implements ignoring.

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

llvm-svn: 276965
2016-07-28 07:18:23 +00:00
Lang Hames 242fde1b36 [lld][MachO] Remove some debugging output code that was mistakenly left in in
r276935.

llvm-svn: 276944
2016-07-28 00:28:48 +00:00
Lang Hames 436f7d6606 [lld][MachO] Re-apply r276921 with fix - initialize strings for debug string
copies.

llvm-svn: 276935
2016-07-27 22:55:30 +00:00
Lang Hames f2260567ca [lld][MachO] Temporarily revert r276921 - it's causing bot-failures on Linux.
llvm-svn: 276928
2016-07-27 22:46:02 +00:00
Lang Hames 560333749f [lld][MachO] Add debug info support for MachO.
This patch causes LLD to build stabs debugging symbols for files containing
DWARF debug info, and to propagate existing stabs symbols for object files
built using '-r' mode. This enables debugging of binaries generated by LLD
from MachO objects.

llvm-svn: 276921
2016-07-27 21:31:25 +00:00
Rafael Espindola 0b113671c5 Make toPhdrFlags a member function. NFC.
llvm-svn: 276868
2016-07-27 14:10:56 +00:00
Davide Italiano 8c83382a95 [ELF] Support --output. Also output= can take two dashes.
llvm-svn: 276826
2016-07-27 01:57:15 +00:00
Davide Italiano e7282797aa [ELF/LinkerScript] Support EXCLUDE_FILE inside KEEP.
Differential Revision:	https://reviews.llvm.org/D22795

llvm-svn: 276825
2016-07-27 01:44:01 +00:00
Simon Atanasyan 219ab361f4 [ELF][MIPS] Attempt to fix Windows buildbot
llvm-svn: 276812
2016-07-26 21:28:34 +00:00
Rui Ueyama 3b452a7a22 Move code for MIPS from createInputSection to initializeSections.
We already have code for ARM in initializeSections, so this
is more consistent.

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

llvm-svn: 276811
2016-07-26 21:26:02 +00:00
Simon Atanasyan 8a5c9ea9ba [ELF][MIPS] Replace binary test input file by asembler code in the test. NFC
llvm-svn: 276809
2016-07-26 21:11:34 +00:00
Simon Atanasyan 240bc16532 [ELF][MIPS] Do not emit .got section in case of relocatable output
llvm-svn: 276808
2016-07-26 21:11:30 +00:00
Simon Atanasyan 72170d2753 [ELF][MIPS] Use section type to recognize .reginfo and .MIPS.options sections
It is faster and more correct method than string comparision.

llvm-svn: 276807
2016-07-26 21:11:26 +00:00
Rui Ueyama f7791bb9c6 Remove return type that can trivially be inferred.
llvm-svn: 276794
2016-07-26 19:34:10 +00:00
George Rimar b567b628b7 [ELF] - replace error() with llvm_unreachable.
llvm-svn: 276790
2016-07-26 18:46:13 +00:00
George Rimar 6930a6dc82 Attemp to fix build bot:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/25329/steps/build_Lld

llvm-svn: 276789
2016-07-26 18:41:06 +00:00
George Rimar a9c5a52846 [ELF] Linkerscript: symbol assignments with indentifiers on the right side of expression.
In symbol assignments symbol may appear on the right-hand side of the expression:
(https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l8)

kernphys = CONSTANT (MAXPAGESIZE);
 . = kernbase + kernphys + SIZEOF_HEADERS;

Patch implements that.

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

llvm-svn: 276784
2016-07-26 18:18:58 +00:00
George Rimar 630c617912 [ELF] - Linkerscript: implemented ALIGN modificatior of output sections.
Output section description can contain ALIGN modificator:
https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description

Patch implements it.

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

llvm-svn: 276780
2016-07-26 18:06:29 +00:00
George Rimar 276b4e6428 [ELF] Linkerscript: implement DATA_SEGMENT_RELRO_END.
In compare with what GNU linkers do (https://sourceware.org/binutils/docs/ld/Builtin-Functions.html),
this implementation simple:

Do not touch DATA_SEGMENT_ALIGN, it do what it do now - just aligns to the page boundary.
Parameters of DATA_SEGMENT_RELRO_END is ignored. That should be correct as it is usually just a 24 bytes
shift that allows to protect first 3 entries of got.plt with relro. 
(https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l146). 

DATA_SEGMENT_RELRO_END just aligns to the page boundary. 
That is what expected because all sections that are not affected by relro should be on another memory page.
So at fact the difference with documented behavior is that we do not pad DATA_SEGMENT_ALIGN. 
3 entries of got.plt are uncovered by relro, but functionality is simple and equal to lld behavior 
for case when script is not given.

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

llvm-svn: 276778
2016-07-26 17:58:44 +00:00
Rui Ueyama 1b59f27c9a Add `static` to a function that is used only in one file.
llvm-svn: 276774
2016-07-26 17:35:42 +00:00
Lang Hames 75069a1668 [lld][MachO] Add support for S_ATTR_DEBUG to the MachO YAML reader/writer.
This enables proper recognition of debug sections by attribute, which will be
used in the near future by test-cases for MachO debugging support.

llvm-svn: 276770
2016-07-26 17:17:17 +00:00
George Rimar 4509a4f52a [ELF] - Merged 2 lines. NFC.
llvm-svn: 276768
2016-07-26 17:01:18 +00:00
George Rimar 528e0bfa12 [ELF] Linkerscript: simplify DATA_SEGMENT_ALIGN evaluation
We can simplify the evaluation of DATA_SEGMENT_ALIGN
just to simple align(). That way it will work exactly like we have in non-script case.

Change was suggested by Rafael Ávila de Espíndola

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

llvm-svn: 276745
2016-07-26 14:00:10 +00:00
Rafael Espindola cc83ad18f7 Disable test on windows.
llvm-svn: 276742
2016-07-26 12:38:18 +00:00
George Rimar bfc4a4b7a1 [ELF] - Fixed possible iterator overflow.
We can have Opt.Commands size greater then Sections.size().
For example if we have next script:

SECTIONS { 
.aaa : { *(.aaa) }           
.bbb : { *(.bbb) }   
.ccc : { *(.ccc) }   
}

and next code:

.global _start
_start:
 nop

.section .aaa,"a"
 .quad 0

Then amount of sections is less than amound of Opt.Commands
and if we for example have all commands NoConstraint,
that overflowed the iterator used.

llvm-svn: 276741
2016-07-26 10:47:09 +00:00
Eugene Leviant f9d897c7a7 [ELF/Linkerscript] Remove special handling of TLS/NOTE/RELRO sections (patch from ruiu)
llvm-svn: 276731
2016-07-26 07:20:40 +00:00
Peter Collingbourne 76681d6ab5 Add qualification to fix MSVC build.
llvm-svn: 276720
2016-07-26 02:10:56 +00:00
Peter Collingbourne feee2103c6 COFF: Implement /linkrepro flag.
This flag is implemented similarly to --reproduce in the ELF linker.

This patch implements /linkrepro by moving the cpio writer and associated
utility functions to lldCore, and using that implementation in both linkers.

One COFF-specific detail is that we store the object file from which the
resource files were created in our reproducer, rather than the resource
files themselves. This allows the reproducer to be used on non-Windows
systems for example.

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

llvm-svn: 276719
2016-07-26 02:00:42 +00:00
Rui Ueyama 29c5a2a9b7 Split getPhdrsIndices. NFC.
llvm-svn: 276717
2016-07-26 00:27:36 +00:00
Rui Ueyama f510fa6b68 Replace std::find_if with plain for loop. NFC.
llvm-svn: 276715
2016-07-26 00:21:15 +00:00
Rui Ueyama 6b2748104b Split LinkerScript::createSections into small functions.
createSections function is getting longer, so it is time to split it
into small functions. The reason why the function is long is because
it has deeply nested for-loops. This patch constructs temporary data
to reduce nesting level.

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

llvm-svn: 276706
2016-07-25 22:51:07 +00:00
Rui Ueyama 63dc650938 Fix parameter names.
match() returns true of the first argument, a target string, matches
one of the second argument, a list of glob patterns. Calling the
target string, which is not a glob pattern, "Pattern" was very confusing.

llvm-svn: 276705
2016-07-25 22:41:42 +00:00
Rui Ueyama 96bdd5bc81 Do not pass InputFile to reportDiscarded().
Because the file from which an input section is created can be
obtained using getFile().

llvm-svn: 276702
2016-07-25 22:26:28 +00:00
Rui Ueyama efc4066b47 Make ConstraintKind an enum class.
llvm-svn: 276697
2016-07-25 22:00:10 +00:00
Davide Italiano 0ed42b0ca0 [LinkerScript] Refactor KEEP handling in a separate function
This will grow because I have a patch to support more complex
constructs, e.g.:

KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))

Let's make this a separate function.

llvm-svn: 276695
2016-07-25 21:47:13 +00:00
Rui Ueyama 3c291e1aa2 Re-commit "Split LinkerScript::createSections".
Re-commit r276543 with a fix for buildbots.

llvm-svn: 276693
2016-07-25 21:30:00 +00:00
Eugene Leviant 6f531f4674 [ELF] Fix bug in test case
llvm-svn: 276659
2016-07-25 17:24:56 +00:00
Rui Ueyama cc1f10df5f Remove trailing whitespaces.
llvm-svn: 276649
2016-07-25 16:51:52 +00:00
Davide Italiano 748d9ea9cb [ELF/LinkerScript] Use correct section name in a test.
llvm-svn: 276642
2016-07-25 16:10:40 +00:00
Eugene Leviant 1823d6c8af [ELF] Test case for correct input section order, when sections are listed in linker script
llvm-svn: 276630
2016-07-25 10:59:20 +00:00
George Rimar 58e5c4dcfe [ELF] - Linkerscript: implemented output section [address] attribute.
Output section description in SECTIONS looks like that:

section [address] [(type)] :
...
{
...
}

Patch implements support of address atribute.

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

llvm-svn: 276619
2016-07-25 08:29:46 +00:00
Davide Italiano 373a533a0a [ELF] Fix the semantic of PROVIDE in linker scripts.
PROVIDE request us to define a symbol only if it is referenced and is
not defined by any object included in the link. We created the
symbol in the symbol table no matter what.

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

llvm-svn: 276592
2016-07-25 00:25:18 +00:00
Rui Ueyama edebbdf12a Simplify. NFC.
llvm-svn: 276586
2016-07-24 23:47:31 +00:00
Davide Italiano e71b25b7d1 [ELF] Move linker script tests to a subdirectory. NFCI.
llvm-svn: 276582
2016-07-24 23:29:18 +00:00
Davide Italiano 054a679634 [ELF] Support PROVIDE/PROVIDE_HIDDEN inside output sections description.
Differential Revision:  https://reviews.llvm.org/D22738

llvm-svn: 276579
2016-07-24 23:13:48 +00:00
Rui Ueyama 113cdec9ec Merge readSymbolAssignment with readAssignment. NFC.
llvm-svn: 276575
2016-07-24 23:05:57 +00:00
Rui Ueyama 708019c41b Make readExpr return an Expr object instead of a vector of tokens.
Previously, we handled an expression as a vector of tokens. In other
words, an expression was a vector of uncooked raw StringRefs.
When we need a value of an expression, we used ExprParser to run
the expression.

The separation was needed essentially because parse time is too
early to evaluate an expression. In order to evaluate an expression,
we need to finalize section sizes. Because linker script parsing
is done at very early stage of the linking process, we can't
evaluate expressions while parsing.

The above mechanism worked fairly well, but there were a few
drawbacks.

One thing is that we sometimes have to parse the same expression
more than once in order to find the end of the expression.
In some contexts, linker script expressions have no clear end marker.
So, we needed to recognize balanced expressions and ternary operators.

The other is poor error reporting. Since expressions are parsed
basically twice, and some information that is available at the first
stage is lost in the second stage, it was hard to print out
apprpriate error messages.

This patch fixes the issues with a new approach.

Now the expression parsing is integrated into ScriptParser.
ExprParser class is removed. Expressions are represented as lambdas
instead of vectors of tokens. Lambdas captures information they
need to run themselves when they are created.

In this way, ends of expressions are naturally detected, and
errors are handled in the usual way. This patch also reduces
the amount of code.

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

llvm-svn: 276574
2016-07-24 18:19:40 +00:00
Rui Ueyama 8a9bb7baeb Rollback r276538 and r276540 to unbreak asan bot.
llvm-svn: 276543
2016-07-24 02:05:09 +00:00
Rui Ueyama d227620582 Simplify. NFC.
llvm-svn: 276540
2016-07-24 01:18:18 +00:00
Rui Ueyama 01151e9c24 Split LinkerScript::createSections.
createSections is getting longer, so it is probably time to split.

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

llvm-svn: 276538
2016-07-24 01:06:18 +00:00
Davide Italiano 8ab4108df2 [ELF/Linkerscript] Define an absolute if we find an undefined.
Otherwhise undefined references to symbols defined in linker scripts
are never resolved.

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

llvm-svn: 276536
2016-07-23 22:09:04 +00:00
Rui Ueyama adca245f79 Remove Phdr typedef.
I don't think this typedef contributes to readability.

llvm-svn: 276525
2016-07-23 14:18:48 +00:00
Rui Ueyama 36a153cd83 Make a pure function a non-member file-scoped function.
llvm-svn: 276524
2016-07-23 14:09:58 +00:00
Eugene Leviant a31c91b150 [ELF] Support PROVIDE and PROVIDE_HIDDEN inside SECTIONS
llvm-svn: 276398
2016-07-22 07:38:40 +00:00
Simon Atanasyan d2ae303eb0 [ELF][MIPS] Apply mask while reading implicit addend and writing result of R_MIPS_26 relocation.
llvm-svn: 276395
2016-07-22 05:56:43 +00:00
Davide Italiano 246f681e0b [ELF/LinkerScript] Support ONLY_IF_{RO, RW} directive.
Differential Revision:   https://reviews.llvm.org/D22660

llvm-svn: 276384
2016-07-22 03:36:24 +00:00
Rafael Espindola 3abe3aab22 Really fix invalid EhSectionPiece access.
I wonder what is the most idiomatic way to write this.

llvm-svn: 276338
2016-07-21 21:15:32 +00:00
Rafael Espindola 2deeb6093d Fix PR28575.
Not all relocations from a .eh_frame that point to an executable
section should be ignored. In particular, the relocation finding the
personality function should not.

This is a reduction from trying to bootstrap a static lld on linux.

llvm-svn: 276329
2016-07-21 20:18:30 +00:00
George Rimar 92e93fb4ba [ELF] - Basic support of linkerscript commands: DATA_SEGMENT_ALIGN, DATA_SEGMENT_END, CONSTANT
It is called basic because:

CONSTANT expression can refer to COMMONPAGESIZE and MAXPAGESIZE.
This sizes are usually different and used for possible optimization of
memory consumption. 
More details are here: https://sourceware.org/ml/binutils/2002-02/msg00265.html
We currently do not support this optimization, so both CONSTANT(MAXPAGESIZE)
and CONSTANT(COMMONPAGESIZE) just return Target->PageSize value.

DATA_SEGMENT_ALIGN and DATA_SEGMENT_END are used as a part of opt.
The latter one is just ignored now.
According to documentation DATA_SEGMENT_ALIGN has 2 possible
calculation, but since we do not support mentioned opt - it 
is always calculated now as (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - 1))).

In general this should work for now until we deside to support this opt.

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

llvm-svn: 276323
2016-07-21 19:48:00 +00:00
Rui Ueyama 629e0aa5be Update comment.
llvm-svn: 276322
2016-07-21 19:45:22 +00:00
Reid Kleckner 3c944ec81a Fix MSVC 2015 compilation failure around range-for without curly braces
It doesn't appear to like this pattern:
  for (auto X : Xs)
    if (...) { ... }
    else ...;

We have heard anecdotes that range based for loops are implemented as a
token rewrite in MSVC's lexer, and that the most challenging part of the
rewrite is finding the end of the for loop. That makes sense, given that
it's a lexer.

llvm-svn: 276315
2016-07-21 18:39:28 +00:00
Rafael Espindola 069b1c1b37 Use just built llvm-as in tests.
llvm-svn: 276313
2016-07-21 18:08:36 +00:00
Eugene Leviant 8a8a822a96 [ELF] Fix bug in program header FLAGS processing + test case update (found by grimar)
llvm-svn: 276301
2016-07-21 16:13:54 +00:00
George Rimar 10e576e109 [ELF] - Cleanup of LinkerScript<ELFT>::assignAddresses()
LinkerScript<ELFT>::assignAddresses is becoming larger and looks 
it can be good time for splitting. I expect to can more SectionsCommand's there, 
and dispatching some of them separatelly can help to keep method smaller either.

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

llvm-svn: 276300
2016-07-21 16:07:40 +00:00
George Rimar e37dde8d18 [ELF] - Fixed 3 testases failtures on win32 configuration.
Had 3 testcases failtures:
ELF/eh-frame-merge.s 
ELF/gc-sections-eh.s
ELF/gc-sections-lsda.s​

Problem was that OutputOff is size_t, which is 32
for this configuration and next
condition never was checked correctly:

if (PieceI->OutputOff == (uintX_t)-1)
  continue;

llvm-svn: 276296
2016-07-21 15:35:06 +00:00
Konstantin Zhuravlyov 667e245e38 ELF/AMDGPU: Add support for R_AMDGPU_ABS32
Differential Revision: https://reviews.llvm.org/D21654

llvm-svn: 276295
2016-07-21 15:30:13 +00:00
George Rimar eea3114ff9 [ELF] - Linkerscript: add InputSectionDescription command to LS parser.
This adds InputSectionDescription command to represent
the input section declaration.

This leads to next cleanup:
SectionRule removed.
ScriptConfiguration::Sections mamber removed.
LinkerScript<ELFT>::getOutputSection() removed.

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

llvm-svn: 276283
2016-07-21 14:26:59 +00:00
Rafael Espindola 6eae9f2c67 Delete SplitInputSection.
This opens the way for having a different Piece type for EhInputSection.

llvm-svn: 276275
2016-07-21 13:32:37 +00:00
Rui Ueyama dace838138 Simplify symbol version handling.
r275711 for "speedng up symbol version handling" was committed
by misunderstanding; the benchmark number was measured with
a debug build. The number with a release build didn't actually change.
This patch removes false optimizations added in that patch.

llvm-svn: 276267
2016-07-21 13:13:21 +00:00
Rui Ueyama fd03cfd27a Instantiate Interp output section only when needed.
This change simplifies interaction between Writer and the linker script
because we can make needsInterpSection() a file-scope function.

llvm-svn: 276261
2016-07-21 11:01:23 +00:00
Eugene Leviant 865bf8637b [ELF] Support FLAGS attribute in program header definition
llvm-svn: 276260
2016-07-21 10:43:25 +00:00
George Rimar f6c3ccef5e [ELF] - Linkerscript: remove excessive ScriptConfiguration::Filler field
Previously OutputSectionCommand::Filler was introduced, but unused.
Patch fixes that.

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

llvm-svn: 276253
2016-07-21 07:48:54 +00:00
George Rimar 076fe15757 [ELF] - Initial support of tree-style linker script implemented.
Approach uses LLVM-style RTTI for representing the linker script
commands in a form of tree for future simplification of parsing.

Core idea and code sample belongs to Rui Ueyama.

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

llvm-svn: 276243
2016-07-21 06:43:01 +00:00
Etienne Bergeron 8430489847 fix warning when generating sphinx doc.
llvm-svn: 276227
2016-07-21 02:27:05 +00:00
Davide Italiano fbcf69587e [MachO] Add a couple of missing braces.
Differential Revision:  https://reviews.llvm.org/D21979

llvm-svn: 276213
2016-07-20 23:55:34 +00:00
Simon Atanasyan 4f90c2f9df [ELF][MIPS] Omit redundant arguments in the `getMipsEFlags` function. NFC
llvm-svn: 276176
2016-07-20 20:30:41 +00:00
Rafael Espindola 2197311c31 Delete EhInputSection::getOffset.
We no longer need it for relocations in .eh_frame.

The only relocations that point to .eh_frame are the ones trying to
find the output .eh_frame.

This actually fixes a bug in the symbol value code. It was not
handling -1 as an indicator for a piece not being included in the
output.

llvm-svn: 276175
2016-07-20 20:19:58 +00:00
Simon Atanasyan a088bce959 [ELF][MIPS] Create PLT entry specific for MIPS ABI version R6
llvm-svn: 276173
2016-07-20 20:15:33 +00:00
Simon Atanasyan f463709d7d [ELF][MIPS] Pick arch flag from the first input file.
LLD still does not produce a correct combination of MIPS ELF flags if
input files have different sets of ELF flags (i.e. EF_MIPS_ARCH_32 and
EF_MIPS_ARCH_32R2). But now we do not stick to "R2" ABI version and can
emit EF_MIPS_ARCH_32R6 for example.

llvm-svn: 276172
2016-07-20 20:15:24 +00:00
Rui Ueyama 18f084ff62 Function names should start with lowercase letters.
llvm-svn: 276165
2016-07-20 19:36:41 +00:00
Rui Ueyama 703296aeda Return a vector from createPhdrs instead of return nothing.
This way is consistent with createSections.

llvm-svn: 276164
2016-07-20 19:36:39 +00:00
Rui Ueyama b0f6c59023 Replace parallel arrays with a StringSwitch.
llvm-svn: 276163
2016-07-20 19:36:38 +00:00
Rui Ueyama 047404f711 Remove `else` after `break`.
llvm-svn: 276162
2016-07-20 19:36:36 +00:00
Rafael Espindola 228d27c70f Avoid use of uninitialized iterators.
llvm-svn: 276157
2016-07-20 18:54:31 +00:00
Chandler Carruth 1d175fbc46 Add yet more explicit template instantiations. These were always needed
but things happened to work on some platforms prior to r276133. This
should be the complete set (I hope).

llvm-svn: 276155
2016-07-20 18:47:33 +00:00
Rafael Espindola 0f7cedaa1e Create thunks before regular relocation scan.
We will need to do something like this to support range extension
thunks since that process is iterative.

Doing this also has the advantage that when doing the regular
relocation scan the offset in the output section is known and we can
just store that. This reduces the number of times we have to run
getOffset and I think will allow a more specialized .eh_frame
representation.

By itself this is already a performance win.

firefox
  master 7.295045737
  patch  7.209466989 0.98826892235
chromium
  master 4.531254468
  patch  4.509221804 0.995137623774
chromium fast
  master 1.836928973
  patch  1.823805241 0.992855612714
the gold plugin
  master 0.379768791
  patch  0.380043405 1.00072310839
clang
  master 0.642698284
  patch  0.642215663 0.999249070657
llvm-as
  master 0.036665467
  patch  0.036456225 0.994293213284
the gold plugin fsds
  master 0.40395817
  patch  0.404384555 1.0010555177
clang fsds
  master 0.722045545
  patch  0.720946135 0.998477367518
llvm-as fsds
  master 0.03292646
  patch  0.032759965 0.994943428477
scylla
  master 3.427376378
  patch  3.368316181 0.98276810292

llvm-svn: 276146
2016-07-20 17:58:07 +00:00
Rafael Espindola f53f4f5a5e Use iterators to avoid dereferencing end().
Thanks to George Rimar for finding the problem.

llvm-svn: 276144
2016-07-20 17:41:18 +00:00
Rui Ueyama a7f7884df8 Simplify output section ownership.
This patch simplifies output section management by making
Factory class have ownership of sections that creates.

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

llvm-svn: 276141
2016-07-20 17:19:03 +00:00
George Rimar 31d842f55f [ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection
Previously it was harder to read and also has a error:
command kind was not checked.

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

llvm-svn: 276137
2016-07-20 16:43:03 +00:00
Eugene Leviant f2ea038a4e [ELF] Attempt to fix FreeBSD build bot (no template instantiation for getOutputSectionName)
llvm-svn: 276133
2016-07-20 15:42:34 +00:00
George Rimar 70ce0a9f74 Removed trailing whitespaces. NFC.
llvm-svn: 276126
2016-07-20 15:09:10 +00:00
Peter Smith 441cf5d818 Initial support for the local dynamic model ARM TLS relocations:
- R_ARM_TLS_LDM32
- R_ARM_TLS_LDO32

The local dynamic implementation and tests follows the same model as 
the other ARM TLS models. The R_ARM_TLS_LDO32 is implemented as R_ABS 
expr type as the getVA() for a TLS symbol will return the offset from the 
start of the TLS block.

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

llvm-svn: 276123
2016-07-20 14:56:26 +00:00
Eugene Leviant e63d81bd05 [ELF] Create output sections in LinkerScript class
llvm-svn: 276121
2016-07-20 14:43:20 +00:00
George Rimar b084125dbf [ELF] - Fixed integral constant overflow warning under MSVS 2015. NFC.
Under MSVS 2015 I observed integral constant overflow warning when aggregate initialization was used
to init the bit field. Patch fixes that.

llvm-svn: 276118
2016-07-20 14:26:48 +00:00
Rafael Espindola 5b7a79f92a Avoid some binary searches.
In here we are iterating relocations in order, so we can do the same
with the pieces of .eh_frame and avoid a binary search.

The link times I got with this patch were:

firefox
  master 7.22977811
  patch  7.141041442 0.987726225252
chromium
  master 4.478966851
  patch  4.506602207 1.00617002914
chromium fast
  master 1.894713371
  patch  1.866446889 0.98508139414
the gold plugin
  master 0.386193907
  patch  0.382374918 0.990111213743
clang
  master 0.654849589
  patch  0.647899815 0.989387220949
llvm-as
  master 0.037212718
  patch  0.036858172 0.990472450843
the gold plugin fsds
  master 0.410876711
  patch  0.407418613 0.991583611562
clang fsds
  master 0.734623069
  patch  0.728237526 0.991307728726
llvm-as fsds
  master 0.033446197
  patch  0.03302833 0.987506292569
scylla
  master 3.38134402
  patch  3.414188846 1.00971354166

llvm-svn: 276108
2016-07-20 11:47:50 +00:00
Peter Smith 9d450256d2 Support for standard model ARM TLS
Add relocations and identification functions for the Initial Exec
and Global Dynamic TLS model defined in Addenda to, and Errata in,
the ABI for the ARM Architecture.
    
ARM uses variant 1 of the thread local storage data
structures as defined in ELF Handling for Thread-Local Storage.
    
The "experimental" descriptor based model that can be selected in
gcc, but not clang with -mtls-dialect=gnu2 is not supported.
    
The relocations R_ARM_TLS_LE12 and R_ARM_TLS_IE12GP are not
supported, I know of no ARM Toolchain that supports these relocations
as they limit the size of the TLS block.
    
No code relaxation is supported as the standard ARM TLS model puts
the relocations on literal data.
    
Support for the local dynamic model will come in a follow up patch.

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

llvm-svn: 276095
2016-07-20 08:52:27 +00:00
Rafael Espindola 74df5c7eeb Fix build with gcc 6.
llvm-svn: 275972
2016-07-19 12:33:46 +00:00
Eugene Leviant bbe3860244 [ELF] Minimal PHDRS parser and section to segment assignment support
llvm-svn: 275965
2016-07-19 09:25:43 +00:00
George Rimar b91e7118d4 Reformat comment from 3 to 2 lines. NFC.
llvm-svn: 275961
2016-07-19 07:42:07 +00:00
George Rimar 6ad330acaa Fixed comment. NFC.
llvm-svn: 275959
2016-07-19 07:39:07 +00:00
Rafael Espindola 01c078966d Delete dead code.
And make it easier to spot code going dead by using elf::.

llvm-svn: 275858
2016-07-18 18:24:41 +00:00
Hans Wennborg 708cf064ca docs/conf.py: update version to 4.0
llvm-svn: 275847
2016-07-18 18:12:14 +00:00
Hans Wennborg 72acd60772 Trunk release notes are now for 4.0.0
The 3.9 release are on the 3.9 branch.

llvm-svn: 275845
2016-07-18 18:07:03 +00:00
Rafael Espindola 3fab868675 Pass section by reference. NFC.
llvm-svn: 275803
2016-07-18 16:05:09 +00:00
Rui Ueyama e33579072d Remove SymbolBody::PlaceholderKind.
In the last patch for --trace-symbol, I introduced a new symbol type
PlaceholderKind and store it to SymVector storage. It made all code
that iterates over SymVector to recognize and skip PlaceholderKind
symbols. I found that that's annoying.

In this patch, I removed PlaceholderKind and stop storing them to SymVector.
Now the information whether a symbol is being watched by --trace-symbol
is stored to the Symtab hash table.

llvm-svn: 275747
2016-07-18 01:35:00 +00:00
Rui Ueyama d6328526ba Iterate over SymVector instead of Symtab hash table.
SymVector contains all symbols, so we can iterate either Symtab or SymVector
to visit all symbols. Iterating over SymVector makes the next change for
--trace-symbol possible.

llvm-svn: 275746
2016-07-18 01:34:57 +00:00
Rui Ueyama 25a6d57b9c Unbreak msan buildbot.
llvm-svn: 275728
2016-07-17 19:55:22 +00:00
Rui Ueyama 77fa5ee160 Remove dead code.
llvm-svn: 275724
2016-07-17 18:27:17 +00:00
Rui Ueyama 69c778c084 Implement almost-zero-cost --trace-symbol.
--trace-symbol is a command line option to watch a symbol.
Previosly, we looked up a hash table for a new symbol if the
option is given. Any code that looks up a hash table for each
symbol is expensive because the linker handles a lot of symbols.
In our design, we look up a hash table strictly only once
for a symbol, so --trace-symbol was an exception.

This patch improves efficiency of the option by merging the
hash table into the symbol table.

Instead of looking up a separate hash table with a string,
this patch sets `Traced` flag to symbols specified by --trace-symbol.
So, if you insert a symbol and get a symbol with `Traced` flag on,
you know that you need to print out a log message for the symbol.
This is nearly zero cost.

llvm-svn: 275716
2016-07-17 17:50:09 +00:00
Rui Ueyama b06700fa78 Make Lazy's ctro protected because it shouldn't be instantiated directly.
llvm-svn: 275715
2016-07-17 17:44:41 +00:00
Rui Ueyama bef5d16a90 Remove duplicate public specifier.
llvm-svn: 275714
2016-07-17 17:44:40 +00:00
Rui Ueyama 2a7c1c1507 Print out file names for common symbols for --trace-symbol.
Previously, there was no way to get a file name for a DefinedCommon
symbol. This patch adds it.

llvm-svn: 275712
2016-07-17 17:36:22 +00:00
Rui Ueyama 663b8c2769 Handle versioned symbols efficiently.
Versions can be assigned to symbols in two different ways.
One is the usual version scripts, and the other is special
symbol suffix '@'. If a symbol contains '@', the string after
that is considered to specify a version name.

Previously, we look for '@' for all symbols.

Anything that works on every symbol can be expensive because
the linker has to handle a lot of symbols. The search for '@'
was not an exception.

In this patch, I made two optimizations.

The first optimization is to handle '@' only when at least one
version is defined. If no versions are defined, no versions can
be assigned to any symbols, so it's waste of time to search for '@'.

The second optimization is to scan only suffixes of symbol names
instead of entire symbol names. Symbol names can be very long, but
symbol versions are usually short, so scanning entire symbol names
is waste of time, too.

There are some error cases which we no longer be able to detect
with this patch. I don't think it's a major drawback because they
are minor errors. Speed is more important.

This change improves LLD with debug info self-link time from
6.6993 seconds to 6.3426 seconds (or -5.3%).

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

llvm-svn: 275711
2016-07-17 17:23:17 +00:00
Rui Ueyama 434b56179e Add a pointer to a source file to SymbolBody.
Previously, each subclass of SymbolBody had a pointer to a source
file from which it was created. So, there was no single way to get
a source file for a symbol. We had getSourceFile<ELFT>(), but the
function was a bit inconvenient as it's a template.

This patch makes SymbolBody have a pointer to a source file.
If a symbol is not created from a file, the pointer has a nullptr.

llvm-svn: 275701
2016-07-17 03:11:46 +00:00
Rui Ueyama 7a7a96e199 Do not invoke FileCheck with `not` command.
We should use CHECK-NOT instead.

llvm-svn: 275700
2016-07-17 01:34:39 +00:00
Rui Ueyama 3ec5c84606 Attempt to unbreak Windows bot.
llvm-svn: 275695
2016-07-16 19:16:15 +00:00
Rui Ueyama 818bb2f8dc Remove redundant namespace specifiers.
llvm-svn: 275694
2016-07-16 18:55:47 +00:00
Rui Ueyama 962b277d2d Resurrect code that was lost in conflicting commits.
llvm-svn: 275693
2016-07-16 18:45:25 +00:00
Rui Ueyama f953a8ac17 Use skip() instead of peek() and expect().
llvm-svn: 275692
2016-07-16 18:45:23 +00:00
George Rimar ee0e63804f Update for r275682:
I think 
# REQUIRES: shell 
is required instead of 
# XFAIL: win32

llvm-svn: 275683
2016-07-16 12:34:06 +00:00
George Rimar 50dcece2a0 Recommit r275257 "[ELF] - Implement extern "c++" version script tag"
BSD toolchain contains a bug:
https://sourceforge.net/p/elftoolchain/tickets/491/

In short demangler works differently, fix was to update the testcase.
It should fix the FreeBSD bot failture:
http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/19432/steps/test_lld/logs/stdio

Original commit message was:
[ELF] - Implement extern "c++" version script tag

Patch implements 'extern' version script tag.
Currently only values in quotes(") are supported.

Matching of externs is performed in the same pass as exact match of globals.

Differential revision: http://reviews.llvm.org/D21930

llvm-svn: 275682
2016-07-16 12:26:39 +00:00
Rui Ueyama c755599997 Simplify. NFC.
llvm-svn: 275675
2016-07-16 04:19:29 +00:00
Rui Ueyama af469d47e9 Rename SymbolVersions VersionDefinitions.
SymbolVersions sounds like it had versions for a symbol, so rename it.

llvm-svn: 275674
2016-07-16 04:09:27 +00:00
Rui Ueyama bc94dd9b28 Rename Version VersionDefinition.
The identifier `Version` was used too often in the code to handle
symbol versions. The struct that contains version definitions is
named `Version`. Local variables for version ID are named `Version`.
Local varaible for version string are named `Version`.

This patch give them different names.

llvm-svn: 275673
2016-07-16 04:02:00 +00:00
Rui Ueyama 52654ebb12 Use ScriptParserBase::skip() instead of peek() and next().
skip(S) consumes a token if the next token is S,
so it can be used instead of peek() & next().

llvm-svn: 275672
2016-07-16 03:45:59 +00:00
Rui Ueyama c9b4c073b2 Simplify. NFC.
llvm-svn: 275670
2016-07-16 03:12:16 +00:00
Rui Ueyama 2506866ff6 Simplify default symbol version management. NFC.
llvm-svn: 275669
2016-07-16 03:08:26 +00:00
Rui Ueyama e9381bd2d8 Remove redundant variable.
llvm-svn: 275667
2016-07-16 02:47:42 +00:00
Rui Ueyama f524464e2f Set sh_addralign in the constructor for consistency. NFC.
llvm-svn: 275666
2016-07-16 02:36:00 +00:00
Rui Ueyama 9f61964769 Make Verdef and Verdaux adjacent in the version definition section.
Previously, Verdefs and Verdauxs are separated in the section.
The new layout is easier to write as we do not have to maintain
two pointers and can avoid passing a reference to a pointer.

llvm-svn: 275665
2016-07-16 02:29:45 +00:00
Rui Ueyama 0ff953e811 Use SymbolVersion::Id instead of a hard-coded local variable.
llvm-svn: 275660
2016-07-16 02:00:43 +00:00
Rui Ueyama 429ef2af6a ELF: Include filenames in error messages.
llvm-svn: 275608
2016-07-15 20:38:28 +00:00
Rui Ueyama 188d2c34e6 Remove variables. NFC.
llvm-svn: 275605
2016-07-15 20:05:05 +00:00
Eugene Leviant 0e36f42846 [ELF] Overriding reserved symbols in linker script
llvm-svn: 275549
2016-07-15 11:20:04 +00:00
Rui Ueyama 3d9b26b4ad Inline traceUndefined function.
llvm-svn: 275531
2016-07-15 04:57:46 +00:00
Rui Ueyama eba9b63cbc Update comments.
llvm-svn: 275530
2016-07-15 04:57:44 +00:00
Rui Ueyama 177746a739 Remove redundant `return`.
llvm-svn: 275528
2016-07-15 04:32:11 +00:00
Rui Ueyama 05ef4cff44 Merge SymbolAssignmentKind and ExprKind.
In a linker script, `.` is a special symbol indicating a counter.
Previously, we had two expression types, ExprKind and SymbolAssignmentKind
for `.` and all the other symbol names, respectively. But we could merge
them because the former is a special case of the latter.

llvm-svn: 275527
2016-07-15 04:19:37 +00:00
Rui Ueyama 601b07c7f5 ELF: Remove member variables that are used only in one function.
Differential Revision: https://reviews.llvm.org/D22396

llvm-svn: 275526
2016-07-15 03:06:42 +00:00
Rui Ueyama 112351dc38 Avoid writing to errs().
We should write to ErrorOS instead. Normaly, *ErrorOS == errs(),
but they can be different if LLD is embedded.

llvm-svn: 275525
2016-07-15 02:51:05 +00:00
Rui Ueyama a9d9eda0ce Inline a vairable that is used only once. NFC.
llvm-svn: 275524
2016-07-15 02:42:18 +00:00
Rui Ueyama 48da5cf236 ELF: Simplify path constructions for -save-temps. NFC.
llvm-svn: 275523
2016-07-15 02:17:13 +00:00
Rui Ueyama f8292e9ac9 ELF: Make check() always return a value.
This patch corresponds to r275511 for COFF.

llvm-svn: 275521
2016-07-15 02:01:03 +00:00
Rui Ueyama aa2db88984 ELF: Make error() to always set HasError.
Previously, it checked for the EC parameter and set HasError
only when there was an error. But in most places we called
error only when error had occurred, so this behavior was confusing.

llvm-svn: 275517
2016-07-15 01:38:54 +00:00
Rui Ueyama bb57954241 COFF: Update error messages so that they start with lowercase letters.
llvm-svn: 275513
2016-07-15 01:12:24 +00:00
Rui Ueyama 5694ebbc8b Remove unnecessary explicit call of Twine ctor.
llvm-svn: 275512
2016-07-15 01:06:40 +00:00
Rui Ueyama 659a4f2f38 Make check() always return a value.
Previously, one of two check functions didn't return a value.
It was confusing. This patch makes both functions return values.

llvm-svn: 275511
2016-07-15 01:06:38 +00:00
Rui Ueyama 0d09a865c6 COFF: Remove `void error()` functions and use fatal instead.
This change makes the control flow more explicit.

llvm-svn: 275504
2016-07-15 00:40:46 +00:00
Rui Ueyama 1a3fd13776 COFF: Remove unnecessary explicit calls of Twine ctor.
llvm-svn: 275501
2016-07-14 23:43:36 +00:00
Rui Ueyama 606047939c COFF: Rename noreturn error -> fatal.
This new name is also consistent with ELF.

llvm-svn: 275500
2016-07-14 23:37:14 +00:00
Rui Ueyama 7e75866c51 COFF: Rename non-noreturn error -> check.
The new name is consistent with ELF.

llvm-svn: 275499
2016-07-14 23:37:10 +00:00
Peter Collingbourne 765aa2d1c2 COFF: Update remaining #include paths.
llvm-svn: 275480
2016-07-14 21:30:37 +00:00
Peter Collingbourne 6ccb257925 ELF: Update #include path for D22173.
llvm-svn: 275477
2016-07-14 21:21:20 +00:00
Rui Ueyama cb7d6e955d Update error message to use "ld.lld" instead of "lld -flavor gnu".
Dispatching based on argv[0] seems to be more convenient for users
than dispatching based on -flavor option. Currently, when a user
invoke LLD as "lld", we recommend them pass -flavor option. This
patch changes the message so that we recommend use ld.lld, ld or
lld-link instead.

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

llvm-svn: 275448
2016-07-14 17:57:33 +00:00
Rui Ueyama 941faa77ad Remove TargetInfo::getImageBase. NFC.
llvm-svn: 275447
2016-07-14 17:43:28 +00:00
Rui Ueyama cafc0f2e03 Set DT_MIPS_BASE_ADDRESS correctly if -image-base is given.
Differential Revision: http://reviews.llvm.org/D22323

llvm-svn: 275446
2016-07-14 17:40:18 +00:00
Benjamin Kramer 56a46bc680 Upgrade all the .arcconfigs to https.
llvm-svn: 275409
2016-07-14 13:15:37 +00:00
Eugene Leviant b030411414 [ELF] r275383 reverted due to buildbot failure
llvm-svn: 275385
2016-07-14 09:21:24 +00:00
Eugene Leviant 219d9b2b18 [ELF] Allow overriding reserved symbols in linker scripts
llvm-svn: 275383
2016-07-14 08:26:41 +00:00
Rui Ueyama 3b04d833c4 Set sh_addralign to 1 instead of 0.
ELF spec says that alignment of 0 is equivalent to 1.
Previously, we arbitrary set to 0 or 1, but always setting to 1
makes our program simpler.

llvm-svn: 275374
2016-07-14 05:46:24 +00:00
Rui Ueyama 0fad6ea551 Attempt to unbreak msan bot.
r275301 made .got section be aligned on Target->GotEntrySize,
so GotEntrySize must have been initialized. We didn't initialize
it for AMDGPU.

llvm-svn: 275373
2016-07-14 05:46:22 +00:00
Lang Hames 622ef17f5d [lld] Update LLD for Archive::child_iterator change in LLVM r275361.
llvm-svn: 275362
2016-07-14 02:35:18 +00:00
Rui Ueyama 729822fe39 Update the readme text.
llvm-svn: 275305
2016-07-13 19:14:25 +00:00
Rui Ueyama 803b120ba1 Add GotEntrySize/GotPltEntrySize to ELF target.
Patch by H.J Lu.

For x86-64 psABI, the entry size of .got and .got.plt sections is 8
bytes for both LP64 and ILP32.  Add GotEntrySize and GotPltEntrySize
to ELF target instead of using size of ELFT::uint.  Now we can generate
a simple working x32 executable.

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

llvm-svn: 275301
2016-07-13 18:55:14 +00:00
Rui Ueyama 484a49514f Rename VAStart -> ImageBase. NFC.
Config members are named after corresponding command line options.
This patch renames VAStart ImageBase so that they are in line with
--image-base.

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

llvm-svn: 275298
2016-07-13 18:40:59 +00:00
Petr Hosek 1ddcacb949 [ELF] Rename the test to reflect the option name
This is to follow the convention of naming the test after the name
of the option.

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

llvm-svn: 275295
2016-07-13 18:31:44 +00:00
George Rimar bd69903692 [ELF] - Add predefined sections to output sections list in one place.
Minor cleanup.
Currently it looks wierd that having method addPredefinedSections()
we still add 2 sections outside it without real reasons.
Patch fixes that.

Differential revision: http://reviews.llvm.org/D19981

llvm-svn: 275269
2016-07-13 14:26:31 +00:00
George Rimar dd64bb38bd Reverted r275257 "[ELF] - Implement extern "c++" version script tag"
It broke build bots:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/8204
http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/19432

llvm-svn: 275258
2016-07-13 08:19:04 +00:00
George Rimar e05103ea11 [ELF] - Implement extern "c++" version script tag
Patch implements 'extern' version script tag.
Currently only values in quotes(") are supported.

Matching of externs is performed in the same pass as exact match of globals.

Differential revision: http://reviews.llvm.org/D21930

llvm-svn: 275257
2016-07-13 07:46:00 +00:00
Saleem Abdulrasool f27d4068a5 COFF: drop the dependency on LIB.EXE for implibs
lld currently relies on lib.exe in order to generate an empty import library.
The "empty" import library consists of 5 members:
  - first linker member
  - second linker member
  - Import Descriptor
  - NULL Import Descriptor
  - NULl Thunk

The first two entries (first and second linker members) are string tables which
are never updated.  Therefore, they may as well as not be present.  A subsequent
change to add that is probably warranted.  However, this does not prevent the
use of the linker.

The Import Descriptor is the content which is most important.  It provides an
Import Name Table entry for the library (as specified by the LIBRARY directive
in the DEF file).  Additionally, it contains undefined references to the NULL
Import Descriptor and the library NULL Thunk Data.  This ensures that the linker
will pull in the subsequent objects from the import library for the link.  The
Import Descriptor has a single symbol (__IMPORT_DESCRIPTOR_<Library>) which
contains 3 relocations, one to the INT (Import Name Table) entry, one to the ILT
(Import Lookup Table) entry, and one to the IAT (Import Address Table) entry.

The NULL Import Descriptor is the last import descriptor and terminates the
import descriptor array.  It contains a single symbol
(__NULL_IMPORT_DESCRIPTOR).

The NULL Thunk contains a single symbol (\x7f<Library>_NULL_THUNK_DATA) and
provides the terminator for the ILT and IAT.

These files are currently constructed manually following the example of the
Short Import Library format.  This is arguably less than ideal, and it may be
possible to use MCAssembler and feed it the fragments to construct the object.

The major difference between the LIB (LINK) generated objects and the ones
generated here is that they are all one section shorter (.debug$S) as they do
not contain the debug information and one symbol shorter (@comp.id) as they do
not contain the RICH signature.

Move the logic related to the librarian into a new source file (Librarian.cpp).

llvm-svn: 275242
2016-07-13 03:19:27 +00:00
Rui Ueyama 1e52f25d46 Add -m elf32_x86_64.
Patch by H.J. Lu.

This patch adds -m elf32_x86_64 to lld. But it doesn't generate working
x32 binaries.

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

llvm-svn: 275236
2016-07-12 23:28:33 +00:00
Rui Ueyama 46626e1f04 Add ILP32 support to X86_64TargetInfo.
Patch by H.J. Lu.

As x86-64 psABI supports both LP64 and ILP32, this patch adds <ELFT>
template to X86_64TargetInfo.

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

llvm-svn: 275235
2016-07-12 23:28:31 +00:00
Rui Ueyama b933df1835 Simplify. NFC.
Config->Pic is true if (Config->Pie || Config->Shared) is true,
so this extra check was redundant.

llvm-svn: 275234
2016-07-12 23:28:30 +00:00
Petr Hosek d7bd2389ce [ELF] Support for setting the base address
The -image-base option allows for overriding the base address.

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

llvm-svn: 275206
2016-07-12 19:37:53 +00:00
George Rimar 6892afaa2d Recommit r275161 "[ELF] - Move section factory out from writer to make it reusable."
With fix:
* fixed compilation error under linux:

template <class ELFT> class OutputSectionFactory {
...
  typedef typename SectionKey<ELFT::Is64Bits> Key;

changed to:
template <class ELFT> class OutputSectionFactory {
...
  typedef typename elf::SectionKey<ELFT::Is64Bits> Key;

llvm-svn: 275166
2016-07-12 09:49:43 +00:00
George Rimar d8f547fab4 Revert r275161 "[ELF] - Move section factory out from writer to make it reusable."
It broke build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-debian-fast/builds/39652

llvm-svn: 275163
2016-07-12 09:11:13 +00:00
George Rimar 5d53d1f42c [ELF] - Make few members of Writer to be global and export them for reuse
Creating sections on linkerscript side requires some methods
that can be reused if are exported from writer.

Patch implements that change.

Differential revision: http://reviews.llvm.org/D20104

llvm-svn: 275162
2016-07-12 08:50:42 +00:00
George Rimar e51f7f4d39 [ELF] - Move section factory out from writer to make it reusable.
Since linkerscript should create sections by itself
(if SECTIONS command is present),
then we might want to reuse the OutputSectionFactory (D19976 already do that now),
so this patch moves it out from writer cpp file for that purpose.

Differential revision: http://reviews.llvm.org/D19977

llvm-svn: 275161
2016-07-12 08:38:04 +00:00
George Rimar 7899d48dff [ELF] - Add Id field to Version struct.
That helps to avoid expressions like I + 2 in code
that assigns version number to symbols.

Change was suggested by Rui Ueyama.

Differential revision: http://reviews.llvm.org/D22086

llvm-svn: 275159
2016-07-12 07:44:40 +00:00
Eugene Leviant eda81a1b86 [ELF] Support for symbol assignment in linker scripts within SECTIONS {} block
llvm-svn: 275158
2016-07-12 06:39:48 +00:00
Rui Ueyama ec1b80fd11 Remove unused parameters.
llvm-svn: 275153
2016-07-12 03:49:41 +00:00
Rui Ueyama 89c3762a7a Update comments.
llvm-svn: 275003
2016-07-09 23:16:00 +00:00
Rui Ueyama 0d410c265c Attempt to fix buildbots.
llvm-svn: 275001
2016-07-09 23:02:37 +00:00
Rui Ueyama 95d2a9f91a Remove unused forward declarations.
llvm-svn: 274998
2016-07-09 22:54:27 +00:00
Rui Ueyama e2efadced7 Remove Target::writeThunk.
Only MipsThunk were using the function, and the way how it wrote
thunk contents was different from ARM thunks. This patch makes
them consistent.

llvm-svn: 274997
2016-07-09 22:52:32 +00:00
Rui Ueyama 3d2bbb13d0 Make ARM thunks consistent with MIPS in coding style.
Although they are in the same .cpp file, the way they were written
were slightly different, so they looked more different than they were.
This patch makes their styles consistent.

llvm-svn: 274996
2016-07-09 22:52:30 +00:00