Commit Graph

11047 Commits

Author SHA1 Message Date
George Rimar 676dc17db0 [LLD][ELF] - Apply clang-format to InputSections.cpp. NFC.
llvm-svn: 338498
2018-08-01 08:11:54 +00:00
George Rimar a4211551f1 [LLD][ELF] - Removed excessive llvm:: prefix. NFC.
llvm-svn: 338497
2018-08-01 08:10:50 +00:00
Rumeet Dhindsa 9d9113fc13 Allow oformat to accept format starting with elf as acceptable format. isOutputFormatBinary returns false in such case.
Example: --oformat elf64-x86-64

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

llvm-svn: 338445
2018-07-31 21:58:26 +00:00
David L. Jones 2a895e57af [lld] Fix test RUN commands so they don't fail when run in a read-only filesystem.
Some test setups run tests in a read-only path, which means that opening the
default output path (a.out) for write will fail. This change adds appropriate -o
flags so the tests will not fail spuriously.

llvm-svn: 338440
2018-07-31 21:15:58 +00:00
Peter Collingbourne 2da4e52182 ELF: Add libcall symbols to the link when LTO is being used.
If any of our inputs are bitcode files, the LTO code generator may create
references to certain library functions that might not be explicit in the
bitcode file's symbol table. If any of those library functions are defined
in a bitcode file in an archive member, we need to arrange to use LTO to
compile those archive members by adding them to the link beforehand.

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

llvm-svn: 338434
2018-07-31 20:36:17 +00:00
Rui Ueyama 0e1ba29ac3 Simplify. NFC.
llvm-svn: 338409
2018-07-31 18:13:36 +00:00
Rui Ueyama 7f97570e79 Make ICF log output order deterministic.
This patch does the same thing as r338153 for COFF.
Note that this patch affects only the order of log messages.
The output file is already deterministic.

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

llvm-svn: 338406
2018-07-31 18:04:58 +00:00
George Rimar 7a49ce4ac4 [LLD][ELF] - ICF: Check we do not fold sections which relocations reffering to absolute symbols with a different values.
This adds a test for the following uncovered piece of code:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L263

Without that lines we would crash.

