Commit Graph

651 Commits

Author SHA1 Message Date
Rafael Espindola b47c6e5cbd Fix a crash.
We would crash if a SHF_LINK_ORDER section pointed to a non
InputSection section. Since those sections are not merged in order,
SHF_LINK_ORDER is pretty meaningless and we can error on that case.

llvm-svn: 304327
2017-05-31 19:09:52 +00:00
George Rimar 3b189d1643 [ELF] - Do not allow -r to eat comdats.
This is PR33052, "Bug 33052 - -r eats comdats ".

To fix it I stop removing group section from out when -r is given
and fixing SHT_GROUP content when writing it just like we do some
other fixup, e.g. for Rel[a]. (it needs fix for section indices that
are in group).

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

llvm-svn: 304140
2017-05-29 08:37:50 +00:00
Rui Ueyama 2f106b4690 When uncompressing sections, remove SHF_COMPRESSED bits. NFC.
In this way, the content and the flag is always consistent, which I
think better than removing the bit when input sections reaches the Writer.

llvm-svn: 303926
2017-05-25 22:00:36 +00:00
Kamil Rytarowski e739e49c0f Replace std::call_once with llvm:call_once
Summary:
This is required on some platforms, as GNU libstdc++ std::call_once is known to be buggy.

This fixes operation of LLD on at least NetBSD and perhaps OpenBSD and Linux PowerPC.

The same change has been introduced to LLVM and LLDB.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, #lld

Tags: #lld

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

llvm-svn: 303788
2017-05-24 18:31:48 +00:00
Rafael Espindola a6465bbb72 Alternative way to detemplate GotSection.
GetSection is a template because write calls relocate.

relocate has two parts. The non alloc code really has to be a
template, as it is looking a raw input file data.

The alloc part is only a template because of getSize.

This patch folds the value of getSize early, detemplates
getRelocTargetVA and splits relocate into a templated non alloc case
and a regular function for the alloc case. This has the nice advantage
of making sure we collect all the information we need for relocations
before getting to InputSection::relocateNonAlloc.

Since we know got is alloc, it can just call the function directly and
avoid the template.

llvm-svn: 303355
2017-05-18 16:45:36 +00:00
Peter Smith d54f368e6a [ELF] Support R_ARM_SBREL32 Relocation
This change adds support for the R_ARM_SBREL32 relocation. The relocation
is a base relative relocation that is produced by clang/llvm when -frwpi
is used. The use case for the -frwpi option is position independent data
for embedded systems that do not have a GOT. With -frwpi all data is
accessed via an offset from a base register (usually r9), where r9 is set
at run time to where the data has been loaded. The base of the data is
known as the static base.

The ARM ABI defines the static base as:
B(S) is the addressing origin of the output segment defining the symbol S.
The origin is not required to be the base address of the segment. For
simplicity we choose to use the base address of the segment.

The ARM procedure call standard only defines a read write variant using
R_ARM_SBREL32 relocations. The read-only data is accessed via pc-relative
offsets from the code, this is implemented in clang as -fropi.

Fixes PR32924

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

llvm-svn: 303337
2017-05-18 09:12:21 +00:00
George Rimar 69b17c35d9 [ELF] - Detemplate access to SymTab, DynSymTab, GnuHashTab. NFC.
Follow up for r303150.

llvm-svn: 303153
2017-05-16 10:04:42 +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 b3aa2c9b9e Reduce template usage. NFC.
llvm-svn: 302828
2017-05-11 21:33:30 +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 0faa53aaab Remove useless local variable.
llvm-svn: 300294
2017-04-14 01:35:04 +00:00
Rui Ueyama c49bdd6d5d Replace uintX_t with uint64_t.
We generally want to use uint64_t instead of uintX_t if the 64-bit
type works for both 32-bit and 64-bit because it is simpler than
the variable-size type.

llvm-svn: 300293
2017-04-14 01:34:45 +00:00
George Rimar e7bf968803 [ELF] - Stop producing broken output for R_386_GOT32[X] relocations.
Previously we silently produced broken output for R_386_GOT32X/R_386_GOT32 
relocations if they were used to compute the address of the symbol’s global
offset table entry without base register when position-independent code is disabled.

Situation happened because of recent ABI changes. Released ABI mentions that
R_386_GOT32X can be calculated in a two different ways (so we did not follow ABI here 
before this patch), but draft ABI also mentions R_386_GOT32 relocation here. 
We should use the same calculations for both relocations.

Problem is that we always calculated them as G + A - GOT (offset from end of GOT),
but for case when PIC is disabled, according to i386 ABI calculation should be G + A,
what should produce just an address in GOT finally.

ABI: https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-draft.pdf (p36, p60).
llvm-svn: 299812
2017-04-08 06:14:14 +00:00
Rui Ueyama b87602032a Change the error message format for undefined symbols.
Previously, undefined symbol errors are one line like this
and wasn't easy to read.

  /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Writer.cpp:207: undefined symbol 'lld:🧝:EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >::addSection(lld:🧝:InputSectionBase*)'

This patch make it more structured like this.

  bin/ld.lld: error: undefined symbol: lld:🧝:EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true>
  >>> Referenced by Writer.cpp:207 (/ssd/llvm-project/lld/ELF/Writer.cpp:207)
  >>>               Writer.cpp.o in archive lib/liblldELF.a

Discussion thread:
http://lists.llvm.org/pipermail/llvm-dev/2017-March/111459.html

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

llvm-svn: 299097
2017-03-30 19:13:47 +00:00
Rui Ueyama 8d753caa78 Remove parameter names from template instantiations to make them compact. NFC.
llvm-svn: 299025
2017-03-29 20:15:29 +00:00
Rui Ueyama ff524bf739 Sort. NFC.
llvm-svn: 298797
2017-03-26 04:10:43 +00:00
Rui Ueyama 34e3d50d18 Force @{init,fini}_array if section name starts with ".{init,fini}_array.".
Fixes https://bugs.llvm.org/show_bug.cgi?id=32307.

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

llvm-svn: 298569
2017-03-23 01:00:41 +00:00
Rui Ueyama 7ab38c3a12 Define Config::Is64.
This is a shorthand for Config->Wordsize == 8. So this is not strictly
necessary but seems handy. "Is 64 bit?" is easier to read than "Is
wordsize 8 byte?"

llvm-svn: 298463
2017-03-22 00:01:11 +00:00
George Rimar 1ec03e46a7 [ELF] - Detemplate InputSection::getRelocatedSection(). NFC.
llvm-svn: 298353
2017-03-21 09:13:27 +00:00
George Rimar 76e562ab1b [ELF] - Detemplate InputSectionBase::uncompress(). NFC
llvm-svn: 298351
2017-03-21 09:08:58 +00:00
George Rimar 9353e2dbfb [ELF] - Detemplate InputSectionBase::getLinkOrderDep(). NFC.
llvm-svn: 298346
2017-03-21 08:29:48 +00:00
Simon Atanasyan d34a3631b2 [ELF][MIPS] Calculate relocations agains _gp_disp / __gnu_local_gp using dedicated 'expressions'
The patch introduces two new relocations expressions R_MIPS_GOT_GP and
R_MIPS_GOT_GP_PC. The first one represents a current value of `_gp`
pointer and used to calculate relocations against the `__gnu_local_gp`
symbol. The second one represents the offset between the beginning of
the function and the `_gp` pointer's value.

There are two motivations for introducing new expressions:
- It's better to keep all non-trivial relocation calculations in the
  single place - `getRelocTargetVA` function.
- Relocations against both `_gp_disp` and `__gnu_local_gp` symbols
  depend on the `_gp` value. It's a magical value points to the "middle"
  of GOT. Now all relocations use a common `_gp` value. But in fact,
  under some conditions each input file might require its own `_gp`
  value. I'm going to implement it in the future patches. So it's
  better to make `MipsGotSection` responsible for calculation of
  the `_gp` value.

llvm-svn: 298306
2017-03-20 21:03:43 +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
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
Eugene Leviant 2968547997 [ELF] Fix error reporting for synthetic sections
Synthetic sections don't belong to any input file, but still they
are input sections. Whenever problem occurs with relocations in
these sections lld crashes in error reporting, trying to print
input file name.

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

llvm-svn: 297711
2017-03-14 08:33:45 +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
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 35ae65ee2b Rename one of the getOffset methods.
It is sufficiently different in that it returns an offset in the input
file, not the output section.

llvm-svn: 297290
2017-03-08 15:57:17 +00:00
Rafael Espindola 76b6bd355d Remove unnecessary template. NFC.
llvm-svn: 297287
2017-03-08 15:44:30 +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 bdd2e3e36c Remove redundant member of InputSectionBase. NFC.
With this InputSectionBase is now 144 bytes.

llvm-svn: 297278
2017-03-08 14:12:52 +00:00
Rafael Espindola c8de15bdda Rename remaining uses of Addralign to Alignment.
llvm-svn: 297146
2017-03-07 15:11:21 +00:00
Rui Ueyama af6198d96d Remove Config->Rela and define Config->isRela() instead.
llvm-svn: 297108
2017-03-07 00:43:53 +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 2a80e1180e Make Discarded a InputSectionBase.
NFC, just a bit simpler.

llvm-svn: 297087
2017-03-06 22:36:19 +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
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 9320cb0719 De-template SyntheticSection.
This class didn't use ELFT.

llvm-svn: 296313
2017-02-27 02:56:02 +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
Rui Ueyama 9d1bacb1b4 Remove useless template so that Out<ELFT> becomes just Out.
llvm-svn: 296307
2017-02-27 02:31:26 +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 66b4e21534 Convert EhOutputSection to be a synthetic section.
With this we complete the transition out of special output sections,
and with the previous patches it should be possible to merge
OutputSectionBase and OuputSection.

llvm-svn: 296023
2017-02-23 22:06:28 +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
Petr Hosek b27bb59a5d [ELF] Ignore R_*_NONE relocs when relocating non-alloc sections
We shouldn't report an error for R_*_NONE relocs since we're emitting
them when writing relocations to discarded sections.

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

llvm-svn: 295936
2017-02-23 06:22:28 +00:00
Rafael Espindola c8d0c7a0e3 Add another missing instantiation.
llvm-svn: 295932
2017-02-23 03:38:14 +00:00
Rafael Espindola 277155b054 Add missing template instantiations.
llvm-svn: 295929
2017-02-23 03:18:03 +00:00
Rafael Espindola 4b8baab907 Trying to fix the windows build.
llvm-svn: 295925
2017-02-23 02:50:50 +00:00
Rafael Espindola c404d50d7c Merge InputSectionData and InputSectionBase.
Now that InputSectionBase is not a template there is no reason to have
the two.

llvm-svn: 295924
2017-02-23 02:32:18 +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
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
Rafael Espindola d50c8598fb Set the correct r_offset even when creating a R_*_NONE.
With this lld can use its own -r output when a fde is discarded.

