Commit Graph

6663 Commits

Author SHA1 Message Date
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
Rafael Espindola cceb92a075 Pass Binding instead of IsWeak to addBitcode.
We were computing the binding on both the caller and callee.

llvm-svn: 280156
2016-08-30 20:53:26 +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 7af6452927 [ELF] - Use early return. NFC.
This addresses forgotten review comment for r280067:
"[ELF] - Versionscript: support wildcards for extern "c++" tag."

llvm-svn: 280068
2016-08-30 09:39:36 +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
George Rimar c3ec9d0cbf [ELF] - Cleanup of scanVersionScript(): do not change local Demangled variable. NFC.
llvm-svn: 280066
2016-08-30 09:29:37 +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 dcbf2cbfca COFF: disambiguate make_unique (NFC)
This disambiguates `llvm::make_unqiue` and `std::make_unique` for the Windows
buildbots.

llvm-svn: 280014
2016-08-29 21:33:01 +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 449cf3e44a Removed trailing whitespace. NFC.
llvm-svn: 279729
2016-08-25 10:39:04 +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
Nico Weber d08aa5c391 fix typo "varaibles"
llvm-svn: 279638
2016-08-24 16:36:41 +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
Duncan P. N. Exon Smith c9e8bc191c ADT: Remove uses of ilist_*sentinel_traits, NFC
llvm-svn: 279458
2016-08-22 18:59:33 +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
Rui Ueyama 189b871a62 Format.
llvm-svn: 279415
2016-08-22 04:55:41 +00:00
Rui Ueyama 464daadc3d Do not add .interp, .dynamic nor .eh_frame_hdr to segments just by type.
Summary:
We previously added these output sections to segments just by type.
Therefore, if there's a PHDRS command like this

  PHDRS {
    headers PT_PHDR PHDRS;
    interp PT_INTERP;
  }

  SECTIONS {
    . = SIZEOF_HEADERS;
    .interp : { *(.interp) } :text
  }

then .interp was added to "interp" segment even though the linker
is not instructed to do so by SECTIONS command. This patch removes
the default behavior to simplify.

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

llvm-svn: 279414
2016-08-22 04:55:20 +00:00
Saleem Abdulrasool 9f8bc029bd COFF: hoist a local variable
Create a local variable for the rdata section.  NFC.

llvm-svn: 279407
2016-08-21 23:05:43 +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
George Rimar dbb76dbde3 [ELF] - Linkerscript: removed duplicate forward declarations, regrouped. NFC.
llvm-svn: 279060
2016-08-18 13:00:49 +00:00
George Rimar 43ec1c532e [ELF] - Inline defineSymbolVersion(). NFC.
llvm-svn: 279059
2016-08-18 12:53:57 +00:00
Ed Maste dec9808353 ELF: ignore -EB and -EL options
Differential Revision:	https://reviews.llvm.org/D23124

llvm-svn: 279058
2016-08-18 12:44:45 +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
Rui Ueyama 6ad7dfcc1e Merge readAt and readAlign.
Now that they are identical.

llvm-svn: 278953
2016-08-17 18:59:16 +00:00
George Rimar 545afafb70 [ELF] - Linkerscript: make readAt() signature to be consistent with others read*(). NFC.
llvm-svn: 278931
2016-08-17 14:48:17 +00:00
George Rimar 206fffa192 Attemp to fix linux build bot after r278911 ("[ELF] - linkerscript AT keyword (in output section description) implemented.")
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/26289/steps/build_Lld/logs/stdio

llvm-svn: 278914
2016-08-17 08:16:57 +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
Davide Italiano 8dd4e70222 [Driver] Remove break after return. NFCI.
llvm-svn: 278834
2016-08-16 18:23:44 +00:00
Ed Maste b2c8037c35 ELF: ignored option -G may be joined with its argument
llvm-svn: 278819
2016-08-16 16:26:46 +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 b6f1bb13ae [ELF] Linkerscript: fix bug in assignOffsets (check Sym for non-null)
llvm-svn: 278663
2016-08-15 09:19:51 +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 b6c52e8dfa [ELF] - Remove excessive loop in LinkerScript<ELFT>::assignAddresses()
After 278461 "Create only one section for a name in LinkerScript."
this loop is excessive. 
Patch also reorders code slightly to use early return.

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

