Commit Graph

6401 Commits

Author SHA1 Message Date
Rui Ueyama 400fc1af43 Remove dead ctor.
llvm-svn: 277255
2016-07-30 00:13:30 +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
Lang Hames 70c80b336b [lld][MachO] Replace some std::string with char* buffers to eliminate mem leaks.
The MachO debug support code (committed in r276935) occasionally needs to
allocate string copies, and was doing so by creating std::strings on a
BumpPtrAllocator. The strings were untracked, so the destructors weren't being
run and we were leaking the memory when the allocator was thrown away. Since
it's easier than tracking the strings, this patch switches the copies to char
buffers allocated directly in the bump-ptr allocator.

llvm-svn: 277208
2016-07-29 20:04:18 +00:00
Rafael Espindola 716a94787c Don't crash if PT_TLS is empty.
llvm-svn: 277202
2016-07-29 19:24:27 +00:00
Kevin Enderby 01e41f11a7 Matching change needed to lld for llvm trunk change r277177.
Where Archive::getMemoryBufferRef() was changed to return Expected<>

llvm-svn: 277183
2016-07-29 17:56:00 +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
Rui Ueyama 1acefcd11e Remove dead declaration.
llvm-svn: 277159
2016-07-29 16:08:04 +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 c3cb884c8e [ELF] - Linkerscript: make addSection() global function instead lambda. NFC.
llvm-svn: 277150
2016-07-29 15:12:48 +00:00
George Rimar eaee2af51e [ELF] - Update comment. NFC.
llvm-svn: 277147
2016-07-29 15:07:11 +00:00
Rui Ueyama ed94271350 Remove `continue` at end of a for-loop.
llvm-svn: 277122
2016-07-29 06:21:06 +00:00
Rui Ueyama f71caa2b49 Split readOutputSectionDescription.
llvm-svn: 277121
2016-07-29 06:14:07 +00:00
Rui Ueyama 202042439c Add comments.
llvm-svn: 277116
2016-07-29 05:52:33 +00:00
Rui Ueyama 8d083e6a0a Remove `Ignore` flag from SymbolAssignment class.
Previously, Ignore flag is set if we don't want to assign
a value to symbols. It happens if a symbol assingment is in
PROVIDE() and there's already a symbol with the same name.

The previous code had a subtle but that we assume that the
existing symbol is an absolute symbol even if it is not.
This patch fixes the issue by always overwriting an absolute
symbol.

llvm-svn: 277115
2016-07-29 05:48:39 +00:00
Petr Hosek 14cd5c2405 [ELF] Allow arbitrary code alignment in .eh_frame
According to the specification, CIE code alignment factor is an
arbitrary unsigned LEB128 encoded value.

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

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

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

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

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

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

Patch implements this.

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

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

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

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

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

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

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

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

. = SEGMENT_START(seg, val);

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

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

For new this just always evaluates the expression to val.

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

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

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

So patch implements ignoring.

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

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

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

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

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

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

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

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

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

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

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

Patch implements that.

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

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

Patch implements it.

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

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

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

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

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

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

llvm-svn: 276770
2016-07-26 17:17:17 +00:00