Commit Graph

313 Commits

Author SHA1 Message Date
Rui Ueyama ee17371897 Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.
This should resolve the issue that lld build fails in some hosts
that uses case-insensitive file system.

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

llvm-svn: 326339
2018-02-28 17:38:19 +00:00
Fangrui Song 9cd5df0e15 [ELF] Add comment for preemptible and fix typo. NFC
Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 325855
2018-02-23 02:05:48 +00:00
Sam Clegg 3141ddc58d Consistent (non) use of empty lines in include blocks
The profailing style in lld seem to be to not include such empty lines.
Clang-tidy/clang-format seem to handle this just fine.

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

llvm-svn: 325629
2018-02-20 21:53:18 +00:00
Rafael Espindola b960325989 Simplify RelocationBaseSection::addReloc.
Now that we have R_ADDEND, UseSymVA was redundant. We only want to
write the symbol virtual address when using an expression other than
R_ADDEND.

llvm-svn: 325360
2018-02-16 16:53:04 +00:00
Alexander Richardson cfb6093379 Ensure that Elf_Rel addends are always written for dynamic relocations
Summary:
This follows up on r321889 where writing of Elf_Rel addends was partially
moved to RelocationBaseSection. This patch ensures that the addends are
always written to the output section when a input section uses RELA but the
output is REL.

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

llvm-svn: 325328
2018-02-16 10:01:17 +00:00
Rafael Espindola 35cf8bbe36 Add a simpler version of addReloc. NFC.
Extracted from a patch by Alexander Richardson!

llvm-svn: 325016
2018-02-13 16:03:52 +00:00
Alexander Richardson 6b367faa45 [ELF] Make overlapping output sections an error
Summary:
While trying to make a linker script behave the same way with lld as it did
with bfd, I discovered that lld currently doesn't diagnose overlapping
output sections. I was getting very strange runtime failures which I
tracked down to overlapping sections in the resulting binary. When linking
with ld.bfd overlapping output sections are an error unless
--noinhibit-exec is passed and I believe lld should behave the same way
here to avoid surprising crashes at runtime.

The patch also uncovered an errors in the tests: arm-thumb-interwork-thunk
was creating a binary where .got.plt was placed at an address overlapping
with .got.

Reviewers: ruiu, grimar, rafael

Reviewed By: ruiu

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

llvm-svn: 323856
2018-01-31 09:22:44 +00:00
Rafael Espindola 62003fbb02 Inline foot gun into only valid use.
Symbol had both Visibility and getVisibility() and they had different
meanings. That is just too easy to get wrong.

getVisibility() would compute the visibility of a particular symbol
(foo in bar.o), and Visibility stores the computed value we will put
in the output.

There is only one case when we want what getVisibility() provides, so
inline it.

llvm-svn: 322590
2018-01-16 19:28:28 +00:00
Rafael Espindola 3c3544652b Fix another case we were using the wrong visibility.
llvm-svn: 322580
2018-01-16 18:21:23 +00:00
Rafael Espindola b5506e6baf Rename --icf-data and add a corresponding flag for functions.
When we have --icf=safe we should be able to define --icf=all as a
shorthand for --icf=safe --ignore-function-address-equality.

For now --ignore-function-address-equality is used only to control
access to non preemptable symbols in shared libraries.

llvm-svn: 322152
2018-01-10 01:37:36 +00:00
Rafael Espindola 4b6833332b Rewrite our relocation processing.
This splits relocation processing in two steps.

First, analyze what needs to be done at the relocation spot. This can
be a constant (non preemptible symbol, relative got reference, etc) or
require a dynamic relocation. At this step we also consider creating
copy relocations.

Once that is done we decide if we need a got or a plt entry.

The code is simpler IMHO. For example:

- There is a single call to isPicRel since the logic is not split
  among adjustExpr and the caller.
- R_MIPS_GOTREL is simple to handle now.
- The tracking of what is preemptible or not is much simpler now.

This also fixes a regression with symbols being both in a got and copy
relocated. They had regressed in r268668 and r268149.

The other test changes are because of error messages changes or the
order of two relocations in the output.

llvm-svn: 322047
2018-01-09 00:13:54 +00:00
Rafael Espindola d1bd95cf73 Move scanReloc to an auxiliary function.
The body of the in scanRelocs is fairly big. This moves it to its own
function.

It is not a big readability win by itself, but should help further
refactoring.

llvm-svn: 322035
2018-01-08 22:20:44 +00:00
Rafael Espindola 8d13b213d4 Simplify handling of size relocations.
This is possible now that getSize is not a template.

llvm-svn: 321900
2018-01-05 21:41:17 +00:00
Rafael Espindola 73584cb587 Centralize Config->IsRela handling.
This merges the two places were we check Config->IsRela to decide how
to write a relocation addend.