llvm-svn: 278554
2016-08-12 19:32:45 +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
Duncan P. N. Exon Smith 623c4c1572 MachO: Use ilist_half_embedded_sentinel_traits, NFC
Use ilist_half_embedded_sentinel_traits for the list of
lld::mach_o::normalized::TrieEdge, rather than duplicating the code.

llvm-svn: 278523
2016-08-12 16:25:04 +00:00
Duncan P. N. Exon Smith 4a1e87d9c6 Core: Use ilist_full_embedded_sentinel_traits for SimpleReference
Avoid custom code for sentinel traits in SimpleReference (the ilist node
for references to a SimpleDefinedAtom), since they'll soon/eventually
disappear from ilist entirely.

Rather than using a BumpPtrAllocator, this drops the lazy sentinel
characteristics and stores the sentinel directly in the ilist.  This
unconditionally allocates the sentinel.

At first glance, this looks like it might increase memory usage
slightly, since an unreferenced SimpleDefinedAtom pays for a
6-pointer-sized sentinel even when its list of references is empty.  In
practice, the sentinel was being lazily allocated at the first call to
DefinedAtom::begin/end anyway.  I don't expect any real memory effects
here.

Moreover, this is an intermediate state.  The ilist_*sentinel_traits are
being phased out.

As a preview of the final state: in lieu of a NodeTy sentinel, the ilist
will have a single, untemplated list_node_base that has next/prev
pointers.  This base node will serve both as a sentinel and as a pointer
to the head of the list (the same memory layout as
ilist_half_embedded_sentinel_traits, but without the UB).

