Commit Graph

3549 Commits

Author SHA1 Message Date
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
Rafael Espindola 3bab91332f Fix which file is in an error message.
When reporting an invalid relocation we were blaming the destination
file instead of the file with the relocation.

llvm-svn: 310084
2017-08-04 18:33:16 +00:00
George Rimar ce6080819c [ELF] - Remove ScriptLexer::Error field and check ErrorCount instead.
D35945 introduces change when there is useless to check Error flag
in few places, but ErrorCount must be checked instead.

But then we probably can just check ErrorCount always. That should simplify
things. Patch do that.

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

llvm-svn: 310046
2017-08-04 10:34:14 +00:00
George Rimar d6bcde389a [ELF] - Fix "--symbol-ordering-file doesn't work with linker scripts"
This is PR33889,

Patch adds support of combination of linkerscript and
-symbol-ordering-file option.

If no sorting commands are present in script inside section declaration
and no --sort-section option specified, code uses sorting from ordering 
file if any exist.

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

llvm-svn: 310045
2017-08-04 10:25:29 +00:00
James Henderson a5bc09a86f [ELF] Explicitly write null bytes in string tables
Following r309829, if a string table appears in an executable segment, the strings
will not be null terminated. This is a problem, for example, for the .dynstr
section when using -no-rosegment. The strings end up being terminated with 0xcc
because prior to this patch, LLD did not explicitly write the null terminators.
This change fixes that by always writing the null terminators.

Reviewers: rafael

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

llvm-svn: 310042
2017-08-04 09:07:55 +00:00
Reid Kleckner a5d3909678 [PDB] Loosen checks for section contribution sizes
The PDB debug data directory entry has an absolute path in it. This will
make it different on every machine.

llvm-svn: 309989
2017-08-03 21:20:41 +00:00
Reid Kleckner 175af4bcc7 [PDB] Fix section contributions
Summary:
PDB section contributions are supposed to use output section indices and
offsets, not input section indices and offsets.

This allows the debugger to look up the index of the module that it
should look up in the modules stream for symbol information. With this
change, windbg can now find line tables, but it still cannot print local
variables.

Fixes PR34048

Reviewers: zturner

Subscribers: hiraditya, ruiu, llvm-commits

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

llvm-svn: 309987
2017-08-03 21:15:09 +00:00
George Rimar 5fb17128f7 [ELF] - Do not segfault if linkerscript tries to access Target too early.
Following possible scripts triggered accessing to Target when it was not yet
initialized (was nullptr).

MEMORY { name : ORIGIN = DATA_SEGMENT_RELRO_END; }
MEMORY { name : ORIGIN = CONSTANT(COMMONPAGESIZE); }

Patch errors out instead.

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

llvm-svn: 309953
2017-08-03 16:05:08 +00:00
Reid Kleckner 9dcd3e78ae [PDB] Improve rsds test to check that we fill in the file offset as well as the RVA
llvm-svn: 309902
2017-08-02 23:32:26 +00:00
Petr Hosek edd6c3587c [ELF] When the code segment is the last, align it to the page boundary
When the data segment is the last segment, it is correct to leave
it unaligned. However, when the code segment is the last segment,
it should be aligned to the page boundary to avoid loading the
non-segment parts of the ELF file at the end of the file.

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

llvm-svn: 309829
2017-08-02 16:35:00 +00:00
George Rimar b0d9fbeeeb [ELF] - Recommit r309252 "[ELF] - Fix missing relocation when linking executable with --unresolved-symbols=ignore-all"
With fix for undefined weak symbols in executable.

Original commit message:
This is PR32112. Previously when we linked executable with 
--unresolved-symbols=ignore-all and undefined symbols, like:

_start:
callq und@PLT

we did not create relocations, though it looks in that case
we should delegate handling of such symbols to runtime linker,
hence should emit them. Patch fixes that.

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

llvm-svn: 309796
2017-08-02 07:51:08 +00:00
Zachary Turner 8d927b6bf9 [lld/pdb] Add an empty globals stream.
We don't write any actual symbols to this stream yet, but for
now we just create the stream and hook it up to the appropriate
places and give it a valid header.

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

llvm-svn: 309608
2017-07-31 19:36:08 +00:00
Rafael Espindola aee5a8743e Never export weak undefined from executable.
Before we were doing it with --export-dynamic. That seems incorrect.
The intention of --export-dynamic is to export symbols *defined* in
the executable.

llvm-svn: 309605
2017-07-31 18:52:47 +00:00
Rafael Espindola d21ac10f6d Fix the order of section that are not on an order file.
They were being placed before sections that were listed.

llvm-svn: 309391
2017-07-28 15:36:15 +00:00
George Rimar 60833f6e22 [ELF] - Do not crash when ALIGN/DATA_SEGMENT_ALIGN expression used with zero value.
Previously we would crash when tried to ALIGN(0).
Patch uses value 1 instead in this case, that
looks to be consistent with GNU linkers
and reasonable and simple behavior itself.

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

llvm-svn: 309372
2017-07-28 09:27:49 +00:00
Rafael Espindola 06ad7ed70c Add a test.
This would have found the error in r309252.

llvm-svn: 309329
2017-07-27 22:08:11 +00:00
Reid Kleckner eacdf04fdd [PDB] Write public symbol records and the publics hash table
Summary:
MSVC link.exe records all external symbol names in the publics stream.
It provides similar functionality to an ELF .symtab.

Reviewers: zturner, ruiu

Subscribers: hiraditya, llvm-commits

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

llvm-svn: 309303
2017-07-27 18:25:59 +00:00
George Rimar 13f7dcdbc3 Revert r309252 "[ELF] - Fix missing relocation when linking executable with --unresolved-symbols=ignore-all"
It broke bot:
http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/4231

