Commit Graph

3691 Commits

Author SHA1 Message Date
George Rimar bb451903f5 [ELF] - Accept --defsym foo=value form.
Previously we accepted --defsym=foo=value only.

Reported by Sean Silva.

llvm-svn: 302227
2017-05-05 11:59:15 +00:00
Rafael Espindola 02ed7575e7 Simplify the header allocation.
In the non linker script case we would try very early to find out if
we could allocate the headers. Failing to do that would add extra
alignment to the first ro section, since we would set PageAlign
thinking it was the first section in the PT_LOAD.

In the linker script case the header allocation must be done in the
end, causing some duplication.

We now tentatively add the headers to the first PT_LOAD and if it
turns out they don't fit, remove them. With this we only need to
allocate the headers in one place in the code.

llvm-svn: 302186
2017-05-04 19:34:17 +00:00
Rafael Espindola 808f2d3c62 Reduce code duplication. NFC.
llvm-svn: 302155
2017-05-04 14:54:48 +00:00
Rafael Espindola 7c4eafa3ee Fix accounting of tbss.
We were correctly computing the size contribution of a .tbss input
section (it is none), but we were incorrectly considering the
alignment of the output section: it was advancing Dot instead of
ThreadBssOffset.

As far as I can tell this was always wrong in our linkerscript
implementation, but that became more visible now that the code is
shared with the non linker script case.

llvm-svn: 302107
2017-05-04 03:00:27 +00:00
Rui Ueyama b201a20eab Remove a comment that is no longer true.
llvm-svn: 302090
2017-05-03 23:10:33 +00:00
Rui Ueyama fd7deda57a Accept archive files with no symbol table instad of warning on them.
It seems virtually everyone who tries to do LTO build with Clang and
LLD was hit by a mistake to forget using llvm-ar command to create
archive files. I wasn't an exception. Since this is an annoying common
issue, it is probably better to handle that gracefully rather than
reporting an error and tell the user to redo build with different
configuration.

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

llvm-svn: 302083
2017-05-03 21:03:08 +00:00
Peter Collingbourne 1c697e99b6 Revert r301897, "ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO."
It doesn't matter what binding we store in a non-UsedInRegularObj undefined
symbol because we should reset it when we see a real undefined symbol in
a combined LTO object. The fact that we weren't doing so before is a bug
(PR32899) which is now fixed.

llvm-svn: 302067
2017-05-03 19:23:30 +00:00
Rafael Espindola 5e20c75e3a Handle mixed strong and weak undefined symbols.
We were ignoring strong undefined symbols if they followed weak ones.

Fixes pr32899.

llvm-svn: 302065
2017-05-03 18:40:27 +00:00
Peter Smith c60b4510ea [ELF] Fix problems with fabricateDefaultCommands() and --section-start
The --section-start <name>=<address> needs to be translated into equivalent
linker script commands. There are a couple of problems with the existing
implementation:
- The --section-start with the lowest address is assumed to be at the start
of the map. This assumption is incorrect, we have to iterate through the
SectionStartMap to find the lowest address.
- The addresses in --section-start were being over-aligned when the
sections were marked as PageAlign. This is inconsistent with the use of
SectionStartMap in fixHeaders(), and can cause problems when the PageAlign
causes an "unable to move location counter backward" error when the
--section-start with PageAlign is aligned to an address higher than the next
--section-start. The ld.bfd and ld.gold seem to be more consistent with this
approach but this is not a well specified area.
    
This change fixes the problems above and also corrects a typo in which
fabricateDefaultCommands() is called with the wrong parameter, it should be
called with AllocateHeader not Config->MaxPageSize.

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

llvm-svn: 302007
2017-05-03 08:44:50 +00:00
Rui Ueyama 9decbfee32 Remove a dead function declaration.
llvm-svn: 301982
2017-05-02 22:42:24 +00:00
Joel Jones 93340741b8 Remove _NC suffix from ELF relocations TLSDESC_{LD64,ADD}_LO12
llvm-svn: 301979
2017-05-02 22:01:30 +00:00
Rui Ueyama c344313803 Fix typo.
llvm-svn: 301975
2017-05-02 21:16:06 +00:00
Rafael Espindola a0f30da62e Revert "Fix misnamed #include. Remove _NC suffix from ELF relocations TLSDESC_{LD64,ADD}_LO12"
This reverts commit r301964. It broke the build.

