Commit Graph

55 Commits

Author SHA1 Message Date
George Rimar ec02b8d4c0 [ELF] - Partial support of --gdb-index command line option (Part 3).
Patch continues work started in D24706 and D25821.

in this patch symbol table and constant pool areas were
added to .gdb_index section output.

This one finishes the implementation of --gdb-index functionality in LLD.

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

llvm-svn: 289810
2016-12-15 12:07:53 +00:00
George Rimar 8b54739328 [ELF] - Partial support of --gdb-index command line option (Part 2).
Patch continues work started in D24706,

in this patch address area was added to .gdb_index section output.

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

llvm-svn: 289790
2016-12-15 09:08:13 +00:00
Peter Smith 532bc984f5 [ELF] Accept first SHT_ARM_ATTRIBUTES section
The eglibc library, as used by Ubuntu 14.04 requires the presence of an
SHT_ARM_ATTRIBUTES section in for the purposes of checking hard/soft float
compatibility when dlopen() is used. Unfortunately when the section is not
present dlopen() fails with a generic could not find file message.
    
This change makes lld keep the first .ARM.attributes section that it
encounters and propagates it to the output. This is not a complete
SHT_ARM_ATTRIBUTES implementation, that would involve reading the contents
of the section and joining each individual attribute. It should suffice
for a homogenous build all libraries and executables on the same system
with a compatible set of command line options.

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

llvm-svn: 289642
2016-12-14 10:36:12 +00:00
Simon Atanasyan b9666655c2 [ELF][MIPS] Fix .MIPS.options ri_gp_value on MIPS64
The VA of _gp was being truncated to 32 bits when calling getVa(), but
for 64bit MIPS we need to write a 64 bit value to .MIPS.options.

Patch by Alexander Richardson.

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

llvm-svn: 289432
2016-12-12 14:30:18 +00:00
Peter Smith baffdb8bc2 [ELF] ifunc implementation using synthetic sections
This change introduces new synthetic sections IpltSection, IgotPltSection
that represent the ifunc entries that would previously have been put in
the PltSection and the GotPltSection. The separation makes sure that
the R_*_IRELATIVE relocations are placed after the non R_*_IRELATIVE
relocations, which permits ifunc resolvers to know that the .got.plt
slots will be initialized prior to the resolver being called.

A secondary benefit is that for ARM we can move the IgotPltSection and its
dynamic relocations to the .got and .rel.dyn as the ARM glibc expects all
the R_*_IRELATIVE relocations to be in the .rel.dyn

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

llvm-svn: 289045
2016-12-08 12:58:55 +00:00
George Rimar 3fb5a6dc9e [ELF] - Add support of proccessing of the rest allocatable synthetic sections from linkerscript.
This change continues what was started by D27040
Now all allocatable synthetics should be available from script side.

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

llvm-svn: 288150
2016-11-29 16:05:27 +00:00
Simon Atanasyan 160bf723f5 [ELF][MIPS] Make stable an order of GOT page address entries
llvm-svn: 288137
2016-11-29 13:26:04 +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
Simon Atanasyan a0efc4268c [ELF][MIPS] Replace the magic number of GOT header entries by constant. NFC
llvm-svn: 288128
2016-11-29 10:23:50 +00:00
Rafael Espindola f1e245315b Use relocations to fill statically known got entries.
Right now we just remember a SymbolBody for each got entry and
duplicate a bit of logic to decide what value, if any, should be
written for that SymbolBody.

With ARM there will be more complicated values, and it seems better to
just use the relocation code to fill the got entries. This makes it
clear that each entry is filled by the dynamic linker or by the static
linker.

llvm-svn: 288107
2016-11-29 03:45:36 +00:00
George Rimar 11992c86d9 [ELF] - Add support for access to most of synthetic sections from linkerscript.
This is important for cases like:

  .sdata        : {
    *(.got.plt .got)
...
  }

That was not supported before as there was no way to get access to 
synthetic sections from script.

More details on review page.

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

