Commit Graph

4505 Commits

Author SHA1 Message Date
Rafael Espindola 568ee2c089 Don't crash on invalid.
llvm-svn: 319404
2017-11-30 06:18:31 +00:00
Rafael Espindola bdcfb178b5 Delete dead code.
llvm-svn: 319403
2017-11-30 05:52:42 +00:00
Rafael Espindola 8ce6db0c4b Error instead of ignoring broken debug info.
Thanks to Davide for noticing.

llvm-svn: 319401
2017-11-30 05:37:35 +00:00
Rui Ueyama 1bf618a9da Remove unused condition.
Looks like all tests pass without this `isLocal()`.

Differential Revision: https://reviews.llvm.org/D39780

llvm-svn: 319395
2017-11-30 01:08:09 +00:00
Rui Ueyama 8ed548a481 Fix typo.
llvm-svn: 319394
2017-11-30 01:04:26 +00:00
Rafael Espindola dfebd3601d Use Symbol::File directly.
We are already paying the cost of storing a InputFile in every
Symbol, so use it uniformly.

llvm-svn: 319378
2017-11-29 22:47:35 +00:00
Rafael Espindola 07b7ee4394 Simplify. NFC.
llvm-svn: 319370
2017-11-29 22:20:03 +00:00
Rafael Espindola f893396d1b Don't crash on broken debug info.
llvm-svn: 319367
2017-11-29 22:09:16 +00:00
Rafael Espindola cf5dc9f24c Replace a dyn_cast with a cast. NFC.
llvm-svn: 319361
2017-11-29 21:29:52 +00:00
Rafael Espindola ea5610648c Replace another dyn_cast with a cast.
llvm-svn: 319335
2017-11-29 18:43:34 +00:00
Rafael Espindola d42f7e5cae Replace a dyn_cast with a cast.
It is always accessed, so there is no value in a dyn_cast.

llvm-svn: 319334
2017-11-29 18:32:57 +00:00
Peter Smith 31dddc97ae [ELF][AArch64] Add support for AArch64 range thunks.
The AArch64 unconditional branch and branch and link instructions have a
maximum range of 128 Mib. This is usually enough for most programs but
there are cases when it isn't enough. This change adds support for range
extension thunks to AArch64. For pc-relative thunks we follow the small
code model and use ADRP, ADD, BR. This has a limit of 4 gigabytes.

Differential Revision: https://reviews.llvm.org/D39744

llvm-svn: 319307
2017-11-29 11:15:12 +00:00
Peter Smith 8fca2e12ab [ELF] Make sure SHT_ARM_ATTRIBUTES is only recognized by Arm Targets
The SHT_ARM_ATTRIBUTES section type is in the processor specific space
adding guard to make sure that it is only recognized when EMachine is
EM_ARM.

llvm-svn: 319304
2017-11-29 10:20:46 +00:00
Rafael Espindola 09b53f6fd8 Delete dead code. NFC.
llvm-svn: 319274
2017-11-29 01:55:03 +00:00
Rafael Espindola b262cbe6b7 Replace copyFrom with memcpy.
It was only used for --wrap and I don't think the fields with special
treatment had a meaningful impact on that feature.

llvm-svn: 319265
2017-11-29 00:31:39 +00:00
Rafael Espindola 97d05f95b9 Copy the visibility in copyFrom.
This is simpler and matches bfd's behavior on the changed test.

llvm-svn: 319248
2017-11-28 23:06:09 +00:00
Rui Ueyama 2017d52b54 Move Memory.{h,cpp} to Common.
Differential Revision: https://reviews.llvm.org/D40571

llvm-svn: 319221
2017-11-28 20:39:17 +00:00
Rafael Espindola 1d4b3023dc Bring back r319008.
This includes a fix to mark copy reloc aliases as used.

Original message:

[ELF] Do not keep symbols if they referenced only from discarded sections.

This patch also ensures that in case of "--as-needed" is used,
DT_NEEDED entries are not created if they are required only by
these eliminated symbols.

llvm-svn: 319215
2017-11-28 20:17:58 +00:00
Rui Ueyama 3e03944f02 Factor out more code to Common/Args.cpp.
Differential Revision: https://reviews.llvm.org/D40540