llvm-svn: 295143
2017-02-15 01:53:23 +00:00
Rafael Espindola 60b02509dd Handle .eh_frame pointing to discarded section in -r.
This is a really horrible case. If a .eh_frame points to a discarded
section, it is not clear what is the correct thing to do.

It looks like ld.bfd discards the entire .eh_frame content and gold
discards the second relocation, leaving one frame with an fde that
refers to a bogus location. This is similar to what gold does.

llvm-svn: 295133
2017-02-15 00:59:50 +00:00
Rafael Espindola a8541675e0 Revert "Relax the restriction on what relocations can be in a non-alloc section."
This reverts commit r295102.

In the link of seabios the assumption seems to be that the section has
an actual address, so this is not sufficient. Changing the assembly
code to add a "a" flag seems like the correct thing to do instead of
extending this hack.

Sorry about the noise.

Original message:

    Relax the restriction on what relocations can be in a non-alloc section.

    The main thing that they can't have is relocations that require the
    creation of gots or plt.  For now also accept R_PC.

    Found while linking seabios.

llvm-svn: 295130
2017-02-15 00:27:47 +00:00
Rafael Espindola ee29e42b33 Relax the restriction on what relocations can be in a non-alloc section.
The main thing that they can't have is relocations that require the
creation of gots or plt.  For now also accept R_PC.

Found while linking seabios.

llvm-svn: 295102
2017-02-14 20:14:03 +00:00
Rafael Espindola 08d6a3f133 Create only one section symbol per section.
Unfortunately some consumers of our .o files produced with -r expect
only one section symbol per section. That is true of at least of go's
own linker.

Combining them is a somewhat convoluted process. We have to create a
symbol for every section since we don't know which ones will be
needed. The relocation sections also have to be written first to
handle the Elf_Rel addend.

I did consider a completely different approach:

We could remove the -r special case of relocation sections when
reading. We would instead have a copyRelocs function that is used
instead of scanRelocs. It would create a DynamicReloc for each
relocation and a RelocationSection for each input relocation section.

A complication of such change is that DynamicReloc would have to take
a section index and a input section instead of a symbol since with
-emit-relocs some DynamicReloc would hold relocations referring to the
dynamic symbol table and other to the static symbol table.

That would be a pretty big change, and if we do it it is probably
better to do it as a refactoring.

llvm-svn: 294816
2017-02-11 01:40:49 +00:00
George Rimar 82bd8be6d8 Recommit r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
with temporarily file name fix in testcase.

Original commit message:

-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294469
2017-02-08 16:18:10 +00:00
George Rimar 0b2cc8190d Reverted r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
Broked build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/5835/steps/test/logs/stdio