llvm-svn: 321889
2018-01-05 20:08:38 +00:00
Rafael Espindola a3ce1fdaba Inline a function that is only called once. NFC.
llvm-svn: 321780
2018-01-04 01:33:41 +00:00
Rafael Espindola bba410668a Use references for a few arguments that are never null.
llvm-svn: 321772
2018-01-03 23:26:20 +00:00
Rafael Espindola 9cded98ad6 Mention symbol name in error message.
llvm-svn: 321769
2018-01-03 22:55:46 +00:00
Rafael Espindola 7c99c14722 Use getLocation to improve error message.
llvm-svn: 321768
2018-01-03 22:44:58 +00:00
Rafael Espindola 7137b8c298 Update code as this also handles GOT relocations.
llvm-svn: 321738
2018-01-03 16:54:18 +00:00
Rafael Espindola 49422f341a Use a switch. NFC.
llvm-svn: 321737
2018-01-03 16:52:15 +00:00
Rafael Espindola cc333d7400 Refactor duplicated expression.
llvm-svn: 321736
2018-01-03 16:38:46 +00:00
Rafael Espindola 6e102b2fc6 Use a swtich. NFC.
llvm-svn: 321734
2018-01-03 16:29:43 +00:00
Rafael Espindola 28aa6e2bc5 Simplify mips gprel handling.
We normally add checks on the architecture independent Expr instead of
on the architecture dependent relocation type.

llvm-svn: 321733
2018-01-03 16:16:05 +00:00
Rafael Espindola b5153ef7e8 Don't assume that size relocations are always constant.
llvm-svn: 321688
2018-01-03 03:58:58 +00:00
Rafael Espindola 4b2350d79b Produce relocations with weak undef if the section is RW.
If a section is RW there is no reason to drop a relocation with a weak
undefined symbol.

llvm-svn: 321684
2018-01-03 01:24:58 +00:00
Rafael Espindola 465e7c94ed Allow copy relocation with -z notext.
This makes adjustExpr a bit simpler too IMHO.

It seems that some of the complication around relocation processing
is that we are trying to create copy relocations too early. It seems
we could handle a few simple cases first and continue.

llvm-svn: 321507
2017-12-28 00:23:49 +00:00
Rafael Espindola e2e070c6c4 Don't try to preempt protected symbols with -z notext.
I will send a followup patch removing the FIXME this patch adds.

llvm-svn: 321499
2017-12-27 20:53:13 +00:00
George Rimar a0ab8d7a58 [ELF] - Allow relocation to a weak undefined symbol when -z notext is given.
Previously we failed to resolve them when produced executables:
"relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC"

Patch fixes it so that we resolve them to 0 for executables. 
And for -shared case we still should produce the relocation.

This finishes fixing PR35720.

DIfferential revision: https://reviews.llvm.org/D41551

llvm-svn: 321473
2017-12-27 07:29:55 +00:00
Rafael Espindola a9c490b71d Allow relocations in rw sections to create plt entries.
If a relocation cannot be implemented by the dynamic linker and the
section is rw, allow creating a plt entry to use as the function
address as if the section was ro.

This matches bfd and gold. It also matches our behavior with -z
notext.

llvm-svn: 321430
2017-12-24 19:02:10 +00:00
Rafael Espindola 9a84f6b954 Detemplate reportDuplicate.
We normally avoid "switch (Config->EKind)", but in this case I think
it is worth it.

It is only executed when there is an error and it allows detemplating
a lot of code.

llvm-svn: 321404
2017-12-23 17:21:39 +00:00
George Rimar 3bdf6baa25 [ELF] - Allow using PLT relocations when "-z notext" is given.
This is part of PR35720.

Currently LLD allows dynamic relocations against text when -z notext is given.
Though for non-PIC relocations like R_X86_64_PC32 that does not work,
we produce "relocation R_X86_64_PC32 cannot be used against shared object;"
error because they may overflow in runtime.

Solution implemented is to use PLT for them.

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

llvm-svn: 321400
2017-12-23 09:00:37 +00:00
Rafael Espindola a973cc2282 Call isStaticLinkTimeConstant only once per relocation.
It is a pretty expensive function. Some of the speedups:

clang: 1.92%
chrome: 1.15%
linux-kernel: 1.40%
llvm-svn: 321311
2017-12-21 21:45:35 +00:00
Rafael Espindola a32ddc4639 Use a reference for the shared symbol file.
Every shared symbol has a file, so we can use a reference.

llvm-svn: 321187
2017-12-20 16:28:19 +00:00
Rafael Espindola 4c74feffd4 Don't write preemptible symbol values to the .got.
It is not necessary and matches what bfd and gold do.

This was a regression from r315658.

llvm-svn: 321023
2017-12-18 20:35:15 +00:00
Rafael Espindola 87e0deaea7 Move RelaPlt and RelaIplt to InX. NFC.
llvm-svn: 320327
2017-12-10 20:07:03 +00:00
Rafael Espindola 58946cdb08 Move RelaDyn to InX. NFC.
llvm-svn: 320324
2017-12-10 19:44:42 +00:00
Rafael Espindola d26b52fd34 Remove some includes from InputFiles.h.
They were not used in InputFiles.h and it was getting too easy to add
circular includes.

