Commit Graph

3584 Commits

Author SHA1 Message Date
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 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 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
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
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
George Rimar 51d193f8b3 [ELF] - Fix for "Bug 34238 - LTO is optimizing away symbols referenced from linker scripts"
Code suggested by Rui Ueyama in PR34238 comments.

Previously LTO optimized away symbols referenced from linker script
because did not see that them are used from regular objects.

Patch adds such symbols as undefined earlier, before running LTO,
what sets IsUsedInRegularObj for them and fixes the issue.

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

llvm-svn: 311534
2017-08-23 08:37:22 +00:00
Rui Ueyama e158f7c329 Revert r311468: If --dynamic-list is given, only those symbols are preemptible
This reverts commit r311468 because it broke some CFI bots.

llvm-svn: 311497
2017-08-22 21:54:58 +00:00
Rui Ueyama 9cbbacb910 If --dynamic-list is given, only those symbols are preemptible
Patch by Rafael Espíndola.

This is PR34053.

The implementation is a bit of a hack, given the precise location where
IsPreemtible is set, it cannot be used from
SymbolTable::handleAnonymousVersion.

I could add another method to SymbolTable if you think that would be
better.

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

llvm-svn: 311468
2017-08-22 16:31:47 +00:00
George Rimar 5bd647dfd0 [ELF] - Remove outdated comment. NFC.
llvm-svn: 311449
2017-08-22 11:11:11 +00:00
George Rimar 3a1af22099 [ELF] - Make IR symbols be visible when doing relocatable link.
This is PR33097.
Previously when doing relocatable link, all IR symbols were absent
in result object file. Patch makes external symbols to be exported.

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

llvm-svn: 311431
2017-08-22 08:36:54 +00:00
Eric Beckmann 87c6acf38a Integrate manifest merging library into LLD.
Summary: Now that the llvm-mt manifest merging libraries are complete, we may use them to merge manifests instead of needing to shell out to mt.exe.

Subscribers: mgorny, llvm-commits

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

llvm-svn: 311424
2017-08-22 03:15:28 +00:00
Sam Elliott 29404b3a62 [lld] Update Tests for Emitting Single Inline Remark
Summary: This change depends on https://reviews.llvm.org/D36054 and should be landed at the same time.

Reviewers: anemet

Reviewed By: anemet

Subscribers: llvm-commits, emaste

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

llvm-svn: 311348
2017-08-21 16:41:59 +00:00
Zachary Turner d1de2f4f5e [llvm-pdbutil] Add support for dumping detailed module stats.
This adds support for dumping a summary of module symbols
and CodeView debug chunks.  This option prints a table for
each module of all of the symbols that occurred in the module
and the number of times it occurred and total byte size.  Then
at the end it prints the totals for the entire file.

Additionally, this patch adds the -jmc (just my code) option,
which suppresses modules which are from external libraries or
linker imports, so that you can focus only on the object files
and libraries that originate from your own source code.

llvm-svn: 311338
2017-08-21 14:53:25 +00:00
James Henderson d447a7a128 [ELF] Remove dependency on hexdump from lit test
hexdump is not part of the GNU coreutils, and so is not required to be able to
build and test LLVM, according to the documentation. This change removes the
dependency on hexdump from a lit test.

Reviewers: grimar

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

llvm-svn: 311335
2017-08-21 14:11:08 +00:00
George Rimar f7ef2a13f6 [ELF] - Recommit "[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions."
With fix: explicitly specify ouput format for hexdump tool call.

Original commit message:

