Commit Graph

9060 Commits

Author SHA1 Message Date
Rui Ueyama 9011320921 Remove a redundant local variable.
llvm-svn: 312823
2017-09-08 19:41:35 +00:00
Rafael Espindola 8016bdfd93 Handle empty dynamic lists.
llvm-svn: 312820
2017-09-08 18:53:43 +00:00
Rafael Espindola ee6a352a8d Handle lazy symbols is computeIsPreemptible.
llvm-svn: 312812
2017-09-08 18:41:49 +00:00
Rafael Espindola 716c57bfb5 Simplify. NFC.
We handled all undefined symbols before this.

llvm-svn: 312808
2017-09-08 18:23:25 +00:00
Rafael Espindola bb468da200 Simplify as this runs before copy relocations are created.
llvm-svn: 312807
2017-09-08 18:21:14 +00:00
Rafael Espindola d72d97b3be If --dynamic-list is given, only those symbols are preemptible.
This allows combining --dynamic-list and version scripts too. The
version script controls which symbols are visible, and
--dynamic-list controls which of those are preemptible.

Unlike previous versions, undefined symbols are still considered
preemptible, which was the issue breaking the cfi tests.

This fixes pr34053.

llvm-svn: 312806
2017-09-08 18:16:59 +00:00
Dmitry Mikulin 1e30f07ce7 Currently lld creates a single section to collect all commons. There is no way
to separate commons based on file name patterns. The following linker script
construct does not work because commons are allocated before section placement
is done and the only synthesized BssSection that holds all commons has no file
associated with it:
SECTIONS { .common_0 : { *file0.o(COMMON) }}

This patch changes the allocation of commons to create a section per common
symbol and let the section logic do the layout.

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

llvm-svn: 312796
2017-09-08 16:22:43 +00:00
George Rimar 9a2da39837 [ELF] - Simplify #2. NFC.
llvm-svn: 312789
2017-09-08 13:40:07 +00:00
George Rimar 7ac3825afb [ELF] - Simplify. NFC.
llvm-svn: 312787
2017-09-08 13:26:45 +00:00
George Rimar 113a5ca029 [ELF] - Simplify and improve symbols.s testcase.
There is no need to check anything excepr that
symbol is not in output.
Previously additional iformation like symbol values
or flags were checked, that was not correct.
For example if we would provide symbol with different
value/visibility/type for case when should not provide 
symbol at all, testcase would not fail.

llvm-svn: 312779
2017-09-08 09:31:01 +00:00
George Rimar 5f37541c73 [ELF] - Linkerscript: implement REGION_ALIAS.
REGION_ALIAS(alias, region)

Alias names can be added to existing memory regions created with
the MEMORY command. Each name corresponds to at most one
memory region.

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

llvm-svn: 312777
2017-09-08 08:23:15 +00:00
Rafael Espindola 0ff545c018 Revert "Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible""
This reverts commit r312757.

Evgenii Stepanov reports that it broke some tests.

llvm-svn: 312771
2017-09-08 01:09:52 +00:00
Peter Collingbourne 052e855e2b COFF: Implement ThinLTO cache and cache pruning support.
Differential Revision: https://reviews.llvm.org/D37607

llvm-svn: 312770
2017-09-08 00:50:50 +00:00
Rui Ueyama 721b71d532 Replace CRLF.
llvm-svn: 312765
2017-09-07 23:54:32 +00:00
Rui Ueyama d63ac33948 Remove a stale comment.
llvm-svn: 312763
2017-09-07 23:54:20 +00:00
Peter Collingbourne cef809938d COFF: Remove unnecessary casts. NFCI.
llvm-svn: 312762
2017-09-07 23:49:09 +00:00
Rafael Espindola b7d0be5896 Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible"
If --dynamic-list is given, only those symbols are preemptible.

This allows combining --dynamic-list and version scripts too. The
version script controls which symbols are visible, and --dynamic-list
controls which of those are preemptible.

This fixes pr34053.

