Commit Graph

2652 Commits

Author SHA1 Message Date
Davide Italiano 5ac0d7c5ad [LinkerScript] Filler can have a decimal value.
llvm-svn: 277222
2016-07-29 22:21:28 +00:00
Rafael Espindola 716a94787c Don't crash if PT_TLS is empty.
llvm-svn: 277202
2016-07-29 19:24:27 +00:00
George Rimar 9e69450ec7 [ELF] - Linkerscript: implemented SIZEOF(section)
SIZEOF(section)
Return the size in bytes of the named section, if that section has been allocated.

SIZEOF(section) often used in scripts. Few examples from the wild:
https://github.com/chipKIT32/pic32-Arduino-USB-Bootloader-original/blob/master/boot-linkerscript.ld
https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/gba_cart.ld

Patch implements it.

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

llvm-svn: 277165
2016-07-29 16:18:47 +00:00
George Rimar 0702c4e86e [ELF] - Linkerscript: Implemented SORT command.
When the SORT keyword is used, the linker will sort the files or sections into ascending order by name before placing them in the output file.
It is used in FreeBSD script:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l139

This is PR28689.

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

llvm-svn: 277153
2016-07-29 15:32:46 +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
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 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
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
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
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
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
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
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
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 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
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
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 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
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
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
Eugene Leviant 865bf8637b [ELF] Support FLAGS attribute in program header definition
llvm-svn: 276260
2016-07-21 10:43:25 +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
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
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
Eugene Leviant bbe3860244 [ELF] Minimal PHDRS parser and section to segment assignment support
llvm-svn: 275965
2016-07-19 09:25:43 +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 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 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
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 429ef2af6a ELF: Include filenames in error messages.
llvm-svn: 275608
2016-07-15 20:38:28 +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 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
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
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 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
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
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
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
Peter Smith fb05cd997c Recommit R274836 Add Thunk support framework for ARM and Mips
The TinyPtrVector of const Thunk<ELFT>* in InputSections.h can cause 
build failures on certain compiler/library combinations when Thunk<ELFT> 
is not a complete type or is an abstract class. Fixed by making Thunk<ELFT>
non Abstract.

type or is an abstract class 

llvm-svn: 274863
2016-07-08 16:10:27 +00:00
Peter Smith eeb827447e Revert R274836 Add Thunk support framework for ARM and Mips
This seems to be causing a buildbot failure on lld-x86_64-freebsd. Will
reproduce locally and fix. 

llvm-svn: 274841
2016-07-08 12:25:50 +00:00
Peter Smith de01b98a26 Add Thunk support framework for ARM and Mips
Generalise the Mips LA25 Thunk code and implement ARM and Thumb
    interworking Thunks.
    
    - Introduce a new module Thunks.cpp to store the Target Specific Thunk
      implementations.
    - DefinedRegular and Shared have a ThunkData field to record Thunk.
    - A Target can have more than one type of Thunk.
    - Support PC-relative calls to Thunks.
    - Support Thunks to PLT entries.
    - Existing Mips LA25 Thunk code integrated.
    - Support for ARMv7A interworking Thunks.
    
    Limitations:
    - Only one Thunk per SymbolBody, this is sufficient for all currently
      implemented Thunks.
    - ARM thunks assume presence of V6T2 MOVT and MOVW instructions.

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

llvm-svn: 274836
2016-07-08 11:13:40 +00:00
George Rimar c61bcd80af [ELF] - Do not error out when version declaration not found when building executable.
When building executable usually version script is absent.
Before this patch error was shown in the case when
symbol name contained version and there was no script to match it.
  Instead of error out patch allows
to create new version declaration in this case and use it.
gnu linkers do the same.

That is PR28359.

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

llvm-svn: 274828
2016-07-08 06:47:28 +00:00
Rui Ueyama f731d0afed Test --demangle feature.
Previously, it was not tested because the test was written in
a way that it passed on a platform that does not support
abi::__cxa_demangle. Now we restrict this test to Unix (by adding
"REQUIRES: shell") and assume that it always demangle symbols.
Thanks to Davide to find out the issue.

llvm-svn: 274808
2016-07-07 23:43:09 +00:00
Rafael Espindola 580d7a1b1e -Bsymbolic should not make symbols more preemptable.
But it was doing that for protected undefined symbols.

llvm-svn: 274803
2016-07-07 22:50:54 +00:00
Rafael Espindola 4225342e95 This now works on unix too.
With this there are no unsupported tests on linux in test/ELF :-)

llvm-svn: 274752
2016-07-07 13:52:04 +00:00
George Rimar f73a25812f [ELF] - Fixed incorrect logic of version assignments when mixing wildcards with values matching.
Previously we had incorrect logic here. Imagine we would have the next script:

LIBSAMPLE_1.0
{
  global:
   a_2;
 local:
  *;
};

LIBSAMPLE_2.0
{
  global:
   a*;
};
According to previous logic it would assign version 1 to a_2 and then
would try to reassign it to version 2 because of applying wildcard a*.
And show a warning about that.