llvm-svn: 319211
2017-11-28 19:58:45 +00:00
Rafael Espindola b45c164fc2 Handle binding in --wrap.
Copying the binding seems reasonable and matches the bfd behavior.

llvm-svn: 319196
2017-11-28 18:02:22 +00:00
Peter Smith 57eb046984 [ELF] Read ARM BuildAttributes section to determine supported features.
lld assumes some ARM features that are not available in all Arm
processors. In particular:
- The blx instruction present for interworking.
- The movt/movw instructions are used in Thunks.
- The J1=1 J2=1 encoding of branch immediates to improve Thumb wide
  branch range are assumed to be present.

This patch reads the ARM Attributes section to check for the
architecture the object file was compiled with. If none of the objects
have an architecture that supports either of these features a warning
will be given. This is most likely to affect armv6 as used in the first
Raspberry Pi.

Differential Revision: https://reviews.llvm.org/D36823

llvm-svn: 319169
2017-11-28 13:51:48 +00:00
Igor Kudrin a46522f369 Revert r319008, "[ELF] Do not keep symbols if they referenced only from discarded sections."
and r319051, "Add a missing test."

r319008 broke the LTO bots;
r319051 depends on changes in r319008.

llvm-svn: 319154
2017-11-28 08:39:40 +00:00
Martin Storsjo 2d614ced55 Fix shared library builds of lld, broken in SVN r319138
llvm-svn: 319152
2017-11-28 08:12:03 +00:00
Rui Ueyama 53fe469162 Factor out common code to Common/Strings.cpp.
Differential Revision: https://reviews.llvm.org/D40530

llvm-svn: 319138
2017-11-28 02:15:26 +00:00
Rafael Espindola 9e3381e8dc Store the real binding of shared symbols.
Currently we mark every shared symbol as STB_WEAK.

That is a hack to make it easy to decide when a .so is needed or not
because of a reference to a given symbol.

That hack leaks when we create copy relocations as shown by the update
to relocation-copy-alias.s.

This patch stores the original binding when we first read a shared
symbol. We still have to update the binding to weak if we see a weak
undef, but I find the logic easier to read where it is now.

llvm-svn: 319127
2017-11-28 01:04:51 +00:00
Sam Clegg a80d94d52b Rename `Symtab` private memory to avoid confusion with global `Symtab`
This is also consistent with SymVector that exists in COFF port
and soon to be added to the wasm port.

Split off as part of https://reviews.llvm.org/D40371

Differential Revision: https://reviews.llvm.org/D40525

llvm-svn: 319113
2017-11-27 23:16:06 +00:00
Sam Clegg e2ed092e01 Consistent use of <internal> when displaying internal symbol names
Differential Revision: https://reviews.llvm.org/D40510

llvm-svn: 319108
2017-11-27 22:49:16 +00:00
Peter Smith 2809926c4d [ELF][ARM] Refine check for when undefined weak needs a Thunk
When an undefined weak reference has a PLT entry we must generate a range
extension thunk for any B or BL that can't reach the PLT entry.

This change explicitly looks for whether a PLT entry exists rather than
assuming that weak references never need PLT entries unless Config->Shared
is in operation. This covers the case where we are linking an executable
with dynamic linking, hence a PLT entry will be needed for undefined weak
references. This case comes up in real programs over 32 Mb in size as there
is a B to a weak reference __gmon__start__ in the Arm crti.o for glibc.

Differential Revision: https://reviews.llvm.org/D40248

llvm-svn: 319020
2017-11-27 11:49:18 +00:00
Igor Kudrin 40007586fc [ELF] Do not keep symbols if they referenced only from discarded sections.
This patch also ensures that in case of "--as-needed" is used,
DT_NEEDED entries are not created if they are required only by
these eliminated symbols.

Differential Revision: https://reviews.llvm.org/D38790

llvm-svn: 319008
2017-11-27 05:51:10 +00:00
Rafael Espindola f8e405db46 Delete dead code.
The parent constructor is already setting the binding.