llvm-svn: 294466
2017-02-08 16:10:14 +00:00
George Rimar d6ae624552 [ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3
-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294464
2017-02-08 15:53:33 +00:00
Rafael Espindola c06f54122e Don't worry about dropping SHF_MERGE.
Now that it doesn't impact which sections are merged, this is not a
problem.

llvm-svn: 294054
2017-02-03 21:50:40 +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
George Rimar e3c2051d27 [ELF] - Added additional comments on top of r292789 (D29021)
It was requested during post commit review.

llvm-svn: 292903
2017-01-24 09:31:02 +00:00
George Rimar 190bac5d51 [ELF] - Stop handling local symbols in a special way.
Previously we stored kept locals in a KeptLocalSyms arrays,
belonged to files.

Patch makes SymbolTableSection to store locals in Symbols member,
that already present and was used for globals.
SymbolTableSection already had NumLocals counter member, so change
itself is trivial.

That allows to simplify handling of -r,
Body::DynsymIndex is no more used as "symbol table index" for relocatable
output.

Change was suggested during review of D28773 and opens road for D28612.

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

llvm-svn: 292789
2017-01-23 14:07:23 +00:00
Rui Ueyama 7aa90ad65b Do not use the same name for both a class and a variable.
llvm-svn: 291835
2017-01-12 21:44:20 +00:00
Rui Ueyama 52be82590c Improve an error message and remove fatal(Error &, const Twine &)
llvm-svn: 291834
2017-01-12 21:43:58 +00:00
Rui Ueyama 1d8460755e Remove dead code.
llvm-svn: 291812
2017-01-12 21:09:58 +00:00
George Rimar f09519c362 [ELF] - Do not crash if user section has name equal to one of synthetic sections.
Previously we just crashed when had user defined
section .shstrtab, for example. Which name equals to synthetic one,
but have different type.

Testcase reveals an issue.

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

llvm-svn: 291765
2017-01-12 13:00:31 +00:00
George Rimar 0d8af3697a [ELF] - Reuse Decompressor class.
Intention of change is to get rid of code duplication.
Decompressor was introduced in D28105.

Change allows to get rid of few methods relative to decompression.

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

llvm-svn: 291758
2017-01-12 10:53:31 +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
Rui Ueyama c207a89c91 Remove `Compressed` member from InputSectionData.
This value is used only once, and we can compute a value.
So we don't need to save it.

llvm-svn: 290164
2016-12-20 05:47:55 +00:00
Rui Ueyama 9381eb1045 Remove lld/Support/Memory.h.
I thought for a while about how to remove it, but it looks like we
can just copy the file for now. Of course I'm not happy about that,
but it's just less than 50 lines of code, and we already have
duplicate code in Error.h and some other places. I want to solve
them all at once later.

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

llvm-svn: 290062
2016-12-18 14:06:06 +00:00
Sean Silva 7608626631 Rename InputSection.cpp:getSymVA to getRelocTargetVA.
This name was really confusing because there is also another static
helper Symbols.cpp:getSymVA which has the same name.

llvm-svn: 289733
2016-12-14 22:45:52 +00:00
Rui Ueyama 520d9169e6 Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.
llvm-svn: 289084
2016-12-08 18:31:13 +00:00
Rui Ueyama c8e6884871 Inline MergeInputSection::getData().
This change seems to make LLD 0.6% faster when linking Clang with
debug info. I don't want us to have lots of local optimizations,
but this function is very hot, and the improvement is small but
not negligible, so I think it's worth doing.

llvm-svn: 288757
2016-12-06 02:19:30 +00:00
Adhemerval Zanella 6afe128ae5 ELF/AArch64: consolidate getAArch64Page implementation
This patch avoid getAArch64Page code duplication by removing the
implementation at InputSection.

llvm-svn: 288668
2016-12-05 14:14:26 +00:00
Rui Ueyama 5cb712ed3c Simplify ICF alignment handling.
llvm-svn: 288630
2016-12-05 01:31:39 +00:00
Rafael Espindola 27004d336f Ignone SHF_INFO_LINK.
Some elf producers (dtrace) put this flag in relocation sections and
some (MC) don't. If we don't ignore the flag we end up with multiple
relocation sections poiting to the same section, which we don't
support.

llvm-svn: 288585
2016-12-03 15:26:18 +00:00
George Rimar 9b3ae73fc8 [ELF] - Disable emiting multiple output sections when merging is disabled.
When -O0 is specified, we do not do section merging.
Though before this patch several sections were generated instead
of single, what is useless.

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

llvm-svn: 288151
2016-11-29 16:11:09 +00:00
Simon Atanasyan 9fae3b8a2c [ELF][MIPS] Do not change MipsGotSection state in the getPageEntryOffset method
The MipsGotSection::getPageEntryOffset calculates index of GOT entry
with a "page" address. Previously this method changes the state
of MipsGotSection because it modifies PageIndexMap field. That leads
to the unpredictable results if getPageEntryOffset called from multiple threads.

The patch makes getPageEntryOffset constant. To do so it calculates GOT
entry index but does not update PageIndexMap field. Later in the
MipsGotSection::writeTo method linker calculates "page" addresses and
writes them to the output.

llvm-svn: 288129
2016-11-29 10:23:56 +00:00
Rui Ueyama e8a077badf Change return types of split{Non,}Strings.
They return new vectors, but at the same time they mutate other vectors,
so returning values doesn't make much sense. We should just mutate two
vectors.

llvm-svn: 287979
2016-11-26 15:15:11 +00:00
Rui Ueyama 1df9316922 Fix typo.
llvm-svn: 287951
2016-11-25 20:41:45 +00:00
Rui Ueyama 2555952ba8 Parallelize uncompress() and splitIntoPieces().
Uncompressing section contents and spliting mergeable section contents
into smaller chunks are heavy tasks. They scan entire section contents
and do CPU-intensive tasks such as uncompressing zlib-compressed data
or computing a hash value for each section piece.

Luckily, these tasks are independent to each other, so we can do that
in parallel_for_each. The number of input sections is large (as opposed
to the number of output sections), so there's a large parallelism here.

Actually the current design to call uncompress() and splitIntoPieces()
in batch was chosen with doing this in mind. Basically what we need to
do here is to replace `for` with `parallel_for_each`.

It seems this patch improves latency significantly if linked programs
contain debug info (which in turn contain lots of mergeable strings.)
For example, the latency to link Clang (debug build) improved by 20% on
my machine as shown below. Note that ld.gold took 19.2 seconds to do
the same thing.

Before:
    30801.782712 task-clock (msec)         #    3.652 CPUs utilized            ( +-  2.59% )
         104,084 context-switches          #    0.003 M/sec                    ( +-  1.02% )
           5,063 cpu-migrations            #    0.164 K/sec                    ( +- 13.66% )
       2,528,130 page-faults               #    0.082 M/sec                    ( +-  0.47% )
  85,317,809,130 cycles                    #    2.770 GHz                      ( +-  2.62% )
  67,352,463,373 stalled-cycles-frontend   #   78.94% frontend cycles idle     ( +-  3.06% )
 <not supported> stalled-cycles-backend
  44,295,945,493 instructions              #    0.52  insns per cycle
                                           #    1.52  stalled cycles per insn  ( +-  0.44% )
   8,572,384,877 branches                  #  278.308 M/sec                    ( +-  0.66% )
     141,806,726 branch-misses             #    1.65% of all branches          ( +-  0.13% )

     8.433424003 seconds time elapsed                                          ( +-  1.20% )

After:
    35523.764575 task-clock (msec)         #    5.265 CPUs utilized            ( +-  2.67% )
         159,107 context-switches          #    0.004 M/sec                    ( +-  0.48% )
           8,123 cpu-migrations            #    0.229 K/sec                    ( +- 23.34% )
       2,372,483 page-faults               #    0.067 M/sec                    ( +-  0.36% )
  98,395,342,152 cycles                    #    2.770 GHz                      ( +-  2.62% )
  79,294,670,125 stalled-cycles-frontend   #   80.59% frontend cycles idle     ( +-  3.03% )
 <not supported> stalled-cycles-backend
  46,274,151,813 instructions              #    0.47  insns per cycle
                                           #    1.71  stalled cycles per insn  ( +-  0.47% )
   8,987,621,670 branches                  #  253.003 M/sec                    ( +-  0.60% )
     148,900,624 branch-misses             #    1.66% of all branches          ( +-  0.27% )

     6.747548004 seconds time elapsed                                          ( +-  0.40% )

llvm-svn: 287946
2016-11-25 20:05:08 +00:00
Rui Ueyama da06bfb794 Move getLocation from Relocations.cpp to InputSection.cpp.
The function was used only within Relocations.cpp, but now we are
using it in many places, so this patch moves it to a file that fits
to the functionality.

llvm-svn: 287943
2016-11-25 18:51:53 +00:00
Eugene Leviant f04777527e [ELF] Add explicit template instantiations for toString
llvm-svn: 287938
2016-11-25 16:42:04 +00:00
Simon Atanasyan 8469b8841c [ELF][MIPS] Fix handling of _gp/_gp_disp/__gnu_local_gp symbols
Offset between beginning of a .got section and _gp symbols used in MIPS
GOT relocations calculations. Usually the expression looks like
VA + Offset - GP, where VA is the .got section address, Offset - offset
of the GOT entry, GP - offset between .got and _gp. Also there two "magic"
symbols _gp_disp and __gnu_local_gp which hold the offset mentioned above.
These symbols might be referenced by MIPS relocations.

Now the linker always defines _gp symbol and uses hardcoded value for
its initialization. So offset between .got and _gp is 0x7ff0. The _gp_disp
and __gnu_local_gp defined if required and initialized by 0x7ff0.
In fact that is not correct because _gp symbol might be defined by a linker
script and holds arbitrary value. In that case we need to use this value
in relocation calculation and initialize _gp_disp and __gnu_local_gp
properly.

The patch fixes the problem and completes fixing the bug #30311.
https://llvm.org/bugs/show_bug.cgi?id=30311

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

llvm-svn: 287832
2016-11-23 22:22:16 +00:00
Rui Ueyama 3fc0f7e54f Define toString() as a generic function to get a string for error message.
We have different functions to stringize objects to construct
error messages. For InputFile, we have getFilename, and for
InputSection, we have getName. You had to memorize them.

I think this is the case where the function overloading comes in handy.

This patch defines toString() functions that are overloaded for all these
types, so that you just call it in error().

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

llvm-svn: 287787
2016-11-23 18:07:33 +00:00
Eugene Leviant c3a44b2fbe [ELF] Refactor several error messages
Differential revision: https://reviews.llvm.org/D26970

llvm-svn: 287753
2016-11-23 10:07:46 +00:00
Eugene Leviant 3582ebf35e [ELF] Fixup buffer pointer when writing synthetic sections
Differential revision: https://reviews.llvm.org/D26980

llvm-svn: 287751
2016-11-23 09:47:38 +00:00
Eugene Leviant 531df4fcef [ELF] Print error location in .eh_frame parser
Differential revision: https://reviews.llvm.org/D26914

llvm-svn: 287750
2016-11-23 09:45:17 +00:00
Rui Ueyama 77f2a87575 Simplify MergeOutputSection.
MergeOutputSection class was a bit hard to use because it provdes
a series of finalize functions that have to be called in a right way
at a right time. It also intereacted with MergeInputSection, and the
logic was somewhat entangled between the two classes.

This patch simplifies it by providing only one finalize function.
Now, all you have to do is to call MergeOutputSection::finalize
when you have added all sections to the output section. Then, it
internally merges strings and initliazes StringPiece objects.
I think this is much easier to understand.

This patch also adds comments.

llvm-svn: 287314
2016-11-18 05:05:43 +00:00
Simon Atanasyan b8bfec686f [ELF][MIPS] Remove 'mips' word from MipsGotSection fields and methods names. NFC
Also add new comments with MIPS GOT description.

llvm-svn: 287264
2016-11-17 21:49:14 +00:00
Simon Atanasyan 725dc14bb2 [ELF][MIPS] Add MipsGotSection to handle MIPS GOT
MIPS GOT handling is very different from other targets so it is better
to keep the code in the separatre section class MipsGotSection. This
patch introduces the new section and moves all MIPS specific code from
GotSection to the new class. I did not rename fields and methods in the
MipsGotSection class to reduce the diff and plan to do that by the
separate commit.

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

llvm-svn: 287150
2016-11-16 21:01:02 +00:00
Eugene Leviant a96d9027a3 [ELF] Convert RelocationSection to input section
Differential revision: https://reviews.llvm.org/D26669

llvm-svn: 287092
2016-11-16 10:02:27 +00:00
George Rimar d8b27769c8 [ELF] - format. NFC.
llvm-svn: 286805
2016-11-14 10:14:18 +00:00
Eugene Leviant ad4439e802 [ELF] Convert .got section to input section
Differential revision: https://reviews.llvm.org/D26498

llvm-svn: 286580
2016-11-11 11:33:32 +00:00
Rui Ueyama 82664d9d4c Remove a member from InputSectionData and use the pool instead.
llvm-svn: 286557
2016-11-11 03:54:59 +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
Eugene Leviant 41ca327b5e [ELF] Convert .got.plt section to input section
Differential revision: https://reviews.llvm.org/D26349

llvm-svn: 286443
2016-11-10 09:48:29 +00:00
Simon Atanasyan fa03b0fafa [ELF][MIPS] Convert .MIPS.abiflags section to synthetic input section
Previously, we have both input and output section for .MIPS.abiflags.
Now we have only one class for .MIPS.abiflags, which is MipsAbiFlagsSection.
This class is a synthetic input section.

.MIPS.abiflags sections are handled as regular sections until
the control reaches Writer. Writer then aggregates all sections
whose type is SHT_MIPS_ABIFLAGS to create a single synthesized
input section. The synthesized section is then processed normally
as if it came from an input file.

llvm-svn: 286398
2016-11-09 21:37:06 +00:00
Simon Atanasyan ce02cf0099 [ELF][MIPS] Convert .reginfo and .MIPS.options sections to synthetic input sections
Previously, we have both input and output sections for .reginfo and
.MIPS.options. Now for each such sections we have one synthetic input
sections: MipsReginfoSection and MipsOptionsSection respectively.

Both sections are handled as regular sections until the control reaches
Writer. Writer then aggregates all sections whose type is SHT_MIPS_REGINFO
or SHT_MIPS_OPTIONS to create a single synthesized input section. In that
moment Writer also save GP0 value to the MipsGp0 field of the corresponding
ObjectFile. This value required for R_MIPS_GPREL16 and R_MIPS_GPREL32
relocations calculation.

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

llvm-svn: 286397
2016-11-09 21:36:56 +00:00
Rafael Espindola 6ff570a395 Make Discarded a InputSection.
It was quite confusing that it had SectionKind of Regular, but was not
actually a InputSection.

llvm-svn: 286379
2016-11-09 16:55:07 +00:00
Rafael Espindola 77dbe9a405 Add a convenience getObj method. NFC.
llvm-svn: 286370
2016-11-09 14:39:20 +00:00
Peter Smith 8339bbd759 [ELF] ARM and AArch64 undefined weak reference values
The ARM 32 and 64-bit ABI does not use 0 for undefined weak references
that are used in PC relative relocations. In particular:
- A branch relocation to an undefined weak resolves to the next
  instruction. Effectively making the branch a no-op
- In all other cases the symbol resolves to the place so that S + A - P
  resolves to A.

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

llvm-svn: 286353
2016-11-09 10:22:29 +00:00
Rafael Espindola 04a2e348bb Split Header into individual fields.
This is similar to what was done for InputSection.

With this the various fields are stored in host order and only
converted to target order when writing.

llvm-svn: 286327
2016-11-09 01:42:41 +00:00
Rafael Espindola 1a5411238e Revert "[ELF] Make InputSection<ELFT>::writeTo virtual"
This reverts commit r286100.

This saves 8 bytes of every InputSection.

llvm-svn: 286235
2016-11-08 14:47:16 +00:00
Eugene Leviant 0a8f1fe6f7 [ELF] Make InputSection<ELFT>::writeTo virtual
Differential revision: https://reviews.llvm.org/D26281

llvm-svn: 286100
2016-11-07 09:04:06 +00:00
Rui Ueyama e8a6102fa9 Rewrite CommonInputSection as a synthetic input section.
A CommonInputSection is a section containing all common symbols.
That was an input section but was abstracted in a different way
than the synthetic input sections because it was written before
the synthetic input section was invented.

This patch rewrites CommonInputSection as a synthetic input section
so that it behaves better with other sections.

llvm-svn: 286053
2016-11-05 23:05:47 +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
Rui Ueyama 6dc7fcbec4 Create SyntheticSections.cpp.
We are going to have many more classes for linker-synthesized
input sections, so it's worth to be added to a separate file
than to the file for regular input sections.

llvm-svn: 285740
2016-11-01 20:28:21 +00:00
Davide Italiano 1da3a52d11 [ELF/GC] Fix pending references to garbage collected sections.
The example reported in PR30793 shows a case where gc reclaims
a SHF_TLS section, but it doesn't reclaim the section containing
the debug info for it.
This is expected, as we do not reclaim non-alloc sections
during the garbage collection phase (and this is not going to
change anytime soon, at least this is what I gathered last I
talked with Rafael about it).
So, we end up with a pending reference, thinking that the input
was invalid (which is not true, as it's GC that removed the
SHT_TLS section, and therefore didn't create the PT_TLS *segment*
for it). In cases like this, just assign a VA of zero at relocation
time instead of error'ing out (this is what gold does as well, FWIW).

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

llvm-svn: 285735
2016-11-01 20:11:01 +00:00
Rafael Espindola 092d3b7f3b Don't store an OutputLoc in every InputSection.
It was only used by build-id and that can easily compute it.

llvm-svn: 285691
2016-11-01 13:57:19 +00:00
Eugene Leviant 282251a226 Convert BuildIdSection to input section
Differential revision: https://reviews.llvm.org/D25627

llvm-svn: 285682
2016-11-01 09:49:24 +00:00
Eugene Leviant c4681203e1 Allow fetching source line, when multiple "AX" sections present
Differential revision: https://reviews.llvm.org/D26070

llvm-svn: 285680
2016-11-01 09:17:50 +00:00
Rafael Espindola 093abab817 Don't create a dummy ELF to process a binary file.
Now that it is easy to create input section and symbols, this is
simple.

llvm-svn: 285322
2016-10-27 17:45:40 +00:00
Rafael Espindola 99558efed6 Pass a InputSectionData to classoff.
This allows a non template class to hold input sections.

llvm-svn: 285221
2016-10-26 18:44:57 +00:00
Rafael Espindola 1854a8ebb8 Delete trivial getters. NFC.
llvm-svn: 285190
2016-10-26 12:36:56 +00:00
Rafael Espindola 0e090522c8 Read section headers upfront.
Instead of storing a pointer, store the members we need.

The reason for doing this is that it makes it far easier to create
synthetic sections. It also avoids reading data from files multiple
times., which might help with cross endian linking and host
architectures with slow unaligned access.

There are obvious compacting opportunities, but this already has mixed
results even on native x86_64 linking.

There is also the possibility of better refactoring the code for
handling common symbols, but this already shows that a custom class is
not necessary.

llvm-svn: 285148
2016-10-26 00:54:03 +00:00
Rafael Espindola 397f0aa0d3 Be a bit more consistent about using getters. NFC.
llvm-svn: 285082
2016-10-25 16:42:46 +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
Simon Atanasyan bed04bf1df [ELF][MIPS] Put local GOT entries accessed via a 16-bit index first
Some MIPS relocations used to access GOT entries are able to manipulate
16-bit index. The other ones like R_MIPS_CALL_HI16/LO16 can handle
32-bit indexes. 16-bit relocations are generated by default. The 32-bit
relocations are generated by -mxgot flag passed to compiler. Usually
these relocation are not mixed in the same code but files like crt*.o
contain 16-bit relocations so even if all "user's" code compiled with
-mxgot flag a few 16-bit relocations might come to the linking phase.

Now LLD does not differentiate local GOT entries accessed via a 16-bit
and 32-bit indexes. That might lead to relocation's overflow if 16-bit
entries are allocated to far from the beginning of the GOT.

The patch introduces new "part" of MIPS GOT dedicated to the local GOT
entries accessed by 32-bit relocations. That allows to put local GOT
entries accessed via a 16-bit index first and escape relocation's overflow.

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

llvm-svn: 284809
2016-10-21 07:22:30 +00:00
Rafael Espindola 113860b9ae Compact SectionPiece.
We allocate a lot of these when linking debug info. This speeds up the
link of debug programs by 1% to 2%.

llvm-svn: 284716
2016-10-20 10:55:58 +00:00
Peter Smith d648603415 [ELF] Allow relative exceptions relocations in shared libraries
The R_ARM_PREL31 and R_ARM_NONE relocations should not be faulted in
shared libraries. In the case of R_ARM_NONE, we have moved the TLS
relaxation hint instruction to R_TLSDESC_CALL so that R_HINT can be used
without side-effects. In the case of R_ARM_PREL31 we permit it to be used
against PLT entries as the personality routines are imported when used in
shared libraries.

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

llvm-svn: 284710
2016-10-20 09:59:26 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +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
Rafael Espindola 2adccee13f Don't gc non-alloca non-string pieces.
We were already doing it for strings. This matches the behavior of
bfd and gold.

llvm-svn: 284598
2016-10-19 14:50:26 +00:00
Rafael Espindola 88eb6482ca Add a faster binary search.
Even with the hash table cache, binary search was still pretty
hot. This can be made even faster with prefetching.

Idea from http://cglab.ca/~morin/misc/arraylayout-v2/

I will suggest moving this to llvm.

llvm-svn: 284594
2016-10-19 14:17:36 +00:00
Rafael Espindola ad74c1cfdf Use reserve instead of grow.
The table was still being resized as grow doesn't account for the fact
that the table needs to remain 3/4 full.

llvm-svn: 284487
2016-10-18 15:31:23 +00:00
Justin Lebar ee34a7343d [ADT] Move CachedHashString to its own header in ADT, and rename to CachedHashStringRef.
Summary:
Reclaiming the name 'CachedHashString' will let us add a type with that
name that owns its value.

Reviewers: timshen

Subscribers: llvm-commits

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

llvm-svn: 284434
2016-10-17 22:24:36 +00:00
Rui Ueyama acb67bcb98 Move a utility function to Strings.cpp.
So that we can use the function from anywhere.

llvm-svn: 284092
2016-10-13 00:13:15 +00:00
Rui Ueyama 5665af836f Fix variable name. NFC.
llvm-svn: 284079
2016-10-12 23:22:59 +00:00
Rui Ueyama 05384080df Support GNU-style ZLIB-compressed input sections.
Previously, we supported only SHF_COMPRESSED sections because it's
new and it's the ELF standard. But there are object files compressed
in the GNU style out there, so we had to support it.

Sections compressed in the GNU style start with ".zdebug_" and
contain different headers than the ELF standard's one. In this
patch, getRawCompressedData is responsible to handle it.

A tricky thing about GNU-style compressed sections is that we have
to rename them when creating output sections. ".zdebug_" prefix
implies the section is compressed. We need to rename ".zdebug_"
".debug" because our output sections are not compressed.
We do that in this patch.

llvm-svn: 284068
2016-10-12 22:36:31 +00:00
Peter Smith 0a259f3b9c [ELF][ARM] Initial implentation of ARM exceptions support
The .ARM.exidx sections contain a table. Each entry has two fields:
- PREL31 offset to the function the table entry describes
- Action to take, either cantunwind, inline unwind, or PREL31 offset to
  .ARM.extab section

The table entries must be sorted in order of the virtual addresses the
first entry of the table describes. Traditionally this is implemented by
the SHF_LINK_ORDER dependency. Instead of implementing this directly we
sort the table entries post relocation. 

The .ARM.exidx OutputSection is described by the PT_ARM_EXIDX program
header

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

llvm-svn: 283730
2016-10-10 09:39:26 +00:00
Rui Ueyama 8c8ff00b28 Improve comments.
Also use uint64_t instead of uintX_t so that you don't have to
think about two different cases to verify that the code is correct.

llvm-svn: 283585
2016-10-07 19:54:57 +00:00
Rafael Espindola 88b9d66d4a Add () for clarity. NFC.
llvm-svn: 283556
2016-10-07 14:23:28 +00:00
George Rimar 7c213fd17e [ELF] - Check that section alignment is a power of 2.
I found that this check still may be useful in some cases.
At fact since we use uint32_t alignment, then maximum value
that is valid for us is 0x80000000. But some broken files,
for example file from testcase may have greater value.
Because of that offset calculation overflow and crash happens.

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

llvm-svn: 283544
2016-10-07 12:27:45 +00:00
Rafael Espindola 5fc2b1d2fe Store the hash in SectionPiece.
This spreads out computing the hash and using it in a hash table. The
speedups are:

firefox
  master 6.811232891
  patch  6.559280249 1.03841162939x faster
chromium
  master 4.369323666
  patch  4.33171853 1.00868134338x faster
chromium fast
  master 1.856679971
  patch  1.850617741 1.00327578725x faster
the gold plugin
  master 0.32917962
  patch  0.325711944 1.01064645023x faster
clang
  master 0.558015452
  patch  0.550284165 1.01404962652x faster
llvm-as
  master 0.032563515
  patch  0.032152077 1.01279662275x faster
the gold plugin fsds
  master 0.356221362
  patch  0.352772162 1.00977741549x faster
clang fsds
  master 0.635096494
  patch  0.627249229 1.01251060127x faster
llvm-as fsds
  master 0.030183188
  patch  0.029889544 1.00982430511x faster
scylla
  master 3.071448906
  patch  2.938484138 1.04524944215x faster

This seems to be because we don't stall as much. When linking firefox
stalled-cycles-frontend goes from 57.56% to 55.55%.

With -O2 the difference is even more significant since we avoid
recomputing the hash. For firefox we go from 9.990295265 to
 9.149627521 seconds (1.09x faster).

llvm-svn: 283367
2016-10-05 19:36:02 +00:00
Rafael Espindola 32aca87bf8 Compact SectionPiece.
It is pretty easy to get the data from the InputSection, so we don't
have to store it.

This opens the way for storing the hash instead.

llvm-svn: 283357
2016-10-05 18:40:00 +00:00
Rafael Espindola 939e9493bf Simplify setting the Live bit in SectionPiece. NFC.
llvm-svn: 283340
2016-10-05 17:02:09 +00:00
George Rimar 422e47a9f5 [ELF] - Do not hang if broken object has option descriptor in .MIPS.options with size of zero.
Previously lld would hang in infinite loop in this case,
patch fixes the issue. Object was found during AFL run.

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

llvm-svn: 283208
2016-10-04 10:23:07 +00:00
Simon Atanasyan 3a61cabbb2 [ELF][MIPS] Do not accept non-zero GP0 value for relocatable object only
Follow-up to r282716. Reject input files with non-zero GP0 value only in
case of relocatable object generation. In other case we can handle
arbitrary GP0 value so it does not have a sense to make the restriction
so wide.

llvm-svn: 283194
2016-10-04 08:24:25 +00:00
George Rimar 2c0a7f081a [ELF] - Do not crash on invalid section alignment.
Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.

Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.

Patch fixes the issue.

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

llvm-svn: 283097
2016-10-03 10:04:38 +00:00
George Rimar f50bafc708 [ELF] - Inlined template argument variable. NFC.
llvm-svn: 282851
2016-09-30 13:46:34 +00:00
Rafael Espindola 2629602f28 Fix another --gc-sections crash.
The missing case was when a merge section was only referenced from
non-alloca sections.

llvm-svn: 282847
2016-09-30 06:48:09 +00:00
Rafael Espindola c1eff79f61 Fix --gc-sections crash.
We would crash when a non-alloca section pointed to a gced part of a
merge section.

That can happen when a C/c++ constant in put in a merge section and
debug info is present.

llvm-svn: 282845
2016-09-30 06:37:29 +00:00
Simon Atanasyan 353fc1e947 [ELF][MIPS] Set GP0 value to zero in case of relocatable object generation
LLD does not update relocations addends when generate a relocatable
object. That is why we should not write a non-zero GP0 value into
the .reginfo and .MIPS.options sections. And we should not accept input
object files with non-zero GP0 value because we cannot handle them
properly.

llvm-svn: 282716
2016-09-29 12:58:48 +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
Davide Italiano 03f7005375 [ELF] Resolve weak undefined TLS symbols when no phdr is available.
If we pass --gc-sections to lld and .tbss is not referenced,
the section is reclaimed and lld doesn't create a TLS program header.
R_TLS tries to access the program header -> lld crashes.
Mimic what bfd/gold do in this case and resolve a weak undefined
TLS symbol to the base of the TLS block, i.e. give it a value of zero.

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

llvm-svn: 282279
2016-09-23 18:47:50 +00:00
Rui Ueyama 2d7fe598f2 Turn a no-op assignment into an assertion.
r279456 guarantees that this condition is always satisfied.

llvm-svn: 281426
2016-09-14 00:09:50 +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 54f1614ec1 Revert "Revert "Compact InputSectionData from 64 to 48 bytes. NFC.""
This reverts commit r281096.

The previous link errors should be fixed by r281208.

llvm-svn: 281209
2016-09-12 13:06:10 +00:00
Rafael Espindola 78fe670994 Revert "Compact InputSectionData from 64 to 48 bytes. NFC."
This reverts commit r281084.

The link was failing on some bots. No idea why. I will try to
reproduce it on Monday.

llvm-svn: 281096
2016-09-09 21:20:30 +00:00
Rafael Espindola 82621dcb10 Compact InputSectionData from 64 to 48 bytes. NFC.
llvm-svn: 281084
2016-09-09 19:42:11 +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
Rafael Espindola 16853bb00f Pack InputSectionData from 72 to 64 bytes. NFC.
llvm-svn: 280925
2016-09-08 12:33:41 +00:00
Rafael Espindola 664c6522fa Delete dead field. NFC.
llvm-svn: 280856
2016-09-07 20:37:34 +00:00
Eugene Leviant 97403d15ee Eliminate LayoutInputSection class
Previously we used LayoutInputSection class to correctly assign
symbols defined in linker script. This patch removes it and uses
pointer to preceding input section in SymbolAssignment class instead.

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

llvm-svn: 280348
2016-09-01 09:55:57 +00:00
Rafael Espindola 79202c378f Fix the implementation of R_386_GOTPC and R_386_GOTOFF.
They were both pointing to the start of the got, not the end.

Fixes pr28924.

llvm-svn: 280310
2016-08-31 23:24:11 +00:00
Rafael Espindola 7f4f9cd546 Use getSize to find the size of a section. NFC.
llvm-svn: 280305
2016-08-31 23:01:13 +00:00
Rafael Espindola e7553e4eac Delete unnecessary template.
llvm-svn: 280237
2016-08-31 13:28:33 +00:00
George Rimar 3e6833b4b2 [ELF] - Fix for PR28976 - Corrupted section contents when using linker scripts
This is fix for PR28976.

Problem was that in scanRelocs, we computed relocation offset too early 
for case when linkerscript was used. Patch fixes the issue 
delaying the calculation.

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

llvm-svn: 279264
2016-08-19 15:46:28 +00:00
Simon Atanasyan 85c6b44817 [ELF][MIPS] Support .MIPS.abiflags section
This section supersedes .reginfo and .MIPS.options sections. But for now
we have to support all three sections for ABI transition period.

llvm-svn: 278482
2016-08-12 06:28:49 +00:00
Eugene Leviant ceabe80e97 [ELF] Symbol assignment within output section description
llvm-svn: 278322
2016-08-11 07:56:43 +00:00
Rui Ueyama d6bd1371fc Include filenames and section names to error messages.
llvm-svn: 277566
2016-08-03 04:39:42 +00:00
George Rimar 7b360f2441 [ELF] - Fix: do not ignore relocations addends when using lld -r
Previously addends were ignored. This is PR28779.
Patch fixes the issue.

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

llvm-svn: 277432
2016-08-02 08:49:57 +00:00
Rui Ueyama 0778490428 Remove DefinedCommon::Section.
Since CommonInputSection is a singleton class, we don't need
to store pointers to all DefinedCommon symbols.

llvm-svn: 277410
2016-08-02 01:35:13 +00:00
Rui Ueyama 09d4f177fc Remove dependency to SymbolTable from CommonInputSection.
llvm-svn: 277103
2016-07-29 03:39:44 +00:00
Rui Ueyama ad10c3d8d4 Make CommonInputSection singleton class.
All other singleton instances are accessible globally.
CommonInputSection shouldn't be an exception.

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

llvm-svn: 277034
2016-07-28 21:05:04 +00:00
Eugene Leviant 3e6b027705 [ELF] Allows setting section for common symbols in linker script
llvm-svn: 277023
2016-07-28 19:24:13 +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 6eae9f2c67 Delete SplitInputSection.
This opens the way for having a different Piece type for EhInputSection.

llvm-svn: 276275
2016-07-21 13:32:37 +00:00
Rafael Espindola 2197311c31 Delete EhInputSection::getOffset.
We no longer need it for relocations in .eh_frame.

The only relocations that point to .eh_frame are the ones trying to
find the output .eh_frame.

This actually fixes a bug in the symbol value code. It was not
handling -1 as an indicator for a piece not being included in the
output.

llvm-svn: 276175
2016-07-20 20:19:58 +00:00
Rafael Espindola 0f7cedaa1e Create thunks before regular relocation scan.
We will need to do something like this to support range extension
thunks since that process is iterative.

Doing this also has the advantage that when doing the regular
relocation scan the offset in the output section is known and we can
just store that. This reduces the number of times we have to run
getOffset and I think will allow a more specialized .eh_frame
representation.

By itself this is already a performance win.

firefox
  master 7.295045737
  patch  7.209466989 0.98826892235
chromium
  master 4.531254468
  patch  4.509221804 0.995137623774
chromium fast
  master 1.836928973
  patch  1.823805241 0.992855612714
the gold plugin
  master 0.379768791
  patch  0.380043405 1.00072310839
clang
  master 0.642698284
  patch  0.642215663 0.999249070657
llvm-as
  master 0.036665467
  patch  0.036456225 0.994293213284
the gold plugin fsds
  master 0.40395817
  patch  0.404384555 1.0010555177
clang fsds
  master 0.722045545
  patch  0.720946135 0.998477367518
llvm-as fsds
  master 0.03292646
  patch  0.032759965 0.994943428477
scylla
  master 3.427376378
  patch  3.368316181 0.98276810292

llvm-svn: 276146
2016-07-20 17:58:07 +00:00
Eugene Leviant e63d81bd05 [ELF] Create output sections in LinkerScript class
llvm-svn: 276121
2016-07-20 14:43:20 +00:00
George Rimar 5d53d1f42c [ELF] - Make few members of Writer to be global and export them for reuse
Creating sections on linkerscript side requires some methods
that can be reused if are exported from writer.

Patch implements that change.

Differential revision: http://reviews.llvm.org/D20104

llvm-svn: 275162
2016-07-12 08:50:42 +00:00
Rui Ueyama ec1b80fd11 Remove unused parameters.
llvm-svn: 275153
2016-07-12 03:49:41 +00:00
Peter Smith fb05cd997c Recommit R274836 Add Thunk support framework for ARM and Mips
The TinyPtrVector of const Thunk<ELFT>* in InputSections.h can cause 
build failures on certain compiler/library combinations when Thunk<ELFT> 
is not a complete type or is an abstract class. Fixed by making Thunk<ELFT>
non Abstract.

type or is an abstract class 

llvm-svn: 274863
2016-07-08 16:10:27 +00:00
Peter Smith eeb827447e Revert R274836 Add Thunk support framework for ARM and Mips
This seems to be causing a buildbot failure on lld-x86_64-freebsd. Will
reproduce locally and fix. 

llvm-svn: 274841
2016-07-08 12:25:50 +00:00
Peter Smith de01b98a26 Add Thunk support framework for ARM and Mips
Generalise the Mips LA25 Thunk code and implement ARM and Thumb
    interworking Thunks.
    
    - Introduce a new module Thunks.cpp to store the Target Specific Thunk
      implementations.
    - DefinedRegular and Shared have a ThunkData field to record Thunk.
    - A Target can have more than one type of Thunk.
    - Support PC-relative calls to Thunks.
    - Support Thunks to PLT entries.
    - Existing Mips LA25 Thunk code integrated.
    - Support for ARMv7A interworking Thunks.
    
    Limitations:
    - Only one Thunk per SymbolBody, this is sufficient for all currently
      implemented Thunks.
    - ARM thunks assume presence of V6T2 MOVT and MOVW instructions.

    Differential revision: http://reviews.llvm.org/D21891

llvm-svn: 274836
2016-07-08 11:13:40 +00:00
Rui Ueyama 1d12ac1d11 Fix endianness issue.
Previously, ch_size was read in host byte order, so if a host and
a target are different in byte order, we would produce a corrupted
output.

llvm-svn: 274729
2016-07-07 03:55:55 +00:00
George Rimar 602fbee9fc [ELF] - Support of compressed input sections implemented.
Patch implements support of zlib style compressed sections.
SHF_COMPRESSED flag is used to recognize that decompression is required.
After that decompression is performed and flag is removed from output.

Differential revision: http://reviews.llvm.org/D20272

llvm-svn: 273661
2016-06-24 11:18:44 +00:00
Simon Atanasyan 002e244717 [ELF][MIPS] Support MIPS TLS relocations
The patch adds one more partition to the MIPS GOT. This time it is for
TLS related GOT entries. Such entries are located after 'local' and 'global'
ones. We cannot get a final offset for these entries at the time of
creation because we do not know size of 'local' and 'global' partitions.
So we have to adjust the offset later using `getMipsTlsOffset()` method.

All MIPS TLS relocations which need GOT entries operates MIPS style GOT
offset - 'offset from the GOT's beginning' - MipsGPOffset constant. That
is why I add new types of relocation expressions.

One more difference from othe ABIs is that the MIPS ABI does not support
any TLS relocation relaxations. I decided to make a separate function
`handleMipsTlsRelocation` and put MIPS TLS relocation handling code
there. It is similar to `handleTlsRelocation` routine and duplicates its
code. But it allows to make the code cleaner and prevent pollution of
the `handleTlsRelocation` by MIPS 'if' statements.

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

llvm-svn: 273569
2016-06-23 15:26:31 +00:00
Rui Ueyama 809d8e2d41 Fix a bug that MIPS thunks can overwrite other section contents.
Peter Smith found while trying to support thunk creation for ARM that
LLD sometimes creates broken thunks for MIPS. The cause of the bug is
that we assign file offsets to input sections too early. We need to
create all sections and then assign section offsets because appending
thunks changes file offsets for all following sections.

This patch separates the pass to assign file offsets from thunk
creation pass. This effectively reverts r265673.

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

llvm-svn: 273532
2016-06-23 04:33:42 +00:00
Simon Atanasyan 4132511cdc [ELF][MIPS] Support GOT entries for non-preemptible symbols with different addends
There are two motivations for this patch. The first one is a preparation
for support MIPS TLS relocations. It might sound like a joke but for GOT
entries related to TLS relocations MIPS ABI uses almost regular approach
with creation of dynamic relocations for each GOT enty etc. But we need
to separate these 'regular' TLS related entries from MIPS specific local
and global parts of GOT. ABI declare simple solution - all TLS related
entries allocated at the end of GOT after local/global parts. The second
motivation it to support GOT relocations for non-preemptible symbols
with addends. If we have more than one GOT relocations against symbol S
with different addends we need to create GOT entries for each unique
Symbol/Addend pairs.

So we store all MIPS GOT entries in separate containers. For non-preemptible
symbols we have to maintain two data structures. The first one is MipsLocal
vector. Each entry corresponds to the GOT entry from the 'local' part
of the GOT contains the symbol's address plus addend. The second one
is MipsLocalMap. It is a map from Symbol/Addend pair to the GOT index.

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

llvm-svn: 273127
2016-06-19 21:39:37 +00:00
Rui Ueyama 424b408165 Rename Align -> Alignment.
I think it is me who named these variables, but I always find that
they are slightly confusing because align is a verb.
Adding four letters is worth it.

llvm-svn: 272984
2016-06-17 01:18:46 +00:00
Rafael Espindola e1979aed0a Implement gd to ie relaxation for aarch64.
llvm-svn: 271815
2016-06-04 23:33:31 +00:00
Rafael Espindola 69f5402b26 Use adjustRelaxExpr for tls relaxations too.
This remove some EM_386 specific code from InputSection.cpp and opens
the way for more relaxations.

llvm-svn: 271814
2016-06-04 23:22:34 +00:00
Rafael Espindola 12dc446939 Fix implicit plt creation on aarch64.
We were not handling page relative relocations.

llvm-svn: 271798
2016-06-04 19:11:14 +00:00
Rafael Espindola e37d13b9ec Start adding tlsdesc support for aarch64.
This is mostly extracted from http://reviews.llvm.org/D18960.

The general idea for tlsdesc is that the two GD got entries are used
for a function pointer and its argument. The dynamic linker sets
both. In the non-dlopen case the dynamic linker sets the function to
the identity and the argument to the offset in the tls block.

All that the static linker has to do in the non-dlopen case is
relocate the code to point to the got entries and create a dynamic
relocation.

The dlopen case is more complicated, but can be implemented in another patch.

llvm-svn: 271569
2016-06-02 19:49:53 +00:00
George Rimar f10c8290fa [ELF] - Implemented support for test/binop relaxations from latest ABI.
Patch implements next relaxation from latest ABI:

"Convert memory operand of test and binop into immediate operand, where binop is one of adc, add, and, cmp, or,
sbb, sub, xor instructions, when position-independent code is disabled."

It is described in System V Application Binary Interface AMD64 Architecture Processor 
Supplement Draft Version 0.99.8 (https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, 
B.2 "B.2 Optimize GOTPCRELX Relocations").

Differential revision: http://reviews.llvm.org/D20793

llvm-svn: 271405
2016-06-01 16:45:30 +00:00
Rafael Espindola a8433c1d1b Revert "bar"
This reverts commit r271365.
Sorry, wrong branch.

llvm-svn: 271366
2016-06-01 06:15:22 +00:00
Rafael Espindola 74540516ef bar
llvm-svn: 271365
2016-06-01 06:13:54 +00:00
Rui Ueyama 8b972d221e Simplify. NFC.
llvm-svn: 271133
2016-05-28 18:40:38 +00:00
Rui Ueyama 406b469de4 Avoid doing binary search.
MergedInputSection::getOffset is the busiest function in LLD if string
merging is enabled and input files have lots of mergeable sections.
It is usually the case when creating executable with debug info,
so it is pretty common.

The reason why it is slow is because it has to do faily complex
computations. For non-mergeable sections, section contents are
contiguous in output, so in order to compute an output offset,
we only have to add the output section's base address to an input
offset. But for mergeable strings, section contents are split for
merging, so they are not contigous. We've got to do some lookups.

We used to do binary search on the list of section pieces.
It is slow because I think it's hostile to branch prediction.

This patch replaces it with hash table lookup. Seems it's working
pretty well. Below is "perf stat -r10" output when linking clang
with debug info. In this case this patch speeds up about 4%.

Before:

       6584.153205 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.09% )
               238 context-switches          #    0.036 K/sec                    ( +-  6.59% )
                 0 cpu-migrations            #    0.000 K/sec                    ( +- 50.92% )
         1,067,675 page-faults               #    0.162 M/sec                    ( +-  0.15% )
    18,369,931,470 cycles                    #    2.790 GHz                      ( +-  0.09% )
     9,640,680,143 stalled-cycles-frontend   #   52.48% frontend cycles idle     ( +-  0.18% )
   <not supported> stalled-cycles-backend
    21,206,747,787 instructions              #    1.15  insns per cycle
                                             #    0.45  stalled cycles per insn  ( +-  0.04% )
     3,817,398,032 branches                  #  579.786 M/sec                    ( +-  0.04% )
       132,787,249 branch-misses             #    3.48% of all branches          ( +-  0.02% )

       6.579106511 seconds time elapsed                                          ( +-  0.09% )