llvm-svn: 320256
2017-12-09 16:56:18 +00:00
Rafael Espindola 91fac59a81 Add a call to std::vector::reserve.
This reduces total allocations when linking clang fsds from 263.21MB
to 174.62MB.

This also has some very nice speed improvements on some
benchmarks. Chromium and clang fsds link 6% faster.

llvm-svn: 319976
2017-12-06 22:32:19 +00:00
Rafael Espindola a834b529c3 Fix a crash.
This is a constructed testcase I noticed while working on another
patch.

llvm-svn: 319874
2017-12-06 02:53:43 +00:00
Rafael Espindola dfebd3601d Use Symbol::File directly.
We are already paying the cost of storing a InputFile in every
Symbol, so use it uniformly.

llvm-svn: 319378
2017-11-29 22:47:35 +00:00
Rui Ueyama 2017d52b54 Move Memory.{h,cpp} to Common.
Differential Revision: https://reviews.llvm.org/D40571

llvm-svn: 319221
2017-11-28 20:39:17 +00:00
Rafael Espindola 1d4b3023dc Bring back r319008.
This includes a fix to mark copy reloc aliases as used.

Original message:

[ELF] Do not keep symbols if they referenced only from discarded sections.

This patch also ensures that in case of "--as-needed" is used,
DT_NEEDED entries are not created if they are required only by
these eliminated symbols.

llvm-svn: 319215
2017-11-28 20:17:58 +00:00
Alexander Richardson f463042312 [ELF][MIPS] Fix crash in LLD when linking code that needs PIC thunks
Summary:
The bug triggers when the following conditions are met:
    - A thunk is created in a given input section S
    - A linker script is specified
    - There is at least one matcher in the linker script .text section output
      that does not match any of the sections in the input files, before the matcher
      that matches section S.

The issue was found when linking the FreeBSD kernel for MIPS when built
with -fPIC. Patch by Alfredo Mazzinghi.

Reviewers: ruiu, psmith, atanasyan

Reviewed By: ruiu

Subscribers: peter.smith, emaste, sdardis, krytarowski, llvm-commits

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

llvm-svn: 318653
2017-11-20 15:37:19 +00:00
Peter Smith a2db4349d5 [ELF] Fix typo in comment for getISDThunkSec [NFC]
The ISR in the comment should read ISD for InputSectionDescription. The use
of ISR (InputSectionRange) was from the original implementation that did not
use the sections from InputSectionDescription directly.

llvm-svn: 317469
2017-11-06 10:36:18 +00:00
Peter Collingbourne e9a9e0a1e7 ELF: Merge DefinedRegular and Defined.
Now that DefinedRegular is the only remaining derived class of
Defined, we can merge the two classes.

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

llvm-svn: 317448
2017-11-06 04:35:31 +00:00
Rui Ueyama 48882249dd Rename Body -> Sym.
This patch is mechanically created by

  sed -i -e s/Body/Sym/g lld/ELF/*.{cpp,h}

and clang-format-diff.

llvm-svn: 317392
2017-11-04 00:31:04 +00:00
Rui Ueyama f52496e1e0 Rename SymbolBody -> Symbol
Now that we have only SymbolBody as the symbol class. So, "SymbolBody"
is a bit strange name now. This is a mechanical change generated by

  perl -i -pe s/SymbolBody/Symbol/g $(git grep -l SymbolBody lld/ELF lld/COFF)

nd clang-format-diff.

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

llvm-svn: 317370
2017-11-03 21:21:47 +00:00
George Rimar 82f0c42dad [ELF] - Teach LLD to report line numbers for data symbols.
This is PR34826.

Currently LLD is unable to report line number when reporting
duplicate declaration of some variable.

That happens because for extracting line information we always use
.debug_line section content which describes mapping from machine
instructions to source file locations, what does not help for
variables as does not describe them.

In this patch I am taking the approproate information about
variables locations from the .debug_info section.

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

llvm-svn: 317080
2017-11-01 07:42:38 +00:00
Rui Ueyama f1f00841d9 Merge SymbolBody and Symbol into one class, SymbolBody.
SymbolBody and Symbol were separated classes due to a historical reason.
Symbol used to be a pointer to a SymbolBody, and the relationship
between Symbol and SymbolBody was n:1.

r2681780 changed that. Since that patch, SymbolBody and Symbol are
allocated next to each other to improve memory locality, and they have
1:1 relationship now. So, the separation of Symbol and SymbolBody no
longer makes sense.

This patch merges them into one class. In order to avoid updating too
many places, I chose SymbolBody as a unified name. I'll rename it Symbol
in a follow-up patch.

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

llvm-svn: 317006
2017-10-31 16:07:41 +00:00
Rafael Espindola 566dbdc2fd Skip abs symbols when handling copy reloc aliases.
Since we now only check st_value, we have to consider the case where
the section index is special.

llvm-svn: 316928
2017-10-30 17:26:12 +00:00