Generally Ian Lance Tailor wrote about next rules that should be applied:
(http://www.airs.com/blog/archives/300)

Here are the current rules for gold:

"If there is an exact match for the mangled name, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look for an extern C++ or an extern Java exact match. If we find an exact match, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look through the wildcard patterns, ignoring “*” patterns. We look through the version tags in reverse order. For each version tag, we look through the global patterns and then the local patterns. We use the first match we find (i.e., the last matching version tag in the file).
Otherwise, we use the “*” pattern if there is one. We give a warning if there are multiple “*” patterns."

Patch makes wildcard matching to be in revered order and to follow after the regular naming matching.

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

llvm-svn: 274739
2016-07-07 07:45:27 +00:00
Rui Ueyama 287956f72b Correctly define "zlib" feature.
We have "REQUIRES: zlib" in our test, but zlib was not defined,
so the test did not run on any platform.

llvm-svn: 274730
2016-07-07 03:55:57 +00:00
Rui Ueyama 1d12ac1d11 Fix endianness issue.
Previously, ch_size was read in host byte order, so if a host and
a target are different in byte order, we would produce a corrupted
output.

llvm-svn: 274729
2016-07-07 03:55:55 +00:00
Rui Ueyama 0f282a593f Do not call warning() from ELFOptTable::parse().
warning() depends on Config->FatalWarnings, so we don't want to call
that function before we initialize that member.

llvm-svn: 274723
2016-07-07 01:58:04 +00:00
Rafael Espindola 9639ec1e66 Read the implicit addend of R_386_GOT32X.
llvm-svn: 274690
2016-07-06 21:48:50 +00:00
Rafael Espindola d03e659140 Recognize R_386_GOT32X.
We don't relax it, but we at least recognize it.

llvm-svn: 274687
2016-07-06 21:41:39 +00:00
Davide Italiano f296a7eeae [ELF] Introduce a flag to parse response files according to windows rules.
Differential Revision:  http://reviews.llvm/org/D22015

llvm-svn: 274684
2016-07-06 21:24:34 +00:00
Rafael Espindola 1f6929bff6 Use / instead of \ on windows created cpio files
Otherwise when extracting these files on a unix system one
ends up with files named like "repro\bar\foo.o".

llvm-svn: 274622
2016-07-06 12:09:51 +00:00
Davide Italiano c03d610cff [ELF] Support --entry= option variant. Update tests while I'm there.
llvm-svn: 274524
2016-07-04 21:50:50 +00:00
Tom Stellard 391e3a873e ELF/AMDGPU: Add support for GOT relocations
Reviewers: arsenm, rafael, tony-tye, kzhuravl, ruiu

Subscribers: llvm-commits, kzhuravl

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

llvm-svn: 274514
2016-07-04 19:19:07 +00:00
Rafael Espindola 8e51e67eb7 Add a test for accessing __tls_get_addr with a GOT.
This was already passing, but missing a test.

llvm-svn: 274513
2016-07-04 17:34:53 +00:00
George Rimar 857644cef8 [ELF] - Implemented --fatal-warnings option.
--fatal-warnings: Treat warnings as errors

DIfferential revision: http://reviews.llvm.org/D21969

llvm-svn: 274504
2016-07-04 13:43:12 +00:00
George Rimar 33b9de4b32 [ELF] - Depricate version references.
This is PR28358

According to
https://www.akkadia.org/drepper/dsohowto.pdf

"The fourth point, the VERS 1.0 version being referred to in the VERS 2.0 definition, is not really important in symbol versioning. It marks the predecessor relationship of the two versions and it is done to maintain the similar- ities with Solaris’ internal versioning. It does not cause any problem it might in fact be useful to a human reader so predecessors should always be mentioned."

Patch partially reverts 273423 "[ELF] - Implemented version script hierarchies.",
version references are just ignored now.

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

llvm-svn: 274345
2016-07-01 11:45:10 +00:00
Eugene Leviant 467c4d5538 [ELF] Fix first PT_LOAD segment VA calculation, when linker script is used
llvm-svn: 274342
2016-07-01 10:27:36 +00:00
George Rimar e86dcd0cbd [ELF] - Added support for --unresolved-symbols option.
Option has next description (http://linux.die.net/man/1/ld):
"--unresolved-symbols=method
Determine how to handle unresolved symbols. There are four possible values for method
according to documentation:

ignore-all: Do not report any unresolved symbols.
report-all: Report all unresolved symbols. This is the default.
ignore-in-object-files: Report unresolved symbols that are contained in shared libraries, but ignore them if they come from regular object files.
ignore-in-shared-libs: Report unresolved symbols that come from regular object files, but ignore them if they come from shared libraries."

Since report-all is default and we traditionally do not report about undefined symbols in lld,
report-all does not report about undefines from DSO. 
ignore-in-object-files also does not do that. Handling of that option differs from what gnu linkers do.

Option works in next way in lld:
ignore-all: Do not report any unresolved symbols.
report-all: Report all unresolved symbols except symbols from DSOs. This is the default.
ignore-in-object-files: The same as ignore-all.
gnore-in-shared-libs: The same as report-all.

This is PR24524.

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

llvm-svn: 274123
2016-06-29 12:35:04 +00:00
Rui Ueyama 94f3a731e5 Convert DOS-style newlines.
llvm-svn: 274118
2016-06-29 10:39:00 +00:00
George Rimar dbbf60e590 [ELF] - Check the input bitcode files for compatibility.
Previously BC files were not checked for the same platform etc,
That lead to confusing error "Invalid section header entry size (e_shentsize) in ELF header" when
mixing files for different architectures.

Patch fixes PR28324.

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

llvm-svn: 274113
2016-06-29 09:46:00 +00:00
Davide Italiano 60976ba86d [LTO] Infer ELFKind/EMachine from Bitcode files
So that users are not forced to pass `-m` on the command line
when the inputs are all bitcode.

PR:   28268
Differential Revision:  http://reviews.llvm.org/D21779

llvm-svn: 274107
2016-06-29 06:12:39 +00:00
Davide Italiano 8e1131dc46 [ELF] Support for wildcard in version scripts.
Example:

VERSION_1.0 {
  global: foo*;
  local: *; }

now correctly matches all the symbols which name starts with
`foo`.

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

llvm-svn: 274091
2016-06-29 02:46:51 +00:00
Rafael Espindola 857d7c5dd0 Handle empty versions.
They are significant now that we support @ in symbol names.

llvm-svn: 274071
2016-06-28 21:48:33 +00:00
Rafael Espindola 2100aa08b7 Don't check the section index, it is not relevant for this test.
llvm-svn: 274070
2016-06-28 21:47:17 +00:00
George Rimar 4365158689 [ELF] - Implemented support of default/non-default symbols versions
t is possible to create new version of symbol instead of depricated one
using combination of version script and asm commands. For example:

__asm__(".symver b_1,b@LIBSAMPLE_1.0");
int b_1() { return 10; }
__asm__(".symver b_2,b@@LIBSAMPLE_2.0");
int b_2() { return 20; }

This code makes b_2() to be default implementation for b().
b_1() is used for compatibility with binaries compiled against
library of older version LIBSAMPLE_1.0.

This patch implements support for above functionality in lld.

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

llvm-svn: 274002
2016-06-28 08:21:10 +00:00
George Rimar 36b2c0a683 [ELF] - Implemented --no-undefined-version flag
Option checks for cases where a version script explicitly lists
a symbol, but the symbol is not defined and errors out such
cases if any.

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

llvm-svn: 273998
2016-06-28 08:07:26 +00:00
Davide Italiano 4fdc648592 [ELF] Warn for duplicate symbols in version scripts instead of erroring out.
Emitting an error in this case breaks real-world application (e.g. libreoffice).
See http://reviews.llvm.org/D21555 for context.

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

llvm-svn: 273989
2016-06-28 03:40:49 +00:00
Chris Bieneman 677c6e4173 [yaml2obj] Hopefully the last test case update from r273915
Should fix the last LLD bots.

llvm-svn: 273942
2016-06-27 21:06:40 +00:00
Chris Bieneman 4e5bdaaca4 [yaml2obj] One more missing test case update from r273915
Should fix the last LLD bots.

llvm-svn: 273939
2016-06-27 20:47:00 +00:00
Chris Bieneman ca5170e3e4 [yaml2obj] Updating LLD tests to account for LLVM r273915
This removed the -format flag from yaml2obj in favor of YAML tags.

llvm-svn: 273920
2016-06-27 20:17:08 +00:00
Rui Ueyama 20d8d55b05 Fix library search order.
Previously, we searched for a .so file from all library paths and
then searched for a .a file. That logic is wrong. What we need to
do is to look for a .so and a .a for each library path.

llvm-svn: 273846
2016-06-27 07:26:28 +00:00
Lang Hames 3b3b4d792f [lld][MachO] Add support for x86-64 negDelta64 references and fix negDelta32.
These references are used to implement MachO/x64-64 subtractor relocations
where the minuend is being fixed up, rather than the subtrahend. The 64-bit
version was not previously supported, the 32-bit version was partially
implemented but contained bugs not caught by existing test cases. This
patch fixes both functionality and test coverage.

llvm-svn: 273759
2016-06-25 00:29:54 +00:00
Davide Italiano e160f0d0d6 [ELF] Allow --reproduce to be specified as an environment variable.
PR: 28257
Differential Revision:   http://reviews.llvm.org/D21628

llvm-svn: 273698
2016-06-24 18:02:50 +00:00
George Rimar 6a7cfd039e [ELF] - Fix incorrect logic in VersionScriptParser::parseVersion()
Previously the next sample script would generate 2 entries in 
Config->SymbolVersions with the same version name.

VERSION {
 global: c;
};
That happened because parseVersionSymbols() was called twice.
At first for "global:" and since there is no local tag, it was called again.
Patch fixes the issue, testcase was updated to demonstrate.

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

llvm-svn: 273663
2016-06-24 11:23:55 +00:00
George Rimar 602fbee9fc [ELF] - Support of compressed input sections implemented.
Patch implements support of zlib style compressed sections.
SHF_COMPRESSED flag is used to recognize that decompression is required.
After that decompression is performed and flag is removed from output.

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

llvm-svn: 273661
2016-06-24 11:18:44 +00:00
Simon Atanasyan 002e244717 [ELF][MIPS] Support MIPS TLS relocations
The patch adds one more partition to the MIPS GOT. This time it is for
TLS related GOT entries. Such entries are located after 'local' and 'global'
ones. We cannot get a final offset for these entries at the time of
creation because we do not know size of 'local' and 'global' partitions.
So we have to adjust the offset later using `getMipsTlsOffset()` method.

All MIPS TLS relocations which need GOT entries operates MIPS style GOT
offset - 'offset from the GOT's beginning' - MipsGPOffset constant. That
is why I add new types of relocation expressions.

One more difference from othe ABIs is that the MIPS ABI does not support
any TLS relocation relaxations. I decided to make a separate function
`handleMipsTlsRelocation` and put MIPS TLS relocation handling code
there. It is similar to `handleTlsRelocation` routine and duplicates its
code. But it allows to make the code cleaner and prevent pollution of
the `handleTlsRelocation` by MIPS 'if' statements.

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

llvm-svn: 273569
2016-06-23 15:26:31 +00:00
Rui Ueyama 3cda384e37 Attempt to fix Windows buildbots.
llvm-svn: 273537
2016-06-23 07:14:09 +00:00
Rui Ueyama d60dae8a6a Implement --trace-symbol=symbol option.
Patch by Shridhar Joshi.

This option provides names of all the link time modules which define and
reference symbols requested by user. This helps to speed up application
development by detecting references causing undefined symbols.
It also helps in detecting symbols being resolved to wrong (unintended)
definitions in case of applications containing multiple definitions for
same symbols with different types, bindings.

Implements PR28226.

llvm-svn: 273536
2016-06-23 07:00:17 +00:00
Rui Ueyama 809d8e2d41 Fix a bug that MIPS thunks can overwrite other section contents.
Peter Smith found while trying to support thunk creation for ARM that
LLD sometimes creates broken thunks for MIPS. The cause of the bug is
that we assign file offsets to input sections too early. We need to
create all sections and then assign section offsets because appending
thunks changes file offsets for all following sections.

This patch separates the pass to assign file offsets from thunk
creation pass. This effectively reverts r265673.

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

llvm-svn: 273532
2016-06-23 04:33:42 +00:00
Davide Italiano 595ee8cb9c [LTO] Include ASM undefs in llvm.compiler_used.
This fixes PR28218. Thanks to Rafael for spotting a failure in
the SHARED_LIBS build!

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

llvm-svn: 273451
2016-06-22 18:09:23 +00:00
George Rimar 4d8465cbe1 [ELF] - Show explicit error if extern keyword is used in version script.
Since we do not have plans to support it in closest future,
it is better than common script parsing error.

llvm-svn: 273426
2016-06-22 15:02:57 +00:00
George Rimar 0ab48b7334 [ELF] - Implemented version script hierarchies.
Patch implements hierarchies for version scripts. 
This allows to handle script files with dependencies, like next one has:

LIBSAMPLE_1.0{
  global:
  a;
};

LIBSAMPLE_2.0
{
  global:
  b;
}LIBSAMPLE_1.0;

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

llvm-svn: 273423
2016-06-22 14:40:45 +00:00
George Rimar d4245a1ffd Update testcases after r273417, which changed llvm-readobj output slightly.
llvm-svn: 273418
2016-06-22 13:45:08 +00:00
George Rimar 5b2503fb3e Added new line at the end of file. NFC.
llvm-svn: 273399
2016-06-22 11:41:37 +00:00
George Rimar b9f4492ef6 [ELF] - Do not crash on unclosed quote (") in scripts.
Found that during investigation of FreeBsd scripts.
Unclosed quote just crashed lld.

llvm-svn: 273398
2016-06-22 11:39:16 +00:00
George Rimar 50b80359c0 [ELF] - Do not allow to mix global symbols versions.
For next version script:
VER1{
  global:
  a;
};

VER2{
  global:
  a;
};
gold would produce warning like:
"warning: using 'VER1' as version for 'a' which is also named in version 'VER2' in script."

Documentation also says we do not want this duplications (https://people.freebsd.org/~deischen/symver/library_versioning.txt):
"Note that you do not want to duplicate symbols in the map file. The .symver directives are all that is required to add compatibility
symbols into old versions."

This patch restricts such mixing and makes lld to produce error in this case.

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

llvm-svn: 273396
2016-06-22 09:10:38 +00:00
Rafael Espindola 254b58dfe3 Revert "Revert "Add a test showing that lto produces relaxable relocations.""
This reverts commit r273247.

lld should always use the new relocations.

llvm-svn: 273266
2016-06-21 14:47:43 +00:00
Rui Ueyama 03a6cec51e Detect invalid use of R_X86_64_GOTTPOFF.
It is an ABI requirement that the relocation must be used
in MOVQ or LEAQ instructions. Previously, we ignored invalid
relocations.

llvm-svn: 273248
2016-06-21 06:03:28 +00:00
James Y Knight fde8f9bd82 Revert "Add a test showing that lto produces relaxable relocations."
This reverts commit r273074.

Reverting this too, after revert in llvm in r273245.

llvm-svn: 273247
2016-06-21 05:54:41 +00:00
Rui Ueyama 55a9def2bf Refactor X86_64TargetInfo::relaxTlsIeToLe.
This patch is to rewrite the function with a table-lookup-ish approach
so that it can read as a series of "convert this pattern to this" pattern.

llvm-svn: 273238
2016-06-21 03:42:32 +00:00
Tom Stellard 1cfb9efdf7 ELF/AMDGPU: Add support for R_AMDGPU_REL32 relocations
Reviewers: rafael, ruiu

Subscribers: kzhuravl, llvm-commits

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

llvm-svn: 273192
2016-06-20 19:48:29 +00:00
Davide Italiano a074fe41bf [ELF] Accept --soname= (two dashes).
Update an existing test to exercise the new functionality, while
I'm here.

llvm-svn: 273175
2016-06-20 17:58:09 +00:00
Rafael Espindola ffe2e06f71 Don't go on an infinite loop on a missing ";".
Thanks to Will Dietz for reporting the issue.

llvm-svn: 273157
2016-06-20 14:02:22 +00:00
George Rimar 35728c3465 [ELF] - Lowercase the error messages text. NFC.
llvm-svn: 273156
2016-06-20 13:48:16 +00:00
George Rimar d3566309eb [ELF] - Recommit r273143("[ELF] - Basic versioned symbols support implemented.")
With fix:
-soname flag was not set in testcase. Hash calculated for base def was different on local
and bot machines because filename fos used for calculating.

Initial commit message:
Patch implements basic support of versioned symbols.
There is no wildcards patterns matching except local: *;
There is no support for hierarchies.
There is no support for symbols overrides (@ vs @@ not handled).

This patch allows programs that using simple scripts to link and run.

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

llvm-svn: 273152
2016-06-20 11:55:12 +00:00
Simon Atanasyan 7b8481bf95 [ELF][MIPS] Fix predicate used for sorting MIPS dynamic symbol tables
Now it conforms requirement for std::stable_sort predicates. That
resolves build-bot failures on Windows hosts.

llvm-svn: 273151
2016-06-20 11:37:56 +00:00
George Rimar d03f97211a Revert r273143 "[ELF] - Basic versioned symbols support implemented."
It broke buildbot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast

llvm-svn: 273146
2016-06-20 10:29:53 +00:00
George Rimar c31fee2212 [ELF] - Basic versioned symbols support implemented.
Patch implements basic support of versioned symbols.
There is no wildcards patterns matching except local: *;
There is no support for hierarchies.
There is no support for symbols overrides (@ vs @@ not handled).

This patch allows programs that using simple scripts to link and run.

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

llvm-svn: 273143
2016-06-20 10:16:33 +00:00
Rui Ueyama 440138c4c8 [COFF] Add /section command line flag.
llvm-svn: 273134
2016-06-20 03:39:39 +00:00
Simon Atanasyan 4132511cdc [ELF][MIPS] Support GOT entries for non-preemptible symbols with different addends
There are two motivations for this patch. The first one is a preparation
for support MIPS TLS relocations. It might sound like a joke but for GOT
entries related to TLS relocations MIPS ABI uses almost regular approach
with creation of dynamic relocations for each GOT enty etc. But we need
to separate these 'regular' TLS related entries from MIPS specific local
and global parts of GOT. ABI declare simple solution - all TLS related
entries allocated at the end of GOT after local/global parts. The second
motivation it to support GOT relocations for non-preemptible symbols
with addends. If we have more than one GOT relocations against symbol S
with different addends we need to create GOT entries for each unique
Symbol/Addend pairs.

So we store all MIPS GOT entries in separate containers. For non-preemptible
symbols we have to maintain two data structures. The first one is MipsLocal
vector. Each entry corresponds to the GOT entry from the 'local' part
of the GOT contains the symbol's address plus addend. The second one
is MipsLocalMap. It is a map from Symbol/Addend pair to the GOT index.

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

llvm-svn: 273127
2016-06-19 21:39:37 +00:00
Rafael Espindola 1040b4479c Add a test showing that lto produces relaxable relocations.
llvm-svn: 273074
2016-06-18 00:36:39 +00:00
Rafael Espindola 6fcbbcb328 This tests depends on non-relaxable relocations.
Make that explicit.

llvm-svn: 273013
2016-06-17 17:01:38 +00:00
Rafael Espindola 678844e68a Don't confuse input and output section offsets.
llvm-svn: 273006
2016-06-17 15:42:36 +00:00
Rafael Espindola f70fb04e4f Make local: optional.
Doing that in an anonymous version is a bit silly, but this opens the
way for supporting it in general.

Since we don't support actual versions, for now we just disable the
version script if we detect that it is missing a local.

llvm-svn: 273000
2016-06-17 13:38:09 +00:00
George Rimar 95eeb7730d [ELF] - Handle every global as unversioned export in versioned script.
Patch updates the version script parser to parse versioned files.
In a simple way, just adding them to VersionScriptGlobals list.

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

llvm-svn: 272934
2016-06-16 18:47:04 +00:00
Rafael Espindola cf1d4987b9 Add support for # comments.
llvm-svn: 272892
2016-06-16 13:29:48 +00:00
Peter Smith fa4d90d5aa Add initial support for Thumb for ARMv7a
Add support for the R_ARM_THM relocations used in the objects present
    in arm-linux-gnueabihf-gcc. These are:
    R_ARM_THM_CALL
    R_ARM_THM_JUMP11
    R_ARM_THM_JUMP19
    R_ARM_THM_JUMP24
    R_ARM_THM_MOVT_ABS
    R_ARM_THM_MOVW_ABS_NC
    
    Interworking between ARM and Thumb is partially supported with BLX.
    The R_ARM_CALL relocation for ARM instructions and R_ARM_THM_CALL
    relocation for Thumb instructions will write out a BL or BLX depending
    on the state of the Target.
    
    Assumptions:
    - Availability of BLX and extended range of Thumb 4-byte Branch
      instructions.
    - In relocateOne if (Val & 0x1) == 1 target is Thumb, 0 is ARM.
      This will hold for objects that comply with the ABI for the
      ARM architecture.
    
    This is sufficient for hello world to work with a recent
    arm-linux-gnueabihf distribution.
    
    Limitations:
    No interworking for R_ARM_JUMP24, R_ARM_THM_JUMP24, R_ARM_THM_JUMP19
    and the deprecated R_ARM_PLT32 and R_ARM_PC24 instructions as these
    cannot be written out as a BLX and need a state change thunk.
    
    No range extension thunks. The R_ARM_JUMP24 and R_ARM_THM_CALL have a
    range of 16Mb

llvm-svn: 272881
2016-06-16 09:53:46 +00:00
Rafael Espindola 7ce1bc71f4 Document an interesting LTO case.
This is a reduction from the only symbol in a build of clang that the
gold plugin internalizes but lld does not.

llvm-svn: 272845
2016-06-15 21:33:11 +00:00
Rafael Espindola cc70da39ff Internalize symbols in comdats.
We were dropping the CanOmitFromDynSym bit when creating undefined
symbols because of comdat.

llvm-svn: 272812
2016-06-15 17:56:10 +00:00
Rafael Espindola 65c65ce897 Don't include --start-lib/--end-lib files twice.
This should never happen with correct programs, but it is trivial
write a testcase where lld would crash or report duplicated
symbols. We now behave like when an archive is used and include the
file only once.

llvm-svn: 272724
2016-06-14 21:56:36 +00:00
Peter Collingbourne a8bf23d656 ELF: Add a test showing that the new local_unnamed_addr attribute can permit internalization.
Part of the fix for PR27553.

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

llvm-svn: 272711
2016-06-14 21:02:15 +00:00
George Rimar 2993ad2248 [ELF] - Change wording of error message.
Previously message told us that relocations could
not be used when making shared object. That was
correct because message could appear (and it is expected) 
when we linked executable.
Message should have being changed to something
that says we can't use a subset of relocations against shared
symbols.

Patch fixes the text.

llvm-svn: 272478
2016-06-11 15:59:09 +00:00
George Rimar 0a2f19701e [ELF] - Properly check that R_X86_64_PC32 and R_X86_64_32 relocations are disallowed in DSO.
Initially we wanted to check that these two relocations are not present when linking DSO because of 
possible overflow in runtime. Patch moves them to writable segment in testcases to allow
proper error check to trigger.
Otherwise error message about using dynamic relocations against text segment was shown.

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

llvm-svn: 272379
2016-06-10 08:15:12 +00:00
George Rimar 3ed2b08dad [ELF] - Inform user that we do not support dynamic relocations against text segment.
It was reported in PR28020, that lld does not link code which
gold do. But in fact that is expected behavior as we do not
support DT_TEXTREL.

This patch changes error message as it can report about relocations against
text segments exclusively, other dynamic relocations errors can 
be handled separately.

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

llvm-svn: 272377
2016-06-10 08:00:01 +00:00
Rafael Espindola e8b8a347c7 Use errorDynRel like every other target.
llvm-svn: 272305
2016-06-09 20:42:04 +00:00
Rafael Espindola 8dbb7e1d61 Also reject 32 bit dynamic relocs when producing executable.
They point to a shared library, so they would still overflow at runtime.

llvm-svn: 272303
2016-06-09 20:35:27 +00:00
Rafael Espindola c845cb6f23 Don't require a dynamic R_X86_64_32 reloc in a test.
llvm-svn: 272302
2016-06-09 20:22:35 +00:00
Peter Collingbourne ca8c994818 ELF: Compute used bit for --as-needed during symbol resolution.
We can now use this to decide whether to emit a verneed during the final
pass over the symbols. We were previously wrongly creating a verneed entry
in the case where all references to a DSO's symbols were weak.

In a future change we may also want to use the used bit to control whether
shared symbols are preemptible and appear in the dynsym. This seems a little
tricky to do at the moment because isNeeded() is templated.

The only other functional change here is that we emit a DT_NEEDED for DSOs
whose symbols are all preempted by objects that appear later in the link. But
that doesn't seem too important to me.

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

llvm-svn: 272282
2016-06-09 18:01:35 +00:00
Rafael Espindola d2454d66e3 Fix global version handling.
We should not ignore the symbol, just the version.

Fixes error with -z defs.

llvm-svn: 272270
2016-06-09 15:45:49 +00:00
Rafael Espindola a8777c2ef8 Handle gd tls relocs pointing to local symbols.
If the symbol is local we don't need to create a R_X86_64_DTPOFF64, we
can just write the correct value in the got.

Should fix pr28018.

llvm-svn: 272205
2016-06-08 21:31:59 +00:00
George Rimar 2030cacc67 [ELF] - Tweak verneed.s test to use new llvm-readobj functionality
Previously this test performed check of binary data. Since
llvm-readobj currently able to dump all 3 types of version relative
sections, that can be used to make this test more transparent.
Patch do that.

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

llvm-svn: 272120
2016-06-08 06:54:23 +00:00
Peter Smith 5dd3c292bc Add missing REQUIRES: arm from test. To fix tests building without ARM.
llvm-svn: 271994
2016-06-07 09:49:40 +00:00
Peter Smith 8646ced053 Initial support for ARM in lld.
Add support for an ARM Target and the initial set of relocations
    and PLT entries that are necessary for an ARM only hello world to
    link. This has been tested against an ARM only sysroot from the
    4.2.0 CodeSourcery Lite release.
    
    Tests have been added to test/ELF for the support that has been
    implemented.
    
    Main limitations:
    - No Thumb support
    - Relocations incomplete
    - No C++ exceptions support
    - No TLS support
    - No range extension or interworking veneer (thunk) support
    - No Build Attribute support
    - No Big-endian support
    
    The deprecated relocations R_ARM_PLT32 and R_ARM_PC24 have been
    implemented as these are used by the 4.2.0 CodeSourcery Lite release.

llvm-svn: 271993
2016-06-07 09:31:52 +00:00
Rafael Espindola acad605df9 Ignore the "globally available" version.
Reduced from a firefox build.

llvm-svn: 271950
2016-06-06 22:42:57 +00:00
Rui Ueyama 4ffda7a9cf Create version.txt in a reproduce archive file.
Differential Revision: http://reviews.llvm.org/D21008

llvm-svn: 271901
2016-06-06 15:34:37 +00:00
George Rimar 8b3c5f2b30 [ELF] - Assign sh_link field of SHT_GNU_versym section to DynSymTab section index.
.gnu.version should have sh_link field initialized with index of DynSymTab section.

GNU documentation looks misses that, but Sun docs mention it, according to
https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-54676/index.html 
versym sh_link is indeed supposed to point to the .dynsym section.

Binutils readelf tool also relies on that:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;h=b6454d353279dc57745cd5a2d68b5f3f69f8e17c;hb=5522f910cb539905d6adfdceab208ddfa5e84557#l9988

Both gold/bfd do the same + after this patch I am able to see this section in readelf output, was unable before in my case.

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

llvm-svn: 271874
2016-06-06 08:04:53 +00:00
Rafael Espindola e325b98836 add missing REQUIRES
llvm-svn: 271859
2016-06-05 22:54:11 +00:00
Rafael Espindola 4f5046ce87 Add a missing REQUIRES.
llvm-svn: 271854
2016-06-05 19:28:44 +00:00
Rafael Espindola 6211d9a4fa Move GlobalDynIndex to SymbolBody.
With that we can have local symbols with a tls gd index.

llvm-svn: 271852
2016-06-05 19:03:28 +00:00
Rafael Espindola 698dba74f8 Include version in --reproduce.
llvm-svn: 271829
2016-06-05 13:19:39 +00:00
Davide Italiano cd76e49888 Attempt to fix non-determinism in test.
Otherwise it could just use a leftover a.out from
some other test.

llvm-svn: 271820
2016-06-05 01:04:59 +00:00
Rafael Espindola e1979aed0a Implement gd to ie relaxation for aarch64.
llvm-svn: 271815
2016-06-04 23:33:31 +00:00
Rafael Espindola d167a25eef Add missing REQUIRES.
llvm-svn: 271799
2016-06-04 19:30:58 +00:00
Rafael Espindola 12dc446939 Fix implicit plt creation on aarch64.
We were not handling page relative relocations.

llvm-svn: 271798
2016-06-04 19:11:14 +00:00
Davide Italiano df24d5b8c8 [LTO] Add --lto-aa-pipeline.
Differential Revision:  http://reviews.llvm.org/D20888

llvm-svn: 271605
2016-06-02 22:58:11 +00:00
Rafael Espindola e37d13b9ec Start adding tlsdesc support for aarch64.
This is mostly extracted from http://reviews.llvm.org/D18960.

The general idea for tlsdesc is that the two GD got entries are used
for a function pointer and its argument. The dynamic linker sets
both. In the non-dlopen case the dynamic linker sets the function to
the identity and the argument to the offset in the tls block.

All that the static linker has to do in the non-dlopen case is
relocate the code to point to the got entries and create a dynamic
relocation.

The dlopen case is more complicated, but can be implemented in another patch.

llvm-svn: 271569
2016-06-02 19:49:53 +00:00
George Rimar f10c8290fa [ELF] - Implemented support for test/binop relaxations from latest ABI.
Patch implements next relaxation from latest ABI:

"Convert memory operand of test and binop into immediate operand, where binop is one of adc, add, and, cmp, or,
sbb, sub, xor instructions, when position-independent code is disabled."

It is described in System V Application Binary Interface AMD64 Architecture Processor 
Supplement Draft Version 0.99.8 (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, 
B.2 "B.2 Optimize GOTPCRELX Relocations").

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

llvm-svn: 271405
2016-06-01 16:45:30 +00:00
Davide Italiano 64ebf32ef3 [LTO] Fix (incorrect) TLS attribute mismatch.
When we undefine, we also preserve type of symbol so that we get
it right in the combined LTO object.

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

llvm-svn: 271403
2016-06-01 16:38:13 +00:00
Rafael Espindola 3d6d4c39be Handle the -T option.
We were not reading it or including in the --reproduce archive.

llvm-svn: 271367
2016-06-01 06:17:27 +00:00
Rafael Espindola a8433c1d1b Revert "bar"
This reverts commit r271365.
Sorry, wrong branch.

llvm-svn: 271366
2016-06-01 06:15:22 +00:00
Rafael Espindola 74540516ef bar
llvm-svn: 271365
2016-06-01 06:13:54 +00:00
Rafael Espindola 3b1ecb563f Make test more realistic.
It doesn't make mach sense to fetch less than 64 bits from a got
entry.

llvm-svn: 271116
2016-05-28 15:38:13 +00:00
Simon Atanasyan 9a9a3169e3 [ELF][MIPS] Always resolve MIPS GP-relative relocations to 'local' definitions
In case of MIPS, GP-relative relocations always resolve to a definition
in a regular input file, ignoring the one-definition rule. Such
relocations are used to setup GP relative offsets in a function's
prologue. So we, for example, should not attempt to create a dynamic
relocation even if the target symbol is preemptible.

Fixes bug 27880.

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

llvm-svn: 271100
2016-05-28 04:49:57 +00:00
Rafael Espindola 6af546188f Avoid having to check in a binary.
llvm-svn: 270986
2016-05-27 12:27:21 +00:00
Peter Collingbourne 5079f3b727 Update LLD for D20550.
Differential Revision: http://reviews.llvm.org/D20704

llvm-svn: 270968
2016-05-27 05:21:45 +00:00
Simon Atanasyan 84bb355c3a [ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo section
MIPS .reginfo and .MIPS.options sections are consumed by the linker, and
the linker produces a single output section. But it is possible that
input files contain section symbol points to the corresponding input
section. In case of generation a relocatable output we need to write
such symbols to the output file.

Fixes bug 27878.

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

llvm-svn: 270910
2016-05-26 20:46:01 +00:00
George Rimar 95433df129 [ELF] - Added support for jmp/call relaxations when R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX are used.
D15779 introduced basic approach to support new relaxations.
This patch implements relaxations for jmp and call instructions,
described in System V Application Binary Interface AMD64 Architecture Processor 
Supplement Draft Version 0.99.8 (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, 
B.2 "B.2 Optimize GOTPCRELX Relocations")

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

llvm-svn: 270721
2016-05-25 16:51:08 +00:00
Ed Maste 2e04361a21 ELF: improve CIE no-augmentation test
Add another possible error that may be reported for the same case. The
original reproduction case that prompted r270706 produced the error
"corrupted CIE" instead of "corrupted or unsupported CIE information".
The specific error depends on arbitrary data later in the file so
check that neither is emitted in case the input is ever changed.

Document the process used to create the input .o and rename the test
file to .s, as requested by Rafael.

llvm-svn: 270709
2016-05-25 15:14:08 +00:00
Ed Maste 594e06b879 ELF: Handle empty CIE augmentation string
"A zero length string indicates that no augmentation data is present."

The FreeBSD/mips toolchain (GCC 4.2.1) generates .debug_frame sections
containing CIE records that have an empty augmentation string.

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

llvm-svn: 270706
2016-05-25 14:45:28 +00:00
George Rimar 5c33b91bbe [ELF] - Implemented optimization for R_X86_64_GOTPCREL relocation.
System V Application Binary Interface AMD64 Architecture Processor Supplement Draft Version 0.99.8 
(https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, B.2 "B.2 Optimize GOTPCRELX Relocations")
introduces possible relaxations for R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX.

That patch implements the next relaxation: 
mov foo@GOTPCREL(%rip), %reg => lea foo(%rip), %reg
and also opens door for implementing all other ones.

Implementation was suggested by Rafael Ávila de Espíndola with few additions and testcases by myself.

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

llvm-svn: 270705
2016-05-25 14:31:37 +00:00
Rui Ueyama c789b631f3 Really define --export-dynamic-symbol= as an alias to --export-dynamic-symbol.
Thanks to Sean for pointing it out.

llvm-svn: 270660
2016-05-25 04:29:55 +00:00
Rafael Espindola 1f5696f9c1 Fix a wrong assumption.
llvm-svn: 270573
2016-05-24 16:03:27 +00:00
Rafael Espindola 820f4bb972 Handle terminator .eh_frame when creating the index.
llvm-svn: 270568
2016-05-24 15:17:47 +00:00
Rafael Espindola bfffa94ea7 Fix crash in .eh_frame marker section.
llvm-svn: 270563
2016-05-24 14:51:50 +00:00
Rafael Espindola fe3a2f1b81 Revert "Simplify. Thanks to Rui for the suggestion."
This reverts commit r270551.

Sorry, I commited the wrong branch :-(

llvm-svn: 270554
2016-05-24 12:12:06 +00:00
Rafael Espindola dba64b8ea4 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270551
2016-05-24 11:53:15 +00:00
Rafael Espindola 97434957ef Update for llvm change.
llvm-svn: 270550
2016-05-24 11:16:14 +00:00
Rui Ueyama afa35a2a37 Remove Writer::ensureBss().
Previously, we created a .bss section when needed. We had a function
ensureBss() for that purpose. Turned out that was error-prone
because it was easy to forget to call that function before accessing
the .bss section.

This patch always make the BSS section. The section is added to the
output when it's not empty.

llvm-svn: 270527
2016-05-24 03:16:51 +00:00
Rui Ueyama 98843087cb Reject zero-sized symbols when creating copy relocations.
Copy relocations are relocations to copy data from DSOs to
executable's .bss segment at runtime. It doesn't make sense to
create such relocations for zero-sized symbols.

GNU linkers don't agree with each other. ld rejects such
relocation/symbol pair. gold don't reject that but do not create
copy relocations as well.  I took the former approach because
I don't think the latter is what user wants.

llvm-svn: 270525
2016-05-24 02:37:40 +00:00
Rui Ueyama f86cb90a2d Do not propagate section name and attributes to .eh_frame.
.eh_frame is always ".eh_frame" and its attribute is fixed.
No need to copy from inputs to outputs. GNU gold also sets
SHT_PROGBITS.

llvm-svn: 270443
2016-05-23 15:12:41 +00:00
Rui Ueyama e75e933efc Refactor EhFrameHdr.
Previously, EhFrameHdr section computed addresses to which FDEs are
applied to. This is not an ideal design because EhFrameHdr does not
know much about FDEs unless EhFrame passes the information to EhFrameHdr.
It is what we did.

This patch simplifies the code by making EhFrame to compute the
values and pass the cooked information to EhFrameHdr. EhFrameHdr no
longer have to know about the details of FDEs such as FDE encodings.

llvm-svn: 270393
2016-05-23 03:00:33 +00:00
Rui Ueyama f8b285c037 Refactor EHOutputSection.
This patch refactors EHOutputSection using SectionPiece struct.
EHRegion class was removed since we can now directly use SectionPiece.

An incomplete support of large CIE/FDE record (> 2^32 bytes) was removed
because it silently created broken executable. There are several places
in the existing code that "size" field is always 4 bytes and at offset 4
in the record, which is not true for 64-bit size records. We will have to
support that in future, but it is better to error out instead of creating
malformed eh_frame sections.

llvm-svn: 270382
2016-05-22 23:16:14 +00:00
Simon Atanasyan 1c980ca5aa [ELF] Take into account offset in the output section when read addends for a non-alloc input section
llvm-svn: 270328
2016-05-21 19:48:54 +00:00
Rafael Espindola fb0ceb5153 Check pc relative relocations too.
llvm-svn: 270264
2016-05-20 20:02:27 +00:00
Dima Stepanov fb8978fc6a Fix the function to set the section VMA/LMA fields in case of using
the linker script. The cycle in the ELF/LinkerScript.cpp:assignAddresses()
routine will be used to go through all the sections and set all the
addresses correctly.

Add new test to check this case.

llvm-svn: 270090
2016-05-19 18:15:54 +00:00
Rafael Espindola e4c86d83fe Drop vestigial support for UseLazyBinding=false.
Lazy binding is quite important for use case like a shared build of
llvm. Also, if someone wants to disable it, it is better done in the
compiler (disable plt generation).

The only reason to keep it is to make it easier to add a new
architecture. But it doesn't really help much as it is possible to start
with non lazy relocation and plt code but still let the generic part
create a dedicated .got.plt and .rela.plt.

llvm-svn: 269982
2016-05-18 21:03:36 +00:00
Davide Italiano d26c4a14ca [LTO] Add the ability to specify a subset of passes to run.
Differential Revision:  http://reviews.llvm.org/D20267

llvm-svn: 269605
2016-05-15 19:29:38 +00:00
Rui Ueyama 109ff37430 Update for a recent format change.
llvm-svn: 269496
2016-05-13 21:58:46 +00:00
Rui Ueyama 9194db78fb Support --build-id=0x<hexstring>.
If you specify the option in the form of --build-id=0x<hexstring>,
that hexstring is set as a build ID. We observed that the feature
is actually in use in some builds, so we want this feature.

llvm-svn: 269495
2016-05-13 21:55:56 +00:00
Rafael Espindola 7229496787 When using Rela, don't write the addend to the output section.
The Elf_Rela has an explicit addend. It doesn't need the addend to be
written to the section being relocated.

Since relative relocations are very common in the output, this is a
noticeable speedup. The results I got were

chromium
  master 4.778149487
  patch  4.761120792 0.996436131802
chromium fast
  master 1.896253636
  patch  1.840990582 0.970856718241
the gold plugin
  master 0.399337811
  patch  0.392279276 0.982324401032
clang
  master 0.666873675
  patch  0.665895708 0.998533504865
llvm-as
  master 0.037101095
  patch  0.037123149 1.00059442989
the gold plugin fsds
  master 0.422473396
  patch  0.414192879 0.980399909016
clang fsds
  master 0.747302008
  patch  0.744843964 0.996710775599
llvm-as fsds
  master 0.033146245
  patch  0.033064531 0.997534743377
scylla
  master 4.08857525
  patch  4.082245184 0.998451767275

llvm-svn: 269417
2016-05-13 14:15:37 +00:00
George Rimar fa91000290 [ELF] implemented -z defs option
Just do not allow to link shared library if there are
undefined symbols.

This fixes PR27447

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

llvm-svn: 269183
2016-05-11 13:48:41 +00:00
Davide Italiano 334fce92d9 [LTO] Don't crash on old DebugInfo.
Drop them and produce a graceful warning instead.

llvm-svn: 269149
2016-05-11 01:07:22 +00:00
George Rimar c191acf097 [ELF] - Implemented -z combrelocs/nocombreloc.
This is the option which sorts relocs to optimize dynamic linker performance.
-z combelocs is the default in gold, also it ignores -z nocombreloc,
this patch do the same.

Patch sorts relocations by symbols only and do not create any
DT_REL[A]COUNT entries. That is different with what gold/bfd do.

More information about option is here:
http://www.airs.com/blog/archives/186
http://people.redhat.com/jakub/prelink.pdf, p.2

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

llvm-svn: 269066
2016-05-10 15:47:57 +00:00
Rafael Espindola 78db5a9dca Print member name in undefined symbol error.
llvm-svn: 268976
2016-05-09 21:40:06 +00:00
Rafael Espindola 4ee6cb3a70 Document and test the first few .got.plt entries.
llvm-svn: 268945
2016-05-09 18:12:15 +00:00
Rafael Espindola 45a33fb799 Allow user defined __init_aray_start.
Fixes pr27683.

llvm-svn: 268926
2016-05-09 15:25:54 +00:00
Daniel Sanders dcb98e61c7 [mips] Fix mips-got16.s following r268900.
$LC0 and $LC1 are no longer present in the symbol table because they are
rewritten to .text+offset and .data+offset.

llvm-svn: 268911
2016-05-09 13:01:01 +00:00
Simon Atanasyan 8c8a5b5f81 [ELF][MIPS] Handling 'packed' N64 ABI relocations
MIPS N64 ABI packs multiple relocations into the single relocation
record. In general, all up to three relocations can have arbitrary types.
In fact, Clang and GCC uses only a few combinations. For now, we support
two of them. That is allow to pass at least all LLVM test suite cases.

<any relocation> / R_MIPS_SUB / R_MIPS_HI16 | R_MIPS_LO16
<any relocation> / R_MIPS_64 / R_MIPS_NONE

The first relocation is a 'real' relocation which is calculated using
the corresponding symbol's value. The second and the third relocations
used to modify result of the first one: extend it to 64-bit, extract
high or low part etc. For details, see part 2.9 'Relocation' at
https://dmz-portal.mips.com/mw/images/8/82/007-4658-001.pdf

llvm-svn: 268876
2016-05-08 14:08:40 +00:00
Rafael Espindola d39dadeb64 Don't produce a relocation to read only memory.
This is hopefully last case where we would produce a relocation to a
read only section.

llvm-svn: 268688
2016-05-05 21:19:38 +00:00
Rafael Espindola 66434562e7 Fix copy relocations in pie.
We were creating the copy relocations just fine, but then thinking that
the .bss position could be preempted and creating a dynamic relocation
to it, which would crash at runtime since that memory is read only.

llvm-svn: 268668
2016-05-05 19:41:49 +00:00
Peter Collingbourne 3ad1c1e242 ELF: Undefine all symbols, not just those that we expect to be defined.
This allows the combined LTO object to provide a definition with the same
name as a symbol that was internalized without causing a duplicate symbol
error. This normally happens during parallel codegen which externalizes
originally-internal symbols, for example.

In order to make this work, I needed to relax the undefined symbol error to
only report an error for symbols that are used in regular objects.

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

llvm-svn: 268649
2016-05-05 17:13:49 +00:00
Rafael Espindola 462220de47 Reuse logic for deciding whether to keep a local symbol or not.
llvm-svn: 268644
2016-05-05 16:38:46 +00:00
Rafael Espindola d89fbca21d Fix --gc-sections when .eh_frame has a lsda.
We have to add sections to the work list, not just mark them live.

llvm-svn: 268628
2016-05-05 13:51:14 +00:00
Peter Collingbourne e29e142a10 ELF: Do not use -1 to mark pieces of merge sections as being tail merged.
We were previously using an output offset of -1 for both GC'd and tail
merged pieces. We need to distinguish these two cases in order to filter
GC'd symbols from the symbol table -- we were previously asserting when we
asked for the VA of a symbol pointing into a dead piece, which would end
up asking the tail merging string table for an offset even though we hadn't
initialized it properly.

This patch fixes the bug by using an offset of -1 to exclusively mean GC'd
pieces, using 0 for tail merges, and distinguishing the tail merge case from
an offset of 0 by asking the output section whether it is tail merge.

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

llvm-svn: 268604
2016-05-05 04:10:12 +00:00
Rui Ueyama ca16c104c6 Merge two tests for the same purpose.
I accidentally added another test file as I didn't notice
that the test file existed.

llvm-svn: 268598
2016-05-05 02:32:09 +00:00
Rui Ueyama ac75a27809 Add a test for --reproduce on Windows.
It is insanely hard to write a test that works both on Windows and Unix.
I tried to workaround it with cpio's minor options, but the behaviors of
the options were myterious. It just doesn't worth to spend time on it.
And probably minor options could break buildbots that doesn't have the
GNU version of cpio command.

In this patch, I simply added a separate test file that runs only on
Windows.

llvm-svn: 268596
2016-05-05 02:18:04 +00:00
Rui Ueyama af2312feb7 Make --reproduce to not produce undesired whitespace.
Fixes bug 27648.

llvm-svn: 268569
2016-05-04 23:12:55 +00:00
Simon Atanasyan da83bbc1a1 [ELF][MIPS] Create combined dynamic relocation type R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE
MIPS N64 ABI packs multiple relocations into the single relocation
record. Particularly it requires to represent dynamic relative
relocation as a combination of R_MIPS_REL32 and R_MIPS_64 relocations.

llvm-svn: 268565
2016-05-04 22:39:40 +00:00
Rafael Espindola de17d28a32 Don't produce relative relocs to ro segments.
We were already checking for non relative relocations.

If we ever decide to add support for rw text segments this means we will
have a single spot to add the flag.

llvm-svn: 268558
2016-05-04 21:40:07 +00:00
Rafael Espindola ac95264d62 Don't depend on dynamic relocatinos in ro sections.
Currently we don't check when creating relative relocations if the
section is read only or not. I am about to fix that, so first update the
patches that depend on the current behavior.

llvm-svn: 268542
2016-05-04 20:25:19 +00:00
Rafael Espindola 1bf2f191b6 Split a testcase.
I will make changes to the -shared side and this reduces the noise in
the other patch.

llvm-svn: 268538
2016-05-04 20:06:49 +00:00
Simon Atanasyan be804559f8 [ELF][MIPS] R_MIPS_GOT_DISP, R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST relocations support
These relocations introduced by MIPS N64 ABI. R_MIPS_GOT_DISP references
GOT entry with full symbol's address, R_MIPS_GOT_PAGE creates GOT entry
with address of memory page which includes symbol's address,
R_MIPS_GOT_OFST used together with R_MIPS_GOT_PAGE. This relocation
calculates offset from beginning of memory page to the symbol address.

llvm-svn: 268525
2016-05-04 17:47:11 +00:00
Daniel Sanders c07f06aeee [mips][ias] Only round section sizes when explicitly requested.
As requested by Rafael Espindola in his post-commit comments on r268036. This
makes the previous behaviour the default while still allowing verification of
IAS.

llvm-svn: 268496
2016-05-04 13:21:06 +00:00
Simon Atanasyan add74f37f2 [ELF][MIPS] Read/write .MIPS.options section
MIPS N64 ABI introduces .MIPS.options section which specifies miscellaneous
options to be applied to an object/shared/executable file. LLVM as well as
modern versions of GNU tools read and write the only type of the options -
ODK_REGINFO. It is exact copy of .reginfo section used by O32 ABI.

llvm-svn: 268485
2016-05-04 10:07:38 +00:00
Rafael Espindola c5b8ed241d Implement --build-id=none.
Both bfd and gold have this. It allows disabling build-id when it is the
default with by adding -Wl,--build-id=none no the clang command line.

llvm-svn: 268435
2016-05-03 20:55:47 +00:00
Peter Collingbourne f3a2b0e8f7 ELF: Fix regression in TLS attribute mismatch logic.
Introduce a special symbol type to indicate that we have not yet seen a type
for the symbol, so we should not report TLS mismatches for that symbol.

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

llvm-svn: 268411
2016-05-03 18:03:47 +00:00
Rafael Espindola 1dd2b3d1d0 Produce cpio files for --reproduce.
We want --reproduce to

* not rewrite scripts and thin archives
* work with absolute paths

Given that, it pretty much has to create a full directory tree. On windows that
is problematic because of the very short maximum path limit. On most cases
users can still work around it with "--repro c:\r", but that is annoying and
not viable for automated testing.

We then need to produce some form of archive with the files. The first option
that comes to mind is .a files since we already have code for writing them.
There are a few problems with them

The format has a dedicated string table, so we cannot start writing it until
all members are known.
Regular implementations don't support creating directories. We could make
llvm-ar support that, but that is probably not a good idea.
The next natural option would be tar. The problem is that to support long path
names (which is how this started) it needs a "pax extended header" making this
an annoying format to write.

The next option I looked at seems a natural fit: cpio files.

They are available on pretty much every unix, support directories and long path
names and are really easy to write. The only slightly annoying part is a
terminator, but at least gnu cpio only prints a warning if it is missing, which
is handy for crashes. This patch still makes an effort to always create it.

llvm-svn: 268404
2016-05-03 17:30:44 +00:00
Rafael Espindola d8dfdfd268 Don't depend on checking the response file when lld fails.
llvm-svn: 268388
2016-05-03 14:29:42 +00:00
Sean Silva 92fbd8df15 Try harder to get the bots green.
The test is now unexpectedly passing on
llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast which is treated as an error.
For now, disable Windows testing of the feature.
Rafael is working on generating an archive, which will hopefully allow
us to turn this test back on.

Unfortunately, we don't have a way to temporarily XFAIL this test just
on llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast.

llvm-svn: 268351
2016-05-03 01:25:28 +00:00
Peter Collingbourne 6a4225962d ELF: Forbid all relative relocations to absolute symbols in PIC, except for weak undefined.
Weak undefined symbols resolve to the image base. This is a little strange,
but it allows us to link function calls to such symbols. Normally such a
call will be guarded with a comparison, which will load a zero from the GOT.

There's one example of such a function call in crti.o in Linux's CRT.

As part of this change, I also needed to make the synthetic start and end
symbols image base relative in the case where their sections were empty,
so that PC-relative references to those symbols would continue to work.

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

llvm-svn: 268350
2016-05-03 01:21:08 +00:00
Sean Silva 2b34def662 Temporarily disable this test on llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast
`REQUIRES: shell` is not appropriate because that would mean that there
are no windows bots testing this, and that is precisely where it needs
the most testing.

Rafael or Rui are working on generating an archive directly, which
should avoid this issue.
We can try to move the bot to a shorter build directory path.

llvm-svn: 268345
2016-05-03 00:36:15 +00:00
Rui Ueyama 6d0cd2b62b Teach Undefined symbols from which file they are created from.
This patch increases the size of Undefined by the size of a pointer,
but it wouldn't actually increase the size of memory that LLD uses
because we are not allocating the exact size but the size of the
largest SymbolBody.

llvm-svn: 268310
2016-05-02 21:30:42 +00:00
Rafael Espindola 6bbd78df6f Revert "Temporary hack to see what is going on on a windows bot."
This reverts commit r268302.

llvm-svn: 268308
2016-05-02 21:21:26 +00:00
Rafael Espindola 732c4646ee Temporary hack to see what is going on on a windows bot.
llvm-svn: 268302
2016-05-02 20:47:06 +00:00
Rui Ueyama ff12f23080 Attempt to fix Windows bots.
llvm-svn: 268275
2016-05-02 18:16:14 +00:00
Rui Ueyama 2664d45267 Fix --reproduce for --export-dynamic-symbol.
--export-dynamic-symbol doesn't take path.

llvm-svn: 268273
2016-05-02 18:12:09 +00:00
Rui Ueyama e951a1d739 Quote arguments for --reproduce.
llvm-svn: 268258
2016-05-02 17:34:17 +00:00
Rafael Espindola 2076567be4 Force llvm-ar to use the gnu format.
Should fix the bots. Otherwise we try to create a thin bsd anchive.

llvm-svn: 268240
2016-05-02 15:16:43 +00:00
Rafael Espindola e85bcbd1c3 Don't include the output dir in the response file.
With this it is possible to use chroot/fakechroot to have a completely
reproducible link even when thin archives or linker scripts have
absolute paths.

llvm-svn: 268231
2016-05-02 14:12:35 +00:00
Rafael Espindola d1cbe4df91 Copy thin archive members with --reproduce.
llvm-svn: 268229
2016-05-02 13:54:10 +00:00
George Rimar af90d54660 [ELF] - keep alive all non-text sections referenced by .eh_frame
Patch implements one of suggestions from Rafael Ávila de Espíndola,
to fix segfault after section that contains personality being
garbage collected.

Suggestion was just to keep alive all non executable sections
referenced by .eh_frame.

This fixes PR27529.

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

llvm-svn: 268228
2016-05-02 13:49:42 +00:00
Rafael Espindola 21e1489048 Don't quote "--hash-style gnu".
Otherwise lld fails to use the response file.

llvm-svn: 268225
2016-05-02 13:00:42 +00:00
Peter Collingbourne 4f9527065c ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.

Performance numbers:

           old(s) new(s)
Without debug info:
chrome      7.178  6.432 (-11.5%)
LLVMgold.so 0.505  0.502 (-0.5%)
clang       0.954  0.827 (-15.4%)
llvm-as     0.052  0.045 (-15.5%)
With debug info:
scylla      5.695  5.613 (-1.5%)
clang      14.396 14.143 (-1.8%)

Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.

The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.

In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.

I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.

This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.

[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html

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

llvm-svn: 268178
2016-05-01 04:55:03 +00:00
Rui Ueyama 2796ae3f69 ELF: --reproduce: quote pathnames for -L and other options.
Previously, arguments for options that take pathnames were not rewritten.

llvm-svn: 268172
2016-04-30 22:46:47 +00:00
Rui Ueyama 9aea957f6d ELF: --reproduce: Copy files referenced by linker scripts.
Previuosly, only files appeared on the command line were copied.

llvm-svn: 268171
2016-04-30 22:23:29 +00:00
Rui Ueyama aa00e96a84 ELF: Make --reproduce to produce a response file.
The aim of this patch is to make it easy to re-run the command without
updating paths in the command line. Here is a use case.

Assume that Alice is having an issue with lld and is reporting the issue
to developer Bob. Alice's current directly is /home/alice/work and her
command line is "ld.lld -o foo foo.o ../bar.o". She adds "--reproduce repro"
to the command line and re-run. Then the following text will be produced as
response.txt (notice that the paths are rewritten so that they are
relative to /home/alice/work/repro.)

  -o home/alice/work/foo home/alice/work/foo.o home/alice/bar.o

The command also produces the following files by copying inputs.

  /home/alice/repro/home/alice/work/foo.o
  /home/alice/repro/home/alice/bar.o

Alice zips the directory and send it to Bob. Bob get an archive from Alice
and extract it to his home directory as /home/bob/repro. Now his directory
have the following files.

  /home/bob/repro/response.txt
  /home/bob/repro/home/alice/work/foo.o
  /home/bob/repro/home/alice/bar.o

Bob then re-run the command with these files by the following commands.

  cd /home/bob/repro
  ld.lld @response.txt

This command will run the linker with the same command line options and
the same input files as Alice's, so it is very likely that Bob will see
the same issue as Alice saw.

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

llvm-svn: 268169
2016-04-30 21:40:04 +00:00
Rafael Espindola a85efd985c Don't create dynamic relocations to ro segments.
These would just crash at runtime.

If we ever decide to support rw text segments this should make it easier
to implement as there is now a single point where we notice the problem.

I have tested this with a freebsd buildworld. It found a non pic
assembly file being linked into a .so,. With that fixed, buildworld
finished.

llvm-svn: 268149
2016-04-30 01:15:17 +00:00
Rafael Espindola cceacd7113 Don't depend on lld creating relocations in ro segments.
We currently don't do a good job of diagnosing inputs that would require
dynamic relocations to be applied to read only segments.

I am about to improve lld in that area, but unfortunately we developed
tests that depend on the current behavior.

To make clear what is actually changing, this first patch just updates
tests to not depend on the current behavior. In most cases this just
means using a rw section instead of a ro one, but that unfortunately
changes many addresses.

llvm-svn: 268145
2016-04-30 00:49:10 +00:00
Rafael Espindola f1e880eb8d Document how to recreate a binary.
llvm-svn: 268136
2016-04-29 23:35:49 +00:00
Rafael Espindola 9e5e2df3f3 Document how to recreate a binary.
llvm-svn: 268134
2016-04-29 23:28:36 +00:00
Rui Ueyama d74ce4d393 Fix typo in test.
llvm-svn: 268080
2016-04-29 17:58:48 +00:00
Rafael Espindola fb4f2fedd1 Be sure to always increment the Versym pointer.
It was getting out of sync if we had undefined symbols at the start of
the symbol table.

llvm-svn: 268077
2016-04-29 17:46:07 +00:00
Rafael Espindola eaaec4a4c8 Fix the alignment of the version info.
llvm-svn: 268070
2016-04-29 17:19:45 +00:00
Rafael Espindola 18da0e589a Fix producing undefined reference to __progname.
We were not producing them if the library had version info.

llvm-svn: 268060
2016-04-29 16:23:31 +00:00
Rui Ueyama fb6d499ed7 ELF: Add -O0 (produce output as fast as possible) mode.
This patch redefines the default optimization level as 1 and adds
new level 0. In the command line, it is -O0. The flag disables
costly but optional features so that the linker produces semantically
correct but larger output quickly. Currently it only disables
section merging.

This flag is not intended to be used for final production linking.
It is intended to be used in compile-link-test cycle.

Time to link clang with debug info is about 2x faster with the flag.

  Head:
  13.24 seconds
  Output size: 1227189664 bytes

  With this patch:
  7.41 seconds
  Output size: 2490281784 bytes

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

llvm-svn: 268056
2016-04-29 16:12:29 +00:00
Daniel Sanders 2c83917c42 [mips] Update tests to account for section size rounding change in r268036.
llvm-svn: 268039
2016-04-29 13:21:26 +00:00
Simon Atanasyan ae77ab71d8 [ELF][MIPS] Accept MIPS 64-bit binaries
LLD accepts MIPS 64-bit binaries, supports corresponding eulation (-m)
arguments and emits 64-bit specific ELF flags.

llvm-svn: 268024
2016-04-29 10:39:17 +00:00
Rui Ueyama 890ce0c188 Do not produce broken debug info.
r267917 produces corrupted debug info because it didn't apply
relocations to right offsets.

llvm-svn: 267979
2016-04-29 03:21:08 +00:00
Rui Ueyama 2b6fb80384 Skip scanRelocs for non-alloc sections.
Relocations against sections with no SHF_ALLOC bit are R_ABS relocations.
Currently we are creating Relocations vector for them, but that is wasteful.
This patch is to skip vector construction and to directly apply relocations
in place.

This patch seems to be pretty effective for large executables with debug info.
r266158 (Rafael's patch to change the way how we apply relocations) caused a
temporary performance degradation for such executables, but this patch makes
it even faster than before.

Time to link clang with debug info (output size is 1070 MB):

  before r266158: 15.312 seconds (0%)
  r266158:        17.301 seconds (+13.0%)
  Head:           16.484 seconds (+7.7%)
  w/patch:        13.166 seconds (-14.0%)

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

llvm-svn: 267917
2016-04-28 18:42:04 +00:00
Rafael Espindola fbb18fb6b9 Add a test showing that we can gc parts of .eh_frame.
llvm-svn: 267884
2016-04-28 14:31:09 +00:00
Rui Ueyama 62ee16faa8 Remove Size from Undefined symbol.
There seems to be no reason to keep st_size of undefined symbols.
This patch removes the member for it. This patch will change outputs
in cases that undefined symbols are copied to output, but I think
this is unimportant.

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

llvm-svn: 267826
2016-04-28 00:26:54 +00:00
Peter Collingbourne 21a12fc69a ELF: Create .gnu.version and .gnu.version_r sections when linking against versioned DSOs.
Differential Revision: http://reviews.llvm.org/D19464

llvm-svn: 267775
2016-04-27 20:22:31 +00:00
Rafael Espindola 520ed3a621 Create a .got when PPC64 uses a TOC.
This simplifies the logic for computing the value of the toc base.

llvm-svn: 267701
2016-04-27 12:21:27 +00:00
George Rimar 5f85732738 [ELF] - Align sections file offsets correctly.
System V ABI 4.1 specifies that program header's p_vaddr should equal p_offset, modulo p_align. 
(https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-83432/index.html).
It was possible to violate this using the linkerscript.
Patch fixes the issue.

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

llvm-svn: 267684
2016-04-27 09:16:28 +00:00
Rui Ueyama 144debcc0f Remove unnecessary trailing semicolons.
Since this semicolon existed in an early test file,
it has spread to many files.

llvm-svn: 267659
2016-04-27 02:58:27 +00:00
Peter Collingbourne 892d498017 ELF: Re-implement -u directly and remove CanKeepUndefined flag.
The semantics of the -u flag are to load the lazy symbol named by the flag. We
were previously relying on this behavior falling out of symbol resolution
against a synthetic undefined symbol, but that didn't quite give us the
correct behavior, so we needed a flag to mark symbols created with -u so
we could treat them specially in the writer. However, it's simpler and less
error prone to implement the required behavior directly and remove the flag.

This fixes an issue where symbols loaded with -u would receive hidden
visibility even when the definition in an object file had wider visibility.

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

llvm-svn: 267639
2016-04-27 00:05:03 +00:00
Rui Ueyama 673b609586 Handle Windows drive letters and ".." for --reproduce.
When --reproduce <path> is given, then we need to concatenate input
file paths to the given path to save input files to the directory.
Previously, path concatenation didn't handle Windows drive letters
so it could generate invalid paths such as "C:\D:\foo". It also didn't
handle ".." path components, so it could produce some bad paths
such as "foo/../../etc/passwd".

In this patch, Windows drive letters and ".." are removed before
concatenating paths.

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

llvm-svn: 267600
2016-04-26 20:36:46 +00:00
Rui Ueyama 3578d334fb Make test/ELF/reproduces.s test to work on Windows.
Previously, the test didn't work on Windows because it tried to
concatenate two (possibly) absolute paths. If two paths are absolute
paths that have drive letters, then the result would become something
like C:\foo\D:\bar. That's not a valid path. I changed the test to
use relative paths.

llvm-svn: 267588
2016-04-26 19:04:35 +00:00
Peter Collingbourne dbcf5b99d0 Remove unnecessary function type directives for ifuncs.
llvm-svn: 267569
2016-04-26 16:50:02 +00:00
Rafael Espindola 1b65ad1725 Don't gc symbols that have to go in the dynamic symbol table.
We were only doing it for .so and --export-dynamic, but those are not
the only ways a symbol ends up in the dynamic symbol table.

Problem diagnostic and earlier patch version by Peter Collingbourne.

llvm-svn: 267568
2016-04-26 16:26:45 +00:00
Peter Collingbourne 5dd550a3ff ELF: Treat IFunc definitions in DSOs as functions.
Differential Revision: http://reviews.llvm.org/D19517

llvm-svn: 267566
2016-04-26 16:22:51 +00:00
Davide Italiano 366290bb26 [ELF] Avoid polluting source directory with temp files.
llvm-svn: 267565
2016-04-26 16:21:59 +00:00
Rafael Espindola 0baa73f317 Handle --as-needed with symbols, not relocations.
This matches the behavior of both gold and bfd.

llvm-svn: 267558
2016-04-26 13:56:26 +00:00
Rafael Espindola 9e32e4fe86 Store the binding in the Symbol.
This remove a fixme, cleans up the weak undef interaction with archives and
lets us keep weak undefs still weak if they resolve to shared.

llvm-svn: 267555
2016-04-26 13:50:46 +00:00
Davide Italiano 957d084811 [Tests] Run reproduces.s only on UNIX until I investigate a windows failure.
llvm-svn: 267505
2016-04-26 00:56:19 +00:00
Davide Italiano 034f58a9bd [ELF] Introduce --reproduce flag.
--reproduce dumps the object files in a directory chosen
(preserving the file system layout) and the linker invocation
so that people can create an archive and upload for debugging.

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

llvm-svn: 267497
2016-04-26 00:22:24 +00:00
Rafael Espindola 926bff8c3e Add support for R_X86_64_PC64.
llvm-svn: 267409
2016-04-25 14:05:44 +00:00
George Rimar ab9390664f [ELF] - Implemented comparsion operators for linkerscript.
Patch adds support of <,>,!=,==,>=,<= operators.

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

llvm-svn: 267382
2016-04-25 08:14:41 +00:00
Peter Collingbourne eb4d823184 Add a note to the test explaining why it doesn't match gold's behaviour.
llvm-svn: 267371
2016-04-25 00:19:47 +00:00
Simon Atanasyan 9cf3bf659c [ELF][MIPS] Add test case to check creation of GOT entries for weak symbols. NFC
llvm-svn: 267327
2016-04-24 05:08:43 +00:00
Peter Collingbourne dbe4187d11 ELF: Simplify preemption logic. Do not include weak undefined symbols in non-DSOs.
Add a test for -Bsymbolic + undefined symbols.

llvm-svn: 267323
2016-04-24 04:29:59 +00:00
Peter Collingbourne 7fa5970e69 Test what I intended to test.
llvm-svn: 267316
2016-04-24 02:42:34 +00:00
Peter Collingbourne 6d01a35ef6 ELF: Forbid undefined symbols with non-default visibility in DSOs.
llvm-svn: 267315
2016-04-24 02:31:04 +00:00
Peter Collingbourne d869a040ee ELF: Always include undefined DSO symbols in the symbol table.
Fixes check-llvm when bootstrapping.

Also remove mostly dead and most likely incorrect logic regarding preemption
of weak undefined symbols.

llvm-svn: 267314
2016-04-24 02:31:02 +00:00
Davide Italiano ae153ec4b4 [ELF] Use llvm-mc rather than checking in a file.
Now that the support for the 'new' relocations is available.

llvm-svn: 267310
2016-04-24 01:56:02 +00:00
Rui Ueyama 9c1112d09a Use ScriptParserBase features to parse linker script expressions.
Previously, we have re-implemented utility functions such as `expect`
or `next` in LinkerScript.cpp. This patch reuses the existing
implementation that is in ScriptParser.cpp.

llvm-svn: 267255
2016-04-23 00:04:03 +00:00
Rafael Espindola 0b9531c8e6 Bring r267164 back with a fix.
The fix is to handle local symbols referring to SHF_MERGE sections.

Original message:

GC entries of SHF_MERGE sections.

It is a fairly direct extension of the gc algorithm. For merge sections
instead of remembering just a live bit, we remember which offsets
were used.

This reduces the .rodata sections in chromium from 9648861 to 9477472
bytes.

llvm-svn: 267233
2016-04-22 22:09:35 +00:00
Rui Ueyama 1e9e615f92 LTO: Merge -lto-no-discard-value-names with -save-temps.
This patch is to remove -lto-no-discard-value-names flag and
instead to use -save-temps as we discussed in the post-commit
review thread for r267020.

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

llvm-svn: 267230
2016-04-22 21:43:10 +00:00
Peter Collingbourne 66ac1d6152 ELF: Implement basic support for --version-script.
This patch only implements support for version scripts of the form:
  { [ global: symbol1; symbol2; [...]; symbolN; ] local: *; };
No wildcards are supported, other than for the local entry. Symbol versioning
is also not supported.

It works by introducing a new Symbol flag which tracks whether a symbol
appears in the global section of a version script.

This patch also simplifies the logic in SymbolBody::isPreemptible(), and
teaches it to handle the case where symbols with default visibility in DSOs
do not appear in the dynamic symbol table because of a version script.

Fixes PR27482.

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

llvm-svn: 267208
2016-04-22 20:21:26 +00:00
Rafael Espindola e2eb5f837b Update test.
Sorry about the noise.

llvm-svn: 267207
2016-04-22 20:21:25 +00:00
Rafael Espindola 55a1d50b3a Add missing options that were required to crash.
llvm-svn: 267204
2016-04-22 20:07:59 +00:00
Rafael Espindola e7809c3a28 Add a reduction of the recent bootstrap failure.
llvm-svn: 267202
2016-04-22 20:05:16 +00:00
Rafael Espindola 46c039f2c0 Revert "GC entries of SHF_MERGE sections."
This reverts commit r267164.

    Revert "Trying to fix the windows build."

    This reverts commit r267168.

Debugging a bootstrap problem.

llvm-svn: 267194
2016-04-22 19:31:35 +00:00
Peter Collingbourne 3a35c4546d ELF: Scan for undefined symbols in shlibs and symbols in dynamic lists before LTO.
This ensures that these features work correctly with bitcode files.

llvm-svn: 267188
2016-04-22 18:47:52 +00:00
Peter Collingbourne 760e583e22 ELF: Implement --export-dynamic-symbol.
llvm-svn: 267184
2016-04-22 18:44:06 +00:00
Davide Italiano 9f8efffe29 [LTO] Create Undefined Bitcode symbol when we drop a comdat member.
Differential Revision:  http://reviews.llvm.org/D19389

llvm-svn: 267181
2016-04-22 18:26:33 +00:00
Rafael Espindola caa831d85a GC entries of SHF_MERGE sections.
It is a fairly direct extension of the gc algorithm. For merge sections
instead of remembering just a live bit, we remember which offsets were
used.

This reduces the .rodata sections in chromium from 9648861 to 9477472
bytes.

llvm-svn: 267164
2016-04-22 16:46:08 +00:00
George Rimar dffc1410c5 [ELF] - Implemented linkerscript ALIGN command
ALIGN(exp)
Return the location counter (.) aligned to the next exp boundary. (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/expressions.html)

Patch implements this command.
This fixes PR27406.

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

llvm-svn: 267145
2016-04-22 11:40:53 +00:00
George Rimar fba45c41df Recommitted r267132 "[ELF] - implemented ternary operator for linkerscript expressions"
With fix: removed redundant Dot parameter.

Original commit message:
[ELF] - implemented ternary operator for linkerscript expressions

Patch implements ternary operator for linkerscript expressions.
Like:

SECTIONS {
 . = 0x1 ? 0x2 : 0x3;
...
}

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

llvm-svn: 267140
2016-04-22 11:28:54 +00:00