llvm-svn: 312757
2017-09-07 23:19:09 +00:00
Rui Ueyama e2f52eb22f Add -no-gdb-index which negates -gdb-index option.
llvm-svn: 312753
2017-09-07 22:40:54 +00:00
Peter Collingbourne 9e26e97955 COFF: PDB: Allow multiple modules with the same name.
It is possible for two modules to have the same name if they are
archive members with the same name, or if we are doing LTO (in which
case all modules will have the name "lto.tmp").

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

llvm-svn: 312744
2017-09-07 20:39:46 +00:00
Rafael Espindola c20759038b Drop --no-threads from tests.
The performance problem with --threads is fixed.

llvm-svn: 312738
2017-09-07 19:07:49 +00:00
Peter Smith 20489ec563 [ELF] Always write non-immediate bits for AArch64 branch instruction.
To support errata patching on AArch64 we need to be able to overwrite
an arbitrary instruction with a branch. For AArch64 it is sufficient to
always write all the bits of the branch instruction and not just the
immediate field. This is safe as the non-immediate bits of the branch
instruction are always the same.

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

llvm-svn: 312727
2017-09-07 16:29:52 +00:00
George Rimar 6823c5f0c0 [ELF] - Rename PhdrEntry::First/Last to FirstSec/LastSec. NFC.
As was suggested in D34956 thread.

llvm-svn: 312712
2017-09-07 11:01:10 +00:00
George Rimar 582ede8922 [ELF] - Store pointer to PT_LOAD instead of pointer to first section in OutputSection
It is a bit more convinent and helps to simplify logic 
of program headers allocation a little.

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

llvm-svn: 312711
2017-09-07 10:53:07 +00:00
Andrew Ng 6dee736c91 [LLD] Fix padding of .eh_frame when in executable segment
The default padding for an executable segment is the target trap
instruction which for x86_64 is 0xCC. However, the .eh_frame section
requires the padding to be zero. The code that writes the .eh_frame
section assumes that its segment is zero initialized and does not
explicitly write the zero padding. This does not work when the .eh_frame
section is in the executable segment (for example when using
-no-rosegment).

This patch changes the .eh_frame writing code to explicitly write the
zero padding.

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

llvm-svn: 312706
2017-09-07 08:43:56 +00:00
James Henderson 7594c61d2d [ELF] Prevent crash with binary inputs with non-ascii file names
If using --format=binary with an input file name that has one or more non-ascii
characters in, LLD has undefined behaviour (it crashes on my Windows Debug build)
when calling isalnum with these non-ascii characters. Instead, of calling
std::isalnum, this patch uses an internal version that ignores the locale and
checks a specific subset of characters.

Reviewers: ruiu

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

llvm-svn: 312705
2017-09-07 08:30:09 +00:00
Rafael Espindola 17e93d28f2 Simplify type. NFC.
llvm-svn: 312675
2017-09-06 22:16:32 +00:00
Davide Italiano a0186dd986 [ELF/Writer] Fix english in a comment. NFCI.
llvm-svn: 312669
2017-09-06 21:16:51 +00:00
Rui Ueyama 0440be4a42 Detect linker script INCLUDE cycles.
Differential Revision: https://reviews.llvm.org/D37524

llvm-svn: 312656
2017-09-06 18:14:08 +00:00
Rui Ueyama fd06b02558 Add a comment.
llvm-svn: 312655
2017-09-06 18:09:06 +00:00
Rui Ueyama a353d9cb18 Remove a trailing empty line that didn't end with '\n'.
llvm-svn: 312652
2017-09-06 17:41:29 +00:00
Peter Smith 1d5a070386 [ELF][AArch64] Add alignment checks for the LDST<N>_ABS_LO12_NC relocations
The R_AARCH64_LDST<N>_ABS LO12_NC relocations where N is 8, 16, 32, 64 or
128 have a scaled immediate. For example R_AARCH64_LDST32_ABS_LO12_NC
shifts the calculated value right by 4. If the target symbol + relocation
addend is not aligned properly then bits of the answer will be lost.

