Commit Graph

11941 Commits

Author SHA1 Message Date
Reid Kleckner 34e9c41164 [COFF] Store Chunk RVAs and section offsets as uint32_t
Saves 8 bytes on SectionChunk, one of the most commonly allocated data
structures.

llvm-svn: 360188
2019-05-07 20:30:41 +00:00
Simon Atanasyan 3bdb81c26d [mips] Fix ld instruction in PLT entries on MIPS64
Use `ld` and `daddiu` instructions in MIPS64 PLT records. That fixes a
segmentation fault.

Patch by Qiao Pengcheng.

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

llvm-svn: 360187
2019-05-07 20:26:23 +00:00
Simon Atanasyan 494b763cfc [mips] Rename test case. NFC
This test case checks MIPS PLT records for N64 ABI. For the N32 ABI case
there is a separate test case `mips-plt-n32.s`.

llvm-svn: 360186
2019-05-07 20:26:12 +00:00
Sam Clegg b33fdb7768 [WebAssembly] Don't generate unused table entries.
When generating PIC output only relocations of type
R_WASM_TABLE_INDEX_REL_SLEB should generate table entries.

R_WASM_TABLE_INDEX_I32 get resolved at runtime via the auto-generated
__wasm_apply_relocs functions.

R_WASM_TABLE_INDEX_SLEB are not allowed in PIC code.

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

llvm-svn: 360165
2019-05-07 15:46:30 +00:00
Nico Weber 4b81e9f8d1 lld-link: Allow /? as option prefix, like -? is allowed
link.exe seems to allow `/?foo` and `-?foo` in addition to `/foo` and `-foo`.

Since lld-link already supports the `-?foo` spelling, support `/?foo` as well.

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

llvm-svn: 360150
2019-05-07 14:15:35 +00:00
Nico Weber 54743d5767 Add typo correction for command-line flags to ELF and COFF lld drivers
For lld-link, unknown '/'-style flags are treated as filenames on POSIX
systems, so only '-'-style flags get typo correction for now. This
matches clang-cl.

PR37006.

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

llvm-svn: 360145
2019-05-07 13:48:30 +00:00
George Rimar 72f7a98876 [LLD][ELF] - Remove symbol-name-offset.elf binary from test cases.
It was possible to convert the test case to YAML test.
After that, we have only one binary test left in LLD/ELF.

llvm-svn: 360139
2019-05-07 12:59:44 +00:00
Fangrui Song f3994e4dfa [ELF] Reorder BitcodeFiles.empty() to call thinLTOCreateEmptyIndexFiles() in only one place
It makes the --plugin-opt=obj-path= and --plugin-opt=thinlto-index-only=
behavior more consistent - the files will be created in the
BitcodeFiles.empty() case, but I assume whether it behaves this way is
not required by anyone.

LTOObj->run() cannot run with empty BitcodeFiles. There would be an error:

    ld.lld: error: No available targets are compatible with triple ""

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

llvm-svn: 360129
2019-05-07 10:40:26 +00:00
Fangrui Song 912251e82f [PPC64] toc-indirect to toc-relative relaxation
This is based on D54720 by Sean Fertile.

When accessing a global symbol which is not defined in the translation unit,
compilers will generate instructions that load the address from the toc entry.

If the symbol is defined, non-preemptable, and addressable with a 32-bit
signed offset from the toc pointer, the address can be computed
directly. e.g.

    addis 3, 2, .LC0@toc@ha  # R_PPC64_TOC16_HA
    ld    3, .LC0@toc@l(3)   # R_PPC64_TOC16_LO_DS, load the address from a .toc entry
    ld/lwa 3, 0(3)           # load the value from the address

    .section .toc,"aw",@progbits
    .LC0: .tc var[TC],var

can be relaxed to

    addis 3,2,var@toc@ha     # this may be relaxed to a nop,
    addi  3,3,var@toc@l      # then this becomes addi 3,2,var@toc
    ld/lwa 3, 0(3)           # load the value from the address

We can delete the test ppc64-got-indirect.s as its purpose is covered by
newly added ppc64-toc-relax.s and ppc64-toc-relax-constants.s