llvm-svn: 301969
2017-05-02 20:19:42 +00:00
Joel Jones f387eb62b9 Fix misnamed #include. Remove _NC suffix from ELF relocations TLSDESC_{LD64,ADD}_LO12
llvm-svn: 301964
2017-05-02 19:31:40 +00:00
Rafael Espindola a8a1a4fc30 Avoid empty .eh_frame sections.
Strip on OpenBSD does not correctly handle an empty .eh_frame section
and produces broken binaries in that case. Currently lld creates such
an empty .eh_frame section, despite the fact that the OpenBSD crtend.o
explicitly inserts a terminator. The Linux LSB "standard":

https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html#EHFRAME

explicitly says that

    The .eh_frame section shall contain 1 or more Call Frame Information (CFI) records.

This diff includes a test that specifically tests the issue I'm seeing
on OpenBSD.

Patch by Mark Kettenis!

llvm-svn: 301931
2017-05-02 15:45:31 +00:00
Peter Collingbourne 99c8fa3bef ELF: Set symbol binding to STB_GLOBAL when undefining symbols during LTO.
If there is a bug in the LTO implementation that causes it to fail to provide
an expected symbol definition, the linker should report an undefined symbol
error. Unfortunately, we were failing to do so if the symbol definition
was weak, as the undefine() function was turning the definition into a weak
undefined symbol, which resolves to zero if the symbol remains undefined. This
patch causes us to set the binding to STB_GLOBAL when we undefine a symbol.

I can't see a good way to test this. The behaviour should only be observable
if there is a bug in the LTO implementation.

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

llvm-svn: 301897
2017-05-02 05:07:41 +00:00
Rui Ueyama dfb1e2a1a1 Update commetns.
llvm-svn: 301896
2017-05-02 02:58:04 +00:00
Rui Ueyama f13a6904b3 Make getArchiveMembers function a non-member function.
It didn't have to be a member function of Driver. This patch makes
that function a file-scoped non-member function.

llvm-svn: 301895
2017-05-02 02:57:45 +00:00
Rui Ueyama 92a8d798b8 Add comments about how we handle mergeable sections with relocations.
Also factored out code.

llvm-svn: 301833
2017-05-01 20:49:09 +00:00
Rafael Espindola 4aa2ef5b0e Fix pr32816.
When using linkerscripts we were trying to sort SHF_LINK_ORDER
sections too early. Instead of always doing two runs of
assignAddresses, record the section order in processCommands.

llvm-svn: 301830
2017-05-01 20:32:39 +00:00
Rui Ueyama 3781137909 Fix comments.
llvm-svn: 301778
2017-04-30 20:58:20 +00:00
Rui Ueyama 789723fddf Ignore -no-keep-memory.
When the -no-keep-memory option is given, BFD linker tries to save
memory in their own way. Since our internal architecture is completely
different from that linker, that option doesn't make sense to us.

llvm-svn: 301772
2017-04-30 13:45:06 +00:00
Rui Ueyama b402a866c1 Move LTO options above "all options beyond this are ignored" comment
llvm-svn: 301771
2017-04-30 13:44:52 +00:00
Rui Ueyama bd27849e4b Rename RPath Rpath for consistency. NFC.
For an option -foo-bar-baz, we have Config->FooBarBaz. Since -rpath is
-rpath and not -r-path, it should be Config->Rpath instead Config->RPath.

llvm-svn: 301759
2017-04-29 23:06:43 +00:00
Rui Ueyama 85a5e69ced Simplify by using getString instead of getLastArg. NFC.
llvm-svn: 301758
2017-04-29 22:56:38 +00:00
Rui Ueyama 543161a10c Report an error if --compress-debug-sections is given while zlib is not availble.
llvm-svn: 301757
2017-04-29 22:56:24 +00:00
Rafael Espindola de8d9897d9 Bring back r301678.
This version uses a set to speed up the synchronize method.

Original message:

    Remove LinkerScript::flush.

    This patch replaces flush with a last ditch attempt at synchronizing
    the section list with the linker script "AST".

    The synchronization is a bit of a hack and should in time be avoided
    by creating the AST earlier so that modifications can be made directly
    to it instead of modifying the section list and synchronizing it back.

    This is the main step for fixing
    https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I
    think the only missing thing would be to have processCommands assign
    section indexes as dummy offsets so that the sort in
    OutputSection::finalize works.

    With this LinkerScript::assignAddresses becomes much simpler, which
    should help with the thunk work.