This change adds an alignment check to the relocations to make sure the
target of the relocation is aligned properly. This matches the behavior of
GNU ld. The motivation is to catch ODR violations such as a declaration of
extern int foo, but a definition of bool foo as the compiler may use
R_AARCH64_LDST32_ABS_LO12_NC for the former, but not align the destination.

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

llvm-svn: 312637
2017-09-06 14:23:06 +00:00
Peter Smith 3ef89b0fc7 [ELF] Move fixSectionAlignments() before first call to assignAddresses()
The fixSectionAlignments() function may alter the alignment of some
OutputSections, this is likely to alter the addresses calculated earlier
in assignAddresses(). By moving the call to fixSectionAlignments() we
make sure that assignAddresses() is consistent with the early calculation
used for RangeThunks and the final call just before writing the image.

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

llvm-svn: 312636
2017-09-06 14:02:14 +00:00
James Henderson 1304e8dd6e [ELF] Rewrite --symbol-ordering-file path in reproducer
The --symbol-ordering-file path was not being rewritten in the response file when
using --reproduce. This patch adds this to the list of switches that are rewritten,
so that the path is somewhere within the reproducer directory tree.

Reviewers: ruiu

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

llvm-svn: 312626
2017-09-06 10:10:49 +00:00
George Rimar c2dffe3aa0 [ELF] - Linkerscript: set load address correctly if MEMORY command used.
Previously LLD did not calculate LMAOffset correctly when
AT and MEMORY were used together.

Patch fixes PR34407.

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

llvm-svn: 312625
2017-09-06 09:35:09 +00:00
Eric Beckmann 0aa4b7d4c5 Fix crbug 759265 by suppressing llvm mt warnings.
Summary:
Previous would throw warning whenever libxml2 is not installed.  Now
only give this warning if merging manifest fails.

Subscribers: llvm-commits

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

llvm-svn: 312604
2017-09-06 01:50:36 +00:00
Nico Weber a05cbb8b95 lld-link: Add --rsp-quoting= flag.
This ports https://reviews.llvm.org/D19425 from clang /
https://reviews.llvm.org/D22015 from the ELF port to COFF lld. This can be
useful when linking COFF files on a posix host.

https://reviews.llvm.org/D37452

llvm-svn: 312594
2017-09-05 23:46:45 +00:00
Rui Ueyama 2ea27186b4 Use raw_string_ostream::str to get a result string.
Looks like raw_string_ostream is buffered. If we do not call `flush`
nor `str`, it is not guaranteed that a result string has all characters
that were written to it.

It wasn't failing on buildbots, but I could reproduce the issue on my
Windows workstation.

llvm-svn: 312577
2017-09-05 21:17:32 +00:00
Rui Ueyama 888da8c232 Do not use invalid iterators to fix Windows build.
std::vector::insert invalidates all iterators, so it was not safe to do

  Script->Opt.Commands.insert(++I, Make(ElfSym::End1));
  Script->Opt.Commands.insert(++I, Make(ElfSym::End2));

because after the first line, `I` is no longer valid.

This patch rewrites fixes the issue. I belive the new code without
higher-order functions is a bit more readable than before.

llvm-svn: 312570
2017-09-05 20:17:37 +00:00
Peter Collingbourne d0e9c167d8 LTO: Try to open cache files before renaming them.
It appears that a potential race between the cache client and the cache
pruner that I thought was unlikely actually happened in practice [1].
Try to avoid the race condition by opening the temporary file before
renaming it. Do this only on non-Windows platforms because we cannot
rename open files on Windows using the sys::fs::rename function.

[1] https://luci-logdog.appspot.com/v/?s=chromium%2Fbb%2Fchromium.memory%2FLinux_CFI%2F1610%2F%2B%2Frecipes%2Fsteps%2Fcompile%2F0%2Fstdout

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

llvm-svn: 312567
2017-09-05 19:51:38 +00:00
Simon Atanasyan 7644191fb1 [MIPS] Convert template parameters to function arguments. NFC
Pass BSIZE and SHIFT as a function arguments to the `writeRelocation`
routine. It does not make a sense to have so many `writeRelocation's`
instances.

