Commit Graph

230 Commits

Author SHA1 Message Date
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
Rui Ueyama 4076fa1e21 De-template SharedSymbol.
Differential Revision: https://reviews.llvm.org/D30351

llvm-svn: 296303
2017-02-26 23:35:34 +00:00
Rafael Espindola 24e6f363c5 Merge OutputSectionBase and OutputSection. NFC.
Now that all special sections are SyntheticSections, we only need one
OutputSection class.

llvm-svn: 296127
2017-02-24 15:07:30 +00:00
Rafael Espindola 774ea7d0a9 Make InputSection a class. NFC.
With the current design an InputSection is basically anything that
goes directly in a OutputSection. That includes plain input section
but also synthetic sections, so this should probably not be a
template.

llvm-svn: 295993
2017-02-23 16:49:07 +00:00
Rafael Espindola b4c9b81aad Convert InputSectionBase to a class.
Removing this template is not a big win by itself, but opens the way
for removing more templates.

llvm-svn: 295923
2017-02-23 02:28:28 +00:00
Rui Ueyama e6e206d4b4 Do not use errs() or outs() directly. Instead use message(), log() or error()
LLD is a multi-threaded program. errs() or outs() are not guaranteed
to be thread-safe (they are actually not).

LLD's message(), log() or error() are thread-safe. We should use them.

llvm-svn: 295787
2017-02-21 23:22:56 +00:00
Rui Ueyama f829e8c97d Removes a trivial accessor.
llvm-svn: 295288
2017-02-16 06:12:41 +00:00
Rui Ueyama 924b361d01 Do not overload a one-bit variable, NeedsCopyOrPltAddr.
This patch removes NeedsCopyOrPltAddr and instead add two variables,
NeedsCopy and NeedsPltAddr. This uses one more bit in Symbol class,
but the actual size doesn't increase because we had unused bits.
This should improve code readability.

llvm-svn: 295287
2017-02-16 06:12:22 +00:00
Rafael Espindola 7386ceac74 Addends should always be signed.
In the target dependent code we already always return a int64_t. In
the target independent code we carefully use uintX_t, which has the
same result given 2 complement rules.

This just simplifies the code to use int64_t everywhere.

llvm-svn: 295263
2017-02-16 00:12:34 +00:00
Peter Smith ebfe994142 [ELF] Use synthetic section to hold copy relocation
When we need a copy relocation we create a synthetic SHT_NOBITS
section that contains the right amount of ZI and assign it to either
.bss or .rel.ro.bss as appropriate. This allows the dynamic relocation
to be placed on the InputSection, removing the last case where a
dynamic relocation is stored as an offset from the OutputSection. This
has the side effect that we can run assignOffsets() after scanRelocs()
without losing the additional ZI needed for the copy relocations.

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

llvm-svn: 294577
2017-02-09 10:27:57 +00:00
Rafael Espindola 9e9754b520 Replace MergeOutputSection with a synthetic section.
With a synthetic merge section we can have, for example, a single
.rodata section with stings, fixed sized constants and non merge
constants.

I can be simplified further by not setting Entsize, but that is
probably better done is a followup patch.

This should allow some cleanup in the linker script code now that
every output section command maps to just one output section.

llvm-svn: 294005
2017-02-03 13:06:18 +00:00
Peter Smith 3a52eb0054 [ELF] Use SyntheticSections for Thunks
Thunks are now implemented by redirecting the relocation to the
symbol S, to a symbol TS in a Thunk. The Thunk will transfer control
to S. This has the following implications:
- All the side-effects of Thunks happen within createThunks()
- Thunks are no longer stored in InputSections and Symbols no longer
  need to hold a pointer to a Thunk
- The synthetic Thunk sections need to be merged into OutputSections
    
This implementation is almost a direct conversion of the existing
Thunks with the following exceptions:
- Mips LA25 Thunks are placed before the InputSection that defines
  the symbol that needs a Thunk.