Reviewed By: ruiu, sfertile

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

llvm-svn: 360112
2019-05-07 04:26:05 +00:00
Sam Clegg 5f8c2edef3 [WebAssembly] Add more test coverage for reloctions against section symbols
The only known user of this relocation type and symbol type is
the debug info sections, but we were not testing the `--relocatable`
output path.

This change adds a minimal test case to cover relocations against
section symbols includes `--relocatable` output.

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

llvm-svn: 360110
2019-05-07 03:53:16 +00:00
Fangrui Song 12fb52007b [AMDGPU][test] Define local symbols used in amdgpu-relocs.s
Differential Revision: https://reviews.llvm.org/D61594

llvm-svn: 360046
2019-05-06 14:17:59 +00:00
Alexander Kornienko 8b92ec521d [lld] A better version of the fix in r359942.
Thanks to George Rimar for the suggestion.

llvm-svn: 360040
2019-05-06 12:11:30 +00:00
Alexander Kornienko 3f796f974d [lld] Specify output file explicitly
The test shouldn't try to create `a.out` in the current directory, which can be
read-only (and it is in our test setup).

llvm-svn: 359942
2019-05-03 23:11:32 +00:00
Reid Kleckner 0a1b1d6e62 Shrink SectionChunk by combining Relocs and SectionName sizes
SectionChunk is one of the most frequently allocated data structures in
LLD, since there are about four per function when optimizations and
debug info are enabled (.text, .pdata, .xdata, .debug$S).

A PE COFF file cannot be larger than 2GB, so there is an inherent limit
on the length of the section name and the number of relocations.
Decompose the ArrayRef and StringRef into pointer and size, and put them
back together in the accessors for section name and relocation list.

I plan to gather complete performance numbers later by padding
SectionChunk with dead data and measuring performance after all the size
optimizations are done.

llvm-svn: 359923
2019-05-03 20:17:14 +00:00
Fangrui Song d45df09435 [ELF] Place SHT_NOTE sections with the same alignment into one PT_NOTE
Summary:
While the generic ABI requires notes to be 8-byte aligned in ELF64, many
vendor-specific notes (from Linux, NetBSD, Solaris, etc) use 4-byte
alignment.

In a PT_NOTE segment, if 4-byte aligned notes are followed by an 8-byte
aligned note, the possible 4-byte padding may make consumers fail to
parse the 8-byte aligned note. See PR41000 for a recent report about
.note.gnu.property (NT_GNU_PROPERTY_TYPE_0).
(Note, for NT_GNU_PROPERTY_TYPE_0, the consumers should probably migrate
to PT_GNU_PROPERTY, but the alignment issue affects other notes as well.)

To fix the issue, don't mix notes with different alignments in one
PT_NOTE. If compilers emit 4-byte aligned notes before 8-byte aligned
notes, we'll create at most 2 segments.

sh_size%sh_addralign=0 is actually implied by the rule for linking
unrecognized sections (in generic ABI), so we don't have to check that.
Notes that match in name, type and attribute flags are concatenated into
a single output section. The compilers have to ensure
sh_size%sh_addralign=0 to make concatenated notes parsable.

An alternative approach is to create a PT_NOTE for each SHT_NOTE, but
we'll have to incur the sizeof(Elf64_Phdr)=56 overhead every time a new
note section is introduced.

Reviewers: ruiu, jakehehrlich, phosek, jhenderson, pcc, espindola

Subscribers: emaste, arichardson, krytarowski, fedor.sergeev, llvm-commits

Tags: #llvm

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

llvm-svn: 359853
2019-05-03 00:35:49 +00:00
Nico Weber 81862f82ee lld-link: Add /force:multipleres extension to make dupe resource diag non-fatal
As a side benefit, lld-link now reports more than one duplicate resource
entry before exiting with an error even if the new flag is not passed.

llvm-svn: 359829
2019-05-02 21:21:55 +00:00
Fangrui Song 0178cff279 [ELF] --plugin-opt=thinlto-index-only: create empty index files even if all bitcode files are lazy
Summary:
The gold plugin behavior (creating empty index files for lazy bitcode
files) was added in D46034, but it missed the case when there is no
non-lazy bitcode files, e.g.

    ld.lld -shared crti.o crtbeginS.o --start-lib bitcode.o --end-lib ...

