Commit Graph

773 Commits

Author SHA1 Message Date
George Rimar bfb7bf7429 [ELF] - R_386_GOTOFF relocation implemented.
R_386_GOTOFF is calculated as S + A - GOT, where:
S - Represents the value of the symbol whose index resides in the relocation entry.
A - Represents the addend used to compute the value of the relocatable field.
GOT - Represents the address of the global offset table.

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

llvm-svn: 256143
2015-12-21 10:00:12 +00:00
George Rimar e72bebaf2d [ELF] - Fixed padding for CIE/FDE entries of .eh_frame section
Spec says both CIE/FDE has "Padding
Extra bytes to align the CIE structure to an addressing unit size boundary."
https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html

Patch aligns CIE/FDE entries to the size of platform pointer.

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

llvm-svn: 256141
2015-12-21 09:38:59 +00:00
Simon Atanasyan 1d7df40711 [ELF][MIPS] MIPS .reginfo sections handling
MIPS .reginfo section provides information on the registers used by
the code in the object file. Linker should collect this information and
write .reginfo section in the output file. This section contains a union
of used registers masks taken from input .reginfo sections and final
value of the `_gp` symbol.

For details see the "Register Information" section in Chapter 4 in the
following document:
ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf

The patch implements .reginfo sections handling with a couple missed
features: a) it does not put output .reginfo section into the separate
REGINFO segment; b) it does not merge `ri_cprmask` masks from input
section. These features will be implemented later.

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

llvm-svn: 256119
2015-12-20 10:57:34 +00:00
Simon Atanasyan 034c4cd58a [ELF] Allow target to configure ELF header flags in the output file
The patch configure ELF header flags for MIPS target. For now the flags
are hard coded. In fact they depends on ELF flags of input object files
and selected emulation.

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

llvm-svn: 256089
2015-12-19 05:51:49 +00:00
George Rimar 6f17e09307 [ELF] - implemented @indntpoff (x86) relocation and its optimization.
@indntpoff is similar to @gotntpoff, but for use in position dependent code. While @gotntpoff resolves to GOT slot address relative to the
start of the GOT in the movl or addl instructions, @indntpoff resolves to the
absolute GOT slot address. ("ELF Handling For Thread-Local Storage", Ulrich Drepper).

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

