Commit Graph

2548 Commits

Author SHA1 Message Date
Rafael Espindola 79202c378f Fix the implementation of R_386_GOTPC and R_386_GOTOFF.
They were both pointing to the start of the got, not the end.

Fixes pr28924.

llvm-svn: 280310
2016-08-31 23:24:11 +00:00
Rui Ueyama 95769b4a29 Linker script: support VERSION command.
Summary:
VERSION commands define symbol versions. The grammar of the
commnad is as follows

  VERSION { version-script-commands }

where version-script-commands is

  [ name ] { version-definitions }.

Note that we already support version-script-commands because
it is being used for version script command.

This patch is based on George's patch https://reviews.llvm.org/D23609

Reviewers: grimar

Subscribers: llvm-commits

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

llvm-svn: 280284
2016-08-31 20:03:54 +00:00
Petr Hosek e5d3ca5031 [ELF] Linkerscript: define symbols outside SECTIONS
Symbol assignments outside of SECTIONS command need to be created
even when SECTIONS command is not used.

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

llvm-svn: 280252
2016-08-31 15:31:17 +00:00
Rafael Espindola 8db87291ef Internalize common variables.
Before this lld was always creating common symbols itself. It worked,
but prevented them from being internalized when possible.

Now it preserves common symbols is the bitcode and they are internalized.

Fixes pr30184.

llvm-svn: 280242
2016-08-31 13:42:08 +00:00
Simon Atanasyan e5532a12f7 [ELF][MIPS] Support R_MIPS_HIGHER / R_MIPS_HIGHEST relocations calculation
llvm-svn: 280223
2016-08-31 11:47:21 +00:00
George Rimar ebf1da565c [ELF] - Fix (partial) for bug 28843 - Make sure we handle options with opposing meanings.
As stated in PR28843:

we should handle command lines with

-target1-rel -target1-abs
--demangle --no-demangle
Patch implements this for specified options.
There are probably other conflicting options can exist,
so fix is called "partial".

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

llvm-svn: 280211
2016-08-31 08:53:21 +00:00
Eugene Leviant aa49819162 Add DT_REL(A)COUNT tag to .dynamic section
This patch groups relative relocations in a single block
in combrelocs mode and adds DT_RELCOUNT or DT_RELACOUNT
tag to .dynamic section

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

llvm-svn: 280210
2016-08-31 08:51:39 +00:00
Eugene Leviant 20889c51b7 Allow adding start/end symbols to any section
Allows adding start and/or end symbols to special output sections,
like .eh_frame_hdr, which aren't lists of regular input sections. 

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

llvm-svn: 280205
2016-08-31 08:13:33 +00:00
Eugene Leviant e4f590faeb Allow .eh_frame_hdr to be placed before .eh_frame
Differential revision: https://reviews.llvm.org/D24041

llvm-svn: 280203
2016-08-31 07:43:50 +00:00
Davide Italiano 35af5b3d21 [LTO] Fix the logic for dropping unnamed_addr.
Differential Revision:  https://reviews.llvm.org/D24037

llvm-svn: 280144
2016-08-30 20:15:03 +00:00
George Rimar 96659df09c [ELF] - Linkerscript: implemented ADDR command.
ADDR(section)
Return the absolute address (the VMA) of the named section.

Used in the wild, eg.: https://searchcode.com/file/53617342/arch/x86/kernel/vmlinux.lds.S

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