llvm-svn: 301745
2017-04-29 15:44:03 +00:00
Davide Italiano d765638ad1 [ELF] When a rel points to a SHF_MERGE section, don't merge the sec.
Fixes PR32785. Thanks to Piotr Padlewski for the report and
Rafael for the fix.

llvm-svn: 301729
2017-04-29 01:24:34 +00:00
Rui Ueyama 3151958cbd Replace PrettyPrinter class in MapFile.cpp with a few non-member functions.
Since the output format has been simplified, the class to print
out a map file doesn't seem to be needed anymore. We can replace
it with a few non-member functions.

llvm-svn: 301715
2017-04-28 23:29:15 +00:00
Rui Ueyama e2f11690fe Eliminate .debug_gnu_pub{names,types} if -gdb-index is given.
This patch is to ignore .debug_gnu_pub{names,types} sections if the
-gdb-index option was given.

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

llvm-svn: 301710
2017-04-28 22:46:55 +00:00
Rui Ueyama 216aa11cc5 Revert r301678: Remove LinkerScript::flush.
This reverts commit r301678 since that change significantly slowed
down the linker. Before this patch, LLD could link clang in 8 seconds,
but with this patch it took 40 seconds.

llvm-svn: 301709
2017-04-28 22:40:58 +00:00
Hans Wennborg ca31b9f89c Flush output in log()
This change was motivated by output from lld-link.exe and link.exe
getting intermixed. There's already a flush() call in message(), so
there's precedence.

llvm-svn: 301693
2017-04-28 21:35:02 +00:00
Rafael Espindola a7a945a13b Rename one of the variables to avoid confusion.
llvm-svn: 301691
2017-04-28 21:23:43 +00:00
Rui Ueyama 3012b371fd Change the format of the map file.
Previously, we printed out input sections and input files in
separate columns as shown below.

  Address          Size             Align Out     In      File    Symbol
  0000000000201000 0000000000000015     4 .text
  0000000000201000 000000000000000e     4         .text
  0000000000201000 000000000000000e     4                 foo.o
  0000000000201000 0000000000000000     0                         _start
  0000000000201005 0000000000000000     0                         f(int)
  000000000020100e 0000000000000000     0                         local
  0000000000201010 0000000000000002     4                 bar.o
  0000000000201010 0000000000000000     0                         foo
  0000000000201011 0000000000000000     0                         bar

This format doesn't make much sense because for each input section,
there's always exactly one input file. This patch changes the format
to this.

  Address          Size             Align Out     In      Symbol
  0000000000201000 0000000000000015     4 .text
  0000000000201000 000000000000000e     4         foo.o:(.text)
  0000000000201000 0000000000000000     0                 _start
  0000000000201005 0000000000000000     0                 f(int)
  000000000020100e 0000000000000000     0                 local
  0000000000201010 0000000000000002     4         bar.o:(.text)
  0000000000201010 0000000000000000     0                 foo
  0000000000201011 0000000000000000     0                 bar

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

llvm-svn: 301683
2017-04-28 20:38:27 +00:00
Rafael Espindola b3bc1ed0d4 Remove LinkerScript::flush.
This patch replaces flush with a last ditch attempt at synchronizing
the section list with the linker script "AST".

The synchronization is a bit of a hack and should in time be avoided
by creating the AST earlier so that modifications can be made directly
to it instead of modifying the section list and synchronizing it back.

This is the main step for fixing
https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I
think the only missing thing would be to have processCommands assign
section indexes as dummy offsets so that the sort in
OutputSection::finalize works.

With this LinkerScript::assignAddresses becomes much simpler, which
should help with the thunk work.

llvm-svn: 301678
2017-04-28 20:22:47 +00:00
Rui Ueyama 8a3ef95fc9 Use toString(Inputfile*) to format a file object.
llvm-svn: 301674
2017-04-28 20:00:09 +00:00
Rui Ueyama 72408fb2ac Remove trailing whitespace from the -Map output.
If a string is shorter than 7 characters, we used to print out
trailing whitespace characters.

llvm-svn: 301668
2017-04-28 18:54:08 +00:00
Rui Ueyama 2634d0ff5c Remove a redundant local variable.
llvm-svn: 301661
2017-04-28 17:50:23 +00:00
Rui Ueyama b882e5910d Speed up the -Map option.
We found that some part of code for the -Map option takes O(m*n)
where m is the number of input sections in some file and n is
the number of symbols in the same file. If you do LTO, we usually
have only a few object files as inputs for the -Map option
feature, so this performance characteristic was worse than I
expected.