llvm-svn: 338379
2018-07-31 13:55:25 +00:00
Peter Smith 70997f9a4e [ELF][ARM] Implement support for Tag_ABI_VFP_args
The Tag_ABI_VFP_args build attribute controls the procedure call standard
used for floating point parameters on ARM. The values are:
0 - Base AAPCS (FP Parameters passed in Core (Integer) registers
1 - VFP AAPCS (FP Parameters passed in FP registers)
2 - Toolchain specific (Neither Base or VFP)
3 - Compatible with all (No use of floating point parameters)

If the Tag_ABI_VFP_args build attribute is missing it has an implicit value
of 0.
    
We use the attribute in two ways:
- Detect a clash in calling convention between Base, VFP and Toolchain.
we follow ld.bfd's lead and do not error if there is a clash between an
implicit Base AAPCS caused by a missing attribute. Many projects
including the hard-float (VFP AAPCS) version of glibc contain assembler
files that do not use floating point but do not have Tag_ABI_VFP_args.
- Set the EF_ARM_ABI_FLOAT_SOFT or EF_ARM_ABI_FLOAT_HARD ELF header flag
for Base or VFP AAPCS respectively. This flag is used by some ELF
loaders.
    
References:
- Addenda to, and Errata in, the ABI for the ARM Architecture for
Tag_ABI_VFP_args
- Elf for the ARM Architecture for ELF header flags
    
Fixes PR36009
    
Differential Revision: https://reviews.llvm.org/D49993

llvm-svn: 338377
2018-07-31 13:41:59 +00:00
George Rimar 511fed8a24 [LLD][ELF] - ICF: add test case testing we do not fold sections with the different flags. NFCI.
Previously the following condition was not tested at all:
https://github.com/llvm-mirror/lld/blob/master/ELF/ICF.cpp#L300

Patch adds a test for `A->Flags != B->Flags` part.

llvm-svn: 338375
2018-07-31 13:32:16 +00:00
Hans Wennborg 1cc3f51b04 windows_support.rst: Add links for downloading
llvm-svn: 338363
2018-07-31 12:02:03 +00:00
Hans Wennborg c7792a6cc7 index.rst: pe/coff does support pdbs now
llvm-svn: 338362
2018-07-31 12:00:26 +00:00
Fangrui Song f35ff042f4 [docs] Sort ld.lld.1 options
Reviewers: ruiu

Subscribers: llvm-commits

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

llvm-svn: 338326
2018-07-30 23:07:44 +00:00
Fangrui Song bac187bece [docs] Add missing options to ld.lld.1
Differential Revision: https://reviews.llvm.org/D49938

llvm-svn: 338320
2018-07-30 22:31:00 +00:00
Fangrui Song 05779bfcc8 [docs] Update ld.lld.1
llvm-svn: 338275
2018-07-30 17:36:38 +00:00
David Bolvansky a932cd409b [AArch64] Support execute-only LOAD segments.
Summary:
This adds an LLD flag to mark executable LOAD segments execute-only for AArch64 targets. 

In AArch64 the expectation is that code is execute-only compatible, so this just adds a linker option to enforce this.

Patch by: ivanlozano (Ivan Lozano)

Reviewers: srhines, echristo, peter.smith, eugenis, javed.absar, espindola, ruiu

Reviewed By: ruiu

Subscribers: dokyungs, emaste, arichardson, kristof.beyls, llvm-commits

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

llvm-svn: 338271
2018-07-30 17:02:46 +00:00
George Rimar 9524dee72e [ELF] - Implement SHT_SYMTAB_SHNDX (.symtab_shndxr) section.
This is relative to https://bugs.llvm.org//show_bug.cgi?id=38119.

SHT_SYMTAB section is able to keep symbols with output section indices
up to 0xff00 (SHN_LORESERVE). But if we have indices that are greater
than that (PR shows that it might happen), we need to use
SHT_SYMTAB_SHNDX extended section. It was not supported by LLD.

Description of the SHT_SYMTAB_SHNDX section is here:
https://docs.oracle.com/cd/E19683-01/817-3677/chapter6-94076/index.html.

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

llvm-svn: 338247
2018-07-30 12:39:54 +00:00
Sid Manning bff6719450 [ELF][HEXAGON] Add R_HEX_32_6_X and R_HEX_12_X
And add a test.

llvm-svn: 338213
2018-07-29 11:59:38 +00:00
Peter Collingbourne e6c78eafde Reland r338088, "ELF: Make --print-icf-sections output deterministic."
The xxHash64 function has been made unsigned-char-independent, so
we can reland this change now.

Original commit message:
> The icf-safe.s test currently fails on 32-bit platforms because it uses
> the --print-icf-sections flag and depends on the output appearing in
> a specific order. However, this flag causes the output to depend on
> the order of the sections in the Sections array, which depends on the
> hash values returned from hash_combine, which happen to be different
> for that test between 32-bit and 64-bit platforms.
>
> This change makes the output deterministic by using xxHash64 instead of
> hash_combine.

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

llvm-svn: 338153
2018-07-27 19:10:44 +00:00
Ilya Biryukov cdc92ff254 Revert "ELF: Make --print-icf-sections output deterministic."
This reverts commit r338088. To unbreak our integrate.
The resulting lld output is different if compiled with '-funsigned-char'.

llvm-svn: 338110
2018-07-27 09:01:03 +00:00
Peter Collingbourne b148c9809b ELF: Make --print-icf-sections output deterministic.
The icf-safe.s test currently fails on 32-bit platforms because it uses
the --print-icf-sections flag and depends on the output appearing in
a specific order. However, this flag causes the output to depend on
the order of the sections in the Sections array, which depends on the
hash values returned from hash_combine, which happen to be different
for that test between 32-bit and 64-bit platforms.

This change makes the output deterministic by using xxHash64 instead of
hash_combine.

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

llvm-svn: 338088
2018-07-26 23:34:35 +00:00
Martin Storsjo 6c8cbf6db0 [COFF] Handle comdat sections without leader symbols
Discard them unless they have been associated by other means (yet
uimplemented).

According to MS link.exe, such sections are illegal, but MinGW setups
use them in their take on associative comdats.

This avoids leaving references to the bogus SectionChunk* PendingComdat,
which cannot be dereferenced.

This fixes PR38183.

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

llvm-svn: 338064
2018-07-26 20:14:50 +00:00
Rui Ueyama 279621fbf0 [COFF] clean up global resources after completion
Patch by Andrew Kelley.

Previously, running lld::coff::link() twice in the same process would
access stale pointers because of these global variables not being reset.
After this patch, lld::coff::link() can be called any number of times,
just like its ELF and MACH-O counterparts.

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

llvm-svn: 338042
2018-07-26 17:11:24 +00:00
Fangrui Song 31cc084619 [ELF] Fix linker-script-in-search-path.s
llvm-svn: 337983
2018-07-25 23:29:15 +00:00
Fangrui Song 7610b4d64c [ELF] Make linker-script-in-search-path.s robust per r337972
llvm-svn: 337975
2018-07-25 22:11:00 +00:00
Rui Ueyama 5a0a83daaf Make a test more robust.
Previously, this test fails if there's other test that happens to
create "t.script" in the current directory.

llvm-svn: 337972
2018-07-25 22:01:54 +00:00
Fangrui Song c60f85d073 [ELF] Use search paths for --version-script=
Summary: This behavior matches ld.bfd -Ld --version-script=t.script a.o

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 337969
2018-07-25 21:53:18 +00:00
Peter Collingbourne 6a5368eadb ELF: Do not ICF SHF_LINK_ORDER sections.
We are already ICF'ing these sections as a unit with their dependent
sections, so they don't need to be considered for ICF individually.

This change also "fixes" slowness caused by our quadratic-in-group-size
relocation segregation algorithm on 32-bit ARM platforms with unwind
data and ICF on rodata. In this scenario almost every function's
.ARM.exidx is identical except for the targets of the relocations
that refer to the function and its .ARM.extab, which causes almost
all of the program's .ARM.exidx sections to be initially added to the
same class, which causes us to compare every such section with every
other such section.

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

llvm-svn: 337967
2018-07-25 21:40:54 +00:00
Rui Ueyama 7e95d9e362 Fix error messages for bad symbols.
Previously, the error messages didn't contain symbol name because we
didn't read a symbol name for these error messages.

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

llvm-svn: 337863
2018-07-24 22:52:11 +00:00
Sid Manning 3241724536 [ELF][HEXAGON] Add R_HEX_B15_PCREL_X relocation
Update testcase

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

llvm-svn: 337829
2018-07-24 15:08:13 +00:00
Simon Atanasyan 52854504cc [ELF][MIPS] Fix primary GOT sometimes overflowing by one or two words
If we fail to merge a secondary GOT with the primary GOT but so far only
one merged GOT has been created (the primary one), the final element in
MergedGots is the primary GOT. Thus we should not try to merge with this
final element passing IsPrimary=false, since this will ignore the fact
that the destination GOT does in fact need a header, and those extra two
entries can be enough to allow the merge to incorrectly occur. Instead
we should check for this case before attempting the second merge.

Patch by James Clarke.

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

llvm-svn: 337810
2018-07-24 05:40:37 +00:00
Sam Clegg 8adf7ac5c1 [WebAssembly] Add support for --whole-archive.
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 337777
2018-07-23 23:51:19 +00:00
Peter Collingbourne 00dc23f26e Revert r337638, "ELF: Make sections with KeepUnique bit eligible for ICF."
The gold behaviour with regard to --keep-unique is arguably a bug.
I also noticed a bug in my patch, which is that we mislink the
following program with --icf=safe by merging f3 and f4:

void f1() {}
void f2() {}

__attribute__((weak)) void* f3() { return f1; }
__attribute__((weak)) void* f4() { return f2; }

int main() {
  printf("%p %p\n", f3(), f4());
}

llvm-svn: 337729
2018-07-23 19:36:55 +00:00
Andrew Ng 8d29d74fd0 [LLD] Add llvm-objcopy to test dependencies. NFC.
Dependency on llvm-objcopy was introduced by r337429.

Also sorted the list of dependencies.

llvm-svn: 337693
2018-07-23 14:12:57 +00:00
Andrew Ng e33d691990 [ELF] Fix handling of FDE negative relative PC addr
Signed values for the FDE PC addr were not correctly handled in
readFdeAddr(). If the value is negative and the type of the value is
smaller than 64 bits, the FDE PC addr overflow error would be
incorrectly triggered.

Fixed readFdeAddr() to properly handle signed values by sign extending
where appropriate.

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

llvm-svn: 337683
2018-07-23 11:29:46 +00:00
Peter Collingbourne a052206c4b ELF: Read address significance tables with --icf=all.
Under --icf=all we now only apply KeepUnique to non-executable
address-significant sections. This has the effect of making --icf=all
mean unsafe ICF for executable sections and safe ICF for non-executable
sections.

With this change the meaning of the KeepUnique bit changes to
"does the current ICF mode (together with the --keep-unique and
--ignore-data-address-equality flags) require this section to be
kept unique".

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

