Commit Graph

9035 Commits

Author SHA1 Message Date
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
Rui Ueyama 01d0265106 Simplify writeArchive return type.
writeArchive returned a pair, but the first element of the pair is always
its first argument on failure, so it doesn't make sense to return it from
the function. This patch change the return type so that it does't return it.

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

llvm-svn: 312177
2017-08-30 22:11:03 +00:00
Rui Ueyama c1e101f356 Revert r312171: Support nested static libraries.
This reverts commit r312171 because it is pointed out that that's not a
correct fix (see https://bugs.llvm.org/show_bug.cgi?id=32674#c14) and
also because it broke buildbots.

llvm-svn: 312174
2017-08-30 21:22:59 +00:00
Rui Ueyama a68748659a Support nested static libraries.
MSVC link.exe supports nested static libraries. That is, an .a file can
contain other .a file as its member. It is reported that MySQL actually
depends on this feature.

Fixes https://bugs.llvm.org/show_bug.cgi?id=32674

llvm-svn: 312171
2017-08-30 20:55:41 +00:00
Rui Ueyama f59b709ae4 Move a function from Driver.cpp to InputFile.cpp.
This patch doesn't improve code per se, but it should make the following
patch's diff easier to read.

llvm-svn: 312170
2017-08-30 20:55:18 +00:00
Rui Ueyama 38eab87671 Add -no-eh-frame-hdr which negates -eh-frame-hdr.
Note that ld.bfd and ld.gold have the option.

llvm-svn: 312010
2017-08-29 16:53:24 +00:00
George Rimar db21e5324a [ELF] - Linkerscript: add test for checking interaction with archive files.
Imagine we have archive file with symbols foo and bar.
And script that do foo = 1.
In that case correct behavior is not to fetch symbols from archive but
create absolute symbol. 
If we have script zed = foo then symbol foo will be fetched from archive.
Currently we have Opt.ReferencedSymbols list of symbols referenced
by script and create them undefined early. That allows archives fetching logic 
to work. That is what LLD already do and it seems everything is fine here.

But during writing D37059 I had to add left side of assignments to
Opt.ReferencedSymbols list because wanted to stop optimizing out
these symbols when LTO is involved (LTO also uses this list). 
And testcase from this patch would have fail if we would have it before.

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

llvm-svn: 312004
2017-08-29 15:05:14 +00:00
George Rimar 68980850d7 [ELF] - Mention -fPIC in some error messages.
This is PR32429.

We did not mention -fPIC in error about producing dynamic relocation
in readonly segment before. Patch changes that.

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

llvm-svn: 312003
2017-08-29 15:03:01 +00:00
Rui Ueyama 5ac94e768b Rewrite std::equal as plain for-loops.
Looks like there's no need to use a higher order function. We can simply
use the regular for-loop.

llvm-svn: 311942
2017-08-28 22:28:41 +00:00
Rui Ueyama cbf969eb20 Remove Symtab aliases.
Various classes have `Symtab` member variables even though we have
lld::coff::Symtab variable because previous attempts to make COFF lld's
internal structure resemble to ELF's was incomplete. This patch finishes
that job by removing member variables.

llvm-svn: 311938
2017-08-28 21:51:07 +00:00
Rui Ueyama affb40e9d2 Keep an instance of COFFOptTable alive as long as InputArgList is alive.
Summary:
ArgParser created an instance of COFFOptTable on stack to use it to
parser command line arguments. Parsed arguments were then returned from
the function as InputArgList. This was safe because InputArgList referred
only statically-allocated InfoTable.

That is not a safe assumption after https://reviews.llvm.org/D36782,
which changes the type of its internal table from ArrayRef to std::vector.
To make lld work with that patch, we need to keep an instance of
COFFOptTable at least as long as an InputArgList is alive. This patch
does that.

Reviewers: yamaguchi

Subscribers: llvm-commits

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

llvm-svn: 311930
2017-08-28 20:46:30 +00:00
Simon Atanasyan 3876077ac7 [MIPS] Remove unused function's argument. NFC
llvm-svn: 311889
2017-08-28 14:40:53 +00:00
George Rimar 60608a8ae5 [ELF] - Simplify (use llvm::erase_if). NFC.
llvm-svn: 311878
2017-08-28 09:28:15 +00:00
Rui Ueyama ea65b5aa49 [MACH-O] Fix the ASM code generated for __stub_helpers section
Patch by Patricio Villalobos.

I discovered that lld for darwin is generating the wrong code for lazy
bindings in the __stub_helper section (at least for osx 10.12). This is
the way i can reproduce this problem, using this program:

  #include <stdio.h>

  int main(int argc, char **argv) {
      printf("C: printf!\n");
      puts("C: puts!\n");
      return 0;
  }

Then I link it using i have tested it in 3.9, 4.0 and 4.1 versions:

  $ clang -c hello.c
  $ lld -flavor darwin hello.o -o h1  -lc

When i execute the binary h1 the system gives me the following error:

  C: printf!
  dyld: lazy symbol binding failed:
  BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
  has segment 4 which is too large (0..3)
  dyld: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too
  large (0..3)
  Trace/BPT trap: 5

Investigating the code, it seems that the problem is that the asm code
generated in the file StubPass.cpp, specifically in the line 323,when it
adds, what it seems an arbitrary number (12) to the offset into the lazy
bind opcodes section, but it should be calculated depending on the
MachONormalizedFileBinaryWrite::lazyBindingInfo result.

I confirmed this bug by patching the code manually in the binary and
writing the right offset in the asm code (__stub_helper).

This patch fixes the content of the atom that contains the assembly code
when the offset is known.

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

llvm-svn: 311734
2017-08-24 23:51:40 +00:00
Dmitry Mikulin f300ca211f Currently lld uses base names of files to match against file patterns in
linker script SECTION rules. This patch extends it to use a fully specified
file name as it appears in --trace output to match agains, i.e,
"<path>/<objname>.o" or "<path>/<libname>.a(<objname>.o)".

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

llvm-svn: 311713
2017-08-24 22:01:40 +00:00
Simon Atanasyan 1998f859dc [MIPS] Merge multiple functions for writing relocation result into the single one. NFC
llvm-svn: 311712
2017-08-24 21:57:03 +00:00
Simon Atanasyan c5455e237f [MIPS] Keep all code read addends in the `getImplicitAddend` function
Currently LLD reads the R_MIPS_HI16's addends in the `computeMipsAddend`
function, the R_MIPS_LO16's addends in both `computeMipsAddend` and
`getImplicitAddend` functions. This patch moves reading all addends to
the `getImplicitAddend` function. As a side effect it fixes a "paired"
HI16/LO16 addend calculation if "LO16" part of a pair is not found.

llvm-svn: 311711
2017-08-24 21:56:58 +00:00
Simon Atanasyan 204cae99bb [MIPS] Remove redundant function getPcRelocAddend. NFC
llvm-svn: 311710
2017-08-24 21:56:52 +00:00
Rui Ueyama 8bee41e423 Simplify. NFC.
llvm-svn: 311700
2017-08-24 20:32:58 +00:00
Rui Ueyama 9f7032aaf0 Minor refactoring. NFC.
llvm-svn: 311696
2017-08-24 20:26:54 +00:00
Rui Ueyama 5c19028cec Allow not only -O<number> but also -O <number>.
Fixes https://bugs.llvm.org/show_bug.cgi?id=34311

llvm-svn: 311682
2017-08-24 18:34:44 +00:00
Rui Ueyama 00cf731ecd Make empty arguments visible in error messages.
Before this patch, lld printed out something like

  error: -O: number expected, but got

After this patch, it prints out the same error message like this:

  error: -O: number expected, but got ''

Fixes https://bugs.llvm.org/show_bug.cgi?id=34311

llvm-svn: 311681
2017-08-24 18:34:32 +00:00
Sam Clegg 7dbd1fd73b Update comments: parallel_for_each -> parallelForEach
Also remove unused include of raw_ostream.h

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

llvm-svn: 311587
2017-08-23 19:03:20 +00:00
Petr Hosek b93c5b9f7e [ELF] Don't output headers into a segment if there's no space for them
Currently, LLD checks whether there's enough space for headers by
checking if headers fit below the address of the first allocated
section. However, that's always thue if the binary doesn't start
at zero which means that LLD always emits a segment for headers,
even if no other sections belong to that segment.

This is a problem in cases when linker script is being used with a
non-zero start address when we don't want to make the headers visible
by not leaving enough space for them. This pattern is common in
embedded programming but doesn't work in LLD.

This patch changes the behavior of LLD in case when linker script
is being to match the behavior of BFD ld and gold, which is to only
place headers into a segment when they're covered by some output
section.

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

llvm-svn: 311586
2017-08-23 18:44:34 +00:00
George Rimar de2d1066ae [ELF] - Do not report multiple errors for single one in ScriptLexer::setError.
Previously up to 3 errors were reported at once,
with patch we always will report only one,
just like in other linker code.

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

llvm-svn: 311537
2017-08-23 08:48:39 +00:00
George Rimar 55f207fb1f [ELF] - Repair dynsym-pie.s testcase.
It was broken from begining, because visibility
attributes were not applied properly to
symbols before this patch.

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

llvm-svn: 311536
2017-08-23 08:42:35 +00:00