[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions.

Previously last 4 bytes of executable loads
were not filled with trap instructions,
patch fixes this bug.

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

llvm-svn: 311315
2017-08-21 08:31:14 +00:00
George Rimar 09a6945b48 [ELF] - Revert r311310 "[ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions."
It broke BB:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/11792/steps/test_lld/logs/stdio

llvm-svn: 311314
2017-08-21 08:13:45 +00:00
George Rimar 8902bb8e62 [ELF] - Enable threading in many-sections.s testcase. NFC.
This is PR32942, previously threading was disabled
because slowed down this testcase a lot.
It was fixed in r311312.

llvm-svn: 311313
2017-08-21 08:10:35 +00:00
George Rimar 5d0ea70ad5 [ELF] - Do not segfault when doing logical and/or operations on symbols that have no output sections.
Previously we would crash on samples from testcase,
because were trying to access zero pointer to output section.

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

llvm-svn: 311311
2017-08-21 07:57:12 +00:00
George Rimar c7392cbe9a [ELF] - Do not forget to fill last bytes of PT_LOADs with trap instructions.
Previously last 4 bytes of executable loads
were not filled with trap instructions,
patch fixes this bug.

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

llvm-svn: 311310
2017-08-21 07:51:21 +00:00
George Rimar 7e5b0a5978 [ELF] - Don't segfault when accessing location counter inside MEMORY command.
We would previously crash on next script:
MEMORY { name : ORIGIN = .; }

Patch fixes that.

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

llvm-svn: 311073
2017-08-17 08:47:21 +00:00
Davide Italiano aa33e74f4b [ELF/LTO] -function-sections/-data-sections are exact options.
Also add a test. This fixes r310995 and PR34200.

llvm-svn: 310998
2017-08-16 08:21:04 +00:00
Martin Storsjo 92f32d0c53 [COFF] Don't produce weak aliases in import libraries
When creating an import library from lld, the cases with
Name != ExtName shouldn't end up as a weak alias, but as a real
export of the new name, which is what actually is exported from
the DLL.

This restores the behaviour of renamed exports to what it was in
4.0.

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

llvm-svn: 310992
2017-08-16 05:23:00 +00:00
Martin Storsjo a50275cfe5 [COFF] Fix the name type for stdcall functions in import libraries
Since SVN r303491 and r304573, LLD used the COFFImportLibrary
functions from LLVM. These only had two names, Name and ExtName,
which wasn't enough to convey all the details of stdcall functions.

Stdcall functions got the wrong symbol name in the import library
itself in r303491, which is why it was reverted in r304561. When
re-landed and fixed in r304573 (after adding a test in r304572),
the symbol name itself in the import library ended up right, but the
name type of the import library entry was wrong.

This had the effect that linking to the import library succeeded
(contrary to in r303491, where linking to such an import library
failed), but at runtime, the symbol wouldn't be found in the DLL
(since the caller linked to the stdcall decorated name).

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

llvm-svn: 310989
2017-08-16 05:13:25 +00:00
Zachary Turner 024323cb12 [LLD COFF/PDB] Incrementally update the build id.
Previously, our algorithm to compute a build id involved hashing the
executable and storing that as the GUID in the CV Debug Record chunk,
and setting the age to 1.

This breaks down in one very obvious case: a user adds some newlines to
a file, rebuilds, but changes nothing else. This causes new line
information and new file checksums to get written to the PDB, meaning
that the debug info is different, but the generated code would be the
same, so we would write the same build over again with an age of 1.

Anyone using a symbol cache would have a problem now, because the
debugger would open the executable, look at the age and guid, find a
matching PDB in the symbol cache and then load it. It would never copy
the new PDB to the symbol cache.

This patch implements the canonical Windows algorithm for updating
a build id, which is to check the existing executable first, and
re-use an existing GUID while bumping the age if it already
exists.

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

llvm-svn: 310961
2017-08-15 21:31:41 +00:00
Martin Storsjo d2752aa9ec [COFF] Add support for aligncomm directives
These are emitted for comm symbols in object files, when targeting
a GNU environment.

Alternatively, just ignore them since we already align CommonChunk
to the natural size of the content (up to 32 bytes). That would only
trade away the possibility to overalign small symbols, which doesn't
sound like something that might not need to be handled?

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

llvm-svn: 310871
2017-08-14 19:07:27 +00:00
Zachary Turner 302dc8bccf [PDB] Ignore all S_UDT symbols when writing PDBs.
We don't have the right algorithm for copying S_UDT symbols
from object files to the globals stream, and having it wrong
is worse than not having it at all, since it breaks display
of local variables of UDT types (for example, "dv Foo" fails
in our current implementation, but succeeds if the S_UDT records
are omitted).  Omit them until we fix the algorithm.

llvm-svn: 310867
2017-08-14 18:44:58 +00:00
George Rimar cb38bf526b [ELF] - LTO: Try to be option compatible with the gold plugin.
This is relative to PR30720.

Previously we ignored all --plugin-opt arguments.
Patch adds support for them.

Patch does not add any new LTO options,
and just implements mapping from --plugin-opt to existent ones.

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

llvm-svn: 310826
2017-08-14 10:17:30 +00:00
Zachary Turner b57884e818 Fix some broken tests.
These were pending in a separate patch but I forgot to squash them
before comitting, and this one didn't go through.

llvm-svn: 310764
2017-08-11 21:14:01 +00:00
Rui Ueyama be7e001369 Add `-z muldefs` option.
llvm-svn: 310757
2017-08-11 20:49:48 +00:00
Zachary Turner ee9906d884 [LLD/PDB] Write actual records to the globals stream.
Previously we were writing an empty globals stream.  Windows
tools interpret this as "private symbols are not present in
this PDB", even when they are, so we need to fix this.  Regardless,
without it we don't have information about global variables, so
we need to fix it anyway.  This patch does that.

With this patch, the "lm" command in WinDbg correctly reports
that we have private symbols available, but the "dv" command
still refuses to display local variables.

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

llvm-svn: 310743
2017-08-11 19:00:03 +00:00
Rafael Espindola db1af69342 Avoid crash with local abs symbol.
llvm-svn: 310736
2017-08-11 17:47:12 +00:00
George Rimar f2fe963d83 [ELF] - Do not omit common symbols when -Map is given.
This is PR33886,

previously we did not output common symbols to map,
patch fixes that.

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

llvm-svn: 310703
2017-08-11 11:34:04 +00:00
Rui Ueyama 9c77d27004 Garbage-collect common symbols.
Liveness is usually a notion of input sections, but this patch adds
"liveness" bit to common symbols because they don't belong to any
input section.

This patch is based on https://reviews.llvm.org/D36520

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

llvm-svn: 310617
2017-08-10 15:54:27 +00:00
Hafiz Abid Qadeer 6f1d954ef4 [ELF, LinkerScript] Support ! operator in linker script.
Summary: This small patch adds the support for ! operator in linker scripts. 

Reviewers: ruiu, rafael

Reviewed By: ruiu

Subscribers: meadori, grimar, emaste, llvm-commits

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

llvm-svn: 310607
2017-08-10 15:25:47 +00:00
George Rimar 736a9b20c9 [ELF] - Add a test for --gc-sections --undefined=foo combination.
GC code contains following logic uncovered by tests:

for (StringRef S : Config->Undefined)
  MarkSymbol(Symtab->find(S));

As far I can tell we never had test for that before,
patch fixes it.

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

llvm-svn: 310556
2017-08-10 08:15:33 +00:00
George Rimar 945cd31c4b [ELF] - Linkerscript: disallow discarding COMMON.
This patch restricts following construction:

/DISCARD/ : { *(COMMON) }

Previously LLD would crash.

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

llvm-svn: 310554
2017-08-10 08:07:05 +00:00
Rui Ueyama ae704a5472 Add --icf=none option.
--icf=none negates --icf=all.

llvm-svn: 310526
2017-08-09 21:32:38 +00:00
Zachary Turner 5448dabbdd [PDB] Fix an issue writing the publics stream.
In the refactor to merge the publics and globals stream, a bug
was introduced that wrote the wrong value for one of the fields
of the PublicsStreamHeader.  This caused debugging in WinDbg
to break.

We had no way of dumping any of these fields, so in addition to
fixing the bug I've added dumping support for them along with a
test that verifies the correct value is written.

llvm-svn: 310439
2017-08-09 04:23:59 +00:00
Zachary Turner 946204c83e [PDB] Merge Global and Publics Builders.
The publics stream and globals stream are very similar. They both
contain a list of hash buckets that refer into a single shared stream,
the symbol record stream. Because of the need for each builder to manage
both an independent hash stream as well as a single shared record
stream, making the two builders be independent entities is not the right
design. This patch merges them into a single class, of which only a
single instance is needed to create all 3 streams.  PublicsStreamBuilder
and GlobalsStreamBuilder are now merged into the single GSIStreamBuilder
class, which writes all 3 streams at once.

Note that this patch does not contain any functionality change. So we're
still not yet writing any records to the globals stream. All we're doing
is making it so that when we do start writing records to the globals,
this refactor won't have to be part of that patch.

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

llvm-svn: 310438
2017-08-09 04:23:25 +00:00
Zachary Turner 59e3ae827d [PDB] Fix linking of function symbols and local variables.
The compiler outputs PROC32_ID symbols into the object files
for functions, and these symbols have an embedded type index
which, when copied to the PDB, refer to the IPI stream.  However,
the symbols themselves are also converted into regular symbols
(e.g. S_GPROC32_ID -> S_GPROC32), and type indices in the regular
symbol records refer to the TPI stream.  So this patch applies
two fixes to function records.
  1. It converts ID symbols to the proper non-ID record type.
  2. After remapping the type index from the object file's index
     space to the PDB file/IPI stream's index space, it then
     remaps that index to the TPI stream's index space by.

Besides functions, during the remapping process we were also
discarding symbol record types which we did not recognize.
In particular, we were discarding S_BPREL32 records, which is
what MSVC uses to describe local variables on the stack.  So
this patch fixes that as well by copying them to the PDB.

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

llvm-svn: 310394
2017-08-08 18:34:44 +00:00
Zachary Turner 676386ff30 [lld] Write the DataCRC to the output PDB.
llvm-svn: 310297
2017-08-07 20:23:45 +00:00
Shoaib Meenai 335fad1c24 [lld] Allow rel iplt symbols with dynamic symbol table
Emit these symbols as long as we're building in a static configuration,
even if we're emitting a dynamic symbol table. This is consistent with
both bfd and gold.

Ordinarily, the combination of -static and -export-dynamic wouldn't make
much sense. Unfortunately, cmake versions prior to 3.4 forcefully
injected -rdynamic [1], so it seems worthwhile to support.

[1] https://cmake.org/cmake/help/v3.4/policy/CMP0065.html

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

llvm-svn: 310168
2017-08-05 05:01:07 +00:00
Rui Ueyama fbefee9f36 Replace CRLF.
llvm-svn: 310166
2017-08-05 04:07:21 +00:00
Zachary Turner 6b7db9a66c More PDB buildbot fixes.
llvm-svn: 310131
2017-08-04 21:18:17 +00:00
Zachary Turner dd6f4368d6 Fix broken PDB tests.
llvm-svn: 310130
2017-08-04 21:15:12 +00:00
Zachary Turner fb1cd5090c [llvm-pdbutil] Dump image section headers.
Image section headers are stored in the DBI stream, but we
had no way to dump them.  This patch adds dumping support,
along with some tests that LLD actually dumps them correctly.

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

llvm-svn: 310107
2017-08-04 20:02:38 +00:00