Commit Graph

3854 Commits

Author SHA1 Message Date
Douglas Yung ac8a9a005e Change Requires to REQUIRES so that it works properly.
llvm-svn: 319251
2017-11-28 23:15:20 +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
Rafael Espindola 33e023070f Expand test a bit.
Also make it more reliable by not depending on the order of the
symbols.

This makes the next patch easier to read.

llvm-svn: 319246
2017-11-28 23:03:14 +00:00
Peter Collingbourne bcf7f290ff COFF: Do not add symbols in discarded sections to SEH handler list.
Differential Revision: https://reviews.llvm.org/D40576

llvm-svn: 319229
2017-11-28 21:30:05 +00:00
Rafael Espindola f70502d3a6 Bring r319051 back.
It had been reverted because it depended on r319008 which has been
recommitted.

Original message:

Add a missing test.

We were not testing that we correctly handled a .o with a weak symbol
after a .so.

llvm-svn: 319217
2017-11-28 20:21:44 +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
Rafael Espindola 57ef60f0f9 Add missing test.
This would have found the issue with r319008.

llvm-svn: 319214
2017-11-28 20:13:12 +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 f2508f46ca [COFF] Interpret a period as a separator for section suffix just like '$'
This allows grouping all sections like ".ctors.12345" into ".ctors".

For MinGW, the numerical values for such ctors are all zero-padded,
so a lexical sort is good enough.

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

llvm-svn: 319151
2017-11-28 08:08:37 +00:00
Peter Collingbourne 1621c20ffc Reland r319090, "COFF: Do not create SectionChunks for discarded comdat sections." with a fix for debug sections.
If /debug was not specified, readSection will return a null
pointer for debug sections. If the debug section is associative with
another section, we need to make sure that the section returned from
readSection is not a null pointer before adding it as an associative
section.

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

llvm-svn: 319133
2017-11-28 01:30:07 +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 00e0df26c3 Fix typo in test name
llvm-svn: 319112
2017-11-27 23:09:19 +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 Collingbourne c8477b8234 Revert r319090, "COFF: Do not create SectionChunks for discarded comdat sections."
Caused test failures in check-cfi on Windows.
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/20284

llvm-svn: 319100
2017-11-27 21:37:51 +00:00
Peter Collingbourne 3f2921f5ec COFF: Do not create SectionChunks for discarded comdat sections.
With this change, instead of creating a SectionChunk for each section
in the object file, we only create them when we encounter a prevailing
comdat section.

Also change how symbol resolution occurs between comdat symbols. Now
only the comdat leader participates in comdat resolution, and not any
other external associated symbols. This is more in line with how COFF
semantics are defined, and should allow for a more straightforward
implementation of non-ANY comdat types.

On my machine, this change reduces our runtime linking a release
build of chrome_child.dll with /nopdb from 5.65s to 4.54s (median of
50 runs).

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

llvm-svn: 319090
2017-11-27 20:42:34 +00:00
Rafael Espindola 1fea1e326e Add a missing test.
We were not testing that we correctly handled a .o with a weak symbol
after a .so.

llvm-svn: 319051
2017-11-27 17:18:09 +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
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
Igor Kudrin d95c74ec81 [ELF] Make tests with undefined symbols more explicit.
Differential Revision: https://reviews.llvm.org/D40253

llvm-svn: 318939
2017-11-24 06:42:32 +00:00
Rafael Espindola 83f73f7908 Make a test stricter.
It now has a DT_NEEDED that could be removed by --gc-sections and one
that cannot. Without this all tests would pass if --gc-sections just
removed all DT_NEEDED.

llvm-svn: 318937
2017-11-23 23:40:33 +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 6396c37017 Add testcase for pr34113.
llvm-svn: 318883
2017-11-22 22:00:50 +00:00
Peter Collingbourne 048ac83973 CachePruning: Allow limiting the number of files in the cache directory.
The default limit is 1000000 but it can be configured with a cache
policy. The motivation is that some filesystems (notably ext4) have
a limit on the number of files that can be contained in a directory
(separate from the inode limit).

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

llvm-svn: 318857
2017-11-22 18:27:31 +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
Peter Collingbourne f874bd67d8 COFF: Emit a COFF symbol table if /debug:dwarf is specified.
This effectively reverts r318548 and r318635 while keeping the
functionality behind the flag and preserving the bug fix from r318548.

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