llvm-svn: 280070
2016-08-30 09:54:01 +00:00
George Rimar a2496cbed4 [ELF] - Fix for: bug 29115 - linkerscript does not support non-wildcard filename spec.
FreeBSD/mips script has non-wildcard filename specifications:
.text :
{
 start.o(.text*)

Patch adds support for that, this is PR29115.

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

llvm-svn: 280069
2016-08-30 09:46:59 +00:00
George Rimar 397cd87a69 [ELF] - Versionscript: support wildcards for extern "c++" tag.
Previously for extern keyword only names in quotes (exact match) was supported.
Patch adds support for wildcards, so next scripts can be handled properly:

LIBSAMPLE_1.0 {
   global:            
     extern "C++" {  
       foo*;   
   };                  
 };

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

llvm-svn: 280067
2016-08-30 09:35:03 +00:00
Rui Ueyama 2c8f1f048c Make lld actually compatible with gold in terms of filler handling.
GNU gold handles output section fillers as 32-bit values.
This patch makes LLD compatible with that behavior.

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

llvm-svn: 280018
2016-08-29 22:01:21 +00:00
Saleem Abdulrasool 8fcff934ba COFF: add beginnings of debug directory creation
The IMAGE_FILE_HEADER structure contains a (RVA, size) to an array of
COFF_DEBUG_DIRECTORY records. Each one of these records contains an RVA to a OMF
Debug Directory. These OMF debug directories are derived into newer types such
as PDB70, PDB20, etc. This constructs a PDB70 structure which will allow us to
associate a GUID with a build to actually tie debug information.

llvm-svn: 280012
2016-08-29 21:20:46 +00:00
Eugene Leviant 933dae7435 Implement support for --build-id=uuid switch
Differential revision: https://reviews.llvm.org/D23349

llvm-svn: 279810
2016-08-26 09:55:37 +00:00
Eugene Leviant 0bbb600a9c [ELF] Added test case for PROVIDE and PROVIDE_HIDDEN within section
llvm-svn: 279809
2016-08-26 09:48:32 +00:00
Hemant Kulkarni 3ed7dc705a Fix test corresponding to change r279770
llvm-svn: 279775
2016-08-25 20:43:49 +00:00
George Rimar 86ce267a4a [ELF] - Implemented --oformat binary option.
-oformat output-format
`-oformat' option can be used to specify the binary format for the output object file.

Patch implements binary format output type.

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

llvm-svn: 279726
2016-08-25 09:05:47 +00:00
Peter Smith a52864a78c Canonicalize output section name for .ARM.exidx sections
The ARM Exception handling ABI requires that all ARM exception index
table sections have a prefix of .ARM.exidx and are combined into a
single contiguous block either in their own output section or as part
of another output section.
    
In general clang will output a single .ARM.exidx section per object,
but will use .ARM.exidx.<section name> when -ffunction-sections is used.
    
This change canonicalizes the names of sections with the .ARM.exidx
prefix to just .ARM.exidx, which ensures that there is only a single
output section.

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

llvm-svn: 279617
2016-08-24 09:08:54 +00:00
Rafael Espindola cc3dd629ee Add support for '|' in expressions.
llvm-svn: 279480
2016-08-22 21:33:35 +00:00
Petr Hosek 5b4f6c6b28 [ELF] Only print symbol name when it is available
Not only symbols (like sections) have names, in case where we
fail to create relocation against such symbol, we should not
print out an empty string, instead we should print a generic
message.

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

llvm-svn: 279459
2016-08-22 19:01:53 +00:00
Petr Hosek 901948a205 [ELF] ICF should respect section alignment
When performing ICF, we have to respect the alignment requirement
of each section within each group.

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

llvm-svn: 279456
2016-08-22 18:53:09 +00:00
Petr Hosek 4f7a5c3bb4 [ELF] Define __ehdr_start symbol
This symbol can be used by the program to examine its own headers.

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

llvm-svn: 279452
2016-08-22 18:44:04 +00:00
Ed Schouten 21483f5636 Add R_386_TLS_LE as a relocation having an implicit addend.
TLS on i386 in non-PIE/PIC code seems broken right now, because we don't
properly add the addend encoded in the instruction to the resulting
offset when processing R_386_TLS_LE relocations.

Extend one of the existing tests for TLS on i686 to use an addend.

PR:		https://llvm.org/bugs/show_bug.cgi?id=29068
Reviewed by:	ruiu
Differential Revision:	https://reviews.llvm.org/D23741

llvm-svn: 279368
2016-08-20 10:54:51 +00:00
George Rimar 3e6833b4b2 [ELF] - Fix for PR28976 - Corrupted section contents when using linker scripts
This is fix for PR28976.

Problem was that in scanRelocs, we computed relocation offset too early 
for case when linkerscript was used. Patch fixes the issue 
delaying the calculation.

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

llvm-svn: 279264
2016-08-19 15:46:28 +00:00
George Rimar e1937bb524 [ELF] - Give automatically generated __start_* and __stop_* symbols default visibility.
This patch is opposite to D19024, which made this symbols to be hidden by default.

Unfortunately FreeBSD loader wants to see
start_set_modmetadata_set/stop_set_modmetadata_set in the dynamic symbol table. 
They were not placed there because had hidden visibility.

Patch makes them to have default visibility again.

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

llvm-svn: 279262
2016-08-19 15:36:32 +00:00
George Rimar 03e0560da7 [ELF] - Linkerscript: set correct dynamic tag entries values when LS is used.
Previously DT_PREINIT_ARRAYSZ, DT_INIT_ARRAYSZ and DT_FINI_ARRAYSZ
were set to zero when lincerscript was used becase sections sizes are
calculated later that were taken.

Patch delays values calculation for these entries. Testcase is provided.

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

llvm-svn: 279258
2016-08-19 15:23:39 +00:00
George Rimar db24d9c3e8 [ELF] - Linkerscript: implemented SUBALIGN() command.
You can force input section alignment within an output section by using SUBALIGN. The
value specified overrides any alignment given by input sections, whether larger or smaller.

SUBALIGN is used in many projects in the wild.

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

llvm-svn: 279256
2016-08-19 15:18:23 +00:00
George Rimar a2f96619cb [ELF] - Removed excessive llvm-readobj call from linkerscript-ouputformat.s. NFC.
llvm-svn: 279236
2016-08-19 12:57:45 +00:00
George Rimar 11f83b7941 [ELF] - Do not change binding of symbols when creating relocatable output.
Spec says "A hidden symbol contained in a relocatable object must be either
removed or converted to STB_LOCAL binding by the link-editor when the
relocatable object is included in an executable file or shared object".
But we previously converted symbols to STB_LOCAL even when -r was specified.

Broken binary was produced, this is PR28967, patch fixes the issue.

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

llvm-svn: 279220
2016-08-19 08:31:02 +00:00
Petr Hosek 4071b1bac3 [ELF] Improve error reporting for relocations
We should always include symbol name when reporting relocations
error to simplify debugging of these issues. Without symbol names
users have to manually investigate which of the libraries contain
invalid relocations which can be cumbersome when linking multiple
libraries.

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

llvm-svn: 279162
2016-08-18 21:55:23 +00:00
Simon Atanasyan 978f91ca43 [ELF][MIPS] Support R_MIPS_GOT_HI16 / R_MIPS_GOT_LO16 relocations calculation
llvm-svn: 279119
2016-08-18 19:08:41 +00:00
Simon Atanasyan e933a8e212 [ELF][MIPS] Support R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations calculation
llvm-svn: 279118
2016-08-18 19:08:36 +00:00
Eugene Leviant 3f675e38bd [ELF] Don't add input sections twice when linker script is used
llvm-svn: 279036
2016-08-18 07:27:37 +00:00
Petr Hosek 0df80bef96 [ELF] Linkerscript: support assignment outside SECTIONS
We only support assignments inside SECTIONS, but this does not match
the behavior of GNU linker which also allows them outside SECTIONS.
The only restriction on assignments outside SECTIONS is that they
cannot reference . (they have to be absolute expressions).

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

llvm-svn: 279033
2016-08-18 04:34:27 +00:00
Petr Hosek 1fb2ecc903 [ELF] Allow specifying the stack size
This option can be used to specify the stack size of the
PT_GNU_STACK segment.

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

llvm-svn: 279013
2016-08-17 23:59:58 +00:00
George Rimar 8ceadb38a8 [ELF] - linkerscript AT keyword (in output section description) implemented.
The linker will normally set the LMA equal to the VMA. 
You can change that by using the AT keyword.
The expression lma that follows the AT keyword specifies 
the load address of the section.

Patch implements this keyword.

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

llvm-svn: 278911
2016-08-17 07:44:19 +00:00
Michael J. Spencer e2cc07bc0b [ELF] Set MAXPAGESIZE to 2MiB on x86-64 to match bfd and gold.
The FreeBSD kernel relies on this behavior to not overwrite the boot loader.

llvm-svn: 278889
2016-08-17 02:10:51 +00:00
George Rimar f527a8cd57 [ELF] - Do not exit if -v is specified.
Previously lld showed version number and returned,
that is different from ld and PR28999.

Patch fixed that.

llvm-svn: 278797
2016-08-16 13:25:53 +00:00
Eugene Leviant f9bc3bd2cf [ELF] Ignore .interp section in case linker script specifies PHDRS without PT_INTERP
llvm-svn: 278781
2016-08-16 06:40:58 +00:00
Petr Hosek a35e39ca2e [ELF] Linkerscript: support hidden symbols assignments
This add support for HIDDEN command which can be used to define
a symbol that will be hidden and won't be exported.

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

llvm-svn: 278770
2016-08-16 01:11:16 +00:00
Eugene Leviant a5c8a68535 [ELF] Do not add start and end symbols in case they are already defined
llvm-svn: 278657
2016-08-15 07:24:20 +00:00
George Rimar 8f66df92ba [ELF] - Linkerscript: fix VA value assigned to sections when using constraints.
Previously we searched output section by name to assign VA. That did not
work in the case when multiple output sections with different constraints were defined in script.
Testcase shows the possible issue scenario, patch fixes the issue.

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

llvm-svn: 278561
2016-08-12 20:38:20 +00:00
George Rimar 67e3ff83f5 [ELF] - Do not use mergeable sections when LS is used.
After latest changes we combine input sections with 
different attributes into single output section. 
Problem here is that regular output sections does not
support adding mergeable input sections (and vise versa).
Patch just temporarily disables merging for now at 
the same way we do for -O0 for example.

This change helps for linking FreeBSD kernel.

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

llvm-svn: 278555
2016-08-12 19:56:57 +00:00
George Rimar 683a35d066 [ELF] - Fix for: error "invalid section index: xxx" when linking FreeBSD kernel.
We found that GNU assembler 2.17.50 [FreeBSD] 2007-07-03
could generate broken objects. STT_SECTION symbols can be
associated with SHT_REL[A]/SHT_SYMTAB/SHT_STRTAB sections.

This is PR28868, patch fixes handling of such files.

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

llvm-svn: 278550
2016-08-12 19:25:54 +00:00
George Rimar 06ae683620 [ELF] - Linkerscript: reimplemented output sections constrains matching functionality.
Previously filtering that was used worked incorrectly. 
For example for next script it would just remove both sections completely:

SECTIONS { 
. = 0x1000;
.aaa : ONLY_IF_RW { *(.aaa.*) } 
. = 0x2000;
.aaa : ONLY_IF_RO { *(.aaa.*) } 
}

Patch fixes above issues and adds testcase showing the issue. Testcase is a subset of
FreeBSD script which has:

.eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) }
...
.eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) }

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

llvm-svn: 278486
2016-08-12 09:07:57 +00:00
Simon Atanasyan 85c6b44817 [ELF][MIPS] Support .MIPS.abiflags section
This section supersedes .reginfo and .MIPS.options sections. But for now
we have to support all three sections for ABI transition period.

llvm-svn: 278482
2016-08-12 06:28:49 +00:00
Rui Ueyama 0b9ce6a48a Create only one section for a name in LinkerScript.
Previously, we created two or more output sections if there are
input sections with the same name but with different attributes.
That is a wrong behavior. This patch fixes the issue.

One thing we need to do is to merge output section attributes.
Currently, we create an output section based on the first input
section's attributes. This may make a wrong output section
attributes. What we need to do is to bitwise-OR attributes.
We'll do it in a follow-up patch.

llvm-svn: 278461
2016-08-12 03:16:56 +00:00
Pete Cooper ef5bea9dca Dead strip DESC bits should only be set on object files.
It only makes sense to set on N_NO_DEAD_STRIP on a relocatable object file.  Otherwise the bits aren't useful for anything.  Matches the ld64 behaviour.

llvm-svn: 278419
2016-08-11 21:27:18 +00:00
Pete Cooper cb7d83c048 Add obj2yaml to the list of tool_patterns in lit. NFC
llvm-svn: 278412
2016-08-11 21:03:56 +00:00
Pete Cooper 1ed8f1f6e5 Better compress lazy binding info to match ld64.
We should be using one of BIND_OPCODE_SET_DYLIB_SPECIAL_IMM, BIND_OPCODE_SET_DYLIB_ORDINAL_IMM,
and BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB depending on whether ordinals are <= 0, <= 15, > 15.

This matches the behaviour of ld64.

llvm-svn: 278407
2016-08-11 20:59:27 +00:00
Pete Cooper 21f475e1c4 Generate slightly more compressed binding opcodes when entries are the same as last time.
We already had logic for binding opcodes had the same addend as last time.  This adds
the cases where the ordinal, symbol name, type, and segment offsets are the same as
the last emitted ordinal.

This gets us one step closer to emitting rebase opcodes as compressed as ld64 can manage.

llvm-svn: 278405
2016-08-11 20:37:02 +00:00
Pete Cooper 91db988dfb Add test for rebase opcodes. We didn't have one. NFC.
This will be used to test upcoming changes to improve binding opcode
emission to match the more compressed form ld64 can generate.

llvm-svn: 278400
2016-08-11 20:31:50 +00:00
Pete Cooper 1e885c529d Add missing RUN line from r278398. This test works with this line but i forgot to push it
llvm-svn: 278399
2016-08-11 20:23:15 +00:00
Pete Cooper 732f1ef9de Arm64 stubs alignment is 2, not 4.
This matches the behaviour of ld64 when looking at the alignment of the stubs section in the final image.

llvm-svn: 278398
2016-08-11 20:18:05 +00:00
Pete Cooper 46cd113c87 Change when we choose to add an LC_LOAD_DYLIB to the final image.
Currently we do this when an atom is used, but we need to do it when a
dylib is referenced on the cmdline as this matches ld64.

This fixes much confusion over which maps are indexed with installName
vs path.  There is likely other confusion so i'll be seeing if i can remove
path() completely in a future commit as path() shouldn't really be needed by anyone.

llvm-svn: 278396
2016-08-11 20:10:14 +00:00
Pete Cooper d9e0f71195 Change all the libSystem test files to be dylibs instead of normalized files. Currently NFC.
A future commit will change when we choose to add an LC_LOAD_DYLIB to the final image.  Currently
we do this when an atom is used, but we need to do it when a dylib is referenced on the cmdline as
this matches ld64.

To allow this change, libsystem (and other future yaml files representing dylibs) need to be dylibs
so that the loader can see to add them to the referenced dylib list.

llvm-svn: 278386
2016-08-11 18:46:21 +00:00
Pete Cooper 363e7f6914 Fix one more test missed by r278372. The next commit will update libsystem in a way which broke without this fix as it referenced the wrong file
llvm-svn: 278385
2016-08-11 18:43:42 +00:00
Pete Cooper 932bce6ade Fix off-by-one error in default currentVersion.
A version of 0x1000 is 0.16.0, not 1.0.0 as the comment said.  Fix the
value to match the comment, and also the one test case which had this
wrong.

llvm-svn: 278381
2016-08-11 18:41:14 +00:00
Pete Cooper c4a12a08e2 Have one version of libSystem for each arch. NFC.
An upcoming commit will change how we choose to reference a dylib.  Currently
dylibs are only given an LC_LOAD_DYLIB in the final image if an atom is used.
This is different from ld64 which adds the load command when the dylib is referenced
on the cmdline.

In order to change this behaviour, we need libSystem.yaml to actually contain a mach header
so that it is parsed as a dylib, instead of currently being parsed as a normalised file.

To get a mach header, we also require an arch, so now we have one libsystem per arch and
all the tests have been updated to choose the correct one.

llvm-svn: 278372
2016-08-11 18:08:59 +00:00
Simon Atanasyan 2e88174f83 [ELF][MIPS] Add more tests for ELF flags calculation. NFC
llvm-svn: 278359
2016-08-11 17:07:46 +00:00
Simon Atanasyan 5c09e067f7 [ELF][MIPS] Separate different tests by empty lines. NFC
llvm-svn: 278358
2016-08-11 17:07:43 +00:00
Simon Atanasyan a782f16ace [ELF][MIPS] Recognize and print machine name in case of input incompatibility
llvm-svn: 278352
2016-08-11 16:25:17 +00:00
Eugene Leviant ceabe80e97 [ELF] Symbol assignment within output section description
llvm-svn: 278322
2016-08-11 07:56:43 +00:00
Lang Hames 8c2406b1fc [lld][MachO] Fix LC_SEGEMENT[_64] filesize computation in -r mode.
Using vmsize to populate this file works when outputing MachO images, but fails
when outputting relocatable objects. This patch fixes the computation to use
file offsets, which works for both output types.

Fixes <rdar://problem/27727666>

llvm-svn: 278297
2016-08-10 22:15:09 +00:00
Rui Ueyama 2dc5645b94 Check for availability of `cpio` command.
cpio may not be available on Windows, so it is better to check
for availability before running the command in a test.

llvm-svn: 278249
2016-08-10 17:42:26 +00:00
Simon Atanasyan 9ef1215c80 [ELF][MIPS] Take into account combination of EF_MIPS_ARCH and EF_MIPS_MACH flags while checking ISA compatibility
MIPS ISA encoded using two ELF flags: general architecture flag like
EF_MIPS_ARCH_32, EF_MIPS_ARCH_64R6 etc and optional machine variant flag
like EF_MIPS_MACH_4111, EF_MIPS_MACH_OCTEON3 etc. When we check
compatibility between two input files and deduce ELF flags for generated
output we need to take into account both of these flags.

llvm-svn: 278230
2016-08-10 15:06:45 +00:00
George Rimar 215dd47dc9 [ELF] - Fixed section name pattern in two more testcases.
llvm-svn: 278227
2016-08-10 14:02:35 +00:00
George Rimar dfc1b900ac [ELF] - Fixed section name pattern in testcase.
llvm-svn: 278219
2016-08-10 13:06:18 +00:00
George Rimar e32a3598bc [ELF] - Linkerscript: implement SIZEOF_HEADERS.
SIZEOF_HEADERS - Return the size in bytes of the output file’s headers.

It is is a feature used in FreeBsd script, for example.
There is a discussion on PR28688 page about it.

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

llvm-svn: 278204
2016-08-10 07:59:34 +00:00
Pete Cooper 5559b24935 The first string table entry should be a null terminated space, not just null.
This matches the behaviour of ld64 which initializes the string table with
' ' then '\0'.  lld only had the '\0' and needed the ' '.

llvm-svn: 278071
2016-08-08 23:20:04 +00:00
Rui Ueyama 31f32fa62a Refactor getMipsEFlags.
Previously, we incrementally updated the reuslting flag as we check
file flags, so it was not very clear who is updating what flags.
This patch makes them pure functions -- that has no side effect and
don't update arguments to improve readability.

Now each function construct a patial result, and all resutls are then
bitwise-OR'ed to construct the final result.

This patch also creates a new file, Mips.cpp, to move all these
MIPS functions to a separate file.

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

llvm-svn: 278042
2016-08-08 19:39:45 +00:00
George Rimar 28ac19c9ee [ELF] - Linkerscript: do not define _edata,_end,_etext if SECTIONS is used.
I faced that when tried to link FreeBSD kernel. 
It was "duplicate symbol: _edata in (internal) and (internal)" error.
_data was a shared symbol that came from hack.so. At first it was replaced with DefinedRegular by the code
disabled in this patch and later when script tried to define the same symbol - the error was shown.

In the same situation (as given in testcase) ld defines them as UND. gold defines as ABS with zero value. 
Patch just disables any operations of creating these symbols if script do layout.

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

llvm-svn: 277986
2016-08-08 08:42:48 +00:00
Saleem Abdulrasool 45a574130e COFF ARM: Fix typos in the relocation test
Fix comments.  NFC.

Patch by Martin Storsjö!

llvm-svn: 277929
2016-08-06 18:02:51 +00:00
Simon Atanasyan 24c24fedba [ELF][MIPS] Produce a correct and complete set of MIPS ELF header flags
The patch extends the `getMipsEFlags` function. Now in that function
we iterate over all object files, parse ELF header flags and merge them.
If a file is incompatible with previously analyzed ones we show an error
or warning. That can happen if, for example, we try to link files with
incompatible ABI, ISA, NAN encoding etc.

There is an alternative solution. We can check and merge flags and
reject incompatible input modules in the `isCompatible` function which
is called from the `SymbolTable::addFile` method. But in that case we
have to save and keep somewhere a merged ELF flags combination to use it
later in the writer.

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

llvm-svn: 277911
2016-08-06 05:11:41 +00:00
Pete Cooper d0de3683ec ExportTrie nodes need to be visisted in order.
The export trie was being emitted in the order the nodes were
added to the vector, but instead needs to be visited in the order
that the nodes are traversed.  This matches the behaviour of ld64.

llvm-svn: 277869
2016-08-05 21:37:12 +00:00
Saleem Abdulrasool fd063e796f COFF ARM: Apply an existing offset in MOV32T relocations
Don't blindly OR in the new value, but clear the existing one, since it can be
nonzero. Read out the existing value before, and add into the desired offset.
(The add is done outside of the applyMOV, to handle potential overflow between
the two.)

Patch by Martin Storsjö!

llvm-svn: 277846
2016-08-05 18:20:31 +00:00
Saleem Abdulrasool eea45bc478 COFF ARM: Error out if 24 bit thumb branches are out of range
In the ELF linker, the same situation already errors out with "relocation
R_ARM_THM_CALL out of range".

Patch by Martin Storsjö!

llvm-svn: 277838
2016-08-05 17:33:24 +00:00
Saleem Abdulrasool 8202c6dbdf COFF ARM: Clear the J1 and J2 bits when applying relocations to 24 bit branches
The opcode for the bl branches can initially be F000 F800, i.e.
the J1 and J2 bits are already set. Therefore mask these bits out
before or'ing in the new bits.

Patch by Martin Storsjö!

llvm-svn: 277836
2016-08-05 17:28:21 +00:00
Rui Ueyama bdade36769 Use "llvm-objdump -s" instead of hexdump command.
llvm-svn: 277771
2016-08-04 21:23:30 +00:00
George Rimar 54a5486918 [ELF] - Attemp to fix buildbot.
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/25733/steps/test_lld/logs/stdio

Fix: removed excessive whitespace.
llvm-svn: 277711
2016-08-04 09:49:26 +00:00
George Rimar eefa758ee2 [ELF] - Linkerscript: implemented ASSERT() keyword.
ASSERT(exp, message)
Ensure that exp is non-zero. If it is zero, then exit the linker with an error
code, and print message.

ASSERT is useful and was seen in few projects in the wild.

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

llvm-svn: 277710
2016-08-04 09:29:31 +00:00
George Rimar 9e5386ceae [ELF] - Linkerscript: Fixed SORT_BY_ALIGNMENT sorting order.
According to spec:
"SORT_BY_ALIGNMENT will sort sections into descending order by 
alignment before placing them in the output file"

Previously they were sorted into ascending order.

llvm-svn: 277706
2016-08-04 08:56:17 +00:00
George Rimar b32733423f [ELF] - Remove trailing whitespaces. NFC.
llvm-svn: 277705
2016-08-04 08:26:02 +00:00
Eugene Leviant c7611fc567 [ELF] Linkerscript: remove repeated sections in filter()
llvm-svn: 277703
2016-08-04 08:20:23 +00:00
Rui Ueyama c163318b21 Remove buggy PROVIDE-in-output-description command.
With the previous change, it is now obvious that readProvide in
this context appended new commands to a wrong command list.
It was mistakenly adding new commands to the top level.
Thus, all commands inside output section descriptions were
interpreted as they were written on top level.

PROVIDE command naturally requires symbol assignment support
in the output section description. We don't have that one yet.
I removed the implementation because there's no way to fix it now.
We can resurrect the test once we support the symbol assignment
(with a modification to detect errors that we failed to find as
described.)

llvm-svn: 277687
2016-08-04 02:03:29 +00:00
Rui Ueyama 965827d674 Make filler expression compatible with gold.
Previously, a decimal filler expression is interpreted as a byte value.
Gold on the other hand use it as a 32-bit big-endian value.
This patch fixes the compatibility issue.

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

llvm-svn: 277680
2016-08-03 23:25:15 +00:00
Rui Ueyama 6c50990df6 Add EM_IAMCU support.
This patch adds "-m elf_iamcu" to ldd for IAMCU psABI:
https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI

Patch by H.J Lu.

llvm-svn: 277643
2016-08-03 20:15:56 +00:00
George Rimar 350ece4efb [ELF] - Linkerscript: support all kinds of sorting (including nested).
Previously we supported only sorting by name.

When there are nested section sorting commands in linker script, there can be at most 1
level of nesting for section sorting commands.

SORT_BY_NAME (SORT_BY_ALIGNMENT (wildcard section pattern)). It will sort the input
sections by name first, then by alignment if 2 sections have the same name.

SORT_BY_ALIGNMENT (SORT_BY_NAME (wildcard section pattern)). It will sort the input
sections by alignment first, then by name if 2 sections have the same alignment.

SORT_BY_NAME (SORT_BY_NAME (wildcard section pattern)) is treated the same as SORT_
BY_NAME (wildcard section pattern).

SORT_BY_ALIGNMENT (SORT_BY_ALIGNMENT (wildcard section pattern)) is treated the
same as SORT_BY_ALIGNMENT (wildcard section pattern).

All other nested section sorting commands are invalid.

Patch implements that all above.

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

llvm-svn: 277583
2016-08-03 08:35:59 +00:00
Rui Ueyama 3ebc71eb91 Do not handle zero-sized mergeable section as mergeable.
Mergeable sections with size zero are useless because they don't
actually contain data, and therefore there's no merit ot merge them.
However, in reality, there are object files in the wild containing
such sections. Currently, LLD can't handle them proerply.

This patch makes LLD to handle such sections as if they are non-
mergeable to fix the issue.

Fixes bug 28822.

llvm-svn: 277568
2016-08-03 05:28:02 +00:00
Rui Ueyama d6bd1371fc Include filenames and section names to error messages.
llvm-svn: 277566
2016-08-03 04:39:42 +00:00
Rafael Espindola eb685cd798 Support expressions inside FLAGS.
This is an undocumented bfd feature. It is reasonable for making the
scripts a bit more readable.

llvm-svn: 277532
2016-08-02 22:14:57 +00:00
George Rimar 7b360f2441 [ELF] - Fix: do not ignore relocations addends when using lld -r
Previously addends were ignored. This is PR28779.
Patch fixes the issue.

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

llvm-svn: 277432
2016-08-02 08:49:57 +00:00
Davide Italiano 38115ffcef [ELF/ARM] Add support for R_ARM_TARGET1 relocation.
Differential Revision:  https://reviews.llvm.org/D22990

llvm-svn: 277369
2016-08-01 19:28:13 +00:00
Rui Ueyama 3a5be750bb Remove trailing whitespace.
llvm-svn: 277253
2016-07-29 23:48:09 +00:00
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