After:

       6312.317533 task-clock (msec)         #    1.001 CPUs utilized            ( +-  0.19% )
               221 context-switches          #    0.035 K/sec                    ( +-  4.11% )
                 1 cpu-migrations            #    0.000 K/sec                    ( +- 45.21% )
         1,280,775 page-faults               #    0.203 M/sec                    ( +-  0.37% )
    17,611,539,150 cycles                    #    2.790 GHz                      ( +-  0.19% )
    10,285,148,569 stalled-cycles-frontend   #   58.40% frontend cycles idle     ( +-  0.30% )
   <not supported> stalled-cycles-backend
    18,794,779,900 instructions              #    1.07  insns per cycle
                                             #    0.55  stalled cycles per insn  ( +-  0.03% )
     3,287,450,865 branches                  #  520.799 M/sec                    ( +-  0.03% )
        72,259,605 branch-misses             #    2.20% of all branches          ( +-  0.01% )

       6.307411828 seconds time elapsed                                          ( +-  0.19% )

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

llvm-svn: 270999
2016-05-27 14:39:13 +00:00
Simon Atanasyan 84bb355c3a [ELF][MIPS] Handle section symbol points to the .MIPS.options / .reginfo section
MIPS .reginfo and .MIPS.options sections are consumed by the linker, and
the linker produces a single output section. But it is possible that
input files contain section symbol points to the corresponding input
section. In case of generation a relocatable output we need to write
such symbols to the output file.

