Commit Graph

562 Commits

Author SHA1 Message Date
Adhemerval Zanella dbd75b7fa0 [ELF/AArch64] Initial General-dynamic TLS support
This patch adds initial general-dynamic TLS support for AArch64.  Currently
no optimization is done to realx for more performance-wise models (initial-exec
or local-exec).  This patch also only currently handles correctly executable
generation, although priliminary DSO support through PLT specific creation
is also added.

With this change clang/llvm bootstrap with lld is possible in static configuration
(some DSO creation fails due missing Linker script support, not AArch64 specific),
although make check also shows some issues.

llvm-svn: 241192
2015-07-01 21:35:39 +00:00
Simon Atanasyan 253125af03 [Mips] Reject R_MIPS_CALL16 against local symbols
llvm-svn: 240765
2015-06-26 07:25:20 +00:00
Simon Atanasyan b7bcff8796 [Mips] Create LA25 stubs for all branch relocations
llvm-svn: 240763
2015-06-26 07:25:06 +00:00
Rafael Espindola 69e942aefe Update for llvm change.
llvm-svn: 240658
2015-06-25 17:04:12 +00:00
Adhemerval Zanella 3ebea27d66 [ELF] Fix .init_array initialization
Some compilers may not add the section symbol in '.symtab' for the
.init_array and 'ldd' just ignore it.  It results in global constructor
not being called in final executable.

This patch add both '.init_array' and '.fini_array' to be added in
Atom graph generation even when the section contains no symbol.  An
already existing testcase is modified to check for such scenario.

The issue fixes the llvm test-suite regressions for both Single
and MultiSource files.

llvm-svn: 240570
2015-06-24 19:26:00 +00:00
Simon Atanasyan 356d7c52b6 [Mips] Support R_MICROMIPS_HI0_LO16 relocation handling
llvm-svn: 240268
2015-06-22 09:27:05 +00:00
Simon Atanasyan f44f854af3 [Mips] Support R_MICROMIPS_LITERAL relocation handling
llvm-svn: 240267
2015-06-22 09:26:57 +00:00
Simon Atanasyan 692e792575 [Mips] Support R_MIPS_LITERAL relocation handling
llvm-svn: 240266
2015-06-22 09:26:48 +00:00
Simon Atanasyan ca0fe2f4a4 [Mips] Support R_MICROMIPS_SUB relocation handling
llvm-svn: 240265
2015-06-22 09:26:41 +00:00
Simon Atanasyan 1af72b898c [Mips] Reject R_MIPS_GPREL32 against external symbols
llvm-svn: 240264
2015-06-22 09:26:33 +00:00
Simon Atanasyan 74a07c5457 [Mips] Fix test case - do not use R_MIPS_GPREL32 against external symbols
No functional changes.

llvm-svn: 240263
2015-06-22 09:26:25 +00:00
Simon Atanasyan b5d26b1433 [Mips] Reject position-dependent relocations in case of shared library linking
llvm-svn: 240262
2015-06-22 09:26:20 +00:00
Simon Atanasyan 7851f3b111 [Mips] Fix test case - do not use R_MIPS_HI16 for shared library linking
No functional changes.

llvm-svn: 240261
2015-06-22 09:26:12 +00:00
Simon Atanasyan 46d97f246b [Mips] Support R_MICROMIPS_HIGHER / R_MICROMIPS_HIGHEST relocations handling
llvm-svn: 240260
2015-06-22 09:26:05 +00:00
Simon Atanasyan e55110454d [Mips] Support R_MIPS_HIGHER / R_MIPS_HIGHEST relocations handling
llvm-svn: 240259
2015-06-22 09:25:57 +00:00
Simon Atanasyan faf558224d [Mips] Use new llvm-readobj -mips-reginfo flag to check .reginfo content
No functional changes.

