Commit Graph

9140 Commits

Author SHA1 Message Date
Rafael Espindola 8b250344e9 Add a special case for trivial alignment.
Normally to find the offset of a value in a section, we have to
compute the value since the alignment is defined on the final address.

If the alignment is trivial, we can skip the value computation. This
allows us to know the offset even in cases where we cannot yet know
the value.

llvm-svn: 313777
2017-09-20 17:43:44 +00:00
Rafael Espindola e4bad83edb Don't try to compute a value that is known to fail.
We try to evaluate expressions early when possible, but it is not
possible to evaluate them early if they are based on a section.

Before we would get this wrong on ABSOLUTE expressions.

llvm-svn: 313764
2017-09-20 16:42:56 +00:00
George Rimar 94444b9a07 [ELF] - Fix segfault when processing .eh_frame.
Its a PR34648 which was a segfault that happened because
we stored pointers to elements in DenseMap. 
When DenseMap grows such pointers are invalidated.
Solution implemented is to keep elements by pointer
and not by value.

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

llvm-svn: 313741
2017-09-20 09:27:41 +00:00
NAKAMURA Takumi 169dbde262 Revert rL313697, "Compact EhSectionPiece from 32 bytes to 16 bytes."
It broke selfhosting.
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/4896

llvm-svn: 313731
2017-09-20 08:03:18 +00:00
Shoaib Meenai e61ca35463 [COFF] Adjust secrel limit check
According to Microsoft's PE/COFF documentation, a SECREL relocation is
"The 32-bit offset of the target from the beginning of its section". By
my reading, the "from the beginning of its section" implies that the
offset is unsigned.

Change from an assertion to an error, since it's possible to trigger
this condition normally for input files with very large sections, and we
should fail gracefully for those instead of asserting.

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

llvm-svn: 313703
2017-09-20 00:21:58 +00:00
Shoaib Meenai 4aa7f8a30f [COFF] Check for sections larger than 4 GiB
Sections are limited to 4 GiB. Error out early if a section exceeds this
size, rather than overflowing the section size and getting confusing
assertion failures/segfaults later.

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

llvm-svn: 313699
2017-09-19 23:58:05 +00:00
Rui Ueyama 014b0f24ae Compact EhSectionPiece from 32 bytes to 16 bytes.
EhSectionPiece used to have a pointer to a section, but that pointer was
mostly redundant because we almost always know what the section is without
using that pointer. This patch removes the pointer from the struct.

This patch also use uint32_t/int32_t instead of size_t to represent
offsets that are hardly be larger than 4 GiB. At the moment, I think it is
OK even if we cannot handle .eh_frame sections larger than 4 GiB.

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

llvm-svn: 313697
2017-09-19 23:36:48 +00:00
Rui Ueyama 74ea1f0938 Rename CieRecord instance variables.
CieRecord is a struct containing a CIE and FDEs, but oftentimes the
struct itself is named `Cie` which caused some confusion. This patch
renames them `CieRecords` or `Rec`.

llvm-svn: 313681
2017-09-19 21:31:57 +00:00
Rui Ueyama faa38029e2 Simplify. NFC.
llvm-svn: 313667
2017-09-19 20:28:03 +00:00
Rafael Espindola aad64e0a1c Tweak orphan section placement.
Given a linker script that ends in

.some_sec { ...} ;
__stack_start = .;
. = . + 0x2000;
__stack_end = .;

lld would put orphan sections like .comment before __stack_end,
corrupting the intended meaning.

The reason we don't normally move orphans past assignments to . is to
avoid breaking

rx_sec : { *(rx_sec) }
. = ALIGN(0x1000);
/* The RW PT_LOAD starts here*/

but in this case, there is nothing after and it seems safer to put the
orphan section last. This seems to match bfd's behavior and is
convenient for writing linker scripts that care about the layout of
SHF_ALLOC sections, but not of any non SHF_ALLOC sections.

llvm-svn: 313646
2017-09-19 17:29:58 +00:00
George Rimar 072a43b501 [ELF] - Do not merge sections from SHT_GROUP when -relocatable
This is PR34506.

Imagine we have 2 sections the same name but different COMDAT groups:

.section        .foo,"axG",@progbits,bar,comdat
.section        .foo,"axG",@progbits,zed,comdat
When linking relocatable we do not merge SHT_GROUP sections. But still would merge
both input sections .foo into single output section .foo.
As a result we will have 2 different SHT_GROUPs containing the same section, what
is wrong.