This patch rewrites the -Map option feature to speed it up.
I eliminated the O(m*n) bottleneck and also used multi-threading.

As a result, clang link time with the -Map option improved from
18.7 seconds to 11.2 seconds. Without -Map, it takes 7.7 seconds,
so the -Map option is now about 3x faster than before for this
test case (from 11.0 seconds to 3.5 seconds.) The generated output
file size was 223 MiB, and the file contains 1.2M lines.

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

llvm-svn: 301659
2017-04-28 17:19:13 +00:00
Rui Ueyama 42fca6e794 Recommend users use readelf instead of objdump to dump .comment contents.
readelf's output is much easier to read than objdump's as you can see below.

  $ readelf --string-dump .comment foo
  String dump of section '.comment':
    [     1]  GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
    [    2c]  clang version 5.0.0
    [    41]  Linker: LLD 5.0.0

  $ objdump -j .comment -s foo
  Contents of section .comment:
   0000 00474343 3a202855 62756e74 7520342e  .GCC: (Ubuntu 4.
   0010 382e342d 32756275 6e747531 7e31342e  8.4-2ubuntu1~14.
   0020 30342e33 2920342e 382e3400 636c616e  04.3) 4.8.4.clan
   0030 67207665 7273696f 6e20352e 302e3020  g version 5.0.0
   0040 004c696e 6b65723a 204c4c44 20352e30  .Linker: LLD 5.0
   0050 2e3000                               .0.

llvm-svn: 301515
2017-04-27 04:50:08 +00:00
Rui Ueyama c9d82b9e16 Simplify BinaryFile::parse and add comments.
llvm-svn: 301514
2017-04-27 04:01:36 +00:00
Rui Ueyama 63d48e5956 Remove needless type conversions.
llvm-svn: 301513
2017-04-27 04:01:14 +00:00
Rui Ueyama e5ad2986fc Remove unnecessary instantiation of StringRef.
SoName's type has changed from StringRef to std::string, so this
code does not make sense anymore.

llvm-svn: 301490
2017-04-26 23:00:32 +00:00
Rui Ueyama 330e52b018 Removes createELFFile which takes a template class as a template parameter.
This patch is to reduce amount of template uses. The new code is less
exciting and boring than before, but I think it is easier to read.

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

llvm-svn: 301488
2017-04-26 22:51:51 +00:00
Rafael Espindola 4f013bb3b2 Create an OutputSection for each non-empty OutputSectionCommand.
We were already pretty close, the one exception was when a name was
reused in another SECTIONS directive:

SECTIONS {
  .text : { *(.text) }
  .data : { *(.data) }
}
SECTIONS {
  .data : { *(other) }
}

In this case we would create a single .data and magically output
"other" while looking at the first OutputSectionCommand.

We now create two .data sections. This matches what gold does. If we
really want to create a single one, we should change the parser so that
the above is parsed as if the user had written

SECTIONS {
  .text : { *(.text) }
  .data : { *(.data) *(other)}
}

That is, there should be only one OutputSectionCommand for .data and
it would have two InputSectionDescriptions.

By itself this patch makes the code a bit more complicated, but is an
important step in allowing assignAddresses to operate just on the
linker script.

llvm-svn: 301484
2017-04-26 22:30:15 +00:00
Rui Ueyama cf8247ef48 Do flag compatibility check in checkOptions. NFC.
llvm-svn: 301476
2017-04-26 21:27:33 +00:00
Rui Ueyama 08af54c304 Factor out code to parse -build-id. NFC.
llvm-svn: 301475
2017-04-26 21:23:11 +00:00
Rui Ueyama d283eb7091 Make LLD work even if the current directory is not writable.
llvm-svn: 301423
2017-04-26 16:15:07 +00:00
Rui Ueyama 7163027884 Move code to emit error messages from Filesystem.cpp to Driver.cpp.
isFileWritable() checked if a file is writable and then emitted
an error message if it is not writable. So it did more than the
name says. This patch moves error() calls to Driver.

llvm-svn: 301422
2017-04-26 16:14:46 +00:00
George Rimar 3505716d72 [ELF] - Remove dead TLS relocations relative code for MIPS and ARM
This code was not used because of
handleARMTlsRelocation and handleMipsTlsRelocation methods that are called
for these platforms instead of regular TLS code.

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

llvm-svn: 301414
2017-04-26 14:48:36 +00:00