llvm-svn: 239962
2015-06-17 22:28:38 +00:00
Simon Atanasyan f8b082a6aa [Mips] Support R_MICROMIPS_GPREL16 / R_MICROMIPS_GPREL7_S2 relocations handling
llvm-svn: 239960
2015-06-17 22:27:54 +00:00
Simon Atanasyan 17478c5804 [Mips] Support R_MIPS_16 relocation handling
llvm-svn: 239959
2015-06-17 22:27:39 +00:00
Adhemerval Zanella b19f5cfee6 [ELF/x86_64] Fix initial-exec TLS access
Current approach for initial-exec in ELF/x86_64 is to create a GOT entry
and change the relocation to R_X86_64_PC32 to be handled as a GOT offfset.
However there are two issues with this approach: 1. the R_X86_64_PC32 is
not really required since the GOT relocation will be handle dynamically and
2. the TLS symbols are not being exported externally and then correct
realocation are not being applied.

This patch fixes the R_X86_64_GOTTPOFF handling by just emitting a
R_X86_64_TPOFF64 dynamically one; it also sets R_X86_64_TPOFF64 to be
handled by runtime one.  For second part, the patches uses a similar
strategy used for aarch64, by reimplementing buildDynamicSymbolTable
from X86_64ExecutableWriter and adding the TLS symbols in the dynamic
symbol table.

Some tests had to be adjusted due the now missing R_X86_64_PC32 relocation.
With this test the simple testcase:

* t1.c:

__thread int t0;
__thread int t1;
__thread int t2;
__thread int t3;

* t0.c:

extern __thread int t0;
extern __thread int t1;
extern __thread int t2;
extern __thread int t3;

__thread int t4;
__thread int t5;
__thread int t6;
__thread int t7;

int main ()
{
  t0 = 1;
  t1 = 2;
  t2 = 3;
  t3 = 4;

  t4 = 5;
  t5 = 6;
  t6 = 7;
  t7 = 8;

  printf ("%i %i %i %i\n", t0, t1, t2, t3);
  printf ("%i %i %i %i\n", t4, t5, t6, t7);

  return 0;
}

Shows correct output for x86_64.

llvm-svn: 239908
2015-06-17 14:00:12 +00:00
Adhemerval Zanella 9c5831f3de [ELF] Fix wrong TBSS size
This patch fixes the wrong .tbss segment size generated for cases where
multiple modules have non initialized threads variables.  For instance:

* t0.c

__thread int x0;
__thread int x1;
__thread int x2;

extern __thread int e0;
extern __thread int e1;
extern __thread int e2;
extern __thread int e3;

int foo0 ()
{
  return x0;
}

int main ()
{
  return x0;
}

* t1.c

__thread int e0;
__thread int e1;
__thread int e2;
__thread int e3;


lld is generating (for aarch64):

  [14] .tbss             NOBITS           0000000000401000  00001000
       0000000000000010  0000000000000000 WAT       0     0     4

Where is just taking in consideration the largest tbss segment, not all
from all objects.  ld generates a correct output:

  [17] .tbss             NOBITS           0000000000410dec  00000dec
       000000000000001c  0000000000000000 WAT       0     0     4

This issue is at 'lib/ReaderWriter/ELF/SegmentChunks.cpp' where
Segment<ELFT>::assignVirtualAddress is setting wrong slice values, not taking care
of although tbss segments file size does noy play role in other segment virtual
address placement, its size should still be considered.

llvm-svn: 239906
2015-06-17 13:46:07 +00:00
Denis Protivensky 1aaf736d89 [LinkerScript] Add matching of output sections to segments
Add method to query segments for specified output section name.
Return error if the section is assigned to unknown segment.
Check matching of sections to segments during layout on the subject of correctness.
NOTE: no actual functionality of using custom segments is implemented.

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

llvm-svn: 239719
2015-06-15 08:00:51 +00:00
Simon Atanasyan 6df6c75b61 [Mips] Support R_MIPS_PC16 relocation handling
llvm-svn: 239677
2015-06-13 14:48:14 +00:00
Simon Atanasyan 5f54812cb0 [Mips] Handle TLS relocations in -static linking mode
llvm-svn: 239615
2015-06-12 16:13:14 +00:00
Simon Atanasyan d5296b206b [Mips] Define _gpxxx symbols in both static/dynamic linking modes
llvm-svn: 239614
2015-06-12 16:13:00 +00:00
Simon Atanasyan 01cde9cf5a [Mips] Setup EI_ABIVERSION flag
- Set EI_ABIVERSION to '1' in case of non-PIC executable.
- Set EI_ABIVERSION to '3' in case of using FP64/FP64A floating point ABI.