llvm-svn: 287913
2016-11-25 08:05:41 +00:00
Peter Smith 719eb8efa5 [ELF] Add terminating sentinel .ARM.exidx table entry
The .ARM.exidx table has an entry for each function with the first entry
giving the start address of the function, the table is sorted in ascending
order of function address. Given a PC value, the unwinder will search the
table for the entry that contains the PC value.
    
If the table entry happens to be the last, the range of the addresses that
the final unwinding table describes will extend to the end of the address
space. To prevent an incorrect address outside the address range of the
program matching the last entry we follow ld.bfd's example and add a
sentinel EXIDX_CANTUNWIND entry at the end of the table. This gives the
final real table entry an upper bound.
    
In addition the llvm libunwind unwinder currently depends on the presence
of a sentinel entry (PR31091).

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

llvm-svn: 287869
2016-11-24 11:43:55 +00:00
George Rimar 066bf6e1b3 [ELF] - Removed unused method. NFC.
llvm-svn: 287860
2016-11-24 09:42:10 +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
Simon Atanasyan 97deade619 [ELF][MIPS] clang-format the code
llvm-svn: 287738
2016-11-23 05:09:36 +00:00
Rui Ueyama bdfa155fa2 Fix build breakage.
We cannot have MipsRldMap class and In<ELFT>::MipsRldMap.
Renamed the class.

llvm-svn: 287683
2016-11-22 19:24:52 +00:00
Eugene Leviant 17b7a57533 [ELF] Convert .rld_map to input section
Differential revision: https://reviews.llvm.org/D26958

llvm-svn: 287675
2016-11-22 17:49:14 +00:00
Rui Ueyama 1d75de00e8 Do not save unused pointers to In<ELFT>.
llvm-svn: 287617
2016-11-22 04:28:39 +00:00
Rui Ueyama 8b493f1ac6 Remove default definition no one uses.
llvm-svn: 287616
2016-11-22 04:17:12 +00:00
Rui Ueyama 9cfac8a849 Convert MipsOptionsSection to SyntheticSection.
llvm-svn: 287615
2016-11-22 04:13:09 +00:00
Rui Ueyama b71cae90de Convert MipsReginfoSection to SyntheticSection.
llvm-svn: 287614
2016-11-22 03:57:08 +00:00
Rui Ueyama 12f2da870e Convert MipsAbiFlagsSection to SyntheticSection.
llvm-svn: 287613
2016-11-22 03:57:06 +00:00
Rui Ueyama 2d98fead25 Convert BuildId a derived class of SyntheticSection.
Some synthetic sections are not derived calsses of SyntehticSection.
They are derived directly from InputSection. For consistencly, we should
use SyntheticSection.

llvm-svn: 287606
2016-11-22 01:31:32 +00:00
Rui Ueyama ee18d95764 Remove a parameter from getOutputLoc and rename for readability. NFC.
llvm-svn: 287605
2016-11-22 01:10:34 +00:00
Rui Ueyama c4030a1937 Merge BuildId subclasses.
We had five different BuildId subclasses for five different types
of build-ids. They can simply be merged to a single class.

llvm-svn: 287603
2016-11-22 00:54:15 +00:00
Eugene Leviant e9bab5d857 [ELF] Convert Version*** sections to input sections
Differential revision: https://reviews.llvm.org/D26918

llvm-svn: 287554
2016-11-21 16:59:33 +00:00
Eugene Leviant 952eb4d348 [ELF] Convert EhFrameHeader to input section
Differential revision: https://reviews.llvm.org/D26906

llvm-svn: 287549
2016-11-21 15:52:10 +00:00
Eugene Leviant a113a4194c [ELF] Convert GdbIndexSection to input section
Differential revision: https://reviews.llvm.org/D26854

llvm-svn: 287526
2016-11-21 09:24:43 +00:00
Eugene Leviant ff23d3e741 [ELF] Convert PltSection to input section
Differential revision: https://reviews.llvm.org/D26842

