Commit Graph

52 Commits

Author SHA1 Message Date
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
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
Davide Italiano 0e4a3addf0 [ELF] Mark linker defined symbols as .hidden when needed.
I noticed that gold mark these as hidden. While at it I rewrote the test for
this feature to use yaml rather than an object file as input.

Differential Revision:	http://reviews.llvm.org/D9418
Reviewed by:	ruiu

llvm-svn: 236291
2015-05-01 00:07:11 +00:00
Rui Ueyama 035025c0da Remove trailing whitespace characters.
llvm-svn: 235897
2015-04-27 17:18:04 +00:00
Rafael Espindola c08ab8e6e4 Delete unnecessary generality in loadFile.
loadFile could load mulitple files just because yaml has a feature for
putting multiple documents in one file.

Designing a linker around what yaml can do seems like a bad idea to
me. This patch changes it to read a single file.

There are further improvements to be done to the api and they
will follow shortly.

llvm-svn: 235724
2015-04-24 15:51:45 +00:00
Rafael Auler 6fd0afa195 [ELF] Fix bug in ELFFile::createAtoms() that caused lld to mislink musl
When creating the graph edges of the atoms of an ELF file, special care must be
taken with atoms that represent weak symbols. They cannot be the target of any
Reference::kindLayoutAfter edge because they can be merged and point to other
code, screwing up the final layout of the atoms. ELFFile::createAtoms()
correctly handles this corner case. The problem is that createAtoms() assumed
that there can be no zero-sized weak symbols, which is not true. Consider:

my_weak_func1:
my_weak_func2:
my_weak_func3:
code

In this case, we have two zero-sized weak symbols, my_weak_func1 and
my_weak_func2, and one non-zero weak symbol my_weak_func3. createAtoms() would
correctly handle my_weak_func3, but not the first two symbols. This problem
happens in the musl C library when a zero-sized weak symbol is merged and
screws up the file layout. Since this musl code lives at the finalization hooks,
any C program linked with LLD and musl was correctly executing, but segfaulting
at the end.

Reviewers: shankarke

http://reviews.llvm.org/D5606

llvm-svn: 219034
2014-10-03 22:50:50 +00:00
Rui Ueyama 45f4d54c07 Re-commit r218259.
llvm-svn: 218272
2014-09-22 20:48:04 +00:00
Shankar Easwaran 595e056dce [ELF] Implement --rosegment
By default linker would not create a separate segment to hold read only data.

This option overrides that behavior by creating the a separate read only segment
for read only data.

llvm-svn: 217358
2014-09-08 04:05:52 +00:00
Simon Atanasyan 64c0ac2b35 [ELF] Implement parsing `-l` prefixed items in the `GROUP` linker script command.
There are two forms of `-l` prefixed expression:

* -l<libname>
* -l:<filename>

In the first case a linker should construct a full library name
`lib + libname + .[so|a]` and search this library as usual. In the second case
a linker should use the `<filename>` as is and search this file through library
search directories.

The patch reviewed by Shankar Easwaran.

llvm-svn: 213077
2014-07-15 17:17:30 +00:00
Simon Atanasyan ffc1c6af49 [ELF] Fix the file look up algorithm used in the linker script GROUP command.
In general the linker scripts's GROUP command works like a pair
of command line options --start-group/--end-group. But there is
a difference in the files look up algorithm.

The --start-group/--end-group commands use a trivial approach:
a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so'
   suffix and search the path through library search directories.
b) Otherwise, use the path 'as-is'.

The GROUP command implements more compicated approach:
a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so'
   suffix and search the path through library search directories.
b) If the path does not have '-l' prefix, and sysroot is configured,
   and the path starts with the / character, and the script being
   processed is located inside the sysroot, search the path under
   the sysroot. Otherwise, try to open the path in the current
   directory. If it is not found, search through library search
   directories.

https://www.sourceware.org/binutils/docs-2.24/ld/File-Commands.html

The patch reviewed by Shankar Easwaran, Rui Ueyama.

llvm-svn: 207769
2014-05-01 16:22:08 +00:00
Rui Ueyama 6d010e8d42 [ELF] Support response file.
Response file is a command line argument in the form of @file. The GNU-
compatible driver expands the file contents, replacing @file argument.

Differential Revision: http://llvm-reviews.chandlerc.com/D3210

