Commit Graph

791 Commits

Author SHA1 Message Date
Rafael Espindola ae53324cd4 Move function to the file where it is used.
llvm-svn: 256348
2015-12-23 20:37:51 +00:00
Rafael Espindola 97cbe3e39c Place RW sections that go after relro to another memory page.
Before this patch sections that go after relro sequence were placed at
the same memory page with relro ones. It caused segmentation fault on
freebsd.

Fixes PR25790.

Patch by George Rimar with some tweaks by myself.

llvm-svn: 256334
2015-12-23 15:20:38 +00:00
Rafael Espindola 21f7bd4ba1 Simplify memory management.
We no longer need an explicit delete or a polymorphic destructor.

llvm-svn: 256333
2015-12-23 14:35:51 +00:00
Rafael Espindola ce7d39d5e1 Fix the last leak asan found in test/ELF.
llvm-svn: 256316
2015-12-23 03:40:17 +00:00
Rafael Espindola 7300afa36a Fix another asan detected leak.
llvm-svn: 256311
2015-12-23 01:18:40 +00:00
Rafael Espindola 05b0375e93 Fix an asan found leak.
I will make better use of std::unique_ptr in followup patch.

llvm-svn: 256310
2015-12-23 01:14:37 +00:00
Rafael Espindola 5f2c46d62e Fix two asan found bugs:
We were leaking InputFile subclasses data.
UndefinedElf was missing a classof.

llvm-svn: 256309
2015-12-23 01:06:39 +00:00
Rafael Espindola 5d7593bc59 Split Undefined and UndefinedElf.
I am working on adding LTO support to the new ELF lld.

In order to do that, it will be necessary to represent defined and
undefined symbols that are not from ELF files. One way to do it is to
change the symbol hierarchy to look like

Defined : SymbolBody
Undefined : SymbolBody

DefinedElf<ELFT> : Defined
UndefinedElf<ELFT> : Undefined

Another option would be to use bogus Elf_Sym, but I think that is
getting a bit too hackish.

This patch does the Undefined/UndefinedElf. Split. The next one
will do the Defined/DefinedElf split.

llvm-svn: 256289
2015-12-22 23:00:50 +00:00
Rafael Espindola 88dddf9198 Drop remaining uses of the Base typedef idiom.
llvm-svn: 256200
2015-12-21 21:07:31 +00:00
Rafael Espindola 167e62f8c1 Simplify types. NFC.
llvm-svn: 256197
2015-12-21 20:59:29 +00:00
Rafael Espindola 495bb46b34 Remove unnecessary cast.
llvm-svn: 256196
2015-12-21 20:50:51 +00:00
Rafael Espindola 1e2967e81c Remove simple uses of Base::.
They have a tendency to get out of date and obscure where the value/type
is from.

llvm-svn: 256195
2015-12-21 20:47:33 +00:00
Rafael Espindola 0234640882 Remove unnecessary cast.
llvm-svn: 256189
2015-12-21 20:18:04 +00:00
Rafael Espindola 8614dd7e19 Delete dead typedefs.
llvm-svn: 256181
2015-12-21 19:10:27 +00:00
Rafael Espindola 8a9f90e669 Refactor duplicated code. NFC.
llvm-svn: 256180
2015-12-21 19:09:19 +00:00
Simon Atanasyan 0fc0acf180 [ELF][MIPS] Support some of R_MIPS_PCxxx relocations
The patch adds support for R_MIPS_PC16, R_MIPS_PC19_S2, R_MIPS_PC21_S2,
R_MIPS_PC26_S2, R_MIPS_PCHI16, R_MIPS_PCLO16 relocations handling.

llvm-svn: 256172
2015-12-21 17:36:40 +00:00
George Rimar 0b8ed1d162 [ELF] - fixed not properly handled @GOTTPOFF relocation against local symbols
This patch changes sequence of applying relocations, moving tls optimized relocation handling code before code for other locals.
Without that change relocation @GOTTPOFF against local symbol caused runtime error ("unrecognized reloc ...").
That change also should fix other tls optimized relocations, but I did not check them, that's a field for another patch.

R_X86_64_GOTTPOFF relocations against locals can be found when linking against libc.a(malloc.o):
000000000036 000600000016 R_X86_64_GOTTPOFF 0000000000000000 libc_tsd_MALLOC - 4
000000000131 000600000016 R_X86_64_GOTTPOFF 0000000000000000 libc_tsd_MALLOC - 4

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

llvm-svn: 256145
2015-12-21 10:37:33 +00:00
George Rimar a07ff66112 [ELF] - Implemented R_*_IRELATIVE relocations for x86, x64 targets.
This relocation is similar to R_*_RELATIVE except that the value used in this relocation is the program address returned by the function, which takes no arguments, at the address of
the result of the corresponding R_*_RELATIVE relocation as specified in the processor-specific ABI. The purpose of this relocation to avoid name lookup for locally defined STT_GNU_IFUNC symbols at load-time.

More info can be found in ifunc.txt from https://sites.google.com/site/x32abi/documents.

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

llvm-svn: 256144
2015-12-21 10:12:06 +00:00
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