- All ARM Thunks are placed at the end of the OutputSection of the
  first caller to the Thunk.
    
Range extension Thunks are not supported yet so it is optimistically
assumed that all Thunks can be reused.

This is a recommit of r293283 with a fixed comparison predicate as
std::merge requires a strict weak ordering.

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

llvm-svn: 293757
2017-02-01 10:26:03 +00:00
Rui Ueyama f20ee9f11a Revert "[ELF][ARM] Use SyntheticSections for Thunks"
This reverts commit r293283 because it broke MSVC build.

llvm-svn: 293352
2017-01-28 00:48:06 +00:00
Peter Smith 5191c6f945 [ELF][ARM] Use SyntheticSections for Thunks
Thunks are now implemented by redirecting the relocation to the
symbol S, to a symbol TS in a Thunk. The Thunk will transfer control
to S. This has the following implications:
- All the side-effects of Thunks happen within createThunks()
- Thunks are no longer stored in InputSections and Symbols no longer
  need to hold a pointer to a Thunk
- The synthetic Thunk sections need to be merged into OutputSections
    
This implementation is almost a direct conversion of the existing
Thunks with the following exceptions:
- Mips LA25 Thunks are placed before the InputSection that defines
  the symbol that needs a Thunk.
- All ARM Thunks are placed at the end of the OutputSection of the
  first caller to the Thunk.
    
Range extension Thunks are not supported yet so it is optimistically
assumed that all Thunks can be reused.

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

llvm-svn: 293283
2017-01-27 13:10:16 +00:00
Rui Ueyama b2a23cf3c0 Do not allocate space for common symbols with -r
Currently ld.lld -r allocates space for common symbols, whereas ld.bfd
-r doesn't.  As a result the OpenBSD makefile bits for creating libraries
fail as they use ld -X -r to strip local symbols, which results in
duplicate symbol errors because space for the common symbols has been
allocated.

The diff also implements the --define-commons option such that allocation
of commons can be forced even if -r is used.

Patch by Mark Kettenis.

llvm-svn: 292878
2017-01-24 03:41:20 +00:00
Rafael Espindola 1d6d1b44cc Add a isInCurrentDSO helper. NFC.
llvm-svn: 292228
2017-01-17 16:08:06 +00:00
Rafael Espindola 41a93a3edf Give priority to linker scripts over preemption.
LLD exports symbols that are also present in used shared libraries to
make sure they are preempted at runtime. That is a reasonable default,
but we must allow for it to be overwritten with linker script. If we
don't, libraries that expect to be able to hide a c++ delete operator
will fail.

This should fix the firebird build.

llvm-svn: 292146
2017-01-16 17:35:23 +00:00
Rafael Espindola b7e2ee2aba Give local binding to VER_NDX_LOCAL symbols.
We were already dropping them from the dynamic symbol table, but the
regular symbol table was still listing them as globals.

llvm-svn: 291573
2017-01-10 17:08:13 +00:00
Peter Collingbourne feb6629d6d ELF: Reserve space for copy relocations of read-only symbols in relro.
When reserving copy relocation space for a shared symbol, scan the DSO's
program headers to see if the symbol is in a read-only segment. If so,
reserve space for that symbol in a new synthetic section named .bss.rel.ro
which will be covered by the relro program header.

This fixes the security issue disclosed on the binutils mailing list at:
https://sourceware.org/ml/libc-alpha/2016-12/msg00914.html

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

llvm-svn: 291524
2017-01-10 01:21:50 +00:00
Rafael Espindola 2756e04fac Handle versioned undefined symbols.
In order to keep symbol lookup a simple name lookup this patch adds
versioned symbols with an explicit @ to the symbol table.

llvm-svn: 291293
2017-01-06 22:30:35 +00:00
Rui Ueyama ce039266c1 Merge elf::toString and coff::toString.
The two overloaded functions hid each other. This patch merges them.

llvm-svn: 291222
2017-01-06 10:04:08 +00:00