llvm-svn: 278521
2016-08-12 16:19:34 +00:00
Davide Italiano 54eb8ffd55 [Core] Retire yet another unused member function.
The code in lib/ could use a lot of love :(

llvm-svn: 278506
2016-08-12 12:37:23 +00:00
Davide Italiano 0f672ed87a [Core] Simplify a bit. NFCI.
llvm-svn: 278505
2016-08-12 12:34:39 +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
Simon Atanasyan 6be57b3fb1 [ELF][MIPS] Fix the comment
llvm-svn: 278480
2016-08-12 05:43:42 +00:00
Rui Ueyama fbcec353ab Add comments.
llvm-svn: 278473
2016-08-12 04:28:20 +00:00
Rui Ueyama 4f7500bfc2 Rename getSizeOfHeaders -> getHeaderSize.
We have getSectionSize for SIZEOF command. So, I think
getHeaderSize is a better name for SIZEOF_HEADERS.

llvm-svn: 278470
2016-08-12 04:00:22 +00:00
Duncan P. N. Exon Smith 1a2cb97f7b Core: Remove custom next-prev traits from SimpleReference, NFC
There's nothing special about the _next/_prev pointers in
SimpleReference, so just use ilist_node to do the work.

llvm-svn: 278468
2016-08-12 03:35:47 +00:00
Rui Ueyama 2ab5f73d5a Early continue. NFC.
llvm-svn: 278465
2016-08-12 03:33:04 +00:00
Rui Ueyama 0c70d3ccb7 Simplify LinkerScript<ELFT>::createSections.
Previously, we were setting LayoutInputSection's OutputSection member
in createSections. Because when we create LayoutInputSectinos, we
don't know the output section for them, so we backfilled the member
in the function. This patch moves the code to backfill it to assignOffsets.

llvm-svn: 278464
2016-08-12 03:31:09 +00:00
Rui Ueyama 7ad9d6d2f0 Remove excessive parentheses.
llvm-svn: 278462
2016-08-12 03:25:25 +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
Rui Ueyama f34d0e0875 Allocate LayoutInputSections using SpecificBumpPtrAllocator.
llvm-svn: 278453
2016-08-12 01:24:53 +00:00
Rui Ueyama bdf836db1b Simplify output section ownership management.
One reason why we are (ab)using OutputSectionFactory class is
because it owns output sections. Technically there's no need
to have it own sections. So, this patch transfers the ownership
to Out<ELFT>.

llvm-svn: 278452
2016-08-12 01:10:17 +00:00
Rui Ueyama 2de509c370 Remove OutputSectionBuilder::finalize.
The reason why we had to assign offsets only to sections that
don't contain layout sections were unclear. It turned out that
we can live without it.

llvm-svn: 278449
2016-08-12 00:55:08 +00:00
Rui Ueyama e5cc668eb8 Remove useless local variable.
llvm-svn: 278446
2016-08-12 00:36:56 +00:00
Rui Ueyama 48c3f1cebc Split LinkerScript<ELFT>::createSections.
Also avoid to use a lambda that is called only once.

llvm-svn: 278445
2016-08-12 00:27:23 +00:00
Rui Ueyama 1602421c85 Replace a variadic forwarding template function with less complex ones.
llvm-svn: 278439
2016-08-11 23:22:52 +00:00
Rui Ueyama 2c3f501052 Make class hierarchy more shallow.
LayoutInputSection is a dummy class and does not need any features
that the actual implementation (InputSection class) provides.

llvm-svn: 278430
2016-08-11 22:06:55 +00:00
Rui Ueyama f4a30a5d89 Remove trailing whitespace.
llvm-svn: 278420
2016-08-11 21:30:42 +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
Rui Ueyama dd81fe3156 Add comments.
llvm-svn: 278408
2016-08-11 21:00:02 +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
Rui Ueyama eefffedc51 Split getArchName. NFC.
llvm-svn: 278392
2016-08-11 19:22:34 +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
Davide Italiano 7ca0645c80 [Core] Retire addReplacement() member function.
llvm-svn: 278327
2016-08-11 10:50:01 +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
Eugene Leviant 9d278b6040 [ELF] Support LLVM-style casting for OutputSectionBase<ELFT> derived classes
llvm-svn: 278261
2016-08-10 18:10:41 +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
Eugene Leviant e4195dc803 [ELF] Add aarch64elf emulation mode
llvm-svn: 278205
2016-08-10 08:19:35 +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
Saleem Abdulrasool 15f6f6cb97 COFF: reorder the table construction
Reorder the table setup to mirror the indices corresponding to them.  This means
that the table values are filled out as per the enumeration ordering.  Doing so
makes it easier to identify a particular table.  NFC.

llvm-svn: 278199
2016-08-10 04:37:56 +00:00
Davide Italiano c682303d6f [Core] tentativeDefinition() is now unused.
llvm-svn: 278181
2016-08-10 00:01:13 +00:00
George Rimar 16a5930803 [ELF] - Removed dead code. NFC.
llvm-svn: 278115
2016-08-09 10:57:42 +00:00
Rui Ueyama edc521f192 Remove unreachable `return`. NFC.
llvm-svn: 278096
2016-08-09 04:50:26 +00:00
Rui Ueyama 1034c9e342 Remove isOutputDynamic and use Out<ELFT>::DynSymTab instead.
This patch is to not instantiate DynSymTab and DynStrTab if the
output is not a dynamic output.

llvm-svn: 278095
2016-08-09 04:42:01 +00:00
Rui Ueyama cbd434a6c4 Remove redundant variable.
llvm-svn: 278094
2016-08-09 04:31:21 +00:00
Rui Ueyama a8f6feaa1a Separate {Preinit,Init,Fini}Arrays from Out<ELFT>::Dynamic.
Even if an output is not a dynamic object, the output may have
.{preinit,init,fini} sections. Therefore, managing these sections
as Out<ELFT>::Dynamic's members is not correct.

llvm-svn: 278093
2016-08-09 04:25:20 +00:00
Rui Ueyama 84907c5143 Do not pass the SymbolTable to writeResult.
The SymbolTable is always accessible as Symtab<ELFT>::X,
so no need to pass it as an argument.

llvm-svn: 278091
2016-08-09 03:38:23 +00:00
Rui Ueyama 210ef7fbd4 Remove redundant local variable.
llvm-svn: 278085
2016-08-09 01:35:39 +00:00
Rui Ueyama 30634d9b4f Reduce dependency to OutputSectionFactory.
The Factory class is too object-oriented-ish and easy to be abused.
This patch reduces dependency to that class. Eventually we want to
remove the dependency to that class from LinkerScript.

llvm-svn: 278084
2016-08-09 01:35:38 +00:00
Rui Ueyama 75118259ba Do not initialize Out<ELFT>::Opd until needed.
This change makes it clear that we need the variable only within
writeSections.

llvm-svn: 278083
2016-08-09 01:35:37 +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
Saleem Abdulrasool a2cca7e2b4 COFF: handle /debugtype option
Add the support infrastructure for the /debugtype option which takes a comma
delimited list of debug info to generate. The defaults are based on other
options potentially (/driver or /profile). This sets up the infrastructure to
allow us to emit RSDS records to get "build id" equivalents on COFF (similar to
binutils).

llvm-svn: 278056
2016-08-08 22:02:44 +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
Benjamin Kramer df8f196f9a Unpollute the global namespace. lld edition.
llvm-svn: 277926
2016-08-06 13:52:37 +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 a2acc93140 Simplify. NFC.
llvm-svn: 277794
2016-08-05 01:25:45 +00:00
Rui Ueyama 808d13ea49 Move invariants outside of a lambda. NFC.
llvm-svn: 277791
2016-08-05 01:05:01 +00:00
Rui Ueyama 36c1cd235a Make combine() non-member function.
Because this function depends only on its arguments.

llvm-svn: 277790
2016-08-05 01:04:59 +00:00
Rui Ueyama 742c38361b Split InputSectionDescription::Sort into SortInner and SortOuter.
Summary:
The comparator function to compare input sections as instructed by
SORT command was a bit too complicated because it needed to handle
four different cases. This patch split it into two function calls.

This patch also simplifies the parser.

Reviewers: grimar

Subscribers: llvm-commits

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

llvm-svn: 277780
2016-08-04 22:27:00 +00:00
Rui Ueyama bdade36769 Use "llvm-objdump -s" instead of hexdump command.
llvm-svn: 277771
2016-08-04 21:23:30 +00:00
Davide Italiano d62d116add [MachO] Factor out some common code in the Driver.
llvm-svn: 277761
2016-08-04 19:56:26 +00:00
Davide Italiano 6bb5d2ddd3 [MachO/Core] Remove (now) unused static member function. NFCI.
llvm-svn: 277760
2016-08-04 19:49:11 +00:00
Rafael Espindola a4b41dca31 Remove redundant argument.
But always set Script<ELFT>::X->OutputSections.

llvm-svn: 277720
2016-08-04 12:13:05 +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 104165643e Make ScriptParser::read* functions more functional style.
Previously, many read* functions created new command objects and
add them directly to the top-level data structure. This is not
work for some commands because some commands, such as the assignment,
can appear inside and outside of the output section description.

This patch is to not append objects to the top-level data structure.
Callers are now responsible to do that.

llvm-svn: 277686
2016-08-04 02:03:27 +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
Kevin Enderby 0fa9fd0f28 Needed change to lld for the changes to libObject/Archive interfaces now returning Expected<>
for the llvm trunk change in r277656

llvm-svn: 277657
2016-08-03 21:58:48 +00:00
Rui Ueyama e7f912cd8f Create only one vector instead of two.
In this for-loop, we append elements from one vector to another,
which is a bit inefficient.

llvm-svn: 277653
2016-08-03 21:12:09 +00:00
Rui Ueyama 803568866c Rename functions that handle bitcode files.
getELFKind was overloaded with bitcode files and regular object files,
and I found that is a bit confusing. This patch renames them.

llvm-svn: 277646
2016-08-03 20:33:17 +00:00
Rui Ueyama 7fdb4389a2 Do not instantiate Triple twice.
Also removes redundant variables. NFC.

llvm-svn: 277644
2016-08-03 20:25:29 +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