Commit Graph

5003 Commits

Author SHA1 Message Date
Rafael Espindola 96449907a5 Add support for R_X86_64_DTPOFF64.
It is used by clang to produce debug info for tls variables.

llvm-svn: 260384
2016-02-10 16:26:31 +00:00
Rafael Espindola 156ed8ddd7 Use a SymbolBody to represent the personality.
NFC, just more in line with the rest of lld.

Thanks to Rui for the suggestion.

llvm-svn: 260380
2016-02-10 13:19:32 +00:00
Simon Atanasyan eae66c019b [ELF][MIPS] Group and sort initialization of MipsTargetInfo class fields. NFC
llvm-svn: 260365
2016-02-10 10:08:39 +00:00
Simon Atanasyan 6231391fa7 [ELF][MIPS] Rename MipsTargetInfo::relocateOne argument SA to S
MIPS 32-bit ABI uses REL relocation record format. We read addends from
relocation destinations right in the MipsTargetInfo::relocateOne
function.

llvm-svn: 260364
2016-02-10 10:08:35 +00:00
Rui Ueyama d3bd97a97d Rangefy, and replace a switch with `if`s. NFC.
llvm-svn: 260320
2016-02-09 23:11:21 +00:00
Rafael Espindola 9e072d30e5 Fix inverted comparison.
llvm-svn: 260310
2016-02-09 22:47:34 +00:00
Rui Ueyama dbcfedb330 ELF: Add 'using namespace llvm::dwarf'.
Most constants defined in llvm::dwarf namespace start with "DW_".
We don't have to worry about name conflicts.

llvm-svn: 260297
2016-02-09 21:46:11 +00:00
Rui Ueyama 6448f8ae5d ELF: Add .eh_frame 'P', 'R' and 'L' augmentation characters.
This basically reverts commit r260073 because it is found that
augmentation strings don't always start with "zR". It is reported
as https://llvm.org/bugs/show_bug.cgi?id=26541.

llvm-svn: 260294
2016-02-09 21:41:01 +00:00
Pete Cooper e8d9df4ea5 Use __nl_symbol_ptr instead of __got in the stubs pass on x86 archs.
The non lazy atoms generated in the stubs pass use an image cache to
hold all of the pointers.  On arm archs, this is the __got section,
but on x86 archs it should be __nl_symbol_ptr.

rdar://problem/24572729

llvm-svn: 260271
2016-02-09 20:11:17 +00:00
Pete Cooper 35c3318edc Aligned __stub_helper section to 4-bytes.
ld64 aligns most of the stub's to 2 byte alignment, expect for
the stub helper common atoms which are 4 byte aligned.

This adds a new field to StubInfo which tracks this alignment
and ensures that this is the alignment we get in the final image.

rdar://problem/24570220

llvm-svn: 260248
2016-02-09 18:56:37 +00:00
Rafael Espindola a0a65f973a Use the plt entry as the address of some symbols.
This is the function equivalent of a copy relocation.

Since functions are expected to change sizes, we cannot use copy
relocations. In situations where one would be needed, what is done
instead is:
* Create a plt entry
* Output an undefined symbol whose addr is the plt entry.

The dynamic linker makes sure any shared library uses the plt entry as
the function address.

llvm-svn: 260224
2016-02-09 15:11:01 +00:00
NAKAMURA Takumi 3725978b10 lld/test/mach-o/dependency_info.yaml: Forgot to remove XFAIL:win32.
llvm-svn: 260209
2016-02-09 07:44:10 +00:00
NAKAMURA Takumi 9eee62f558 lld/test/mach-o/dependency_info.yaml: Tweak for dos path.
llvm-svn: 260208
2016-02-09 07:30:24 +00:00
NAKAMURA Takumi 127295492d check-lld: Introduce %python.
llvm-svn: 260207
2016-02-09 07:30:18 +00:00
NAKAMURA Takumi c96ae0c8a8 Introduce the feature 'demangler' in check-lld. Mark lld/test/old-elf/X86_64/demangle.test as REQUIRES:demangler.
llvm-svn: 260206
2016-02-09 07:30:11 +00:00
NAKAMURA Takumi f01d3e59b9 Disable lld/test/old-elf/group-cmd-search.test on win32. "XFAIL:win32" was insufficient.
llvm-svn: 260205
2016-02-09 07:30:04 +00:00
Pete Cooper 9b28a4559e Add cmdline options for LC_DATA_IN_CODE load command.
Also added the defaults for whether to generate this load command, which
the cmdline options are able to override.

