Commit Graph

7698 Commits

Author SHA1 Message Date
Peter Collingbourne 4a72c38702 ELF: Align RELRO to the target page size rather than the max page size.
If no bss sections appear after the relro segment, the loader will round
the r/w segment size to the target's page size. Align the relro size in the
same way to ensure that it does not extend past the end of the program's
own memory region.

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

llvm-svn: 293519
2017-01-30 18:20:07 +00:00
George Rimar 87bf5ada39 [ELF] - Change i386 i386-pc8.s/i386-pc16.test to work with 8/16 bits values accordingly.
ld.bfd showed error on previous inputs, result values were larger than 8/16 bits,
though ld.gold accepted them.

ABI says "The R_386_16, and R_386_8 relocations truncate the computed 
value to 16-bits and 8-bits respectively".

Patch changes inputs to have result calculated values of relocations to fit 8 and 16 bits.
That can be used for implementation of more strict checks, like bfd do.

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

llvm-svn: 293479
2017-01-30 13:56:57 +00:00
Rui Ueyama 8e0c326756 Merge a few Cases using StringSwitch::Cases.
llvm-svn: 293452
2017-01-30 01:50:16 +00:00
Rui Ueyama dc0464c274 Return early from getUnresolvedSymbolOption() to simplify.
llvm-svn: 293409
2017-01-29 01:59:11 +00:00
Rafael Espindola 64e5556e9f Fix -Werror build.
llvm-svn: 293390
2017-01-28 19:07:33 +00:00
Rafael Espindola 78493a259d Fix a few symbols that are not actually ABS.
The symbols _end, end, _etext, etext, _edata, edata and __ehdr_start
refer to positions in the file and are therefore not absolute. Making
them absolute was on unfortunate cargo cult of what bfd was doing.

Changing the symbols allows for pc relocations to them to be resolved,
which should fix the wine build.

llvm-svn: 293385
2017-01-28 17:48:21 +00:00
Sylvestre Ledru 1cb3c2f82d Remove unused 'using' declaration. Found by clang-tidy: misc-unused-using-decls NFC
llvm-svn: 293380
2017-01-28 13:41:32 +00:00
Rui Ueyama f20ee9f11a Revert "[ELF][ARM] Use SyntheticSections for Thunks"
This reverts commit r293283 because it broke MSVC build.

llvm-svn: 293352
2017-01-28 00:48:06 +00:00
Rafael Espindola fe12450e8e Revert commits r293276 and r293278.
[ELF] Fixed formatting. NFC

and

    [ELF] Bypass section type check

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

They do the opposite of what was asked for in the code review.

llvm-svn: 293320
2017-01-27 18:39:30 +00:00
Rafael Espindola 403b093eff Fix and simplify the reporting of undefined symbols.
Now reportUndefined only has to look at Config->UnresolvedSymbols and
the symbol. getUnresolvedSymbolOption does all the hard work of
mapping options like -shared and -z defs to one of the
UnresolvedPolicy enum entries.

The critical fix is that now "-z defs --warn-unresolved-symbols" only
warns.

llvm-svn: 293290
2017-01-27 15:52:08 +00:00
Peter Smith 5191c6f945 [ELF][ARM] Use SyntheticSections for Thunks
Thunks are now implemented by redirecting the relocation to the
symbol S, to a symbol TS in a Thunk. The Thunk will transfer control
to S. This has the following implications:
- All the side-effects of Thunks happen within createThunks()
- Thunks are no longer stored in InputSections and Symbols no longer
  need to hold a pointer to a Thunk
- The synthetic Thunk sections need to be merged into OutputSections
    
This implementation is almost a direct conversion of the existing
Thunks with the following exceptions:
- Mips LA25 Thunks are placed before the InputSection that defines
  the symbol that needs a Thunk.
- All ARM Thunks are placed at the end of the OutputSection of the
  first caller to the Thunk.
    
Range extension Thunks are not supported yet so it is optimistically
assumed that all Thunks can be reused.

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

llvm-svn: 293283
2017-01-27 13:10:16 +00:00
Eugene Leviant bcff495b85 [ELF] Fixed formatting. NFC
llvm-svn: 293278
2017-01-27 11:06:23 +00:00
Eugene Leviant 8b7cadcf96 [ELF] Bypass section type check
Differential revision: https://reviews.llvm.org/D28761

llvm-svn: 293276
2017-01-27 11:01:43 +00:00
Simon Dardis 73190d3906 [lld][mips] Correct tests for mips64 implying PIC.
Currently LLVM can only generate PIC code for MIPS64 with the N64 as
it uses the idiom "isPositionIndependent() || IsABI_N64()" throughout the
MIPS backend. r293164 changed this, causing test failures for LLD.

This patch changes the tests minimally to preserve existing test coverage
and one case where the test was "right" in the wrong circumstance.

Reviewers: atanasyan

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