crti.o crtbeginS.o are not bitcode, but our distributed build system
wants bitcode.o.thinlto.bc to confirm all expected outputs are created
based on all of the modules provided to the linker.

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

llvm-svn: 359788
2019-05-02 14:05:20 +00:00
Fangrui Song 8be28cdc52 [Object] Change getSectionName() to return Expected<StringRef>
Summary:
It currently receives an output parameter and returns
std::error_code. Expected<StringRef> fits for this purpose perfectly.

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

llvm-svn: 359774
2019-05-02 10:32:03 +00:00
Fangrui Song d8c2fa99c1 [ELF] Delete a cant-write test from test/lto/thinlto-index-only.ll
The test is performed by thinlto-cant-write-index.ll

llvm-svn: 359769
2019-05-02 09:29:24 +00:00
Nico Weber 413517ecfe lld-link: Make "duplicate resource" error message a bit more concise
Reduces the error message from:
    lld-link: error: failed to parse .res file: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res

To:
    lld-link: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res

Make sure every error message emitted by cvtres contains the name of at
least one ".res" file, so that removing the "failed to parse .res file"
string doesn't lose information.

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

llvm-svn: 359749
2019-05-02 01:52:24 +00:00
Fangrui Song c669ef1721 Delete trailing \r. NFC
llvm-svn: 359745
2019-05-02 00:39:03 +00:00
Ben Dunbobbin 6e32dd6cfd [LLD] Emit dynamic relocations for references to script symbols in -pie links
https://reviews.llvm.org/D55423 caused LLD to stop emitting dynamic relocations for references to script symbols in -pie links.

This patch fixes that regression.

https://reviews.llvm.org/D61298

llvm-svn: 359683
2019-05-01 14:07:31 +00:00
Fangrui Song 5387c2cd17 [llvm-objdump] Print newlines before and after "Disassembly of section ...:"
This improves readability and the behavior is consistent with GNU objdump.

The new test test/tools/llvm-objdump/X86/disassemble-section-name.s
checks we print newlines before and after "Disassembly of section ...:"

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

llvm-svn: 359668
2019-05-01 10:40:48 +00:00
Fangrui Song 4672e52e22 [llvm-readobj] llvm-readobj --elf-output-style=GNU => llvm-readelf
While updating the test, change -l -S to -S -l as the output of -S goes
before -l.

llvm-svn: 359653
2019-05-01 06:02:16 +00:00
Fangrui Song b159906a9a [test] Change llvm-readobj -long-option to --long-option or well-known short options. NFC
Also change some options that have different semantics (cause confusion) in llvm-readelf mode:

-s => -S
-t => --symbols
-sd => --section-data

llvm-svn: 359651
2019-05-01 05:49:01 +00:00
Andrew Ng 24896d304d [LLD][ELF] /DISCARD/ output sections should not be orphans
/DISCARD/ output sections were being treated as orphans. As a result, if
a /DISCARD/ output section has been assigned a PHDR, it could cause
incorrect assignment of sections to segments.

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

llvm-svn: 359565
2019-04-30 14:31:22 +00:00
Andrew Ng 0f4c58f6f4 [LLD][ELF] Fix getRankProximity to "ignore" not live sections
This is a follow up to r358979 which made findOrphanPos only consider
live sections. Unfortunately, this required change to getRankProximity,
used by findOrphanPos, was missed.

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

llvm-svn: 359554
2019-04-30 12:27:06 +00:00
Nico Weber 99bad37013 Add more lld release notes
llvm-svn: 359518
2019-04-29 23:26:21 +00:00
Nico Weber aec5dcc457 Add some lld-link 9.0 release notes
llvm-svn: 359412
2019-04-29 00:42:05 +00:00
George Rimar dee900ae59 [LLD][ELF] - Do not remove empty sections referenced in LOADADDR/ADDR commands.
This is https://bugs.llvm.org//show_bug.cgi?id=38750.

If script references empty sections in LOADADDR/ADDR commands