Patch fixes the issue, preventing merging SHF_GROUP sections with any others.

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

llvm-svn: 313621
2017-09-19 09:40:31 +00:00
George Rimar af52534e8a [ELF] - Don't crash when --emit-relocs is used with --gc-sections
We crashed when --emit-relocs was used
and relocated section was collected by GC.

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

llvm-svn: 313620
2017-09-19 09:28:03 +00:00
George Rimar 696a7f9ac6 [ELF] - Introduce std::vector<InputFile *> global arrays.
This patch removes lot of static Instances arrays from different input file 
classes and introduces global arrays for access instead. Similar to arrays we
have for InputSections/OutputSectionCommands.

It allows to iterate over input files in a non-templated code.

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

llvm-svn: 313619
2017-09-19 09:20:54 +00:00
Rui Ueyama 34a0dd5283 Rename EhSectionPiece::ID -> EhSectionPiece::Sec.
ID sounds like an identifier, but this is actually a pointer to a section.

llvm-svn: 313588
2017-09-18 23:07:33 +00:00
Rui Ueyama e084aac123 Do not use inheritance for EhSectionPiece.
EhSectionPiece inherited from SectionPiece, but we did not actually use
EhSectionPiece objects as SectionPiece ojbects. They were handled as
distinct types. So it didn't make much sense to use inheritance.

llvm-svn: 313587
2017-09-18 23:07:21 +00:00
Rui Ueyama a6ff617967 Remove useless accessor.
llvm-svn: 313586
2017-09-18 23:07:09 +00:00
Zachary Turner d4401d354a [lit] Update clang and lld to use new config helpers.
NFC intended here, this only updates clang and lld's lit configs
to use some helper functionality in the lit.llvm submodule.

llvm-svn: 313579
2017-09-18 22:26:48 +00:00
Rui Ueyama 27a357c9d9 Remove redundant cast<> and null check.
"Repl" member is guranteed to have a non-null pointer. If an input
section is not merged by ICF, "Repl" points to "this". Otherwise, it
points to some other section. It must not be NULL.

llvm-svn: 313556
2017-09-18 19:15:54 +00:00
Davide Italiano 763febc44d [ELF] Remove default argument for lambda.
This is not really OK in C++11, and GCc triggers a warning.
We can switch back to default arguments when C++14 will be the
minimum version of the standard supported, see:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#974

Ack'ed by Rafael.

llvm-svn: 313550
2017-09-18 18:31:49 +00:00
George Rimar c08593a3f8 [ELF] - Fix comment. NFC.
llvm-svn: 313523
2017-09-18 09:46:18 +00:00
George Rimar 8962db9111 [ELF] - Simplify adjustSectionsBeforeSorting().
Does not seem we need to set SectionIndex here.
It is set in finalizeSections() later.

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

llvm-svn: 313522
2017-09-18 08:43:44 +00:00
Rui Ueyama eef6b2a5c9 Revert r303378: Set IMAGE_DLL_CHARACTERISTICS_NO_BIND.
r303378 was submitted because r303374 (Merge IAT and ILT) made lld's
output incompatible with the Binding feature. Now that r303374 was
reverted, we do not need to keep this change.

Pointed out by pcc.

llvm-svn: 313414
2017-09-15 22:49:13 +00:00
Rui Ueyama 02a6fc5e8f Remove redundant parentheses.
llvm-svn: 313408
2017-09-15 22:14:59 +00:00
Zachary Turner ce92db13ea Resubmit "[lit] Force site configs to run before source-tree configs"
This is a resubmission of r313270.  It broke standalone builds of
compiler-rt because we were not correctly generating the llvm-lit
script in the standalone build directory.

The fixes incorporated here attempt to find llvm/utils/llvm-lit
from the source tree returned by llvm-config.  If present, it
will generate llvm-lit into the output directory.  Regardless,
the user can specify -DLLVM_EXTERNAL_LIT to point to a specific
lit.py on their file system.  This supports the use case of
someone installing lit via a package manager.  If it cannot find
a source tree, and -DLLVM_EXTERNAL_LIT is either unspecified or
invalid, then we print a warning that tests will not be able
to run.

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