llvm-svn: 312495
2017-09-04 16:16:46 +00:00
Simon Atanasyan 351cf49579 [MIPS] Add curly brackets to improve code readability. NFC.
llvm-svn: 312494
2017-09-04 16:16:41 +00:00
George Rimar 6fb163162e [ELF] - Add testcase testing .gdb_index generation when base address of CU is used.
Recently (before r312477) lib/DebugInfo incorrectly handled the case
when debug ranges uses base address of CU. Section index was not
calulcated properly and LLD crashed on provided testcase.

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

llvm-svn: 312478
2017-09-04 10:46:15 +00:00
Saleem Abdulrasool 353c57a3f6 COFF: simplify thunk handling (NFC)
Apply the simplification suggestions that Peter Collingbourne made
during the review at D37368.  The returned thunk is cast to the
appropriate type in the SymbolTable, and the constant symbol's body is
not needed directly, so avoid the assignment.  NFC

llvm-svn: 312391
2017-09-01 23:35:43 +00:00
Saleem Abdulrasool 3170ad7431 COFF: handle multiply defined symbols with different storage
If a symbol is locally defined and is DLL imported in another
translation unit, and the object with the locally defined version is
loaded prior to the imported version, then the linker will fail to
resolve the definition of the thunk and return the locally defined
symbol.  This will then be attempted to be cast to an import thunk,
which will clearly fail.

Only return the thunk if the symbol is inserted or a thunk is created.
Otherwise, report a duplication error.

llvm-svn: 312386
2017-09-01 22:12:10 +00:00
Petr Hosek 7ab9f7be0c [ELF] Set p_memsz to p_filesz when aligning the last segment to page boundary
Having p_filesz different from p_memsz is confusing some tools.

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

llvm-svn: 312384
2017-09-01 21:48:20 +00:00
Zachary Turner abb17cc084 [llvm-pdbutil] Support dumping CodeView from object files.
We have llvm-readobj for dumping CodeView from object files, and
llvm-pdbutil has always been more focused on PDB.  However,
llvm-pdbutil has a lot of useful options for summarizing debug
information in aggregate and presenting high level statistical
views.  Furthermore, it's arguably better as a testing tool since
we don't have to write tests to conform to a state-machine like
structure where you match multiple lines in succession, each
depending on a previous match.  llvm-pdbutil dumps much more
concisely, so it's possible to use single-line matches in many
cases where as with readobj tests you have to use multi-line
matches with an implicit state machine.

Because of this, I'm adding object file support to llvm-pdbutil.
In fact, this mirrors the cvdump tool from Microsoft, which also
supports both object files and pdb files.  In the future we could
perhaps rename this tool llvm-cvutil.

In the meantime, this allows us to deep dive into object files
the same way we already can with PDB files.

llvm-svn: 312358
2017-09-01 20:06:56 +00:00
George Rimar e89c5bfbc2 [ELF] - Never call splitIntoPieces() twice. NFC.
Previously it was called twice for .comment synthetic section.
That created 2 pieces of data, which was deduplicated anyways,
but was not clean.

llvm-svn: 312327
2017-09-01 12:04:52 +00:00
Petr Hosek 18821b60b0 [ELF] Generate symbol assignments for predefined symbols
The problem with symbol assignments in implicit linker scripts is that
they can refer synthetic symbols such as _end, _etext or _edata. The
value of these symbols is currently fixed only after all linker script
commands are processed, so these assignments will be using non-final and
hence invalid value.

Rather than fixing the symbol values after all command processing have
finished, we instead change the logic to generate symbol assignment
commands that set the value of these symbols while processing the
commands, this ensures that the value is going to be correct by the time
any reference to these symbol is processed and is equivalent to defining
these symbols explicitly in linker script as BFD ld does.

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

llvm-svn: 312305
2017-09-01 02:23:31 +00:00
George Rimar b08c249a4b [ELF] - Removed unused dummy methods. NFC.
llvm-svn: 312233
2017-08-31 11:05:38 +00:00
George Rimar b2051f176c [ELF] - Fix comment. NFC.
llvm-svn: 312231
2017-08-31 10:14:10 +00:00