llvm-svn: 205038
2014-03-28 19:34:34 +00:00
Rui Ueyama 6d500da3cc Revert "[ELF] Order DT_NEEDED entries by command line order."
This reverts commit r204291 because it broke buildbots.

llvm-svn: 204317
2014-03-20 06:57:28 +00:00
Michael J. Spencer deefb10fd6 [ELF] Order DT_NEEDED entries by command line order.
With this all test-suite tests pass with lld on x86-64 Linux.

llvm-svn: 204291
2014-03-20 01:28:23 +00:00
Alp Toker 32e8beff89 Fix a variety of typos in function names and comments
No change in functionality.

llvm-svn: 196053
2013-12-01 23:51:36 +00:00
Michael J. Spencer 2fd6c7d91c [ELF][x86-64] Generate PLT for R_*_32S relocs.
llvm-svn: 193369
2013-10-24 21:00:25 +00:00
Michael J. Spencer 102f82a74e [ELF] Handle copy relocations for PC32.
This will eventually need to be refactored to better handle COPY relocations,
as other relocations can also generate them. I'm not yet sure the exact
circumstances in which they are needed yet.

llvm-svn: 191567
2013-09-27 21:30:27 +00:00
Michael J. Spencer 3b36473007 [ELF] Mark STT_GNU_IFUNC symbols as code.
llvm-svn: 191566
2013-09-27 21:30:04 +00:00
Michael J. Spencer 32a3f9ee29 [ELF] Add COPY relocations.
llvm-svn: 191467
2013-09-26 22:09:16 +00:00
Joerg Sonnenberger 7d5aed5ce5 A weak reference to a symbol that is only weakly referenced in
dependencies should remain weak, not get promoted to undef or dropped.

llvm-svn: 189793
2013-09-03 12:06:33 +00:00
Shankar Easwaran d5ff08ca5f [ELF] TBSS section has to be special cased so that it doesnot occupy memory space
llvm-svn: 183815
2013-06-12 00:32:32 +00:00
Rafael Espindola a0af48fc93 Fix handling of files without a symbol table.
This fixes a recent regression (r183338). Stripped elf files (like installed
crtn.o for example), are not required to have a symbol table. Handle that
correctly.

llvm-svn: 183573
2013-06-07 21:08:19 +00:00
Rui Ueyama 0e171fe3c4 [lld] Update a test file for r180209.
This binary file is created from shared.c.

llvm-svn: 182410
2013-05-21 20:05:55 +00:00
Michael J. Spencer 9d70cef481 [Core] Allow weak symbols in shared library when linking.
Patch by Rui Ueyama.

llvm-svn: 180209
2013-04-24 19:00:26 +00:00
Michael J. Spencer 8c0526593a [Writer][ELF][x86-64] Handle GOTPCREL relocations to SharedLibraryAtoms.
llvm-svn: 176324
2013-03-01 01:09:46 +00:00
Michael J. Spencer 3e00c5015f [ELF][x86-64] Only emit a PLT entry for a PLT relocation if the target atom is a SharedLibraryAtom.
This seems to be what ld does, but I'm not sure how it works with symbol interposition.

With this hello-world with glibc dynamically linked works.

llvm-svn: 176310
2013-03-01 00:03:56 +00:00
Shankar Easwaran db74ffbe72 [ELF][Hexagon]add typeZeroFillFast
llvm-svn: 175983
2013-02-24 03:09:10 +00:00
Shankar Easwaran 8c55c01d2a sort quickdata for the hexagon target
llvm-svn: 175904
2013-02-22 18:01:08 +00:00
Shankar Easwaran 873c9ffba0 add changes for typeDataFast
llvm-svn: 175901
2013-02-22 17:18:53 +00:00
Shankar Easwaran 25832ede03 functionality to handle global atoms in Merge sections
llvm-svn: 175636
2013-02-20 17:38:37 +00:00
Shankar Easwaran 0da6d71b54 add support for merging common strings
llvm-svn: 174990
2013-02-12 18:46:53 +00:00
Michael J. Spencer c3c8bc1e5c [ELF] Add support for reading dynamic libraries.
llvm-svn: 174916
2013-02-11 23:03:35 +00:00
Michael J. Spencer 7799d15f6e [Driver] Add -L and -l support.
llvm-svn: 174590
2013-02-07 06:47:17 +00:00
Michael J. Spencer 7a0e212f6f [ELF][x86-64] Handle PLT32 relocations to IFUNC.
llvm-svn: 174428
2013-02-05 19:15:03 +00:00
Michael J. Spencer 359b6ff6bb [ELF] Implement GOTPCREL for defined atoms.
llvm-svn: 174426
2013-02-05 19:14:28 +00:00
Michael J. Spencer e6ab9f80a7 [ELF] Replace local dynamic tls access with direct access.
llvm-svn: 174425
2013-02-05 19:14:07 +00:00
Michael J. Spencer b5d6f5e988 [ELF][x86-64] Implement static relocation model for TLS.
This implements the static relocation model for GOT accesses to TLS.