llvm-svn: 313407
2017-09-15 22:10:46 +00:00
Rui Ueyama 432342b6a8 Update the monorepo URL in a lld's document.
llvm-svn: 313396
2017-09-15 21:04:43 +00:00
Rafael Espindola e05e2f8b34 Keep some relocations with undefined weak symbols.
This fixes pr34301.

As the bug points out, we want to keep some relocations with undefined
weak symbols. This means that we cannot always claim that these
symbols are not preemptible as we do now.

Unfortunately, we cannot also just always claim that they are
preemptible. Doing so would, for example, cause us to try to create a
plt entry when we don't even have a dynamic symbol table.

What almost works is to say that weak undefined symbols are
preemptible if and only if we have a dynamic symbol table. Almost
because we don't want to fail the build trying to create a copy
relocation to a weak undefined.

llvm-svn: 313372
2017-09-15 18:05:02 +00:00
George Rimar 3580ef1120 [ELF] - Remove one of OutputSectionFactory::addInputSec().
Patch removes one of OutputSectionFactory::addInputSec methods.
That allows to simplify reporting of discarded sections and
should help to D37561.

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

llvm-svn: 313361
2017-09-15 15:44:00 +00:00
Zachary Turner 83dcb68468 Revert "[lit] Force site configs to run before source-tree configs"
This patch is still breaking several multi-stage compiler-rt bots.
I already know what the fix is, but I want to get the bots green
for now and then try re-applying in the morning.

llvm-svn: 313335
2017-09-15 02:56:40 +00:00
Rafael Espindola 056190c348 Don't make _gp absolute.
_gp points to a position in the file, so it is not really absolute. It
is also simpler to not force it to be absolute, so if there is no
strong ABI requirement we should not do it.

llvm-svn: 313333
2017-09-15 01:49:01 +00:00
Reid Kleckner 0a2016471d [COFF] Remove unused variable NFC
llvm-svn: 313330
2017-09-15 01:07:08 +00:00
Rui Ueyama 0e69bd3c3a Add tests for -out-implib.
llvm-svn: 313289
2017-09-14 19:45:22 +00:00
Rui Ueyama 1f4cdcfec9 Accept not only --foo but also -foo.
GNU ld manual says that multi-letter long option can be prefixed with
either -- or -. Therefore, we should accept not only --subsystem but
also -subsystem, for example.

There is one exception. If an option starts with "o", it should only be
prefixed with -- to avoid ambiguity with -o<filename> option.

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

llvm-svn: 313286
2017-09-14 18:33:21 +00:00
Rui Ueyama b359263011 Filenames are case-insensitive on Windows, so .DEF is the same as .def.
Differential Revision: https://reviews.llvm.org/D37823

llvm-svn: 313285
2017-09-14 18:33:09 +00:00
Zachary Turner a0e55b6403 [lit] Force site configs to be run before source-tree configs
This patch simplifies LLVM's lit infrastructure by enforcing an ordering
that a site config is always run before a source-tree config.

A significant amount of the complexity from lit config files arises from
the fact that inside of a source-tree config file, we don't yet know if
the site config has been run.  However it is *always* required to run
a site config first, because it passes various variables down through
CMake that the main config depends on.  As a result, every config
file has to do a bunch of magic to try to reverse-engineer the location
of the site config file if they detect (heuristically) that the site
config file has not yet been run.

This patch solves the problem by emitting a mapping from source tree
config file to binary tree site config file in llvm-lit.py. Then, during
discovery when we find a config file, we check to see if we have a
target mapping for it, and if so we use that instead.

This mechanism is generic enough that it does not affect external users
of lit. They will just not have a config mapping defined, and everything
will work as normal.

On the other hand, for us it allows us to make many simplifications:

* We are guaranteed that a site config will be executed first
* Inside of a main config, we no longer have to assume that attributes
  might not be present and use getattr everywhere.
* We no longer have to pass parameters such as --param llvm_site_config=<path>
  on the command line.
* It is future-proof, meaning you don't have to edit llvm-lit.in to add
  support for new projects.
* All of the duplicated logic of trying various fallback mechanisms of
  finding a site config from the main config are now gone.

One potentially noteworthy thing that was required to implement this
change is that whereas the ninja check targets previously used the first
method to spawn lit, they now use the second. In particular, you can no
longer run lit.py against the source tree while specifying the various
`foo_site_config=<path>` parameters.  Instead, you need to run
llvm-lit.py.

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