Fixes bug 27878.

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

llvm-svn: 270910
2016-05-26 20:46:01 +00:00
George Rimar 5c33b91bbe [ELF] - Implemented optimization for R_X86_64_GOTPCREL relocation.
System V Application Binary Interface AMD64 Architecture Processor Supplement Draft Version 0.99.8 
(https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r249.pdf, B.2 "B.2 Optimize GOTPCRELX Relocations")
introduces possible relaxations for R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX.

That patch implements the next relaxation: 
mov foo@GOTPCREL(%rip), %reg => lea foo(%rip), %reg
and also opens door for implementing all other ones.

Implementation was suggested by Rafael Ávila de Espíndola with few additions and testcases by myself.

Differential revision: http://reviews.llvm.org/D15779

llvm-svn: 270705
2016-05-25 14:31:37 +00:00
Rafael Espindola bfffa94ea7 Fix crash in .eh_frame marker section.
llvm-svn: 270563
2016-05-24 14:51:50 +00:00
Rafael Espindola 29da3e3577 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270555
2016-05-24 12:17:11 +00:00
Rafael Espindola fe3a2f1b81 Revert "Simplify. Thanks to Rui for the suggestion."
This reverts commit r270551.

Sorry, I commited the wrong branch :-(

llvm-svn: 270554
2016-05-24 12:12:06 +00:00
Rafael Espindola dba64b8ea4 Simplify. Thanks to Rui for the suggestion.
llvm-svn: 270551
2016-05-24 11:53:15 +00:00
Rui Ueyama 0b9a90364b Rename EHInputSection -> EhInputSection.
llvm-svn: 270532
2016-05-24 04:19:20 +00:00
Rui Ueyama f5febef249 Create a new file EhFrame.cpp and move code to read .eh_frame there.
llvm-svn: 270526
2016-05-24 02:55:45 +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 744d47ea05 Make file-local function file-local. NFC.
llvm-svn: 270387
2016-05-23 00:45:54 +00:00
Rui Ueyama 518f1af04d Split MergeInputSection's ctor. NFC.
llvm-svn: 270386
2016-05-23 00:40:24 +00:00
Rui Ueyama 88abd9b300 Move splitInputSection from EHOutputSection to EHInputSection.
llvm-svn: 270385
2016-05-22 23:53:00 +00:00
Rui Ueyama 34dc99e2c5 Store section contents to SectionPiece. NFC.
So that we don't need to cut a slice when we use a SectionPiece.

llvm-svn: 270348
2016-05-22 01:15:32 +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
Simon Atanasyan 1c980ca5aa [ELF] Take into account offset in the output section when read addends for a non-alloc input section
llvm-svn: 270328
2016-05-21 19:48:54 +00:00
Rafael Espindola ebed1fe0de Refactor R_RELAX_TLS_* value computation.
This makes it explicit that each R_RELAX_TLS_* is equivalent to some
other expression.

With this I think we are at a sweet spot for how much is done in
Target.cpp. I did experiment with moving *all* the value math out of it.
It has the advantage that we know the final value in target independent
code, but it gets quite verbose.

llvm-svn: 270277
2016-05-20 21:23:52 +00:00
Rafael Espindola 50223310ba Simplify a bit. NFC.
llvm-svn: 270275
2016-05-20 21:14:06 +00:00
Rafael Espindola 74f3dbe438 Directly compute the right value for R_RELAX_TLS_GD_TO_IE.
This avoid doing math in Target.cpp to compensate.

llvm-svn: 270266
2016-05-20 20:09:35 +00:00
Rafael Espindola 8818ca69dc Make tp offset computation target independent.
This adds direct support for computing offsets from the thread pointer
for both variants. Of the architectures we support, variant 1 is used
only by aarch64 (but that doesn't seem to be documented anywhere.)

llvm-svn: 270243
2016-05-20 17:41:09 +00:00
Simon Atanasyan 4e3a15c9f3 [ELF][MIPS] Rename R_MIPS_GOT_xxx relocation expression kinds
New names reflect purpose of corresponding GOT entries better.
Both expression types related to entries allocated in the 'local'
part of MIPS GOT. R_MIPS_GOT_LOCAL_PAGE is for entries contain 'page'
addresses. R_MIPS_GOT_LOCAL is for entries contain 'full' address.

llvm-svn: 269597
2016-05-15 18:13:50 +00:00
Rafael Espindola 3e0b7837bf Cache result when tail merging too.
This speeds up a link of chromium with -O2 (but no icf,gc) from
1.940664632 to 1.925578119.

llvm-svn: 268639
2016-05-05 16:12:25 +00:00
Peter Collingbourne e29e142a10 ELF: Do not use -1 to mark pieces of merge sections as being tail merged.
We were previously using an output offset of -1 for both GC'd and tail
merged pieces. We need to distinguish these two cases in order to filter
GC'd symbols from the symbol table -- we were previously asserting when we
asked for the VA of a symbol pointing into a dead piece, which would end
up asking the tail merging string table for an offset even though we hadn't
initialized it properly.

This patch fixes the bug by using an offset of -1 to exclusively mean GC'd
pieces, using 0 for tail merges, and distinguishing the tail merge case from
an offset of 0 by asking the output section whether it is tail merge.

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

llvm-svn: 268604
2016-05-05 04:10:12 +00:00
Rafael Espindola ebb04b9eb6 Simplify handling of hint relocations.
llvm-svn: 268501
2016-05-04 14:44:22 +00:00
Simon Atanasyan 5e85a1b5be [ELF][MIPS] Fix typo in the comment. NFC.
llvm-svn: 268486
2016-05-04 10:15:12 +00:00
Simon Atanasyan add74f37f2 [ELF][MIPS] Read/write .MIPS.options section
MIPS N64 ABI introduces .MIPS.options section which specifies miscellaneous
options to be applied to an object/shared/executable file. LLVM as well as
modern versions of GNU tools read and write the only type of the options -
ODK_REGINFO. It is exact copy of .reginfo section used by O32 ABI.

llvm-svn: 268485
2016-05-04 10:07:38 +00:00
Rui Ueyama 890ce0c188 Do not produce broken debug info.
r267917 produces corrupted debug info because it didn't apply
relocations to right offsets.

llvm-svn: 267979
2016-04-29 03:21:08 +00:00
Rui Ueyama 2b6fb80384 Skip scanRelocs for non-alloc sections.
Relocations against sections with no SHF_ALLOC bit are R_ABS relocations.
Currently we are creating Relocations vector for them, but that is wasteful.
This patch is to skip vector construction and to directly apply relocations
in place.

This patch seems to be pretty effective for large executables with debug info.
r266158 (Rafael's patch to change the way how we apply relocations) caused a
temporary performance degradation for such executables, but this patch makes
it even faster than before.

Time to link clang with debug info (output size is 1070 MB):

  before r266158: 15.312 seconds (0%)
  r266158:        17.301 seconds (+13.0%)
  Head:           16.484 seconds (+7.7%)
  w/patch:        13.166 seconds (-14.0%)

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

llvm-svn: 267917
2016-04-28 18:42:04 +00:00
Peter Collingbourne 676c7cd1ed ELF: Move code to where it is used, and related cleanups. NFC.
Differential Revision: http://reviews.llvm.org/D19490

llvm-svn: 267637
2016-04-26 23:52:44 +00:00
Rafael Espindola 6c75238aca Call repl in getSymbolBody. NFC.
Every caller was doing it.

llvm-svn: 267603
2016-04-26 20:45:31 +00:00
Rui Ueyama e12fd0fc2c Fix link failure.
llvm-svn: 267245
2016-04-22 22:59:22 +00:00
Rafael Espindola 0b9531c8e6 Bring r267164 back with a fix.
The fix is to handle local symbols referring to SHF_MERGE sections.

Original message:

GC entries of SHF_MERGE sections.

It is a fairly direct extension of the gc algorithm. For merge sections
instead of remembering just a live bit, we remember which offsets
were used.

This reduces the .rodata sections in chromium from 9648861 to 9477472
bytes.

llvm-svn: 267233
2016-04-22 22:09:35 +00:00
Rafael Espindola 46c039f2c0 Revert "GC entries of SHF_MERGE sections."
This reverts commit r267164.

    Revert "Trying to fix the windows build."

    This reverts commit r267168.

Debugging a bootstrap problem.

llvm-svn: 267194
2016-04-22 19:31:35 +00:00
Rafael Espindola a630380a0c Trying to fix the windows build.
llvm-svn: 267168
2016-04-22 17:10:28 +00:00
Rafael Espindola caa831d85a GC entries of SHF_MERGE sections.
It is a fairly direct extension of the gc algorithm. For merge sections
instead of remembering just a live bit, we remember which offsets were
used.

This reduces the .rodata sections in chromium from 9648861 to 9477472
bytes.

llvm-svn: 267164
2016-04-22 16:46:08 +00:00
Rafael Espindola 197d6a882f This reverts commit r267154 and r267161.
It turns out that this will read data from the section to properly
handle Elf_Rel implicit addends.

Sorry for the noise.

Original messages:

Try to fix Windows lld build.

Move getRelocTarget to ObjectFile.
It doesn't use anything from the InputSection.

llvm-svn: 267163
2016-04-22 16:39:59 +00:00
Rafael Espindola ea4d177977 Move getRelocTarget to ObjectFile.
It doesn't use anything from the InputSection.

llvm-svn: 267154
2016-04-22 14:17:14 +00:00
Rafael Espindola 475dbf42e4 Simplify mips gp0 handling.
In all currently supported cases this is a nop.

llvm-svn: 266888
2016-04-20 17:20:49 +00:00
Rafael Espindola 58cd5db4ef Simplify mips got handling.
This avoids computing the address of a position in the got just to then
subtract got->getva().

llvm-svn: 266831
2016-04-19 22:46:03 +00:00
Rafael Espindola ece62b962e Simplify handling of R_X86_64_TPOFF32. NFC.
llvm-svn: 266609
2016-04-18 12:44:33 +00:00
Rafael Espindola 3f5d634c73 Have getRelExpr handle all cases on x86.
This requires adding a few more expression types, but is already a small
simplification. Having Writer.cpp know the exact expression will also
allow further simplifications.

llvm-svn: 266604
2016-04-18 12:07:13 +00:00
Rafael Espindola 22ef956a45 Change how we apply relocations.
With this patch we use the first scan over the relocations to remember
the information we found about them: will them be relaxed, will a plt be
used, etc.

With that the actual relocation application becomes much simpler. That
is particularly true for the interfaces in Target.h.

This unfortunately means that we now do two passes over relocations for
non SHF_ALLOC sections. I think this can be solved by factoring out the
code that scans a single relocation. It can then be used both as a scan
that record info and for a dedicated direct relocation of non SHF_ALLOC
sections.

I also think it is possible to reduce the number of enum values by
representing a target with just an OutputSection and an offset (which
can be from the start or end).

This should unblock adding features like relocation optimizations.

llvm-svn: 266158
2016-04-13 01:40:19 +00:00
Rafael Espindola 8396f72f7b Simplify handling of mips gp* symbols.
Give them values instead of computing it during relocation.

llvm-svn: 265986
2016-04-11 20:34:27 +00:00
Rafael Espindola 0f7ccc3d92 Update for llvm change.
llvm-svn: 265404
2016-04-05 14:47:28 +00:00
Rafael Espindola ccfe3cb3d6 Don't store an Elf_Sym for most symbols.
Our symbol representation was redundant, and some times would get out of
sync. It had an Elf_Sym, but some fields were copied to SymbolBody.

Different parts of the code were checking the bits in SymbolBody and
others were checking Elf_Sym.

There are two general approaches to fix this:
* Copy the required information and don't store and Elf_Sym.
* Don't copy the information and always use the Elf_Smy.

The second way sounds tempting, but has a big problem: we would have to
template SymbolBody. I started doing it, but it requires templeting
*everything* and creates a bit chicken and egg problem at the driver
where we have to find ELFT before we can create an ArchiveFile for
example.

As much as possible I compared the test differences with what gold and
bfd produce to make sure they are still valid. In most cases we are just
adding hidden visibility to a local symbol, which is harmless.

In most tests this is a small speedup. The only slowdown was scylla
(1.006X). The largest speedup was clang with no --build-id, -O3 or
--gc-sections (i.e.: focus on the relocations): 1.019X.

llvm-svn: 265293
2016-04-04 14:04:16 +00:00
Rafael Espindola 2ee0092053 Don't apply a recolation that the dynamic linker will rewrite.
This matches the behavior of both bfd and gold. Looks like we just got
here for mips because of a bad ordering of an if else chain.

llvm-svn: 265147
2016-04-01 16:21:09 +00:00
Simon Atanasyan 13f6da1d2c [ELF] Implement infrastructure for thunk code creation
Some targets might require creation of thunks. For example, MIPS targets
require stubs to call PIC code from non-PIC one. The patch implements
infrastructure for thunk code creation and provides support for MIPS
LA25 stubs. Any MIPS PIC code function is invoked with its address
in register $t9. So if we have a branch instruction from non-PIC code
to the PIC one we cannot make the jump directly and need to create a small
stub to save the target function address.
See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

- In relocation scanning phase we ask target about thunk creation necessity
by calling `TagetInfo::needsThunk` method. The `InputSection` class
maintains list of Symbols requires thunk creation.

- Reassigning offsets performed for each input sections after relocation
scanning complete because position of each section might change due
thunk creation.

- The patch introduces new dedicated value for DefinedSynthetic symbols
DefinedSynthetic::SectionEnd. Synthetic symbol with that value always
points to the end of the corresponding output section. That allows to
escape updating synthetic symbols if output sections sizes changes after
relocation scanning due thunk creation.

- In the `InputSection::writeTo` method we write thunks after corresponding
input section. Each thunk is written by calling `TargetInfo::writeThunk` method.

- The patch supports the only type of thunk code for each target. For now,
it is enough.

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

llvm-svn: 265059
2016-03-31 21:26:23 +00:00
Rafael Espindola 287e100db2 No relocation needs bot SA and ZA.
Pass only one of them to relocateOne.

llvm-svn: 264866
2016-03-30 13:27:50 +00:00
Rafael Espindola abc9a12929 Simplify mips addend processing.
It is now added to the addend in the same way as a regular Elf_Rel
addend.

llvm-svn: 264864
2016-03-30 12:45:58 +00:00
Rafael Espindola da99df366d Fix handling of addends on i386.
Because of merge sections it is not sufficient to just add them while
applying a relocation.

llvm-svn: 264863
2016-03-30 12:40:38 +00:00
Rui Ueyama f43d15009c Fix comments.
The original comments were separated by new code that is irrelevant to
the comment. This patch moves the comment to the right place and update it.

llvm-svn: 264816
2016-03-30 00:43:49 +00:00
Rafael Espindola 163974dd33 Simplify AHL handling.
This simplifies a few things

* Read the value as early as possible, instead of passing a pointer to
  the location.
* Print the warning for missing pair close to where we find out it is
  missing.
* Don't pass the value to relocateOne.

llvm-svn: 264802
2016-03-29 23:05:59 +00:00
Rafael Espindola 5432287bad Make needsPlt a plain function instead of a template.
llvm-svn: 264267
2016-03-24 12:55:27 +00:00
Rafael Espindola 69082f051d Revert "bar"
This reverts commit r263799.
It was a mistake. Sorry about that.

llvm-svn: 263801
2016-03-18 18:11:26 +00:00
Rafael Espindola c2cfd9fa34 bar
llvm-svn: 263799
2016-03-18 18:09:32 +00:00
Rui Ueyama 9328b2cdde Use ELFT instead of ELFFile<ELFT>.
llvm-svn: 263510
2016-03-14 23:16:09 +00:00
Rui Ueyama 54945f692b Simplify. NFC.
llvm-svn: 263391
2016-03-13 20:34:34 +00:00
Rui Ueyama c4466605d8 ELF: Redefine canBeDefined as a member function of SymbolBody.
We want to make SymbolBody the central place to query symbol information.
This patch also renames canBePreempted to isPreemptible because I feel that
the latter is slightly better (the former is three words and the latter
is two words.)

llvm-svn: 263386
2016-03-13 19:48:18 +00:00
Simon Atanasyan d27e61c591 [ELF][MIPS] Add elf namespace name to the ObjectFile.
NFC. Follow-up to r263381.

llvm-svn: 263382
2016-03-13 15:48:41 +00:00
Simon Atanasyan 604aee134a [ELF][MIPS] Factor out SumVA adjustments into a couple of separate functions. NFC.
The patch does not reduce the size of the code but makes
InputSectionBase::relocate cleaner a bit.

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

llvm-svn: 263381
2016-03-13 15:37:38 +00:00
Rui Ueyama fc467e77b8 Use RelTy instead of Elf_Rel_Impl<ELFT, isRela> for readability.
llvm-svn: 263368
2016-03-13 05:06:50 +00:00
Rui Ueyama 84be8c5219 Remove redundant check.
The control reaches here only when linking MIPS binaries.

llvm-svn: 263359
2016-03-13 03:43:32 +00:00
Rui Ueyama 2039847062 Simplify findMipsPairedReloc function signature. NFC.
llvm-svn: 263356
2016-03-13 03:09:40 +00:00
Simon Atanasyan 92a32559fd [ELF][MIPS] Put type of symbol (local/global) to the findMipsPairedReloc and call it from the single place. NFC.
llvm-svn: 263339
2016-03-12 11:58:15 +00:00
George Rimar 777f96304e Recommit of r263252, [ELF] - Change all messages to lowercase to be consistent.
which was reverted because included
unrelative changes by mistake.

Original commit message:

[ELF] - Change all messages to lowercase to be consistent.

That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

Differential revision: http://reviews.llvm.org/D18085

llvm-svn: 263337
2016-03-12 08:31:34 +00:00
Rui Ueyama f714955402 Revert r263252: "[ELF] - Change all messages to lowercase to be consistent."
This reverts commit r263252 because the change contained unrelated changes.

llvm-svn: 263272
2016-03-11 18:46:51 +00:00
George Rimar 96bcdae1a5 [ELF] - Change all messages to lowercase to be consistent.
That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

Differential revision: http://reviews.llvm.org/D18085

llvm-svn: 263252
2016-03-11 16:40:55 +00:00
Rafael Espindola 36a73d2deb More MSVC fixes.
llvm-svn: 263251
2016-03-11 16:32:46 +00:00
Rafael Espindola b20dcb1483 Trying to fix the MSVC build.
llvm-svn: 263249
2016-03-11 16:23:45 +00:00
Rafael Espindola 1f5b70f64f Represent local symbols with DefinedRegular.
llvm-svn: 263237
2016-03-11 14:21:37 +00:00
Simon Atanasyan 019049fca9 [ELF][MIPS] Update comment about creation local GOT entries for non-local symbols. NFC.
llvm-svn: 263236
2016-03-11 13:57:53 +00:00
Rafael Espindola 38e5d4e73a Simplify now that local symbols can use getVA.
It is really odd that Mips differentiates symbols that are born local
and those that become local because of hidden visibility. I don't know
enough mips to known if this is a bug or not.

llvm-svn: 263228
2016-03-11 13:04:28 +00:00
George Rimar a4ab97d89c [ELF] - Early continue in InputSectionBase<ELFT>::relocate(). NFC.
llvm-svn: 263227
2016-03-11 12:57:52 +00:00
George Rimar 1d9738c2d1 [ELF] - Evaluate addend earlier and use it instead getAddend() calls. NFC.
llvm-svn: 263226
2016-03-11 12:53:17 +00:00
Rafael Espindola 87d9f10733 Compute value of local symbol with getVA.
llvm-svn: 263225
2016-03-11 12:19:05 +00:00
Rafael Espindola 67d72c02bc Create a SymbolBody for locals.
pr26878 shows a case where locals have to be in the got.

llvm-svn: 263222
2016-03-11 12:06:30 +00:00
Rafael Espindola f3314b2e4f Move getLocalRelTarget to the file where it is used.
llvm-svn: 263152
2016-03-10 19:00:22 +00:00
Rafael Espindola e02f4dfb9e Remove an unnecessary hack.
It doesn't look like anything is depending on using local dynamic tls
relocations with preemptable  symbols.

llvm-svn: 262957
2016-03-08 21:17:31 +00:00
Rafael Espindola 1f04c44885 Delete isTlsDynRel.
It was a badly specified hack for when a tls relocation should be
propagated to the dynamic relocation table.

This replaces it with a not as bad hack of saying that a local dynamic
tls relocation is never preempted.

I will try to remove even that second hack in the next patch.

llvm-svn: 262955
2016-03-08 20:24:36 +00:00
George Rimar 2f0fab53e4 [ELF] - Simplify a SymbolBody class interface a bit.
Get rid of few accessors in that class, and replace
them with direct fields access.

Differential revision: http://reviews.llvm.org/D17879

llvm-svn: 262796
2016-03-06 06:26:18 +00:00
Rafael Espindola d405f4721c Refactor target independent code.
The rules for when we can relax tls relocations are target independent.
The only things that are target dependent are the relocation values.

llvm-svn: 262748
2016-03-04 21:37:09 +00:00
Davide Italiano 255730cdc5 [ELF] Generalize symbol type handling.
SymbolBody constructor and friends take isFunc and isTLS boolean arguments.
ELF symbols have already a type so than be easily passed as argument.
If we want to support another type, this scheme is not good enough, that is,
the current code logic would require passing another `bool isObject` around.
Up to two argument, this stretching exercise was a little bit goofy but
still acceptable, but with more types to support, is just too much, IMHO.

Change the code so that the type is passed instead.

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

llvm-svn: 262684
2016-03-04 01:55:28 +00:00
Rafael Espindola 75714f618c Rename 'fatal' to 'check' when it doesn't always fail.
llvm-svn: 262666
2016-03-03 22:24:39 +00:00
Rafael Espindola 1130935c4a Simplify error handling.
This makes fatal return T when there is no error. This avoids the need
for quite a few temporaries.

llvm-svn: 262626
2016-03-03 16:21:44 +00:00
George Rimar 4cfe572932 [ELF] - add support for relocations against local symbols when producing relocatable output.
There was a known limitation for -r option:
relocations against local symbols were not supported. 
For example rel[a].eh_frame sections contained relocations against sections
and that was not supported for -r before. Patch fixes that.

Differential review: http://reviews.llvm.org/D17813

llvm-svn: 262590
2016-03-03 07:49:35 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rafael Espindola a350e266aa Refactor multiple calls to canBePreempted.
llvm-svn: 262018
2016-02-26 14:33:23 +00:00
Rafael Espindola 993f0273e3 Fix some confusion about what can be preempted.
For shared libraries we allow any weak undefined symbol to eventually be
resolved, even if we never see a definition in another .so. This matches
the behavior when handling other undefined symbols in a shared library.

For executables, we require seeing a definition in a .so or resolve it
to zero. This is also similar to how non weak symbols are handled.

llvm-svn: 262017
2016-02-26 14:27:47 +00:00
Simon Atanasyan 860fbf094e [ELF][MIPS] Calculate combined addend for R_MIPS_GOT16 against local symbol
R_MIPS_GOT16 relocation against local symbol requires index of a local
GOT entry which contains page address corresponds to sum of the symbol
address and addend. The addend in that case is calculated using addends
from the R_MIPS_GOT16 and paired R_MIPS_LO16 relocations.

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

llvm-svn: 261930
2016-02-25 21:33:56 +00:00
Rui Ueyama 0b28952993 ELF: Implement ICF.
This patch implements the same algorithm as LLD/COFF's ICF. I'm
not going to repeat the same description about how it works, so you
want to read the comment in ICF.cpp in this patch if you want to know
the details. This algorithm should be more powerful than the ICF
algorithm implemented in GNU gold. It can even merge mutually-recursive
functions (which is harder than one might think).

ICF is a fairly effective size optimization. Here are some examples.

 LLD:   37.14 MB -> 35.80 MB (-3.6%)
 Clang: 59.41 MB -> 57.80 MB (-2.7%)

The lacking feature is "safe" version of ICF. This merges all
identical sections. That is not compatible with a C/C++ language
requirement that two distinct functions must have distinct addresses.

But as long as your program do not rely on the pointer equality
(which is in many cases true), your program should work with the
feature. LLD works fine for example.

GNU gold implements so-called "safe ICF" that identifies functions
that are safe to merge by heuristics -- for example, gold thinks
that constructors are safe to merge because there is no way to
take an address of a constructor in C++. We have a different idea
which David Majnemer suggested that we add NOPs at beginning of
merged functions so that two or more pointers can have distinct
values. We can do whichever we want, but this patch does not
include neither.

http://reviews.llvm.org/D17529

llvm-svn: 261912
2016-02-25 18:43:51 +00:00
George Rimar 58941ee12a [ELF2] - Basic implementation of -r/--relocatable
-r, -relocatable - Generate relocatable output

Currently does not have support for files containing 
relocation sections with entries that refer to local 
symbols (like rel[a].eh_frame which refer to sections
and not to symbols)

Differential revision: http://reviews.llvm.org/D14382

llvm-svn: 261838
2016-02-25 08:23:37 +00:00
Rui Ueyama 733153de3c ELF: Do not instantiate InputSectionBase::Discarded.
"Discarded" section is a marker for discarded sections, and we do not
use the instance except for checking its identity. In that sense, it
is just another type of a "null" pointer for InputSectionBase. So,
it doesn't have to be a real instance of InputSectionBase class.

In this patch, we no longer instantiate Discarded section but instead
use -1 as a pointer value. This eliminates a global variable which
needed initialization at startup.

llvm-svn: 261761
2016-02-24 18:33:35 +00:00
Rafael Espindola 795dc5a0fb Move target independent code out of x86_64 only path.
The logic for deciding if an undefined symbol should have the value of a
got entry is not target specific.

llvm-svn: 261760
2016-02-24 18:24:23 +00:00
Rui Ueyama 5ac589171d ELF: Remove InputSectionBase::getAlign and instead add Align member.
This is a preparation for ICF. If we merge two sections, we want to
align the merged section at the largest alignment requirement.
That means we want to update the alignment value, which was
impossible before this patch because Header is a const value.

llvm-svn: 261712
2016-02-24 00:38:18 +00:00
Rui Ueyama 8fc070d64d ELF: Remove InputSectionBase::isLive and use Live member instead. NFC.
This is also a preparation for ICF.

llvm-svn: 261711
2016-02-24 00:23:15 +00:00
Rui Ueyama d7e4a281c4 ELF: Make some functions constant. NFC.
This is a preparation for ICF.

llvm-svn: 261710
2016-02-24 00:23:13 +00:00
Rafael Espindola f7ae359d2c Simplify. NFC.
llvm-svn: 261668
2016-02-23 18:53:29 +00:00
Rafael Espindola 5e8b54afdb Remove a trivial getter.
llvm-svn: 261590
2016-02-22 23:16:05 +00:00
George Rimar e9e1d323c6 Fixed comments formatting. NFC.
llvm-svn: 261214
2016-02-18 15:17:01 +00:00