llvm-svn: 318962
2017-11-24 19:06:14 +00:00
Peter Smith 80e4be7eae [ELF] Rename .bss.rel.ro to .data.rel.ro.bss for some Linker Scripts.
LLD uses .bss.rel.ro for read-only copy relocations whereas the ld.bfd and
gold linkers use .data.rel.ro. In some linker scripts including ld.bfd's
internal linker script, the relro sections are placed sequentially assuming
.data.rel.ro is used. LLD's use of .bss.rel.ro means that the copy
relocations get matched into the .bss section causing the relro sections to
be non-contiguous.

This change checks for a .data.rel.ro OutputSection when a linker script
with the SECTIONS command is used. The section will match in the
.data.rel.ro output section and will maintain contiguous relro.

Differential Revision: https://reviews.llvm.org/D40365

Fixes PR35265

llvm-svn: 318940
2017-11-24 08:48:29 +00:00
Rui Ueyama 15475e92c6 Use lambdas to store lazy-evaluated .dynamic entries.
Differential Revision: https://reviews.llvm.org/D40338

llvm-svn: 318938
2017-11-24 02:15:51 +00:00
Peter Smith c076b280df [ELF] Skip over empty sections when checking for contiguous relro
When checking for contiguous relro sections we can skip over empty sections.
If there is an empty non-relro section in the middle of a contiguous block
of relro sections then it cannot be written to so it is safe to include in
PT_GNU_RELRO header. If there is a contiguous block of empty relro sections
then no PT_GNU_RELRO header is required for them.

Differential Revision: https://reviews.llvm.org/D40364

llvm-svn: 318924
2017-11-23 15:10:00 +00:00
Peter Smith dc3bd88b22 [ELF] Give error message when relro sections are not contiguous.
If a linker script is used that names linker generated synthetic sections
it is possible that the OutputSections for which isRelroSection() is true
are not contiguous. When the relro sections are not contiguous we cannot
describe them with a single PT_GNU_RELRO PHDR. Unfortunately at least one
contemporary dynamic loader only supports one PT_GNU_RELRO PHDR so we
cannot output more than one of these PHDRs. As not including relro
sections in the PHDR will lead to security sensitive sections being
writeable we choose to give an error message instead.

Differential Revision: https://reviews.llvm.org/D40359

[ELF] Skip over empty sections when checking for contiguous relro

llvm-svn: 318920
2017-11-23 14:53:10 +00:00
Rafael Espindola de56343cf0 Simplify as-needed handling.
This is a reduction of a patch by Rui Ueyama.

llvm-svn: 318852
2017-11-22 17:50:42 +00:00
Simon Atanasyan 167306a56c [MIPS] Write PLT0 entry in case of linking N64 ABI code
llvm-svn: 318831
2017-11-22 12:34:29 +00:00
James Henderson f70c5beb22 [ELF] Fix DT_MIPS_LOCAL_GOTNO value for thunks and linker scripts
The MIPS GOT section has a number of local entries based on the number of pages
needed for output sections referenced by GOT page relocations. The number is
recorded in the DT_MIPS_LOCAL_GOTNO dynamic section tag. However, the dynamic tag
is added before assignAddresses has been called, meaning that any section size used
to calculate the value will not include size modifications caused by, for example,
linker scripts and thunks.

This change moves the calculation of DT_MIPS_LOCAL_GOTNO until writeTo, by which
time the output section sizes have been finalized.

Reviewers: ruiu, rafael

Differential Revision: https://reviews.llvm.org/D39493

llvm-svn: 318828
2017-11-22 12:04:21 +00:00
Alexander Richardson d642494828 [ELF] Fix rewriting of --sysroot in reproducer tars
Summary:
I noticed that the reproducers files I was getting from building CheriBSD
didn't work because the --sysroot option was not being rewritten. I've
updated the test to also verify that the rewritten path matches uses a
FileCheck capature instead of a {{.+}} regex

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: llvm-commits, emaste

Differential Revision: https://reviews.llvm.org/D40125

llvm-svn: 318656
2017-11-20 15:49:48 +00:00
Alexander Richardson 1de78471f5 [ELF] Fall back to search dirs for linker scripts specified with -T
Summary:
This matches the behaviour of ld.bfd:
https://sourceware.org/binutils/docs/ld/Options.html#Options

