Commit Graph

6536 Commits

Author SHA1 Message Date
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