llvm-svn: 287346
2016-11-18 14:35:03 +00:00
Eugene Leviant b96e809c7f [ELF] Convert HashTableSection to input section
Differential revision: https://reviews.llvm.org/D26834

llvm-svn: 287326
2016-11-18 09:06:47 +00:00
Eugene Leviant be809a7125 [ELF] Convert GnuHashTableSection to input section
Differential revision: https://reviews.llvm.org/D26792

llvm-svn: 287322
2016-11-18 06:44:18 +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
Eugene Leviant 9230db94b7 [ELF] Convert SymbolTableSection to input section
Differential revision: https://reviews.llvm.org/D26740

llvm-svn: 287216
2016-11-17 09:16:34 +00:00
Rui Ueyama 729ac793a2 Rename a function so that that starts with a lowercase letter.
llvm-svn: 287202
2016-11-17 04:10:09 +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
Eugene Leviant 6380ce2212 [ELF] Convert DynamicSection to input section.
This patch introduces the following changes:
- DynamicSection now inherits InputSection<ELFT> and was moved
  to SyntheticSections.h/.cpp.
- Link and Entsize fields of DynamicSection are propagated to 
  its output section
- In<ELFT>::SyntheticSections was removed.
- Finalization of synthetic sections was removed from 
  OutputSection<ELFT>::finalize. Now finalizeSyntheticSections is
  used instead.

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

llvm-svn: 286950
2016-11-15 12:26:55 +00:00
Eugene Leviant 22eb026886 [ELF] Convert StringTableSection to input section
Differential revision: https://reviews.llvm.org/D26549

llvm-svn: 286799
2016-11-14 09:16:00 +00:00
Eugene Leviant 17afb64d4f [ELF] Set 'Live = true' in SyntheticSection ctor. NFC.
llvm-svn: 286588
2016-11-11 13:03:58 +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 3da3f06dd3 Include version string into ".comment" section.
Summary:
This patch adds a ".comment" section to an output. The comment
section contains the linker's version string. You can now
find out whether a binary is created by LLD or not using objdump
command like this.

  $ objdump -s -j .comment foo

  foo:     file format elf64-x86-64

  Contents of section .comment:
   0000 00474343 3a202855 62756e74 7520342e  .GCC: (Ubuntu 4.
   0010 382e342d 32756275 6e747531 7e31342e  8.4-2ubuntu1~14.
   ...
   00c0 766d2f74 72756e6b 20323835 38343629  vm/trunk 285846)
   00d0 004c696e 6b65723a 204c4c44 20342e30  .Linker: LLD 4.0
   00e0 2e302028 7472756e 6b203238 36343036  .0 (trunk 286406
   00f0 2900                                 ).

Compilers emits .comment section as well, so the output contains
both compiler and linker information.

Alternative considered:

I first tried to add a SHT_NOTE section because GNU gold does that.
A NOTE section starts with a header which contains content type.
It turned out that ld.gold sets type NT_GNU_GOLD_VERSION to their
NOTE section. So the NOTE type is only for GNU gold (surprise!)

Next, I tried to create ".linker-version" section. However, it seems
that reusing the existing ".comment" section is better because 1)
other tools already know about .comment section and is able to strip
it and 2) the result contans not only linker info but also compiler
info.

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

llvm-svn: 286496
2016-11-10 20:20:37 +00:00
Rafael Espindola 0e876cfb2e Replace duplicated '16' with a named constant.
Thanks to Michael Spencer for the suggestion.

llvm-svn: 286462
2016-11-10 15:41:34 +00:00
Eugene Leviant 12e8a92acd [ELF] Make SyntheticSection::writeTo pure virtual. NFC.
llvm-svn: 286445
2016-11-10 12:50:59 +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 c0e47fbfb2 Delete the InterpSection class.
We can just use a regular InputSection.

llvm-svn: 286237
2016-11-08 14:56:27 +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
Rafael Espindola 682a5bc2c1 Delete the CommonSection class.
With the current infrastructure it can be just an ordinary
InputSection like the real .bss sections.

llvm-svn: 286234
2016-11-08 14:42:34 +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