llvm-svn: 239613
2015-06-12 16:12:50 +00:00
Simon Atanasyan c859644f67 [Mips] Check symbol alignment for some MIPS relocations.
llvm-svn: 239225
2015-06-06 17:26:28 +00:00
Simon Atanasyan 439af8550e [Mips] Perform an overflow checking for relocations results
llvm-svn: 239224
2015-06-06 17:26:18 +00:00
Simon Atanasyan 24945e6745 [Mips] Add test to check jal -> jalx conversion
No functional changes.

llvm-svn: 239180
2015-06-05 18:26:44 +00:00
Simon Atanasyan 6eadaf1921 [Mips] Add test to check relocation result shifting in case of N64 ABI
llvm-svn: 239179
2015-06-05 18:26:38 +00:00
Simon Atanasyan efad3402f0 [Mips] Fix rel-gprel16.test test case
This test case uses too large GP0 value. Now the test is correct. Later
we need to implement overflow checking to catch such cases.

llvm-svn: 239178
2015-06-05 18:26:33 +00:00
Simon Atanasyan 1a58aca55f [Mips] Fix hilo16-9-micro.test test case
This test case uses too large addends in relocations. Now the test is correct.
Later we need to implement overflow checking to catch such cases.

llvm-svn: 239177
2015-06-05 18:26:25 +00:00
Rafael Espindola 010ce27c0c Fix the test to use the correct size.
For some reason llvm's r239045 made lld propagate data_1's size. This indicates
a bug somewhere in lld.

I hesitated between changing the test or just checking in a .o produced with
the old llvm-mc. Since the size is now correct, it seemed better to update the
test.

llvm-svn: 239067
2015-06-04 18:49:12 +00:00
Adhemerval Zanella 9f0c63bfdf [ELF/AArch64] Fix TLS initial executable relocation
This patch fixes the TLS initial executable for AArch64.  Current
implementation have two issues: 1. does not generate dynamic
R_AARCH64_TLS_TPREL64 relocation for the external module symbols,
and 2. does not export the TLS initial executable symbol in dynamic
symbol table.

The fix follows the MIPS strategy to add a arch-specific GOTSection
class to keep track of TLS symbols required to be place in dynamic
symbol table. It also overrides the buildDynamicSymbolTable for
ExecutableWrite class to add the symbols.

It also adds some refactoring on AArch64RelocationPass.cpp based on ARM
backend.

llvm-svn: 238981
2015-06-03 21:44:03 +00:00
Adhemerval Zanella 4bcc13d988 [ELF/AArch64] Fix correct TCB aligment calculation
This patch fixes the TLS local relocations alignment done by @238258.
As pointed out, the TLS size should not be considered, but rather the
TCB size based on maximum output segment alignment.  Although it has
not shown in the TLS simple cases for test-suite, more comprehensible
tests with more local TLS variable showed wrong relocations values
being generated.

The local TLS testcase is expanded to add more tls variable (both
exported and static) initialized or not.

llvm-svn: 238960
2015-06-03 20:39:30 +00:00
Simon Atanasyan 2944e4a43d [Mips] Do not put the .reginfo section into the separate segment
The .reginfo should not belong to the separate segment if there is
a .MIPS.abiflags section.

llvm-svn: 238688
2015-05-31 20:37:13 +00:00
Simon Atanasyan c140b41c39 [Mips] Sort segments so PT_MIPS_ABIFLAGS goes right after the PT_INTERP
llvm-svn: 238687
2015-05-31 20:36:58 +00:00
Simon Atanasyan c90c425735 [Mips] Reading, merging and writing .MIPS.abiflags section
http://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking

llvm-svn: 238686
2015-05-31 20:36:43 +00:00
Simon Atanasyan bb399f3d57 [ELF][Mips] Do not merge ELF flags in the `isCompatible` routine
We do not need to merge ELF flags from DSO. But `isCompatible` is called
for all input files. So this change move ELF flags merging into the
MipsELFFile class.

llvm-svn: 238304
2015-05-27 08:45:31 +00:00
Adhemerval Zanella f3c1c065aa [ELF/AArch64] Fix local TLS relocations
This patch fixes the R_AARCH64_TLSLE_ADD_TPREL_HI12 and R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
handling by using the correct offset by using the target layout along with
aarch64 alignments requirements.

It fixes the TLS test-suite SingleSource failures for aarch64:

* SingleSource/UnitTests/Threads/2010-12-08-tls.execution_time
* SingleSource/UnitTests/Threads/tls.execution_time

llvm-svn: 238258
2015-05-26 21:49:39 +00:00
Davide Italiano 683703ea6d [ELF] Add support for -z origin/now options.
Differential Revision:	http://reviews.llvm.org/D9963

llvm-svn: 238169
2015-05-26 01:57:32 +00:00
Simon Atanasyan 0b22359858 [ELF] Fix lld when no unique sections is used
Original patch of Shankar Easwaran with additional test case.
The yaml2obj does not allow to create an object file with non-unique
sections names so the fix uses a binary input object file in the test
case.

llvm-svn: 238115
2015-05-24 16:19:27 +00:00
Simon Atanasyan b2f6afb30a [Mips] Cleanup and reformat test cases, add more checkings
No functional changes.

llvm-svn: 238050
2015-05-22 21:08:37 +00:00
Denis Protivensky 575f7d4f1c [ARM] Ability to add GOT and PLTGOT entries for same symbol
These two serve different purpose:
PLTGOT entries are (usually) lazily resolved and serve as trampolines
to correctly call dynamically linked functions. They often have
R_*_JUMP_SLOT dynamic relocation type used.
Simple GOT entries hold other things, one of them may be
R_*_GLOB_DAT to correctly reference global and static data. This
is also used to hold dynamically linked function's address.

To properly handle cases when shared object's function is called
and at the same time its address is taken, we need to be able to have
both GOT and PLTGOT entries bearing different dynamic relocation types
for the same symbol.

llvm-svn: 238015
2015-05-22 11:23:39 +00:00
Denis Protivensky 214122cffc [ARM] Implement R_ARM_GLOB_DAT for GOT entries
This is used when referencing global or static data in shared
objects. This is also used when function's address is taken and
function call is made indirectly.

llvm-svn: 238014
2015-05-22 11:00:31 +00:00
Denis Protivensky af1c9dd513 [ARM] Add dynamic symbols to the dynamic library writer
llvm-svn: 237898
2015-05-21 12:52:00 +00:00
Denis Protivensky ad52e44e98 [ARM] Move out common Writer functionality to ARMELFWriter
llvm-svn: 237891
2015-05-21 11:16:40 +00:00
Denis Protivensky 56b12d75bf [ARM] Add needed symbols during dynamic executable linking
These include _GLOBAL_OFFSET_TABLE_ and _DYNAMIC.

llvm-svn: 237791
2015-05-20 13:39:33 +00:00
Leny Kholodov bde4144338 [ARM] Generation of .ARM.exidx/.ARM.extab sections
This patch provides generation of .ARM.exidx & .ARM.extab sections which are
used for unwinding. The patch adds new content type typeARMExidx for atoms from
.ARM.exidx section and integration of atoms with such type to the ELF
ReaderWriter. exidx.test has been added with checking of contents of .ARM.exidx
section and .ARM.extab section.

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

llvm-svn: 236873
2015-05-08 16:04:11 +00:00
Denis Protivensky 679c2c3639 [ARM] Check overflow of R_ARM_THM_JUMP11
llvm-svn: 236842
2015-05-08 12:45:11 +00:00
Denis Protivensky 73e927885c [ARM] Check overflow of R_ARM_CALL/JUMP24
llvm-svn: 236841
2015-05-08 12:36:40 +00:00