Commit Graph

7712 Commits

Author SHA1 Message Date
Rafael Espindola bba87168f9 Strip file path from the -o option while creating reproduce.txt.
This is a fix for Bugzilla 28579.

The problem is that in --reproduce links the file path in -o option is
copied verbatim. When "lld @response.txt" link is run against the
extracted test case, if -o contains anything other that a plain file
name, the link will likely fail because the target directory in -o may
not exists. Stripping the directory path will create the output file
in the top level test directory.

Patch by Dmitry Mikulin!

llvm-svn: 293792
2017-02-01 18:04:45 +00:00
Peter Smith 3a52eb0054 [ELF] 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.

This is a recommit of r293283 with a fixed comparison predicate as
std::merge requires a strict weak ordering.

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

llvm-svn: 293757
2017-02-01 10:26:03 +00:00
George Rimar 697507556a [ELF] - Recommit r293749. Improve comment. NFC.
llvm-svn: 293751
2017-02-01 09:14:22 +00:00
George Rimar 091f9b35c7 [ELF] - Revert r293749
Accidentally lost the commit title and message,
will recommit.

llvm-svn: 293750
2017-02-01 09:12:29 +00:00
George Rimar f46e54f078 (no commit message)
llvm-svn: 293749
2017-02-01 09:05:45 +00:00
George Rimar cc4d3e5745 [ELF] - Linkerscript: properly mark minus expression with non-absolute flag
This is alternative to D28857 which was incorrect.

One of linux scripts contains:

vvar_start = . - 2 * (1 << 12);
vvar_page = vvar_start;
vvar_vsyscall_gtod_data = vvar_page + 128;
Previously we did not mark first expression as non-absolute,
though it contains location counter.

And LLD failed with error:
relocation R_X86_64_PC32 cannot refer to absolute symbol

This patch should fix the issue, and opens road for doing the same for other operators
(though not clear if that is needed).

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

llvm-svn: 293748
2017-02-01 09:01:16 +00:00
Rui Ueyama eb1ad400f9 Print alignment in decimal instead of hexadecimal.
Previously, we were printing out something like this for
sections/symbols with alignment 16

  0000000000201000 0000000000000182    10 .data

which I think confusing. I think printing it in decimal is better.

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

llvm-svn: 293685
2017-01-31 20:42:34 +00:00
Rui Ueyama 59a7ceebb3 Check R_386_{PC,}{8,16} for overflow.
It is not clear what we should do when overflow occurs for these
relocations because the relocations are not an official part of
the i386 psABI. But checking for overflow is generally a good to do
and is consistent with other relocations such as R_X86_64_8.

llvm-svn: 293683
2017-01-31 20:28:32 +00:00
George Rimar 7d9eaf713c [ELF] - Report filename for unknown relocation error.
Our reporting for that case was just like:
ld.lld: error: do not know how to handle relocation 'R_386_PC8' (23)
It did not give any information about error location.

Patch adds filename to error.

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

llvm-svn: 293640
2017-01-31 15:37:51 +00:00
Michal Gorny da7ceb5e1b [cmake] Support running tests in stand-alone builds
Add the CMake bits necessary to run lld tests (and unittests) when
building stand-alone. The code is based on the equivalent code in clang,
and includes:

1. checking for Python, searching for lit and necessary LLVM test tools
(FileCount and not),

2. building LLVM test tools (FileCount and not) from LLVM sources if
they are not installed,

3. building gtest libraries from LLVM sources,

4. adjusting dependencies so that test targets depend only on those LLVM
targets that are available for a particular variant of stand-alone
build.

With this patch, I am able to successfully run 1002 (+10 unsupported)
lit tests on Gentoo using installed LLVM.

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

llvm-svn: 293630
2017-01-31 14:10:20 +00:00
Eugene Leviant 0c0789bc3f [ELF] Bypass section type check #2
Differential revision: https://reviews.llvm.org/D29278

llvm-svn: 293613
2017-01-31 10:26:52 +00:00
George Rimar 2fe079233b [ELF] - Linkerscript: do not fail on additional semicolons in linkerscript.
Linux kernel linkerscript contains additional semicolon (last line):

.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
  __apicdrivers = .;
  *(.apicdrivers);

I checked that both gold and bfd are able to parse something like:

.text : { ;;*(.text);;S = 0;; } }

Patch do the same.

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

llvm-svn: 293612
2017-01-31 08:50:11 +00:00
Rafael Espindola 6138cf87ce Make the test future proof.
It currently depends on the fact that we don't concatenate merge
sections with the same name but different properties.

llvm-svn: 293583
2017-01-31 01:38:48 +00:00
Peter Collingbourne f8c065fde2 Add missing aarch64 requirement.
llvm-svn: 293529
2017-01-30 18:49:38 +00:00
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