llvm-svn: 293275
2017-01-27 11:01:10 +00:00
Rafael Espindola 0b034d6f25 Fix -r when the input has a relocation with no symbol.
Should fix a few freebsd packages with dtrace.

llvm-svn: 293177
2017-01-26 14:09:18 +00:00
Rui Ueyama 80166d4afe Remove unused #include.
llvm-svn: 293144
2017-01-26 03:02:30 +00:00
Rui Ueyama 8a8a953e99 Rename NotFlags -> NegFlags.
Negative flags are still bit flags, so I think "not flag" is a very good name.

llvm-svn: 293143
2017-01-26 02:58:59 +00:00
Rui Ueyama 481ac9967b Use StringRef::lower only once instead of calling ::tolower many times.
llvm-svn: 293142
2017-01-26 02:58:39 +00:00
Rui Ueyama 24e626cc76 Split ScriptParser::readMemory.
llvm-svn: 293141
2017-01-26 02:58:19 +00:00
Davide Italiano f8ff8fca22 [ELF] Add warn-unresolved-symbols/error-unresolved-symbols options
Patch by Dmitry Mikulin.
PR: 31735

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

llvm-svn: 293139
2017-01-26 02:19:20 +00:00
Peter Collingbourne d22ec64b8a ELF: Simplify naming of object files created with save-temps.
Now we never append a number to the file name for task ID 0.

This is similar to r293132 in the gold plugin.

llvm-svn: 293138
2017-01-26 02:18:28 +00:00
Rui Ueyama ec29bee7ad Add file comments to Driver.cpp.
llvm-svn: 293130
2017-01-26 01:52:05 +00:00
Bob Haarman 25c731874d COFF: add test for /INCLUDE directives specified in bitcode
Summary: MSVC allows linker options to be specified in source code. One of these is the /INCLUDE directive, which specifies that a symbol must be added to the symbol table, even if it otherwise wouldn't be. Existing tests cover the case where the linker is given an object file with an /INCLUDE directive, but we also need to cover the case where /INCLUDE is specified in a bitcode file (as would happen when using LTO). This new test covers that case.

Reviewers: pcc, ruiu

Reviewed By: ruiu

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

llvm-svn: 293107
2017-01-25 23:07:40 +00:00
Adrian McCarthy 6b6b8c4fb9 NFC: Rename (PDB) RawSession to NativeSession
This eliminates one overload on the term Raw.

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

llvm-svn: 293104
2017-01-25 22:38:55 +00:00
Rui Ueyama bfe02642da Fix typo.
llvm-svn: 293100
2017-01-25 21:49:23 +00:00
Rui Ueyama 82a7868d4b Do not use .s extension for non-assembly files.
llvm-svn: 293096
2017-01-25 21:28:19 +00:00
Rui Ueyama 965bed8b82 Make error messages more consistent with other messages.
llvm-svn: 293095
2017-01-25 21:27:59 +00:00
Rafael Espindola c0fc253071 Change the --retain-symbols-file implementation.
It now uses the same infrastructure as symbol versions. This fixes us
creating a dynamic relocation without a corresponding dynamic symbol.

This also means that unlike gold and bfd we keep a STB_LOCAL in the
static symbol table. It seems an odd feature to offer precise control
over what is in a symbol table that is not used by the dynamic
linker. We can bring this back if needed, but it would probably be
better to just have --discard option that tells the linker to keep in
the static symbol table only what is in the dynamic one.

Should fix the eog build.

llvm-svn: 293093
2017-01-25 21:23:06 +00:00
Rui Ueyama 6ec3b468dd Remove useless cast and update a comment.
llvm-svn: 293089
2017-01-25 21:05:17 +00:00
Rafael Espindola c7b9dfaf0b Make this test more strict.
While at it, also remove unused command line options.

llvm-svn: 293084
2017-01-25 20:53:36 +00:00
Michal Gorny 30dc91a707 [cmake] Fix -rpath-link in stand-alone build
Set LLVM_LIBRARY_OUTPUT_INTDIR as expected by llvm_setup_rpath() macro
when doing stand-alone builds. This is required to pass correct
-rpath-link when linking shared libraries, and therefore ensure that
the linker can find dependency libraries correctly during the build.

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

llvm-svn: 293078
2017-01-25 19:33:14 +00:00
George Rimar f242ffa095 [ELF] - Implemented support for R_386_PC8/R_386_8 relocations.
These relocations are used in linux kernel.

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

llvm-svn: 293054
2017-01-25 13:36:49 +00:00
Peter Smith 9694376a93 [ELF] Add local mapping symbols to ARM PLT entries
Mapping symbols allow a mapping symbol aware disassembler to
correctly disassemble the PLT when the code immediately prior to the
PLT is Thumb.

To implement this we add a function to add symbols with local
binding to be defined in SyntheticSymbols.

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

llvm-svn: 293044
2017-01-25 10:31:16 +00:00
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