llvm-svn: 337640
2018-07-21 02:14:59 +00:00
Peter Collingbourne 37f25a24bb ELF: Make sections with KeepUnique bit eligible for ICF.
The only restriction is that we cannot merge more than one KeepUnique
section together. This matches gold's behaviour and reduces code size
when using --icf=safe.

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

llvm-svn: 337638
2018-07-21 00:17:11 +00:00
Nico Weber bbfe0b79e2 Omit path to lld binary from lld's error, warning, and log output.
lld currently prepends the absolute path to itself to every diagnostic it
emits. This path can be longer than the diagnostic, and makes the actual error
message hard to read.

There isn't a good reason for printing this path: if you want to know which lld
you're running, pass -v to clang – chances are that if you're unsure of this,
you're not only unsure when it errors out. Some people want an indication that
the diagnostic is from the linker though, so instead print just the basename of
the linker's path.

Before:

```
$ out/bin/clang -target x86_64-unknown-linux -x c++ /dev/null -fuse-ld=lld 
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crt1.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crti.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtbegin.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc_s
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lc
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: unable to find library -lgcc_s
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtend.o: No such file or directory
/Users/thakis/src/llvm-mono/out/bin/ld.lld: error: cannot open crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

After:

```
$ out/bin/clang -target x86_64-unknown-linux -x c++ /dev/null -fuse-ld=lld 
ld.lld: error: cannot open crt1.o: No such file or directory
ld.lld: error: cannot open crti.o: No such file or directory
ld.lld: error: cannot open crtbegin.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lc
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: cannot open crtend.o: No such file or directory
ld.lld: error: cannot open crtn.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

