Commit Graph

91 Commits

Author SHA1 Message Date
George Rimar a8dba48762 [ELF] - Combine LinkerScriptBase and LinkerScript<ELFT>
Patch removes templated linkerscript class.

Unfortunately that required 2 additional static methods
findSymbol() and addRegularSymbol() because code
depends on Symtab<ELFT>::X

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

llvm-svn: 298241
2017-03-20 10:09:58 +00:00
Rui Ueyama d57e74b7d3 Compute Config member function return values only once.
We had a few Config member functions that returns configuration values.
For example, we had is64() which returns true if the target is 64-bit.
The return values of these functions are constant and never change.

This patch is to compute them only once to make it clear that they'll
never change.

llvm-svn: 298168
2017-03-17 23:29:01 +00:00
Evgeniy Stepanov 4b78036ba8 [ELF] Restore GC handling of LINK_ORDER, C-named sections.
__start_xxx symbol keeps section xxx alive only if it is not
SHF_LINK_ORDER. Such sections can be used for user metadata, when
__start_xxx is used to iterate over section contents at runtime, and
the liveness is determined solely by the linked (associated) section.

This was earlier implemented in r294592, and broken in r296723.

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

llvm-svn: 298154
2017-03-17 22:04:52 +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
Rui Ueyama df8eb17d21 Remove Config->Mips64EL and define Config->isMips64EL() instead.
llvm-svn: 297107
2017-03-07 00:43:33 +00:00
Rafael Espindola 5c02b741eb Detemplate EhInputSection. NFC.
llvm-svn: 297077
2017-03-06 21:17:18 +00:00
Rafael Espindola 6119b865ec Detemplate merge (input and synthetic) sections. NFC.
llvm-svn: 297061
2017-03-06 20:23:56 +00:00
Rafael Espindola 692b2f88d3 Fully precise gc handling of __start and __stop symbols.
This puts us at parity with bfd, which could already gc this case.

I noticed the sections not being gced when linking a modified freebsd
kernel. A section that was not gced and not mentioned in the linker
script would end up breaking the expected layout. Since fixing the gc
is relatively simple and an improvement, that seems better than trying
to hack the orphan placement code.

There are 173 input section in the entire link whose names are valid C
identifiers, so this is probably not too performance critical.

llvm-svn: 297049
2017-03-06 18:48:18 +00:00
Rafael Espindola 066d3d2141 Pass a callback to resolveReloc. NFC.
This is consistent with rest of the file and opens the way for a
relocation keeping multiple sections alive.

llvm-svn: 296788
2017-03-02 19:29:28 +00:00
Rafael Espindola 4368bdb270 Make gc a bit more aggressive.
We were not gcing any section whose name was a C identifier. Both gold
and bfd only keep those if they are used.

To avoid having to create the __start/__stop symbols early or doing
string lookups in resolvedReloc, this patch just looks for undefined
symbols __start/__stop to decide if a section is needed or not.

llvm-svn: 296723
2017-03-02 01:50:34 +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
Rui Ueyama 3ead2e73ee De-template ResolvedReloc as it doesn't actually depends on ELFT.
Pointed out by Bob Haarman.

llvm-svn: 296377
2017-02-27 20:32:34 +00:00
Rui Ueyama 536a26706f Move SymbolTable<ELFT>::Sections out of the class.
The list of all input sections was defined in SymbolTable class for a
historical reason. The list itself is not a template. However, because
SymbolTable class is a template, we needed to pass around ELFT to access
the list. This patch moves the list out of the class so that it doesn't
need ELFT.

llvm-svn: 296309
2017-02-27 02:32:08 +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
George Rimar 09015fee3c [ELF] - Allow section to have multiple dependent sections.
That fixes a case when section has more than one metadata 
section. Previously GC would collect one of such sections 
because we had implementation that stored only last one as
dependent.

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

llvm-svn: 295298
2017-02-16 08:41:19 +00:00
Rafael Espindola ed441c7060 Handle gcing user created metadata.
In particular, this should allow us to gc unused asan metadata.

llvm-svn: 294592
2017-02-09 15:17:56 +00:00
Rafael Espindola 9f0c4bb795 Parse relocations only once.
Relocations are the last thing that we wore storing a raw section
pointer to and parsing on demand.

With this patch we parse it only once and store a pointer to the
actual data.

The patch also changes where we store it. It is now in
InputSectionBase. Not all sections have relocations, but most do and
this simplifies the logic. It also means that we now only support one
relocation section per section. Given that that constraint is
maintained even with -r with gold bfd and lld, I think it is OK.