If scriptfile does not exist in the current directory, ld looks for it in
the directories specified by any preceding '-L' options. Multiple '-T'
options accumulate.

Reviewers: ruiu, grimar

Reviewed By: ruiu, grimar

Subscribers: emaste, llvm-commits

Differential Revision: https://reviews.llvm.org/D40129

llvm-svn: 318655
2017-11-20 15:43:20 +00:00
Alexander Richardson f463042312 [ELF][MIPS] Fix crash in LLD when linking code that needs PIC thunks
Summary:
The bug triggers when the following conditions are met:
    - A thunk is created in a given input section S
    - A linker script is specified
    - There is at least one matcher in the linker script .text section output
      that does not match any of the sections in the input files, before the matcher
      that matches section S.

The issue was found when linking the FreeBSD kernel for MIPS when built
with -fPIC. Patch by Alfredo Mazzinghi.

Reviewers: ruiu, psmith, atanasyan

Reviewed By: ruiu

Subscribers: peter.smith, emaste, sdardis, krytarowski, llvm-commits

Differential Revision: https://reviews.llvm.org/D40174

llvm-svn: 318653
2017-11-20 15:37:19 +00:00
Rafael Espindola d0929caa21 Don't use llvm/Config/config.h.
It is private to llvm. Instead use llvm/Config/llvm-config.h and check
LLVM_ON_UNIX. That is the same guard that clang uses before including
unistd.h.

llvm-svn: 318558
2017-11-17 21:40:38 +00:00
George Rimar 5f928ff133 [ELF] - Teach LLD to use information from .debug_str for error reporting.
Recently we teached LLD to report line numbers for duplicate variables
definitions, though currently LLD is unable to do that for case when
strings are not built in .debug_info, but stored in .debug_str instead.
That is because out LLDDwarfObj does not handle .debug_str yet. 
Patch fixes that.

Differential revision: https://reviews.llvm.org/D39542

llvm-svn: 318519
2017-11-17 11:57:47 +00:00
George Rimar 80355234f7 [ELF] - Allow applying SHF_MERGE optimization for relocatable output.
This fixes PR35223.

Here I enabled SHF_MERGE section content merging for -r like
we do for regular linking.

Differential revision: https://reviews.llvm.org/D40026

llvm-svn: 318516
2017-11-17 11:27:57 +00:00
Rui Ueyama 11adb536e1 Ignore -no-ctors-in-init-array.
Patch by dxf@google.com.

llvm-svn: 318513
2017-11-17 08:17:36 +00:00
Rui Ueyama 7212f0ff11 Add a missing #include.
llvm-svn: 318512
2017-11-17 08:17:21 +00:00
Rafael Espindola bec3765bea Remove IsLocal.
Since we always have Binding in the current symbol design IsLocal is
redundant.

llvm-svn: 318497
2017-11-17 01:37:50 +00:00
George Rimar 661a2c1970 [ELF] - Don't emit broken relocations for SHF_MERGE sections when --emit-relocs is used.
Previously our relocations we rewrote were broken for that case.
We emited incorrect addend and broken relocation info field
because did not produce section symbol for mergeable synthetic sections.

Differential revision: https://reviews.llvm.org/D40070

llvm-svn: 318394
2017-11-16 12:33:36 +00:00
Rafael Espindola 8bc2a19ef8 Drop conflicting sh_entsize values.
An output section can include elements from two input sections with
different sh_entsize. When that happens the output section itself
should not have a sh_entsize.

llvm-svn: 318311
2017-11-15 17:35:22 +00:00
Rafael Espindola 3f0b575363 Remove an unnecessary constraint.
Our current implementation of SHF_MERGE can already handle over
aligned elements.

llvm-svn: 318310
2017-11-15 17:31:27 +00:00
Rafael Espindola a5d43d004a Propagate sh_entsize out.
No difference in practice other than having sh_entsize in the output.

This should simplify the patch for handling SHF_MERGE in -r.

Based on a patch by George Rimar.

llvm-svn: 318306
2017-11-15 16:56:20 +00:00