Commit Graph

250 Commits

Author SHA1 Message Date
Rafael Espindola 7415819186 Handle lazy symbols is Symbol::includeInDynsym.
This should fix the lto bootstrap.

It is somewhat hard to remember about lazy symbols deep down in the
link. It might be worth it replacing them with undefined symbols once
we are done adding files.

llvm-svn: 313103
2017-09-13 00:47:06 +00:00
Ben Dunbobbin 0b95d3784a [ELF] Handle references to garbage collected common symbols
https://reviews.llvm.org/rL312796 meant that references to garbage collected common symbols would cause a segfault.

This change fixes the behaviour for references to stripped common symbols.

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

llvm-svn: 313086
2017-09-12 22:41:45 +00:00
Rafael Espindola 67df57a242 Remove Offset from Common.
It is not needed since it is always 0.

llvm-svn: 313076
2017-09-12 21:19:09 +00:00
Dmitry Mikulin 1e30f07ce7 Currently lld creates a single section to collect all commons. There is no way
to separate commons based on file name patterns. The following linker script
construct does not work because commons are allocated before section placement
is done and the only synthesized BssSection that holds all commons has no file
associated with it:
SECTIONS { .common_0 : { *file0.o(COMMON) }}

This patch changes the allocation of commons to create a section per common
symbol and let the section logic do the layout.

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

llvm-svn: 312796
2017-09-08 16:22:43 +00:00
Rafael Espindola db1af69342 Avoid crash with local abs symbol.
llvm-svn: 310736
2017-08-11 17:47:12 +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
Rafael Espindola 35c908f20c Compute isPreemtible only once.
This is probably a small optimization, but the main motivation is
having a way of fixing pr34053 that doesn't require a hash lookup in
isPreempitible.

llvm-svn: 310602
2017-08-10 15:05:37 +00:00
Rafael Espindola 6e93d0546a Move File from SymbolBody to Symbol.
With this Symbol has the same size as before, but DefinedRegular goes
from 72 to 64 bytes.

I also find this a bit easier to read. There are fewer places
initializing File for example.

This has a small but measurable speed improvement on all tests (1%
max).

llvm-svn: 310142
2017-08-04 22:31:42 +00:00
Rafael Espindola 0afcef27a1 Remove redundant flag.
llvm-svn: 310079
2017-08-04 17:43:54 +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
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
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
Rui Ueyama 709fb2bb10 Rename ObjectFile -> ObjFile.
Rename it because it was too easy to conflict with llvm::object::ObjectFile
which broke buildbots several times.

llvm-svn: 309199
2017-07-26 22:13:32 +00:00
Peter Collingbourne 3e2abdef02 ELF: Reword a somewhat misleading error message.
PT_TLS is a type of program header, so we wouldn't expect to see
one in an object file. This error should probably be referring to
the fact that we didn't see a section with the flag SHF_TLS, which
would normally cause us to create a PT_TLS program header.

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

llvm-svn: 307983
2017-07-14 00:22:46 +00:00
Rafael Espindola cf00d4374e Fix PR33635.
This is a semantic revert of r306036.

We have to change the names, otherwise dynamic relocations will point
to the wrong name.

llvm-svn: 307110
2017-07-05 00:43:18 +00:00
George Rimar 4d2f976208 [ELF] - Resolve references properly when using .symver directive
This is PR28414. 
Previously LLD was unable to link following:
(failed with undefined symbol bar)

Version script:
SOME_VERSION { global: *; };

.global _start
.global bar
.symver _start, bar@@SOME_VERSION
_start:
  jmp bar
Manual has next description:

.symver name, name2@@nodename
In this case, the symbol name must exist and be defined within the file being assembled. It is similar to name2@nodename. 
The difference is name2@@nodename will also be used to resolve references to name2 by the linker
https://sourceware.org/binutils/docs/as/Symver.html

Patch implements that. If we have name@@ver symbol and name is undefined, name@@ver is used to resolve references to name.
If name is defined then multiple definition error is emited, that is consistent with what bfd do.

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

llvm-svn: 307077
2017-07-04 13:19:13 +00:00
Rui Ueyama b2269ec4d3 Move copy function from Symbol to SymbolBody.
We could have add this function either Symbol or SymbolBody. I added it
to Symbol at first. But I noticed that if I've added it to SymbolBody,
we could've removed SymbolBody::setName(). So I'll do that in this patch.