.empty  : { *(.empty ) }
.text   : AT(LOADADDR (.empty) + SIZEOF (.empty)) { *(.text) }
then an empty section will be removed and LOADADDR/ADDR will evaluate to null.
It is not that user may expect from using of the generic script, what is a common case.

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

llvm-svn: 359279
2019-04-26 06:59:30 +00:00
Fangrui Song 98b70f6705 [ELF] Change std::max<uint64_t> to uint32_t for section alignment
Summary:
We use `uint32_t SectionBase::Alignment` and `uint32_t
PhdrEntry::p_align` despite alignments being 64 bits in ELF64.
Fix the std::max template arguments accordingly.

The currently 160-byte InputSection will become 168 bytes if we make SectionBase::Alignment uint64_t.

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

llvm-svn: 359268
2019-04-26 04:07:58 +00:00
Sam Clegg b685ddf288 [WebAssembly] Always take into account added when applying runtime relocations
The code we generate for applying data relocations at runtime omitted
the symbols with GOT entries.

Also refactor the code to reduce duplication.

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

llvm-svn: 359207
2019-04-25 17:11:54 +00:00
George Rimar 44f2d74aa5 [LLD][ELF] - Convert symbol-index.s testcase to a YAML test case. NFCI.
This removes one more binary object from the inputs and fixes the
test case description.

Previously it said that:
"symbol-index.elf has incorrect type of .symtab section.
There is no symbol bodies because of that and any symbol index becomes incorrect."

But the real reason of the failture was not the incorrect type of a symbol table,
but invalid index of the symbol used in a relocation, what happened because
previous test tried to read .symtab as a SHT_RELA section.

llvm-svn: 359197
2019-04-25 15:08:52 +00:00
George Rimar e043417268 [LLD][ELF] - Move the test to a correct folder, remove excessive input. NFCI.
This test should live in `invalid` folder.

Also it was possible to avoid adding input
with use of `-docnum=x` yaml2obj argument.

llvm-svn: 359194
2019-04-25 14:53:23 +00:00
Nico Weber c0838af754 lld-link: Implement /swaprun: flag
r191276 added this to old LLD, but it never made it to new LLD -- except
that the flag was in Options.td, so it was silently ignored. I figured
it should be easy to implement, so I did that instead of removing the
flags from Options.td.

I then discovered that link.exe also supports comma-separated lists of
'cd' and 'net', which made the parsing code a bit annoying.

The Alias technique in Options.td is to get nice help output.

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

llvm-svn: 359192
2019-04-25 14:02:26 +00:00
Nico Weber 23cb79ff93 llvm-cvtres: Make new dupe resource error a bit friendlier
For well-known type IDs, include the name of the type.

To not duplicate the ID->name map, make llvm-readobj call this new
function as well.  It has slightly different output, so this also
requires updating a few tests.

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

llvm-svn: 359153
2019-04-24 23:26:30 +00:00
Reid Kleckner 54c8182a3f [COFF] Don't emit .gfids sections when CFG is off
Put them on the list of GuardFidChunks instead of the main Chunks list,
even with CFG is off. It will be ignored if CFG is disabled.

llvm-svn: 359137
2019-04-24 20:38:37 +00:00
Sam Clegg f7f00ebc27 [docs] Copy-edit lld/docs/WebAssembly.rst
Fixes small typos in WebAssembly documentation. I first noticed the
sub-heading "Bahavior", and then decided to review the whole file.

Patch by Christoph Siedentop!

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

llvm-svn: 359103
2019-04-24 15:13:35 +00:00
Fangrui Song 5929553868 [ELF] Delete a redundant SHT_NOBITS -> SHT_PROGBITS after D60131
Differential Revision: https://reviews.llvm.org/D61006

llvm-svn: 359099
2019-04-24 14:44:07 +00:00
Fangrui Song 513d3658e7 [PPC64] Consider localentry offset when computing branch distance
Summary:
We don't take localentry offset into account, and thus may fail to
create a long branch when the gap is just a few bytes smaller than 2^25.

relocation R_PPC64_REL24 out of range: 33554432 is not in [-33554432, 33554431]
relocation R_PPC64_REL24 out of range: 33554436 is not in [-33554432, 33554431]