https://reviews.llvm.org/D49189

llvm-svn: 337634
2018-07-20 23:09:12 +00:00
Nico Weber f6be416687 Simplify; no behavior change.
Reviewed as part of https://reviews.llvm.org/D49189

llvm-svn: 337633
2018-07-20 23:06:34 +00:00
Reid Kleckner 276d7167d0 [PDB] Write the command line after response file expansion
Summary: Fixes PR38085

Reviewers: ruiu, zturner

Subscribers: llvm-commits

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

llvm-svn: 337628
2018-07-20 22:34:20 +00:00
Fangrui Song a66d77b22b [ELF] Check eh_frame_hdr overflow with PC offsets instead of PC absolute addresses
Reviewers: grimar, ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 337610
2018-07-20 20:27:42 +00:00
Martin Storsjo 98ff9f845d [COFF] Sort .reloc before all other discardable sections
If a binary is stripped, which can remove discardable sections (except
for the .reloc section, which also is marked as discardable as it isn't
loaded at runtime, only read by the loader), the .reloc section should
be first of them, in order not to create gaps in the image.

Previously, binaries with relocations were broken if they were stripped
by GNU binutils strip. Trying to execute such binaries produces an error
about "xx is not a valid win32 application".

This fixes GNU binutils bug 23348.