llvm-svn: 318721
2017-11-21 01:14:14 +00:00
Reid Kleckner fa520a2a35 Relax pdb.test checks for debug chunk sizes
llvm-svn: 318700
2017-11-20 21:53:24 +00:00
Reid Kleckner 95cc796cf1 Merge .xdata into .rdata by default
Summary: MSVC does this. The user can override it with their own /merge: flag.

Reviewers: ruiu, pcc

Subscribers: llvm-commits

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

llvm-svn: 318699
2017-11-20 21:49:35 +00:00
Simon Atanasyan eb6847a4af [MIPS] Add test case to check calculation of GOT pages in case of using a linker script. NFC
llvm-svn: 318691
2017-11-20 20:40:45 +00:00
Peter Collingbourne 31275d4472 COFF: Correctly handle relocations against early discarded sections.
Don't crash if we encounter a reference to an early discarded section
(such as .drectve). Instead, handle them the same way as sections
discarded by comdat merging, i.e. either print an error message or
(for debug sections) silently ignore the relocation.

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

llvm-svn: 318689
2017-11-20 19:37:07 +00:00
Rafael Espindola 25219377d7 Add missing test.
Without this we could remove

SS->getFile<ELFT>()->IsUsed = true;

from addUndefined and no test would fail.

llvm-svn: 318688
2017-11-20 19:23:36 +00:00
Peter Collingbourne d01571353d COFF: Stop requiring comdat sections to have an external leader to participate in ICF.
This requirement was added in r254578 to fix pr25686. However, it
appears to have originated from a misdiagnosis of the problem: link.exe
refused to merge the two sections because they are non-executable,
not because they have internal leaders. If I set up a similar scenario
with functions instead of globals I see that link.exe merges them.

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

llvm-svn: 318682
2017-11-20 18:51:29 +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
Peter Collingbourne 8e820552c3 COFF: Fix invalid comdat sections in test cases.
The comdat sections in these test cases do not comply with the COFF
specification, and link.exe rejects them. I plan to make a change to
how we handle comdat sections which would also cause us to reject them.

llvm-svn: 318637
2017-11-20 05:31:37 +00:00
Peter Collingbourne 5e80bdebd2 COFF: Stop emitting a non-standard COFF symbol table into PEs.
Now that our support for PDB emission is reasonably good, there is
no longer a need to emit a COFF symbol table.

Also fix a bug where we would fail to emit a string table for long
section names if /debug was not specified.

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

llvm-svn: 318548
2017-11-17 19:51:20 +00:00
Reid Kleckner d99ac29a24 All .xdata sections are eligble for ICF
Summary:
Many small functions have identical unwind info because they push the
same sets of CSRs in the same order and have the same stack and prologue
size. The VC linker merges duplicate .xdata, and so should LLD.

This reduces the .xdata section size of clang.exe from 1.8MB to 94KB.

Reviewers: pcc, ruiu

Subscribers: llvm-commits

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

llvm-svn: 318547
2017-11-17 19:50:10 +00:00
Sam Clegg c94d393ad5 [WebAssembly] Initial wasm linker implementation
This linker backend is still a work in progress but is
enough to link simple programs including linking against
library archives.

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

llvm-svn: 318539
2017-11-17 18:14:09 +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 690a811df1 [ELF] - Fix BB after r318516
Test did not run under windows because uses zlib.

Content of section changed because now strings
merging is applied.

llvm-svn: 318518
2017-11-17 11:39:26 +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
Andrew Ng c430f08c80 [ELF] Fix broken LTO cache test NFC
Commit r318397 fixed the cache pruning interval which broke this test
as it was assuming that the cache pruning was always being
performed. Explicitly set prune interval to 0s to ensure this.

llvm-svn: 318426
2017-11-16 17:25:12 +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
Martin Storsjo 46304e03ec [COFF] Don't write long section names for sections that will be mapped at runtime
Sections that will be mapped at runtime will only have the short
section name available, since the string table it points into isn't
mapped. Therefore prefer truncating those names over writing a
long name that is unavailable at runtime.

This allows libunwind to find the .eh_frame section at runtime even
if the module was built with debug info enabled.

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

llvm-svn: 318391
2017-11-16 12:06:42 +00:00