Commit Graph

7665 Commits

Author SHA1 Message Date
Rui Ueyama 8981f3aacf Add a file comment to SyntheticSections.h.
llvm-svn: 292980
2017-01-24 21:35:25 +00:00
George Rimar 3a934abe48 [ELF] - Fixed crash after incrementing end iterator.
Next code crashed under MSVS2015 for me:
this->OutSec->Info = this->Info = 1 + It - Symbols.begin();

Because It was end() and addition of 1 is not allowed. 
vector implementation catched and failed that inside:

_Myiter& operator+=(difference_type _Off)
{	// increment by integer
 #if _ITERATOR_DEBUG_LEVEL == 2
if (this->_Getcont() == 0
	|| this->_Ptr + _Off < ((_Myvec *)this->_Getcont())->_Myfirst
	|| ((_Myvec *)this->_Getcont())->_Mylast < this->_Ptr + _Off)
   {	// report error
	_DEBUG_ERROR("vector iterator + offset out of range");
	_SCL_SECURE_OUT_OF_RANGE;

llvm-svn: 292940
2017-01-24 16:07:18 +00:00
Peter Smith ccb34efa92 [ELF] Correct sh_info for static symbol table
The sh_info field of the SHT_SYMTAB section holds the index for the
first non-local symbol. When there are global symbols that are output
with STB_LOCAL binding due to having hidden visibility or matching
the local version from a version script, the calculated value of
NumLocals + 1 does not account for them. This change accounts for
global symbols being output with local binding.

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

llvm-svn: 292910
2017-01-24 10:43:40 +00:00
Pavel Labath dbcc04a5fa [lld][cmake] Fix BUILD_SHARED_LIBS installation
Summary:
This fixes a regression caused by D28397, which switched lld from using
add_llvm_library to llvm_add_library. The latter does not automatically set up
install rules for libraries, as it's expected the project will set them up
manually based on its own needs.

This adds the install rules to add_lld_library for lld. They were inspired by
the similar add_clang_library macro in clang.

Reviewers: ruiu, beanz, davidlt, EricWF, dtzWill

Subscribers: mgorny, llvm-commits

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

llvm-svn: 292909
2017-01-24 10:41:02 +00:00
George Rimar e3c2051d27 [ELF] - Added additional comments on top of r292789 (D29021)
It was requested during post commit review.

llvm-svn: 292903
2017-01-24 09:31:02 +00:00
Rui Ueyama b2a23cf3c0 Do not allocate space for common symbols with -r
Currently ld.lld -r allocates space for common symbols, whereas ld.bfd
-r doesn't.  As a result the OpenBSD makefile bits for creating libraries
fail as they use ld -X -r to strip local symbols, which results in
duplicate symbol errors because space for the common symbols has been
allocated.

The diff also implements the --define-commons option such that allocation
of commons can be forced even if -r is used.

Patch by Mark Kettenis.

llvm-svn: 292878
2017-01-24 03:41:20 +00:00
Meador Inge b889744e5b [LinkerScript] Implement `MEMORY` command
As specified here:

* https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY

There are two deviations from what is specified for GNU ld:

  1. Only integer constants and *not* constant expressions
     are allowed in `LENGTH` and `ORIGIN` initializations.

  2. The `I` and `L` attributes are *not* implemented.

With (1) there is currently no easy way to evaluate integer
only constant expressions.  This can be enhanced in the
future.

With (2) it isn't clear how these flags map to the `SHF_*`
flags or if they even make sense for an ELF linker.

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

llvm-svn: 292875
2017-01-24 02:34:00 +00:00
George Rimar 23be5d94eb [ELF] - Committed missing ld.ldd invocation to constructor.s
Thanks to Meador Ingle for noticing.

llvm-svn: 292799
2017-01-23 16:55:13 +00:00
George Rimar 190bac5d51 [ELF] - Stop handling local symbols in a special way.
Previously we stored kept locals in a KeptLocalSyms arrays,
belonged to files.

Patch makes SymbolTableSection to store locals in Symbols member,
that already present and was used for globals.
SymbolTableSection already had NumLocals counter member, so change
itself is trivial.

That allows to simplify handling of -r,
Body::DynsymIndex is no more used as "symbol table index" for relocatable
output.

Change was suggested during review of D28773 and opens road for D28612.

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

llvm-svn: 292789
2017-01-23 14:07:23 +00:00
George Rimar 8e2eca229e [ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.
It is used in linux kernel script:
http://lxr.free-electrons.com/source/arch/x86/kernel/vmlinux.lds.S#L140

Though CONSTRUCTORS is ignored for ELF.

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

llvm-svn: 292777
2017-01-23 09:36:19 +00:00
Sean Silva 69d65ac44b [docs] Fix typo in section heading.
llvm-svn: 292750
2017-01-22 03:28:56 +00:00
Zachary Turner 18de36bc90 Fix failing lld pdb test.
llvm-svn: 292673
2017-01-20 22:57:24 +00:00
Zachary Turner 760ad4da60 [pdb] Write the Named Stream mapping to Yaml and binary.
Differential Revision: https://reviews.llvm.org/D28919

llvm-svn: 292665
2017-01-20 22:42:09 +00:00
Rafael Espindola 0347c0b874 Don't create a bogus PT_PHDR if we don't allocate the headers.
llvm-svn: 292644
2017-01-20 20:46:15 +00:00
Rafael Espindola 8c495e20bd Reduce code duplication when allocating program headers.
This will simplify a bug fix.

llvm-svn: 292642
2017-01-20 20:41:18 +00:00
Rafael Espindola 338def1506 Simplify. NFC.
addIgnored already creates the symbol only if there is a reference to
it.

llvm-svn: 292628
2017-01-20 18:20:37 +00:00
Peter Smith 94b999b9df [ELF] Cleanup createThunks() NFC.
Include removal of call to getThunkExpr() as it has already been
called and recorded by scanRelocs()
    
Cleanup suggestions by Rafael.

llvm-svn: 292614
2017-01-20 15:25:45 +00:00
George Rimar 60aed44387 [ELF] - Do not crash when assign common symbol's values in script
Found that during attempts of linking linux kernel,
previously we partially duplicated code from getOutputSection(),
and it missed commons symbol case.

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

llvm-svn: 292594
2017-01-20 09:45:36 +00:00
Peter Collingbourne dbd8d9b5a2 ELF: Fix ICF crash on absolute symbol relocations.
If two sections contained relocations to absolute symbols with the same
value we would crash when trying to access their sections. Add a check that
both symbols point to sections before accessing their sections, and treat
absolute symbols as equal if their values are equal.

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

llvm-svn: 292578
2017-01-20 04:58:12 +00:00
Rafael Espindola 2c87688c70 Also define 'end' if it is present in a .so.
I don't know of anything using it, but we should handle it like _end.

llvm-svn: 292513
2017-01-19 19:51:02 +00:00
Rafael Espindola b92e99cc1e Create _end symbol even if a .so defines it.
The freebsd sbrk implementation uses _end to find the initial value of
brk, so it has to be defined in the main binary.

This should fix the emacs build.

llvm-svn: 292512
2017-01-19 19:43:34 +00:00
Peter Smith ee6d7186c3 [ELF] Move createThunks() after scanRelocations()
A necessary first step towards range extension thunks is to delay
the creation of thunks until the layout of InputSections within
OutputSections has been done.
    
The change scans the relocations directly from InputSections rather
than looking in the ELF File the InputSection came from. This will
allow a future change to redirect the relocations to symbols defined
by Thunks rather than indirect when resolving relocations.
    
A side-effect of moving ThunkCreation is that the OutSecOff of
InputSections may change in an OutputSection that contains Thunks.
In well behaved programs thunks are not in OutputSections with
dynamic relocations.
    
Differential Revision: https://reviews.llvm.org/D28811

llvm-svn: 292359
2017-01-18 09:57:14 +00:00
Rui Ueyama 40eaa9968d Return early if writeMapFile failed.
This patch adds a test for an invalid output path for -Map option,
though that test is not for verifying that we are using error()
instead of fatal() in writeMapFile.

llvm-svn: 292336
2017-01-18 03:34:38 +00:00
Peter Collingbourne ae30386fb3 ELF: Add support for relocation type R_X86_64_8.
Although this relocation type is not part of the x86-64 psABI, I intend to
use it internally as part of the ThinLTO implementation.

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

llvm-svn: 292330
2017-01-18 02:20:53 +00:00
Bob Haarman 6c8f736ba7 COFF: add error() and warn() to Error.{cpp,h}
Summary: This copies over some functionality we have in ELF/Error.{cpp,h} and makes it available in COFF/Error.{cpp,h}

Reviewers: pcc, rafael, ruiu

Subscribers:

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

llvm-svn: 292240
2017-01-17 19:07:42 +00:00
Rafael Espindola 1d6d1b44cc Add a isInCurrentDSO helper. NFC.
llvm-svn: 292228
2017-01-17 16:08:06 +00:00
George Rimar 7185a1acec [ELF] - Support optional comma after output section command.
I found this when tried to link linux kernel with LLD:

https://github.com/torvalds/linux/blob/master/arch/x86/entry/vdso/vdso-layout.lds.S#L86

Output section command can have optional comma at the end:

.text		: { *(.text*) }			:text	=0x90909090,

It was documented about 3 years ago for binutils:
https://sourceware.org/ml/binutils/2014-04/msg00045.html

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

llvm-svn: 292225
2017-01-17 15:32:12 +00:00
George Rimar 4b0253af7e [ELF] - Fix for huge-temporary-file.s
Removed mentioning of checks. Sorry for noise.

llvm-svn: 292221
2017-01-17 14:06:44 +00:00
George Rimar ad530b2ac7 [ELF] - Added huge-temporary-file.s testcase.
Inputs shown in that testcase previously created
a huge temporarily file under 32 bits.

It was fixed by D28107. During review was suggested to
add a testcase even without CHECKs for documentation purposes.

Patch do that.

llvm-svn: 292220
2017-01-17 14:04:16 +00:00
George Rimar 2ddab6d186 [ELF] - Do not create huge garbage files on section offset overflow.
Patch changes behavior to not try open the output 
file if we already know about error.

That is not just cleaner, but also fixes nasty behavior of linker that
could create huge temporarily files under certain conditions.

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

llvm-svn: 292219
2017-01-17 13:50:34 +00:00
Davide Italiano 51aff488e5 [ELF] __cxa_demangle is now called itaniumDemangle. Update.
llvm-svn: 292182
2017-01-17 01:59:13 +00:00
Simon Atanasyan 2bd98af563 [ELF][MIPS] Exclude mips .got from PT_GNU_RELRO segment
On MIPS .got section cannot be included into the PT_GNU_RELRO segment.
Sometimes it might work, but in general it is unsupported. One of the
problem is that all sections marked by SHF_MIPS_GPREL should be grouped
together because data in these sections is addressable with a gp
relative address, but such sections might be writable.

This patch exclude mips .got from PT_GNU_RELRO segment and group
SHF_MIPS_GPREL sections.

llvm-svn: 292161
2017-01-16 21:17:23 +00:00
Simon Atanasyan 97a42ea896 [ELF][MIPS] Remove redundant checkings from test cases. NFC
llvm-svn: 292160
2017-01-16 21:17:09 +00:00
Rafael Espindola 41a93a3edf Give priority to linker scripts over preemption.
LLD exports symbols that are also present in used shared libraries to
make sure they are preempted at runtime. That is a reasonable default,
but we must allow for it to be overwritten with linker script. If we
don't, libraries that expect to be able to hide a c++ delete operator
will fail.

This should fix the firebird build.

llvm-svn: 292146
2017-01-16 17:35:23 +00:00
George Rimar 548adcdec4 [COFF] - Fixed format in writeOutSecLine()
The same as https://reviews.llvm.org/rL292102,
fixes next testcases under msvs2015/win32:

25>  Failing Tests (3):
25>      lld :: COFF/lldmap.test
25>      lld :: COFF/weak-external.test
25>      lld :: COFF/weak-external3.test

llvm-svn: 292104
2017-01-16 11:46:55 +00:00
George Rimar 07d94e3529 [ELF] - Fix format specifiers in writeOutSecLine()
I had a error in map-file.s testcase under MSVS2015/win32:

map-file.s:30:16: error: expected string not found in input
// CHECK-NEXT: 0000000000200158 0000000000000030 8 .eh_frame

<stdin>:2:1: note: scanning from here
0000000000200158 10 30 .eh_frame

Format string '%0*x' requires an argument of type 'unsigned int',
but argument has type 'uint64_t'. Proper format is '%0*llx' then.

This fixes testcase failture for me.

llvm-svn: 292102
2017-01-16 11:35:38 +00:00
Rui Ueyama c9807c3370 Use error() instead of fatal() to handle file open error.
llvm-svn: 292090
2017-01-16 01:07:19 +00:00
Rui Ueyama 71e3e3a5c1 Move a flag definition to the right place as -demangle is not ignored.
llvm-svn: 292049
2017-01-15 03:45:46 +00:00
Rui Ueyama ea3f6c3a7e Add -no-{export-dynamic,fatal-warnings}.
llvm-svn: 292048
2017-01-15 03:38:55 +00:00
Rui Ueyama 1705f99c77 Add -print-map and -M options.
llvm-svn: 292046
2017-01-15 02:52:34 +00:00
Rui Ueyama 9c6cdc2022 Add a help text for -Map.
llvm-svn: 292045
2017-01-15 02:52:14 +00:00
Rui Ueyama c9df172553 Fix typo.
llvm-svn: 292044
2017-01-15 02:34:42 +00:00
Rui Ueyama 483ffa3365 Simplify string output. NFC.
llvm-svn: 292042
2017-01-15 01:11:47 +00:00
Rui Ueyama 543731f96a Directly write to a -Map file.
Previous code had a bug that if the program exits with an assert() or
fail() before the control reaches end of writeMapFile(), it leaves a
temporary file, because FileRemover's dtor isn't called in that case.

I could fix that by removeFileOnSignal() and other functions, but
I think we can simply write to the result file directly. I think
that is straightforward and easy to understand.

Additionally, that allows something like `-Map /dev/null` or a bash
hack such as `-Map >(grep symbol-im-looking-for)`. Previously,
that kind of things didn't work.

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

llvm-svn: 292041
2017-01-15 00:41:21 +00:00
Peter Collingbourne 6f24fdb6a0 COFF: Change the /lldmap output format to be more like the ELF linker.
Differential Revision: https://reviews.llvm.org/D28717

llvm-svn: 291990
2017-01-14 03:14:46 +00:00
Rafael Espindola 7c783a49a2 Try to fix the windows bots.
llvm-svn: 291989
2017-01-14 02:45:53 +00:00
Rui Ueyama db540ff057 Split writeMapFile2 to reduce indentation level.
llvm-svn: 291984
2017-01-14 00:37:28 +00:00
Bob Haarman 848c569734 COFF: include relocation type in unsupported relocation message
Summary: When we encouter a relocation type we don't know how to handle, this change causes us to print out the hexadecimal value of the relocation type. This makes troubleshooting a little easier.

Reviewers: ruiu, zturner

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

llvm-svn: 291962
2017-01-13 22:05:22 +00:00
Rafael Espindola 1ebfc59c89 Implement -Map.
The format is not exactly the same as the one in bfd since bfd always
follows a linker script and prints it along.

llvm-svn: 291958
2017-01-13 21:05:46 +00:00
Rafael Espindola 8a59f5c79f Don't add DT_INIT/DT_FINI for undef and shared symbols.
The freebsd dynamic linker doesn't check if the value is null (and it
is reasonable for it to do that). That means that producing a .so with
a null DT_INIT/DT_FINI causes the base address to be called.

This should fix the libreoffice build.

llvm-svn: 291944
2017-01-13 19:18:11 +00:00