Prior to SVN r329370 (which didn't intend to have functional changes),
the code for moving discardable sections to the end didn't clearly
express how other discardable sections should be ordered compared to
.reloc, but the change retained the exact same end result as before.

After SVN r329370, the code (and comments) more clearly indicate that
it tries to make the .reloc section the absolutely last one; this patch
changes that.

This matches how GNU binutils ld sorts .reloc compared to dwarf debug
info sections.

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

Signed-off-by: Martin Storsjö <martin@martin.st>
llvm-svn: 337598
2018-07-20 18:43:35 +00:00
George Rimar c2c7d15486 [ELF] - Fix mistypes in test cases.
llvm-svn: 337528
2018-07-20 08:07:33 +00:00
Martin Storsjo a55fc71614 [COFF] Write the debug directory and build id to a separate section for MinGW
For dwarf debug info, an executable normally either contains the debug
info, or it is stripped out. To reduce the storage needed (slightly)
for the debug info kept separately from the released, stripped binaries,
one can choose to only copy the debug data from the original executable
(essentially the reverse of the strip operation), producing a file with
only debug info.

When copying the debug data from an executable with GNU objcopy,
the build id and debug directory need to reside in a separate section,
as this will be kept while the rest of the .rdata section is removed.

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

llvm-svn: 337526
2018-07-20 05:44:34 +00:00
Sid Manning 690b544f41 [ELF][HEXAGON] Add support for R_HEX_B15_PCREL
Add support and update the testcase.

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

llvm-svn: 337494
2018-07-19 20:27:43 +00:00
Sid Manning bdd71f358d Add support for R_HEX_B32_PCREL_X, R_HEX_B22_PCREL_X relocations
A couple more basic relocations plus testcase.

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

llvm-svn: 337484
2018-07-19 19:10:56 +00:00
George Rimar ed2605d36d [ELF] - Eliminate dead code. NFC.
Code was dead because we call postThunkContents only for SHT_SYMTAB.

llvm-svn: 337460
2018-07-19 14:39:56 +00:00
George Rimar ad760e3ec6 [ELF] - One more test case for .eh_frame_hdr.
This is to test the following error message:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L544

Which occurs when LLD meets unsupported address encoding when scans
.eh_frame to build .eh_frame_hdr section.

llvm-svn: 337458
2018-07-19 14:27:19 +00:00
Takuto Ikuta d855928ec3 [PDB] Add PDBSourcePath flag to support absolutize source file path
This patch changes relative path for source files in obj files to
absolute path in PDB when linking with added flag.

I will make obj file generated by clang-cl independent from build
directory for chromium build. But I don't want to confuse visual studio
debugger or require additional configuration. To attain this goal, I
added flag to convert relative source file path in obj to absolute path
when emitting PDB.

By removing absolute path from obj files, we can share build cache
between chromium developers even when they are doing debug build.
That will make build time faster.

More context:
https://bugs.chromium.org/p/chromium/issues/detail?id=712796
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/5HXSVX-7fPc

llvm-svn: 337439
2018-07-19 04:56:22 +00:00
Martin Storsjo c35e4bf7eb [COFF] Don't produce base relocs for discardable sections
Dwarf debug info contains some data that contains absolute addresses.
Since these sections are discardable and aren't loaded at runtime,
there's no point in adding base relocations for them.

This makes sure that after stripping out dwarf debug info, there are no
base relocations that point to nonexistent sections.

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

llvm-svn: 337438
2018-07-19 04:25:22 +00:00