llvm-svn: 286459
2016-11-10 14:53:24 +00:00
Rafael Espindola 8f9026baff Don't add null and discarded sections to the global list.
Avoids having to skip them multiple times.

llvm-svn: 286261
2016-11-08 18:23:02 +00:00
Rui Ueyama 8c6a5aaf15 Create a vector containing all input sections.
Previously, we do this piece of code to iterate over all input sections.

  for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
    for (InputSectionBase<ELFT> *S : F->getSections())

It turned out that this mechanisms doesn't work well with synthetic
input sections because synthetic input sections don't belong to any
input file.

This patch defines a vector that contains all input sections including
synthetic ones.

llvm-svn: 286051
2016-11-05 22:37:59 +00:00
Rafael Espindola e19abab9a7 Now that the ELFFile constructor does nothing, create it when needed.
This avoids duplicating the buffer in InputFile.

llvm-svn: 285965
2016-11-03 20:44:50 +00:00
Rafael Espindola 454fe154a7 Update for llvm change.
llvm-svn: 285956
2016-11-03 19:07:44 +00:00
Rafael Espindola 1854a8ebb8 Delete trivial getters. NFC.
llvm-svn: 285190
2016-10-26 12:36:56 +00:00
Rafael Espindola 58139d1758 Delete getSectionHdr.
We were fairly inconsistent as to what information should be accessed
with getSectionHdr and what information (like alignment) was stored
elsewhere.

Now all section info has a dedicated getter. The code is also a bit
more compact.

llvm-svn: 285079
2016-10-25 16:14:25 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Rui Ueyama 8da7aa0894 Allow linker-script-defined entry symbols.
Previously, we were checking the existence of an entry symbol
too early. It was done before the linker script processor creates
symbols defined in scripts. Fixes bug 30743.

llvm-svn: 284676
2016-10-20 00:07:36 +00:00
Rafael Espindola 116d83fbe0 Don't call markLiveAt for non alloc sections.
We don't gc them anyway, so just use an early return in Enqueue.

llvm-svn: 284663
2016-10-19 23:13:40 +00:00
Peter Smith 0760605ac5 [ELF][ARM] Garbage collection support for .ARM.exidx sections
.ARM.exidx sections have a reverse dependency on the section they have
a SHF_LINK_ORDER dependency on. In other words a .ARM.exidx section is
live only if the executable section it describes is live. We implement
this with a reverse dependency field in InputSection.

Adding the dependency to InputSection is the simplest implementation
but it could be moved out to a separate map if it were found to decrease
performance for non ARM targets.

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

llvm-svn: 283734
2016-10-10 10:10:27 +00:00
Rui Ueyama a03380808c Early continue. NFC.
llvm-svn: 283382
2016-10-05 21:06:32 +00:00
Rui Ueyama ad9268a7b4 Early return. NFC.
llvm-svn: 283173
2016-10-04 00:46:36 +00:00
Eugene Leviant d2778848ef Don't GC non-alloc mergeable section pieces
Differential revision: https://reviews.llvm.org/D25033

llvm-svn: 282708
2016-09-29 10:27:10 +00:00
Rafael Espindola 615c5ae7ae Read addend from the correct location.
llvm-svn: 282663
2016-09-29 01:20:40 +00:00
George Rimar 74661eb040 [ELF] - Fixed linkage error when using -g --gc-sections together.
r282444 introduced new issue, sample program below
fails to link on

assert(Piece.Live);
int main() { return 0; }
clang test.cpp -c -o out.o -g
ld.lld -flavor gnu --gc-sections out.o -o out