llvm-svn: 255884
2015-12-17 09:32:21 +00:00
George Rimar 003be4fd58 [ELF] - implement support of extended length field for CIE/FDE records of eh_frame.
Ian Lance Taylor writes: "Read 4 bytes. If they are not 0xffffffff, they are the length of the CIE or FDE record. Otherwise the next 64 bits holds the length, and this is a 64-bit DWARF format. This is like .debug_frame." (http://www.airs.com/blog/archives/460), that also consistent with spec (https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html).

Patch implements support of described extended length field and also adds few more checks for safety.

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

llvm-svn: 255883
2015-12-17 09:23:40 +00:00
Rui Ueyama 784b769d32 ELF: Avoid string concatenation if there's no error.
llvm-svn: 255870
2015-12-17 01:51:23 +00:00
Rui Ueyama 02dfd496b0 ELF: Rename relocNeedsCopy -> needsCopyRel
Just "copy" was a bit too ambiguous to say about copy relocations.

llvm-svn: 255866
2015-12-17 01:18:40 +00:00
Rui Ueyama bb93606755 ELF: Separate NeedsCopy and OffsetInBSS.
Previously, OffsetInBSS is -1 if it has no information about copy
relocation, 0 if it needs a copy relocation, and >0 if its offset
in BSS has been assigned. These flags were too subtle. This patch
adds a new flag, NeedsCopy, to carry information about whether
a shared symbol needs a copy relocation or not.

llvm-svn: 255865
2015-12-17 01:14:23 +00:00
Rui Ueyama 8b75b9a589 Add comment about DefinedSynthetic class.
llvm-svn: 255861
2015-12-17 00:48:16 +00:00
Rui Ueyama a02bba648b ELF: Remove accessors that don't hide anything.
llvm-svn: 255857
2015-12-17 00:12:04 +00:00
Rui Ueyama 61805ec343 ELF: Rename IsTLS -> IsTls for consistency with other identifiers containing 'TLS'.
llvm-svn: 255856
2015-12-17 00:12:03 +00:00
Rui Ueyama 62d0e3297b ELF: Rename isTLS -> isTls for consistency.
llvm-svn: 255855
2015-12-17 00:04:18 +00:00
Rui Ueyama 3554f59f5d ELF: Remove a dumb constructor.
Symbol is a struct and can be initialized using an initializer.

llvm-svn: 255854
2015-12-17 00:01:25 +00:00
Rui Ueyama 6be68525d0 Typedef uintX_t at beginning of a function just like others.
llvm-svn: 255853
2015-12-16 23:49:19 +00:00
Rui Ueyama 6192c122f4 ELF: Move shouldUseRela to Writer.cpp.
The function was used only in Writer.cpp and did not depend on SymbolTable.
There is no reason to have that function in SymbolTable.cpp.

llvm-svn: 255850
2015-12-16 23:33:56 +00:00
Rui Ueyama 25b44c9b2b ELF: Make checkCompatibility a non-member function.
Because the function does not use any member of SymbolTable class.

llvm-svn: 255849
2015-12-16 23:31:22 +00:00
Rui Ueyama 38dcc9e355 Simplify. NFC.
llvm-svn: 255846
2015-12-16 23:25:31 +00:00
Rui Ueyama c5b9512958 ELF: Remove duplicate code.
We had duplicate code that were called before addMemberFile.
This patch makes them to be called at beginning of addMemberFile.

llvm-svn: 255845
2015-12-16 23:23:14 +00:00
Rui Ueyama 8957574549 ELF: Remove SymbolTable::addELFFile.
addELFFile was called only from addFile, and what it did was actually
just adding a file to the symbol table. There seems to be no reason
to separate the two.

llvm-svn: 255839
2015-12-16 22:59:13 +00:00
Rui Ueyama a71f3a71cc Do not omit * from auto.
We don't do that in other places in the same file.

llvm-svn: 255833
2015-12-16 22:36:10 +00:00
Rui Ueyama dd7d998919 ELF: Drop 'Sym' suffix from member function names for consistency.
Since the functions are members of SymbolTable class, it is obvious
that they are adding symbols.

llvm-svn: 255832
2015-12-16 22:31:14 +00:00
Rui Ueyama 533336a368 ELF: Factor out common code. NFC.
llvm-svn: 255830
2015-12-16 22:26:48 +00:00
Rui Ueyama f09040120f ELF: Separate error message generation from call of error() or warning().
Previously reportConflict returned only when the third argument is false.
Now it always returns a value.

llvm-svn: 255829
2015-12-16 22:26:45 +00:00
Rui Ueyama 27161302a0 Merge two `if`s for MIPS. NFC.
llvm-svn: 255823
2015-12-16 21:35:39 +00:00
Simon Atanasyan 09dae7c3e7 [ELF][MIPS] Handle R_MIPS_HI16/LO16 relocations against _gp_disp symbol
The `_gp_disp` is a magic symbol designates offset between start of
function and gp pointer into GOT. Only `R_MIPS_HI16` and `R_MIPS_LO16`
relocations are permitted with `_gp_disp`. The patch adds the `_gp_disp`
as an ignored symbol and adjusts symbol value before call the `relocateOne`
for `R_MIPS_HI16/LO16` relocations.

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

llvm-svn: 255768
2015-12-16 14:45:09 +00:00
George Rimar 5be170ed8b Fixed mistype in comment. NFC.
llvm-svn: 255646
2015-12-15 14:20:57 +00:00
George Rimar c7dc0be36a Reapply fixed r255626 that broke buildbot:
[ELF] - refactor of code in RelocationSection<ELFT>::writeTo()

Just a little reformat of 'if' conditions, NFC.

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

Fix was:
* Renamed unsigned Rel; to unsigned Reloc;

llvm-svn: 255631
2015-12-15 08:48:39 +00:00
George Rimar b076446368 Revert of r255626 "[ELF] - refactor of code in RelocationSection<ELFT>::writeTo()"
as it broke buildbot: 
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/17836/steps/build_Lld/logs/stdio
/Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/tools/lld/ELF/OutputSections.cpp:268:14: error: redefinition of 'Rel'
    unsigned Rel;   ^
/Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/tools/lld/ELF/OutputSections.cpp:241:34: note: previous definition is here
  for (const DynamicReloc<ELFT> &Rel : Relocs) {

That compiles fine on my MSVS 2015 thought.

llvm-svn: 255628
2015-12-15 08:39:42 +00:00
George Rimar e3556420c1 [ELF] - refactor of code in RelocationSection<ELFT>::writeTo()
Just a little reformat of 'if' conditions, NFC.

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

llvm-svn: 255626
2015-12-15 08:23:08 +00:00
Simon Atanasyan 350311974b [ELF][MIPS] Remove applying the redundant bit-mask
The `mipsHigh` return type is `uint16_t` so we do not need to extract
low 16-bits from return value explicitly.

llvm-svn: 255622
2015-12-15 06:06:34 +00:00
Simon Atanasyan e4361859c0 [ELF][MIPS] Ignore R_MIPS_JALR relocation for now
The `R_MIPS_JALR` is a relocation generated by gcc and gas. This
relocation points to the `jalr` instruction which might be optimized and
converted to the `b` instruction under some conditions.

Now we just ignore this relocation and keep instructions unchanged.

llvm-svn: 255453
2015-12-13 06:49:14 +00:00
Simon Atanasyan dddbeb7a46 [ELF][MIPS] Match paired relocation using relocation type and symbol index
If we have R_MIPS_HI16 relocation, the paired relocation is the next
R_MIPS_LO16 relocation with the same symbol as a target.

llvm-svn: 255452
2015-12-13 06:49:08 +00:00
Simon Atanasyan 2cd670da02 [ELF][MIPS] Fix calculation of the R_MIPS_HI16 relocation
llvm-svn: 255451
2015-12-13 06:49:01 +00:00
Rafael Espindola 2992563b93 Treat unnamed symbols as locals.
There is work under way in llvm to avoid creating unnecessary names for
symbols. This makes lld capable of handling that.

llvm-svn: 255357
2015-12-11 19:09:21 +00:00
Rafael Espindola a6763e8386 Discard local symbols from SHF_MERGE sections.
This matches the behavior of both gold and bfd ld.

llvm-svn: 255355
2015-12-11 18:49:29 +00:00
Ed Maste f2ac688217 ELF: Allow -e <entry> with -shared
It is reasonable to specify an entry point for shared objects - for
example, for the FreeBSD rtld ld-elf.so.1.

Unlike GNU ld we leave the entry address as 0 if -shared is specified
without -e.

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

llvm-svn: 255349
2015-12-11 17:46:46 +00:00
George Rimar 48651489b3 [ELF] - R_X86_64_SIZE64/R_X86_64_SIZE32 relocations implemented.
R_X86_64_SIZE64/R_X86_64_SIZE32 relocations were introduced in 0.98v of "System V Application Binary Interface x86-64" (http://www.x86-64.org/documentation/abi.pdf).

Calculation for them is Z + A, where:
Z - Represents the size of the symbol whose index resides in the relocation entry.
A - Represents the addend used to compute the value of the relocatable field.

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

llvm-svn: 255332
2015-12-11 08:59:37 +00:00
Rafael Espindola 69d1ca6af2 Fix alignment computation for copy relocs.
Fixes PR25798.

Thanks to Ed Maste for the bug report and suggested fix.

llvm-svn: 255307
2015-12-10 22:53:24 +00:00
Rui Ueyama 01faef0ddc Simplify. NFC.
llvm-svn: 255284
2015-12-10 19:19:04 +00:00
Rui Ueyama ccfc3261f3 Simplify an expression. NFC.
llvm-svn: 255282
2015-12-10 19:13:08 +00:00
Ed Maste 3261be4b8d Add --version-script= alias for --version-script
llvm-svn: 255249
2015-12-10 14:08:45 +00:00
George Rimar a5fbebc206 [ELF] - Implemented --print-gc-sections command line argument.
List all sections removed by garbage collection. This option is only effective if garbage collection has been enabled via the `--gc-sections' option.

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

llvm-svn: 255235
2015-12-10 09:12:18 +00:00
George Rimar b72a9c6f02 [ELF] - Resolve R_386_PLT32 statically in some cases.
If R_386_PLT32 relocation is applied against symbol that can not be preempted then it can be resolved statically.
Patch implements it for x86 target.

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

llvm-svn: 255233
2015-12-10 09:03:39 +00:00
George Rimar 2558e12bac [ELF] - Implement the TLS relocation optimization for 32-bit x86.
Implement the TLS relocation optimization for 32-bit x86 that is described in
"ELF Handling For Thread-Local Storage" by Ulrich Drepper, chapter 5,
"IA-32 Linker Optimizations". Specifically, this patch implements these
optimizations: LD->LE, GD->IE, GD->LD, and IE->LE.

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

llvm-svn: 255103
2015-12-09 09:55:54 +00:00
George Rimar c55b4e25f4 [ELF] - fixed mistype in comment, NFC.
llvm-svn: 254918
2015-12-07 16:54:56 +00:00
George Rimar 95c1a58539 Renamed addLocalModelTlsIndex() -> addCurrentModuleTlsIndex(), NFC.
(per discussion with Michael Spencer)

llvm-svn: 254896
2015-12-07 08:02:20 +00:00
Igor Kudrin cfe47f5b32 [ELF/AArch64] Allow only valid dynamic relocations in the output.
All relocations, which cannot be handled by the dynamic linker,
cause a linking error "rebuild with -fPIC".

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

llvm-svn: 254840
2015-12-05 06:20:24 +00:00
George Rimar 25411f2558 [ELF] - Implemented @tlsgd optimization (GD->IE case, x64).
"Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5 x86-x64 linker optimizations, http://www.akkadia.org/drepper/tls.pdf) shows how GD can be optimized to IE.
This patch implements the optimization.

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

llvm-svn: 254713
2015-12-04 11:20:13 +00:00
Rui Ueyama 7ee3cf7d61 Fix style by sorting switch-cases.
llvm-svn: 254649
2015-12-03 20:59:51 +00:00