llvm-svn: 306590
2017-06-28 19:43:02 +00:00
Rui Ueyama 8e11b6d94b Define Symbol::copyBody function.
This patch adds a utility function to Symbol. This function should
be useful in https://reviews.llvm.org/D33680 too.

llvm-svn: 306587
2017-06-28 19:28:49 +00:00
Rui Ueyama 92c3781959 Add GlobalOffsetTable to ElfSym. NFC.
Most "reserved" symbols are in ElfSym and it looks like there's no
reason to not do the same thing for _GLOBAL_OFFSET_TABLE_. This should
help https://reviews.llvm.org/D34618 too.

llvm-svn: 306292
2017-06-26 15:11:24 +00:00
Rui Ueyama d97265f792 Simplify. NFC.
llvm-svn: 305112
2017-06-09 21:09:08 +00:00
Rafael Espindola db5e56f7b2 Store a single Parent pointer for InputSectionBase.
Before InputSectionBase had an OutputSection pointer, but that was not
always valid. For example, if it was a merge section one actually had
to look at MergeSec->OutSec.

This was brittle and caused bugs like the one fixed by r304260.

We now have a single Parent pointer that points to an OutputSection
for InputSection, but to a SyntheticSection for merge sections and
.eh_frame. This makes it impossible to accidentally access an invalid
OutSec.

llvm-svn: 304338
2017-05-31 20:17:44 +00:00
Rafael Espindola f9e3c9cc22 Detemplate SymbolBody::getGotVA. NFC.
llvm-svn: 302846
2017-05-11 23:28:49 +00:00
Rafael Espindola 88ab9fb163 Detemplate the got.
This is a bit hackish, but allows for a lot of followup cleanups.

llvm-svn: 302845
2017-05-11 23:26:03 +00:00
Rafael Espindola 808f2d3c62 Reduce code duplication. NFC.
llvm-svn: 302155
2017-05-04 14:54:48 +00:00
Rui Ueyama 273bbbc3a7 Remove a useless temporary variable.
llvm-svn: 301278
2017-04-24 23:50:58 +00:00
Rui Ueyama 3e1fc3f6fe Add "1" suffix if there's varaible ends with "2".
If we knew that we'd add End2, Edata2 and Etext2, we'd name their
original symbols with "1". This patch does it.

llvm-svn: 300263
2017-04-13 21:37:56 +00:00
George Rimar e6c5d3862d [ELF] - Define __bss_start symbol.
GNU linkers define __bss_start symbol.
Patch teaches LLD to do that. This is PR32051.

Below is part of standart ld.bfd script:

.data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  .bss            :
  {
Currently LLD can emit up to 3 .bss* sections as one of testcase shows.
Implementation inserts this symbol before first .bss* output section.

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

llvm-svn: 299528
2017-04-05 10:03:25 +00:00
George Rimar 4afe42e5c4 [ELF] - Detemplate SymbolBody::getGotOffset(). NFC.
llvm-svn: 298091
2017-03-17 14:12:51 +00:00
George Rimar f64618a621 [ELF] - Detemplate SymbolBody::getVA and SymbolBody::getPltVA. NFC.
llvm-svn: 298071
2017-03-17 11:56:54 +00:00
George Rimar 1ab9cf49d0 [ELF] - Recommit "[ELF] - Make Bss and BssRelRo sections to be synthetic (#3)."
Was fixed, details on review page.

Original commit message:

That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.

This is splitted from D30541 and polished.
Difference from D30541 that all logic of SharedSymbol
converting to DefinedRegular was removed for now and
probably will be posted as separate patch.

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

llvm-svn: 298062
2017-03-17 10:14:53 +00:00
George Rimar 4670bb00b5 [ELF] - Detemplate SymbolBody::getGotPltVA and SymbolBody::getGotPltOffset(). NFC.
That opens road to detemplate PltSection<ELFT>,
what allows then to detemplate all methods of SymbolBody.

llvm-svn: 297950
2017-03-16 12:58:11 +00:00
George Rimar 69268a8ab3 [ELF] - Detemplate SymbolBody::getOutputSection(). NFC.
llvm-svn: 297943
2017-03-16 11:06:13 +00:00
George Rimar 47bed8c9f7 Revert r297813 "[ELF] - Make Bss and BssRelRo sections to be synthetic (#3)."
I suppose it is the reason of BB fail:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/921

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

llvm-svn: 297933
2017-03-16 08:44:53 +00:00
George Rimar 22e3e7d165 [ELF] - Make Bss and BssRelRo sections to be synthetic (#3).
That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.

This is splitted from D30541 and polished.
Difference from D30541 that all logic of SharedSymbol
converting to DefinedRegular was removed for now and
probably will be posted as separate patch.

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

llvm-svn: 297814
2017-03-15 09:21:29 +00:00
Rafael Espindola 5616adf655 Remove DefinedSynthetic.
With this we have a single section hierarchy. It is a bit less code,
but the main advantage will be in a future patch being able to handle

foo = symbol_in_obj;

in a linker script. Currently that fails since we try to find the
output section of symbol_in_obj.  With this we should be able to just
return an InputSection from the expression.

llvm-svn: 297313
2017-03-08 22:36:28 +00:00
Rafael Espindola fcd208fdb3 Use uint32_t for alignment in more places, NFC.
llvm-svn: 297305
2017-03-08 19:35:29 +00:00
Rui Ueyama 007c002cb6 Revert r297008: [ELF] - Make Bss and BssRelRo sections to be synthetic (#2).
This reverts commit r297008 because it's reported that that
change broke AArch64 bots.

llvm-svn: 297297
2017-03-08 17:24:24 +00:00
Rafael Espindola 5e434b3f11 Remove unnecessary template.
llvm-svn: 297293
2017-03-08 16:08:36 +00:00
Rafael Espindola e1294091d3 Remove unnecessary template. NFC.
llvm-svn: 297292
2017-03-08 16:03:41 +00:00
Rafael Espindola c86b2cddc8 Convert a few more uses of uintX_t to uint64_t.
llvm-svn: 297286
2017-03-08 15:34:04 +00:00
Rafael Espindola 9371bab55a Convert a few uses of uintX_t to uint64_t.
llvm-svn: 297282
2017-03-08 15:21:32 +00:00
Evgeniy Stepanov 5ac5542544 Fix -Werror build error.
tools/lld/ELF/Symbols.cpp:215:13: error: unused variable 'S'
[-Werror,-Wunused-variable]
  if (auto *S = dyn_cast<SharedSymbol>(this)

llvm-svn: 297063
2017-03-06 20:27:38 +00:00
George Rimar c215a2ac40 [ELF] - Make Bss and BssRelRo sections to be synthetic (#2).
In compare with D30458, this makes Bss/BssRelRo to be pure
synthetic sections.

That removes CopyRelSection class completely, making
Bss/BssRelRo to be just regular synthetics.

SharedSymbols involved in creating copy relocations are
converted to DefinedRegular, what also simplifies things.

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

llvm-svn: 297008
2017-03-06 14:37:45 +00:00
Sean Silva d4e606273b Improve comment.
Thanks to Rafael for helping to dig down into what we're really trying
to communicate here.

llvm-svn: 296580
2017-03-01 04:44:04 +00:00
Rui Ueyama 80474a26b9 De-template DefinedRegular.
Differential Revision: https://reviews.llvm.org/D30348

llvm-svn: 296508
2017-02-28 19:29:55 +00:00
Sean Silva 6ab3926ee6 Comment on the typical/simple case of VA calculation
There are many special cases and a layer of abstraction or two in the
way, but the VA calculation in the typical case is actually very simple
and probably makes perfect sense even to somebody new to linkers.

Also, this line brings together many components and is a good place to
start understanding the linker (or improve one's existing
understanding).

llvm-svn: 296451
2017-02-28 09:01:58 +00:00
Sean Silva a9ba450c52 Add a comment.
Naively it seemed at first like getVA had the responsibility of adding
the addend, and getSymVA had the responsibility of getting the symbol
VA.
So it was not obvious to me at first why getVA passes Addend to
getSymVA. In fact, it passes it as a mutable reference.

It turns out that it only matters for SHF_MERGE sections, and in
particular only for STT_SECTION symbols that are used as a hack for
reducing the number of local symbols (e.g. to avoid a local symbol for
each string in the string table).

llvm-svn: 296448
2017-02-28 08:32:56 +00:00
Rui Ueyama 968db48cee Move SymbolTableSection::getOutputSection to SymbolBody::getOutputSection.
That function doesn't use any member of SymbolTableSection, so I
couldn't see a reason to make it a member of that class. The function
takes a SymbolBody, so it is more natural to make it a member of
SymbolBody.

llvm-svn: 296433
2017-02-28 04:02:42 +00:00
Rui Ueyama 9d1bacb1b4 Remove useless template so that Out<ELFT> becomes just Out.
llvm-svn: 296307
2017-02-27 02:31:26 +00:00