There was also a difference to ld64 which is fixed here in that ld64 will
generate an empty data in code command if requested.

rdar://problem/24472630

llvm-svn: 260191
2016-02-09 02:10:39 +00:00
Pete Cooper 41f3e8e408 Generate LC_FUNCTION_STARTS load command.
This load command generates data in the LINKEDIT section which
is a list of ULEB128 delta's to all of the functions in the __text section.

It is then 0 terminated and pointer aligned to pad.

ld64 exposes the -function-starts and no-function-starts cmdline options
to override behaviour from the defaults based on file types.

rdar://problem/24472630

llvm-svn: 260188
2016-02-09 01:38:13 +00:00
Pete Cooper 841a978d22 We should never dead strip mach header symbols.
This was a bug in our handling of these symbols compared to ld64.

Turns out that ld64 always marks these symbols as being not dead stripped.

llvm-svn: 260185
2016-02-09 01:34:13 +00:00
Pete Cooper cea565593f Reorder enum entry as its used for atom sorting.
The atom content type enum is used as a tie breaker to sort atoms.
In that case, we want MachHeader to be before typeCode as it really will
be before the code in the final executable.

Test case to follow in the next commit or two.

llvm-svn: 260184
2016-02-09 01:27:30 +00:00
Pete Cooper d75b7181df Move includes inside guards. NFC.
These includes were before the #ifndef/#define guards.  Moving them to
where they should be.

llvm-svn: 260153
2016-02-08 21:50:45 +00:00
Rafael Espindola a64f7d1148 Fix the alignment of PT_PHDR.
We were claiming it was aligned to 8 bytes even on 32 bit files, which
is not the case.

llvm-svn: 260102
2016-02-08 15:33:53 +00:00
Simon Atanasyan e1bfc2e793 [ELF][MIPS] Support R_MIPS_COPY relocation
Generate R_MIPS_COPY relocation for 'static' relocations against object
symbols defined in a shared libraries.

llvm-svn: 260083
2016-02-08 10:05:13 +00:00
Rui Ueyama be748c2033 ELF: Simplify getFdeEncoding.
I found that the handling of 'L' character in an augmentation string is
wrong because 'L' means that the next byte is the length field. I could
have fixed that by just skipping the next byte, but I decided to take a
different approach.