llvm-svn: 174155
2013-02-01 07:14:14 +00:00
Michael J. Spencer b0ed8e80d8 [ELF][x86-84] Add static TLS support.
llvm-svn: 174154
2013-02-01 07:13:49 +00:00
Michael J. Spencer 289dcedea5 [ELF] Add support for IFUNC.
This sadly doesn't have a test for the final
output because llvm-objdump can't dump relocations
that don't belong to a section :(

llvm-svn: 173808
2013-01-29 16:38:03 +00:00
Michael J. Spencer 563d33a6f1 [ELF] Read IFUNC symbols correctly as typeResolver.
llvm-svn: 173299
2013-01-23 22:08:46 +00:00
Michael J. Spencer ecd5f4062f [ELF] Add support for __init_array_{start,end}.
With this change c++ global constructors and destructors work.

llvm-svn: 172133
2013-01-10 22:41:42 +00:00
Shankar Easwaran 2ca8e7d733 support for adding linker defined symbols
llvm-svn: 172040
2013-01-10 03:16:27 +00:00
Michael J. Spencer 8de8364753 [ELF] Properly handle constant data.
With this hello world works with dietlibc on x86-64 Linux.

llvm-svn: 171711
2013-01-07 08:00:42 +00:00
Michael J. Spencer cdb892488e [ELF] Add common x86_64 relocation types.
llvm-svn: 171703
2013-01-07 06:58:53 +00:00
Hemant Kulkarni 736f7fbee2 Populate entry point into ELF executable.
llvm-svn: 168461
2012-11-21 21:07:36 +00:00
Shankar Easwaran 70b4dcfbcd Adding support to resolve symbols with archive libraries in lld
llvm-svn: 167854
2012-11-13 18:39:10 +00:00
Sid Manning 823e8bb7be This patch changes the following:
* Use conventional naming for KindHandlers.
  * Add X86 relocation routines.
  * Use std::function instead of function pointers in _fixupHandler map.
  * Change _fixupHandler map from std::map to llvm::DenseMap.
  * Add simple testcase for x86 relocations.

llvm-svn: 166700
2012-10-25 17:53:04 +00:00
Sid Manning 2a59024ff8 This update does the following:
* Moves enum Scope from DefinedAtom.h to Atom.h
  * Adds scope method to AbsoluteAtom class
  * Updates YAML to print scope of AbsoluteAtoms
  * Update Native Reader/Writer to handle this new, "attribute"
  * Adds testcase 
Reviewed and approved by Nick Kledzik

llvm-svn: 166189
2012-10-18 17:16:19 +00:00
Sid Manning 42064e5b60 * Add relocation reference support for Hexagon and PowerPC.
- Hexagon has many relocation types, this patch covers just
      a subset, more will be added.
    - PowerPC support was added so that we can verify mixed endian
      environments.
  * Add some basic test cases
  * Update ldd-core to accept -endian flag

llvm-svn: 165477
2012-10-09 02:20:47 +00:00
Sid Manning e861d43f65 This change:
* Updates ReaderELF.cpp contentType method to match ELF.h's logic and now handle
    typeData
  * Add -arch to ldd-core testdriver
  * Add testcase to check typeData
  * Update others to stay in sync with this change.

llvm-svn: 164976
2012-10-01 23:23:05 +00:00
Sid Manning 8caf4de31f Add ELFReference class - parse relocations needed by that class and update DefinedAtom to use the class. Tweak coding style. Add testcase to check relocations. Change was signed-off-by: Michael Spencer
llvm-svn: 164027
2012-09-17 12:49:38 +00:00