Fix that by adding the offset to the symbol VA.

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

llvm-svn: 359094
2019-04-24 14:03:30 +00:00
George Rimar fa34952a00 [LLD][ELF] - Remove binding.elf binary from test case. NFCI.
This introduces YAML based invalid-binding.test instead.

llvm-svn: 359086
2019-04-24 12:16:39 +00:00
George Rimar 1ee7bee224 [LLD][ELD] - Remove excessive lines from test. NFC.
They are not used.

llvm-svn: 359084
2019-04-24 12:00:09 +00:00
Fangrui Song 74780852dc [ELF] Fix a gcc -Wextra warning
Extracted from D61046.

warning: enumeral and non-enumeral type in conditional expression [-Wextra]

Cast SHF_ALLOC to avoid that.

llvm-svn: 359070
2019-04-24 05:33:33 +00:00
Sam Clegg 99cf58339f [WebAssembly] Fix typo in relocation checking
Runtime relocation are generated for relocations of type
R_WASM_MEMORY_ADDR_I32 when in PIC mode (either -shared or -pie).

Followup on https://reviews.llvm.org/D60882.

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

llvm-svn: 358995
2019-04-23 14:49:38 +00:00
George Rimar bb2079b7e1 [LLD][ELF] - Remove dynamic-section-sh_size.elf binary, convert test to yaml. NFCI.
dynamic-section-sh_size.elf was introduced in D25090.
Now it is possible to use yaml2obj instead. 
That is what this patch does.

Also I added one more case of a possibly broken .dynamic
section just in case.

llvm-svn: 358990
2019-04-23 14:21:31 +00:00
George Rimar 95203efc1a [LLD][ELF] - Remove file-class.a binary from inputs and improve the test case.
file-class.a was used to diagnose the "corrupted ELF file: invalid file class"
error when the object was fetched from the archive.

file-class.a contained an object of 16 bytes size. I replaced it with
an echo call (because it is impossible to use yaml2obj for that, and I am
not sure it is worth to support), and also increased its size to 18 bytes.
That allowed to also test a case when such object is a regular input and not an
archive member (we have a bit different logic for these cases).

llvm-svn: 358985
2019-04-23 13:27:54 +00:00
Andrew Ng ccba42c7eb [ELF] Change default output section type to SHT_PROGBITS
This fixes an issue where a symbol only section at the start of a
PT_LOAD segment, causes incorrect alignment of the file offset for the
start of the segment which results in the output of an invalid ELF.

SHT_PROGBITS was the default output section type in the past.

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

llvm-svn: 358981
2019-04-23 12:38:52 +00:00
Alexandre Ganea 2769d58628 [LLD][COFF] Fix /linkrepro with output options that take a filename or path
The following options: /pdb, /out or /implib now emit in the repro.tar/response.txt only a filename stripped from its path, to avoid non-existent paths on the reproducer's machine.

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

llvm-svn: 358980
2019-04-23 12:30:49 +00:00
Andrew Ng 98c858a23b [ELF] Change findOrphanPos to only consider live sections
This patch changes the behaviour of findOrphanPos to only consider live
sections when placing orphan sections. This used to be how it behaved in
the past.

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

llvm-svn: 358979
2019-04-23 12:17:15 +00:00
Fangrui Song 003c18a39c [PPC][PPC64] Improve some llvm-objdump -d -D tests
Various improvement:

Some offsets in disassembly are incorrect after several layout adjustment. Fix them.
llvm-objdump -D should not be used. -D dumps unrelated non-text sections. Replace them with llvm-objdump -d, llvm-readelf -x, etc
Many llvm-objdump -d tests use {{.*}} . Add the option --no-show-raw-insn to avoid check hex bytes.

ppc64-long-branch.s does not need a shared object. Delete it.
Make ppc64-ifunc.s check 2 ifuncs.

Reviewers: ruiu, espindola

Subscribers: emaste, nemanjai, arichardson, kbarton, jsji, llvm-commits

Tags: #llvm

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

llvm-svn: 358975
2019-04-23 11:47:28 +00:00