llvm-svn: 309258
2017-07-27 09:25:16 +00:00
George Rimar 678188d48b [ELF] - Fix missing relocation when linking executable with --unresolved-symbols=ignore-all
This is PR32112. Previously when we linked executable with 
--unresolved-symbols=ignore-all and undefined symbols, like:

_start:
callq und@PLT

we did not create relocations, though it looks in that case
we should delegate handling of such symbols to runtime linker,
hence should emit them. Patch fixes that.

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

llvm-svn: 309252
2017-07-27 07:31:31 +00:00
Rafael Espindola be28c2e4a5 Add --gc-sections to a test.
This shows that the logic in --gc-sections is a bit more precise than
what can be easily done in LTO.

llvm-svn: 309234
2017-07-26 23:47:24 +00:00
Rafael Espindola 4b075bb218 Make __start_sec __end_sec handling more precise.
With this we only ask LTO to keep a C named section if there is a
__start_ or __end symbol.

This is not as strict as lld's --gc-sections, but is as good as we can
get without having a far more detailed ir summary.

llvm-svn: 309232
2017-07-26 23:39:10 +00:00
Nico Weber 268f89d540 lld: /manifestuac:no shouldn't disable /manifestdependency:
Matches link.exe
https://reviews.llvm.org/D35872

llvm-svn: 309231
2017-07-26 23:38:10 +00:00
Rafael Espindola 6c4f5b41a3 Fix the name of the section end symbol.
It is __stop_<sec>, not __end_<sec>.

llvm-svn: 309225
2017-07-26 22:52:53 +00:00
Meador Inge b0e6229742 [ELF, LinkerScript] Memory region name parsing fix
This patch fixes a small issue with respect to how memory region names
are parsed on output section descriptions.  For example, consider:

  .text : { *(.text) } > rom

That can also be written like:

  .text : { *(.text) } >rom

The latter form is accepted by GNU LD and is fairly common.

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

llvm-svn: 309191
2017-07-26 21:51:09 +00:00
Martin Storsjo 38608c0975 [COFF, ARM64] Handle ADRP immediate offsets in relocations
Also handle overflow correctly in LDR/STR relocations. Even if the
offset range of a 8 byte LDR instruction is 15 bit (even if the immediate
itself is 12 bit) due to a 3 bit shift, only include up to 12 bits of offset
after doing the relocation, by limiting the range of the immediate by the
number of shifted bits.

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

llvm-svn: 309175
2017-07-26 20:51:47 +00:00
George Rimar 84941ef158 [ELF] - Change way how we handle --noinhibit-exec
Previously we handled this option implicitly, only
for infering unresolved symbols handling policy.

ld man says: "--noinhibit-exec Retain the executable
output file whenever it is still usable",
and we may want to handle other cases too.

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

llvm-svn: 309091
2017-07-26 09:46:59 +00:00
George Rimar 6977ec6899 [ELF] - Print options aliases in --help
This is PR30422,
previously LLD did not render all option aliases in --help.
With this patch it will.

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

llvm-svn: 309089
2017-07-26 09:21:10 +00:00
Rafael Espindola affe7209c0 LTO: Handle sections with valid C names.
These can be referenced with __start_/__stop_ symbols. I will try to make
this more precise in a followup patch.

llvm-svn: 309048
2017-07-25 22:51:05 +00:00
Martin Storsjo 82eaf6cb50 [COFF] Add support for delay loading DLLs on ARM
Differential Revision: https://reviews.llvm.org/D35768

llvm-svn: 309017
2017-07-25 20:00:37 +00:00
Nico Weber 578363ac08 Attempt to fix lld tests on Windows after 308998.
The test used /manifestinput: without /manifest:embed, which isn't actually
supported.  Just remove this part of the test for now; if it's important to
check this the llvm-readobj part should be extended to check this.

llvm-svn: 309002
2017-07-25 18:39:38 +00:00
Nico Weber a7a2c44e70 lld: only write .manifest files if /manifest is passed, PR33925
Also emit an error if /manifestinput: is used without /manifest:embed.
Increases compatibility with link.exe

https://reviews.llvm.org/D35842

llvm-svn: 308998
2017-07-25 18:08:03 +00:00
George Rimar 4c351c6540 [ELF] - Fix init_fini_priority.s test.
Previously .init_array/.fini_array sections
were not unique and we had 3 .init_array sections +
3 .fini_array input sections passed to linker,
instead of 5 + 5.

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

llvm-svn: 308958
2017-07-25 09:26:35 +00:00
George Rimar f694d33f4c [ELF] - Fix calculation of memory region offset.
This is PR33714.

Previously for each input section offset of memory region
was incremented on a size of output section.

That resulted in a wrong error message saying about
overflow. Patch fixes that.

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

llvm-svn: 308955
2017-07-25 08:29:29 +00:00
Martin Storsjo 405b5bcc36 [COFF] Correctly set the thumb bit in DLL export addresses
The same adjustment is already done for the entry point in
Writer.cpp and for relocations that point to executable code
in Chunks.cpp.

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

llvm-svn: 308953
2017-07-25 06:10:44 +00:00
Martin Storsjo 25712667cb [COFF] Add a test for producing DLLs and import libraries for ARM64
This is a test for LLVM SVN r308951.

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

llvm-svn: 308952
2017-07-25 06:08:25 +00:00
Dmitry Mikulin 97d6a80895 If user requested section alignment is greater than MaxPageSize, propagate it to segment headers correctly.
Differential Revision: https://reviews.llvm.org/D35813

llvm-svn: 308930
2017-07-24 21:27:02 +00:00