Commit Graph

7737 Commits

Author SHA1 Message Date
George Rimar 60ca31dff8 [ELF] - Simplify i386-ps8.s testcase.
Removes dependency on second input file.

llvm-svn: 294178
2017-02-06 09:25:56 +00:00
Rui Ueyama 7ddd7a8b76 Use a utility function to reduce repetition. NFC.
llvm-svn: 294117
2017-02-05 05:18:58 +00:00
Bob Haarman cd7197fec3 fix nullptr dereference in COFF/Symbol.h
llvm-svn: 294064
2017-02-03 23:05:17 +00:00
Rafael Espindola 2b07455315 Simplify. NFC.
Now that each OutputSectionCommand maps to just one OutputSection, we
can remove a few std::vectors.

llvm-svn: 294060
2017-02-03 22:27:05 +00:00
Rafael Espindola cfe53dff72 Simplify. NFC.
llvm-svn: 294057
2017-02-03 21:59:15 +00:00
Rafael Espindola c06f54122e Don't worry about dropping SHF_MERGE.
Now that it doesn't impact which sections are merged, this is not a
problem.

llvm-svn: 294054
2017-02-03 21:50:40 +00:00
Rafael Espindola 2532431332 Stop propagating Entsize.
Now that we combine multiple synthetic merge section into one output
section there is no point in trying to propagate a value.

llvm-svn: 294048
2017-02-03 21:29:51 +00:00
Rafael Espindola 4524268c02 Handle numbers followed by ":" in linker scripts.
This is a fix for Bugzilla 31813.

The problem is that the tokenizer does not create a separate token for
":" unless there's white space before it. Changed it to always create
a token for ":" and reworked some logic that relied on ":" being
attached to some tokens like "global:" and "local:".

llvm-svn: 294006
2017-02-03 13:24:01 +00:00
Rafael Espindola 9e9754b520 Replace MergeOutputSection with a synthetic section.
With a synthetic merge section we can have, for example, a single
.rodata section with stings, fixed sized constants and non merge
constants.

I can be simplified further by not setting Entsize, but that is
probably better done is a followup patch.

This should allow some cleanup in the linker script code now that
every output section command maps to just one output section.

llvm-svn: 294005
2017-02-03 13:06:18 +00:00
Ismail Donmez 82c489f2a6 Fix shared build after r293965 (Core) and r293967 (COFF)
llvm-svn: 293996
2017-02-03 10:13:39 +00:00
Mehdi Amini 1380edf4ef Revert "[ThinLTO] Add an auto-hide feature"
This reverts commit r293970.

After more discussion, this belongs to the linker side and
there is no added value to do it at this level.

llvm-svn: 293993
2017-02-03 07:41:43 +00:00
Bob Haarman 37c22a3ecb added missing dependency on intrinsics_gen to lib/Core
llvm-svn: 293986
2017-02-03 00:53:57 +00:00
Mehdi Amini b0a8ff71e5 [ThinLTO] Add an auto-hide feature
When a symbol is not exported outside of the
DSO, it is can be hidden. Usually we try to internalize
as much as possible, but it is not always possible, for
instance a symbol can be referenced outside of the LTO
unit, or there can be cross-module reference in ThinLTO.

This is a recommit of r293912 after fixing build failures,
and a recommit of r293918 after fixing LLD tests.

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

llvm-svn: 293970
2017-02-03 00:32:38 +00:00
Bob Haarman cde5e5b600 refactor COFF linker to use new LTO API
Summary: The COFF linker previously implemented link-time optimization using an API which has now been marked as legacy. This change refactors the COFF linker to use the new LTO API, which is also used by the ELF linker.

Reviewers: pcc, ruiu

Reviewed By: pcc

Subscribers: mgorny, mehdi_amini

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

llvm-svn: 293967
2017-02-02 23:58:14 +00:00
Bob Haarman fbc229dc8f added missing files for r293965
llvm-svn: 293966
2017-02-02 23:53:10 +00:00
Bob Haarman 35989d6be5 add the ability to call InitTargetOptionsFromCodeGenFlags from multiple objects
Summary: llvm/CodeGen/CommandFlags.h a utility function InitTargetOptionsFromCodeGenFlags which is used to set target options from flags based on the command line. The command line flags are stored in globals defined in the same file, and including the file in multiple places causes the globals to be defined multiple times, leading to linker errors. This change adds a single place in lld where these globals are defined and exports only the utility function. This makes it possible to call InitTargetOptionsFromCodeGenFlags from multiple places in lld, which a follow-up change will do.

Reviewers: davide, ruiu

Reviewed By: davide, ruiu

Subscribers: mgorny

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

llvm-svn: 293965
2017-02-02 23:49:16 +00:00
Rui Ueyama 6697ec293c Update comments.
llvm-svn: 293963
2017-02-02 23:26:12 +00:00
Rafael Espindola 7d99f827b0 Update for llvm change.
llvm-svn: 293937
2017-02-02 21:26:23 +00:00
Rui Ueyama 98469e4de5 Accept `-trace-symbol foo` as well as `-trace-symbol=foo`.
llvm-svn: 293854
2017-02-02 02:21:47 +00:00
Rui Ueyama 9255b91a2b Make `-z stack-size` compatible with ld.bfd.
ld.bfd doesn't handle `-z stack-size=0` as a special case.
We shouldn't do that too.

llvm-svn: 293849
2017-02-02 01:12:45 +00:00
Rui Ueyama a9b29615fb Re-submit r293820: Return Error instead of bool from mergeTypeStreams().
llvm-svn: 293847
2017-02-02 00:47:10 +00:00
Rui Ueyama db00b61860 Simplify createPhdrs. NFC.
Instead of creating multiple PHDRs in a single loop, this patch
runs one for loop for each PHDR type. I think this improves code
readability.

llvm-svn: 293832
2017-02-01 22:42:17 +00:00
Rui Ueyama 7d07a1652d Revert r293820: Return Error instead of bool from mergeTypeStreams().
It broke buildbots.

llvm-svn: 293824
2017-02-01 22:28:43 +00:00
Rui Ueyama 00d4f49717 Return Error instead of bool from mergeTypeStreams().
Previously, mergeTypeStreams returns only true or false, so it was
impossible to know the reason if it failed. This patch changes the
function signature so that it returns an Error object.

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

llvm-svn: 293820
2017-02-01 22:09:34 +00:00
Petr Hosek 4d65ef3be1 [ELF] Handle multiple discontiguous .note sections
There could be multiple discontiguous output .note sections in which
case we need to put these into separate PT_NOTE segments rather then
placing them into a single segment. Where possible, we could reorder
the input sections to make sure that all .note are layed out next to
each other to avoid creation multiple PT_NOTE segments, but even in
that case, it's still possible to construct a discontiguous case e.g.
by using a linker script.

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

llvm-svn: 293811
2017-02-01 20:58:41 +00:00
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