Commit Graph

9156 Commits

Author SHA1 Message Date
Rafael Espindola 474f2bdabe Update for llvm change.
llvm-svn: 313938
2017-09-21 23:13:40 +00:00
Rafael Espindola 5329c75e4f Simplify error handling. NFC.
llvm-svn: 313930
2017-09-21 22:50:52 +00:00
Zachary Turner 0aa02c08a7 Resubmit "[lit] Refactor out some more common lit configuration code."
There were two issues, one Python 3 specific related to Unicode,
and another which is that the tool substitution for lld no longer
rejected matches where a / preceded the tool name.

llvm-svn: 313928
2017-09-21 22:16:40 +00:00
Zachary Turner 5f2fd9b783 Revert "[lit] Refactor out some more common lit configuration code."
This is breaking several bots.  I have enough information to
investigate, so I'm reverting to green until I get it figured
out.

llvm-svn: 313922
2017-09-21 21:45:45 +00:00
Zachary Turner 0d36b657b9 [lit] Refactor out some more common lit configuration code.
debuginfo-tests has need to reuse a lot of common configuration
from clang and lld, and in general it seems like all of the
projects which are tightly coupled (e.g. lld, clang, llvm, lldb,
etc) can benefit from knowing about one other.  For example,
lldb needs to know various things about how to run clang in its
test suite.  Since there's a lot of common substitutions and
operations that need to be shared among projects, sinking this
up into LLVM makes sense.

In addition, this patch introduces a function add_tool_substitution
which handles all the dirty intricacies of matching tool names
which was previously copied around the various config files.  This
is now a simple straightforward interface which is hard to mess
up.

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

llvm-svn: 313919
2017-09-21 21:27:31 +00:00
Shoaib Meenai 75d616b13f [ELF] Fix edge condition in thunk offset calculation
For ARM thunks, the `movt` half of the relocation was using an incorrect
offset (it was off by 4 bytes). The original intent seems to have been
for the offset to have been relative to the current instruction, in
which case the difference of 4 makes sense. As the code stands, however,
the offset is always calculated relative to the start of the thunk
(`P`), and so the `movw` and `movt` halves should use the same offset.
This requires a very particular offset between the thunk and its target
to be triggered, and it results in the `movt` half of the relocation
being off-by-one.

The tests here use ARM-Thumb interworking thunks, since those are the
only ARM thunks currently implemented. I actually encountered this with
a range extension thunk (having Peter's patches cherry-picked locally),
but the underlying issue is identical.

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

llvm-svn: 313915
2017-09-21 21:04:42 +00:00
Zachary Turner bbe23ae675 [lit] Rename lld and clang lit configs to end in .py
This follows in line with a previous patch of renaming LLVM's.

Working on these files is difficult in certain operating systems
and/or environments that don't like handling python code with a
non .py file extension.

llvm-svn: 313892
2017-09-21 17:38:13 +00:00
Simon Atanasyan af273f203c [MIPS] Explicitly list supported relocations for MIPS target. NFC
This is change is inspired by the D28611 patch. New supported
relocations have been added to the switch statement.

llvm-svn: 313882
2017-09-21 14:40:32 +00:00
Simon Atanasyan 6810367610 [MIPS] Restore checking of the disassembler output. NFC
llvm-svn: 313864
2017-09-21 04:55:27 +00:00
Davide Italiano bb0690e486 [AArch64] Properly check alignment for AARCH64_LD_PREL_LO19.
Follow-up suggested by Peter Smith.

llvm-svn: 313850
2017-09-21 00:26:28 +00:00
Davide Italiano 6fb3b428a4 [AArch64] Include test for out of range LD_PREL_LO19.
llvm-svn: 313846
2017-09-21 00:16:29 +00:00
Davide Italiano f681a8fa3a [AArch64] Implement R_AARCH64_ LD_PREL_LO19.
Fixes PR34660.

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

llvm-svn: 313841
2017-09-20 23:49:50 +00:00
Rafael Espindola 9e50291065 Include thin --whole-archive members in --reproduce.
We were only including the thin archive members used via a lazy symbol
before.

llvm-svn: 313832
2017-09-20 22:59:50 +00:00
Rafael Espindola 23be5e8d70 Consider ForceAbsolute again in moveAbsRight.
This patch goes back to considering ForceAbsolute in moveAbsRight, but
only if the second argument is not already absolute.

With this we can handle "foo + ABSOLUTE(foo)" and "ABSOLUTE(foo) + foo".

llvm-svn: 313800
2017-09-20 19:24:57 +00:00
Rafael Espindola 01a409520b Consider only A.Sec in moveAbsRight.
The idea of this function is to simplify the implementation of binary
operators like add.

A value might be absolute because of an ABSOLUTE expression, but it
still depends on the value of a section and we might not be able to
evaluate it early. We should keep such values on the LHS, so that we
can delay the evaluation.

We can now handle both "1 + ABSOLUTE(foo)" and "ABSOLUTE(foo) + 1".

llvm-svn: 313794
2017-09-20 18:56:08 +00:00
Rafael Espindola 9be24cf516 Fix assigning to _gp in linker scripts.
The previous logic was to try to detect if a linker script defined _gp
by checking !ElfSym::MipsGp->Value. That doesn't work in all cases as
the assigned value can be 0.

We now just always defined it Writer.cpp and always overwrite it
afterwards if needed.

llvm-svn: 313788
2017-09-20 18:30:57 +00:00
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