Problem is that .debug_info contains relocations to .debug_str:
Section (7) .rela.debug_info {
..

0xC R_X86_64_32 .debug_str 0x0
0x12 R_X86_64_32 .debug_str 0x37
..
But we do not preserve .debug_str in a right way now.

To fix this we should ignore relocations from non-allocatable sections to allocatable
to allow GC work at full power, but still should proccess relocations from non-allocatable to non-allocatable sections
as usual to mark some parts of debug sections alive to keep them so we do not end 
up with such assert when trying to access dead pieces. That looks like what gold/ld do, they do 
not strip .debug_str section from what I saw using sample provided.

Thanks to Evgeny Leviant for suggestions about how to fix this.

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

llvm-svn: 282495
2016-09-27 15:55:29 +00:00
Rafael Espindola 2b9008e5e5 Non alloca sections should not keep other sections live.
This matches the gold behaviour and is important to prevent debug info
from effectively disabling gc.

llvm-svn: 282444
2016-09-26 21:34:34 +00:00
Eugene Leviant 527a84ec12 Linkerscript: don't crash when GC .debug_line
Differential revision: https://reviews.llvm.org/D24870

llvm-svn: 282393
2016-09-26 09:04:16 +00:00
Eugene Leviant 8287b1bce1 Linkerscript: do not GC non-allocated sections
Differential revision: https://reviews.llvm.org/D24733

llvm-svn: 282391
2016-09-26 08:32:41 +00:00
Davide Italiano 49ab2517f5 [ELF/GC] Don't crash while processing Discarded sections.
The ELF spec doesn't allow relocations to point directly to
a deduplicated COMDAT section but this unfortunately happens in
practice. Bail out early instead of crashing.

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

llvm-svn: 282197
2016-09-22 21:08:51 +00:00
Rui Ueyama 38dbd3eea9 Simplify InputFile ownership management.
Previously, all input files were owned by the symbol table.
Files were created at various places, such as the Driver, the lazy
symbols, or the bitcode compiler, and the ownership of new files
was transferred to the symbol table using std::unique_ptr.
All input files were then free'd when the symbol table is freed
which is on program exit.

I think we don't have to transfer ownership just to free all
instance at once on exit.

In this patch, all instances are automatically collected to a
vector and freed on exit. In this way, we no longer have to
use std::unique_ptr.

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

llvm-svn: 281425
2016-09-14 00:05:51 +00:00
Rui Ueyama 3e9037d419 Inline small funciton.
llvm-svn: 281381
2016-09-13 19:56:27 +00:00
Rafael Espindola c7e1e03498 Store an ArrayRef for Data in InputSectionData.
llvm-svn: 281210
2016-09-12 13:13:53 +00:00
Rafael Espindola 042a3f209b Compute section names only once.
This simplifies error handling as there is now only one place in the
code that needs to consider the possibility that the name is
corrupted. Before we would do it in every access.

llvm-svn: 280937
2016-09-08 14:06:08 +00:00
Benjamin Kramer df8f196f9a Unpollute the global namespace. lld edition.
llvm-svn: 277926
2016-08-06 13:52:37 +00:00
Rafael Espindola 2deeb6093d Fix PR28575.
Not all relocations from a .eh_frame that point to an executable
section should be ignored. In particular, the relocation finding the
personality function should not.

This is a reduction from trying to bootstrap a static lld on linux.

llvm-svn: 276329
2016-07-21 20:18:30 +00:00
Rafael Espindola 3fab868675 Pass section by reference. NFC.
llvm-svn: 275803
2016-07-18 16:05:09 +00:00
Rui Ueyama 03e1cc6322 Remove duplicate declaration.
llvm-svn: 274429
2016-07-02 08:50:05 +00:00
Rui Ueyama 0b9a90364b Rename EHInputSection -> EhInputSection.
llvm-svn: 270532
2016-05-24 04:19:20 +00:00
Rui Ueyama b91bf1a9a0 Do not split mergeable sections if they are gc'ed.
Previously, mergeable section's constructors did more than just
setting member variables; it split section contents into small
pieces. It is not always computationally cheap task because if
the section is a mergeable string section, it needs to scan the
entire section to split them by NUL characters.

If a section would be thrown away by GC, that cost ended up
being a waste of time. It is going to be larger problem if the
section is compressed -- the whole time to uncompress it and
split it up is going to be a waste.

Luckily, we can defer section splitting after GC. We just have
to remember which offsets are in use during GC and apply that later.
This patch implements it.

Differential Revision: http://reviews.llvm.org/D20516

llvm-svn: 270455
2016-05-23 16:55:43 +00:00
Rui Ueyama 90fa3722d2 Simplify SplitInputSection::getRangeAndSize.
This patch adds Size member to SectionPiece so that getRangeAndSize
can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.
Also renamed the function.

llvm-svn: 270346
2016-05-22 00:41:38 +00:00
Rui Ueyama 3ea8727188 Define SectionPiece and use it instead of std::pair<uint_t, uint_t>.
We were using std::pair to represents pieces of splittable section
contents. It hurt readability because "first" and "second" are not
meaningful. This patch give them names.

One more thing is that piecewise liveness information is stored to
the second element of the pair as a special value of output section
offset. It was confusing, so I defiend a new bit, "Live", in the
new struct.

llvm-svn: 270340
2016-05-22 00:13:04 +00:00
Rafael Espindola d89fbca21d Fix --gc-sections when .eh_frame has a lsda.
We have to add sections to the work list, not just mark them live.

llvm-svn: 268628
2016-05-05 13:51:14 +00:00