Teaching the linker about all the types of CIE internal records just to
skip them is silly. And the code doing that is not actually executed now
(that's why the bug did not cause any issue.) It is because the 'R' field,
which we want to read, is always at beginning of the CIE. So I reduced
the code dramatically by assuming that that's always the case. I want to
see how it works in the wild. If it doesn't work, we can roll this back
(with a fix for 'L').

http://reviews.llvm.org/D16939

llvm-svn: 260073
2016-02-08 05:18:44 +00:00
Simon Atanasyan 8a611a858b [ELF][MIPS] Perform two checks using the single llvm-objdump / FileCheck run
NFC

llvm-svn: 260054
2016-02-07 20:36:40 +00:00
Simon Atanasyan b76108a63a [ELF][MIPS] Add comments to describe __gnu_local_gp magic symbol
NFC. Follow-up to r259781.

llvm-svn: 260027
2016-02-07 12:09:40 +00:00
Pete Cooper b8fec3ea62 Set max segment protection level.
The initial segment protection was also being used to set the maximum
segment protection level.  Instead, the maximum should be set according
to the architecture we are linking.  For example on Mac OS it should be
RWX on most pages, but on iOS is often on R_X.

rdar://problem/24515136

llvm-svn: 259966
2016-02-06 00:51:16 +00:00
Pete Cooper 353652f808 Move creation of "__LINKEDIT" segment. NFC.
We currently tag on a "__LINKEDIT" when we are emitting the segments.
However, an upcoming patch aims to set the initprot and maxprot segment members
to their correct values, and in order to share code, its better to create this
segment for real and handle it in buildFileOffsets the same way ld64 does.

The commit for segment protections will add a test for this all being correct so
no test here until that code is committed.

llvm-svn: 259960
2016-02-06 00:14:15 +00:00
Rafael Espindola d0078b2dba Sort headers. NFC.
llvm-svn: 259959
2016-02-06 00:06:26 +00:00
Rui Ueyama 1b45cca6d7 ELF: Simplify readEntryLength.
I removed "CIE/FIE size is too large" error because that was not
checking for correct error conditions. [UINT_MAX - 4, UINT_MAX) is
a correct range as a size of a CIE/FDE record. It's just that the
size cannot be larger than the section size.

llvm-svn: 259951
2016-02-05 23:24:05 +00:00
Rui Ueyama c0c92609c4 ELF: Make EHOutputSection::readEntryLength a non-member function.
This function did not use any fields of the class.

llvm-svn: 259946
2016-02-05 22:56:03 +00:00
Rafael Espindola 95708931cf Fix PT_GNU_RELRO computation.
We were not including TLS sections.

llvm-svn: 259945
2016-02-05 22:55:06 +00:00
Rui Ueyama 5a0b2f75db Simplify. NFC.
llvm-svn: 259903
2016-02-05 19:13:18 +00:00
Rui Ueyama 4197a6ab1b ELF: Make Out<ELFT> initialization less error-prone.
Previously, it was easy to leave some Out<ELFT> fields uninitialized
because assignments to the fields are mixed with output section
instantiations. In this patch, I separate initializations from assignments
to improve readability.

http://reviews.llvm.org/D16864

llvm-svn: 259899
2016-02-05 18:41:40 +00:00
Rafael Espindola abebed982a Rename IsUsedInDynamicReloc to MustBeInDynSym.
The variable was marking various cases where a symbol must be included
in the dynamic symbol table. Being used by a dynamic relocation was only
one of them.

llvm-svn: 259889
2016-02-05 15:27:15 +00:00
Rafael Espindola d30eb7d77d Centralize most calls to setUsedInDynamicReloc.
llvm-svn: 259887
2016-02-05 15:03:10 +00:00
Rui Ueyama 0e53c7dd2c ELF: Make names for TLS module indices shorter.
The previous names contained "Local" and "Current", but what we
are handling is always local and current, so they were redundant.

TlsIndex comes from "tls_index" struct that Ulrich Drepper is using
in this document to describe this data structure in GOT.

llvm-svn: 259852
2016-02-05 00:10:02 +00:00
Rui Ueyama 812293ae1d Simplify. NFC.
llvm-svn: 259848
2016-02-04 23:39:35 +00:00
Rui Ueyama 8e47eba9fd Do not round uintX_t to uint32_t.
On 64-bit computers, this value can be larger than UINT32_MAX.

llvm-svn: 259847
2016-02-04 23:39:33 +00:00
Rui Ueyama f9cec37880 Merge conditions of two nested `if`s.
llvm-svn: 259843
2016-02-04 23:18:22 +00:00
Sean Silva 09247f8955 Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
Summary:
LLVM3.3 (and earlier) would fail to include a relocation section in
the group that the section it was relocating is in. Object files
affected by this issue have been encountered in the wild when using LLD.

This would result in a siutation like:

  Section {
    Index: 5
    Name: .text._Z3fooIiEvv (6)
    Type: SHT_PROGBITS (0x1)
    Flags [ (0x206)
      SHF_ALLOC (0x2)
      SHF_EXECINSTR (0x4)
      SHF_GROUP (0x200)
    ]
    Address: 0x0
    Offset: 0x48
    Size: 5
    Link: 0
    Info: 0
    AddressAlignment: 1
    EntrySize: 0
  }
  Section {
    Index: 6
    Name: .rela.text._Z3fooIiEvv (1)
    Type: SHT_RELA (0x4)
    Flags [ (0x0)
    ]
    Address: 0x0
    Offset: 0x3F0
    Size: 24
    Link: 8
    Info: 5
    AddressAlignment: 8
    EntrySize: 24
  }

In LLD, during symbol resolution, we discard the section containing the
weak symbol, but this amounts to replacing it with
InputSection<ELFT>::Discarded.
When we later saw the corresponding relocation section, we would then
end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is
bogus.

Reviewers: ruiu, rafael

Subscribers: llvm-commits, Bigcheese

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

llvm-svn: 259831
2016-02-04 21:41:07 +00:00
Rafael Espindola de9857e3c1 Avoid code duplication when creating dynamic relocations.
Another case where we currently have almost duplicated code is the
creation of dynamic relocations. First to decide if we need one, then to
decide what to write.

This patch fixes it by passing more information from the relocation scan
to the section writing code. This is the same idea used for r258723.

I actually think it should be possible to simplify this further by
reordering things a bit in the writer. For example, we should be able to
represent almost every position in the file with an OutputSeciton and
offset. When writing it out we then just need to add the offset to the
OutputSection VA.

llvm-svn: 259829
2016-02-04 21:33:05 +00:00
Pete Cooper 8563e5a362 Set CPU_SUBTYPE_LIB64 in mach_header.
On Mac OS 10.5 and later, with X86_64 and outputting a dynamic executable,
ld64 set the CPU_SUBTYPE_LIB64 mask on the cpusubtype in the mach_header.

This adds the same functionality to lld.

rdar://problem/24507177

llvm-svn: 259826
2016-02-04 20:43:43 +00:00
Simon Atanasyan e364e2e9ce [ELF][MIPS] Support R_MIPS_PC32 relocation handling
llvm-svn: 259782
2016-02-04 12:31:39 +00:00
Simon Atanasyan 597df21eb2 [ELF][MIPS] Add handling for __gnu_local_gp symbol
This symbol is a "fake" symbol like "_gp_disp" and denotes
the GOT + 0x7FF0 value.

llvm-svn: 259781
2016-02-04 12:09:49 +00:00
Simon Atanasyan 4b03451cac [ELF][MIPS] Replace needsMipsLocalGot function by canBePreempted
Symbol does not need an entry i the 'global' part of GOT if it cannot be
preempted. So canBePreempted fully satisfies us at least for now.

llvm-svn: 259779
2016-02-04 11:51:45 +00:00
Simon Atanasyan 170356ba32 [ELF][MIPS] Always create global GOT entry for symbols defined in DSO
If relocation against symbol requires GOT entry creation and this symbol
is defined in DSO, the GOT entry should be created in the 'global' part
of the GOT even if we link executable file. Also we do not need to create
a dynamic symbol table entry for global symbol corresponding to the
local GOT entry.

llvm-svn: 259778
2016-02-04 11:51:39 +00:00
Pete Cooper d5c0e4d69b Use unsigned long long instead of uint64_t to appease bots
llvm-svn: 259748
2016-02-04 02:50:47 +00:00
Pete Cooper 4c3eee78f1 Add test missed from r259746
llvm-svn: 259747
2016-02-04 02:50:07 +00:00
Pete Cooper 40576fa0e9 Add support for the source_version cmdline option.
This is of the form A.B.C.D.E and to match ld64's behaviour, is
always output to files, even when the version is 0.

rdar://problem/24472630

llvm-svn: 259746
2016-02-04 02:45:23 +00:00