llvm-svn: 313270
2017-09-14 16:47:58 +00:00
Rui Ueyama cfc2f80df6 Remove {get,set}Align accessor functions and use Alignment member variable instead.
llvm-svn: 313204
2017-09-13 21:54:55 +00:00
Rafael Espindola c57f8cd7ea Simplify. NFC.
The isShared case was handled by the isInCurrentDSO check.

llvm-svn: 313190
2017-09-13 20:47:53 +00:00
Rafael Espindola 3d9f1c032a Add a helper for checking for weak undef. NFC.
llvm-svn: 313188
2017-09-13 20:43:04 +00:00
Rui Ueyama a835babef9 Do not use hasArgNoClaim().
Arg instances can be claimed. After claimed, its `isClaimed` function
returns true. We do not use that notion in lld, so using NoClaim
versions of functions is just confusing. This patch is to just use
hasArg instead of hasArgNoClaim.

llvm-svn: 313187
2017-09-13 20:30:59 +00:00
Rafael Espindola 3e635f2309 Use existing helper. NFC.
llvm-svn: 313184
2017-09-13 20:07:13 +00:00
Rui Ueyama 9c37d8c18b Use getUnaliasedOption so that this switch works for option aliases.
There are no alises handled by this switch, but getUnaliasesdOption is
preferred way of doing this. This is also consistent with ELF and COFF.

llvm-svn: 313180
2017-09-13 19:44:36 +00:00
Rui Ueyama 7d306a598e Move a piece of code above some local variable definitions to make their scope narrower.
llvm-svn: 313178
2017-09-13 19:40:07 +00:00
Martin Storsjo 2ba37d4b3e [MinGW] Only apply -Bstatic to following libraries
This is how the flag is documented in GNU binutils ld; -Bstatic
only applies to -l options after it, until the next -Bdynamic.

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

llvm-svn: 313175
2017-09-13 19:29:44 +00:00
Martin Storsjo 31fe4cd25d [MinGW] Support dllexport on i386
In MinGW configurations (GCC, or clang with a *-windows-gnu target),
the -export directives in the object file contains the undecorated
symbol name, while it is decorated in MSVC configurations. (On the
command line, link.exe takes an undecorated symbol name for the
-export argument though.)

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

llvm-svn: 313174
2017-09-13 19:29:39 +00:00
Rafael Espindola f6c74c472d Remove CopyRelSecOff from SharedSymbol.
This reduces the size of SharedSymbol which in turn reduces the size
of Symbol from 88 to 80 bytes.

llvm-svn: 313154
2017-09-13 16:59:12 +00:00
NAKAMURA Takumi 34fc973b08 lldMinGW itself doesn't require libpthread.
llvm-svn: 313129
2017-09-13 07:59:07 +00:00
George Rimar cb888a620d [ELF] - Refactor of Writer<ELFT>::forEachRelSec.
There is no need to scan over all input sections for relocatable output.
As we do not process or scan relocations anyways.
Patch moves check for Config->Relocatable out to avoid that and also removes
excessive check for isa<EhInputSection> from first for loop. 
It is excessive because we handle all of them in a second for loop below.
That all allowed to simplify code.

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

llvm-svn: 313127
2017-09-13 07:54:47 +00:00
Martin Storsjo 064b0fac93 [MinGW] Support creating DLLs with a def file
Differential Revision: https://reviews.llvm.org/D37761

llvm-svn: 313125
2017-09-13 07:28:13 +00:00
Martin Storsjo 32e1626a2e [MinGW] Add support for the options --[no-]whole-archive
Differential Revision: https://reviews.llvm.org/D37769

llvm-svn: 313124
2017-09-13 07:28:09 +00:00
Martin Storsjo 8278ba51d3 [COFF] Add support for the -wholearchive option
This fixes PR31824.

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

llvm-svn: 313123
2017-09-13 07:28:03 +00:00
Rafael Espindola 7415819186 Handle lazy symbols is Symbol::includeInDynsym.
This should fix the lto bootstrap.

It is somewhat hard to remember about lazy symbols deep down in the
link. It might be worth it replacing them with undefined symbols once
we are done adding files.

llvm-svn: 313103
2017-09-13 00:47:06 +00:00