Commit Graph

11527 Commits

Author SHA1 Message Date
Rui Ueyama 23b28703f9 Remove dead code.
This code is no-op because of r349849.

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

llvm-svn: 349859
2018-12-20 23:47:39 +00:00
Rui Ueyama fb81437638 Simplify. NFC.
llvm-svn: 349850
2018-12-20 22:54:41 +00:00
Fangrui Song 51fe635f81 [ELF] Move IsNeeded logic from SymbolTable::addShared to MarkLive, and check IsUsedInRegularObj
Summary:
In glibc, libc.so is a linker script with an as-needed dependency on ld-linux-x86-64.so.2

    GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a  AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) )

ld-linux-x86-64.so.2 (as-needed) defines some symbols which resolve undefined references in libc.so.6, it will therefore be added as a DT_NEEDED entry, which isn't necessary.

The test case as-needed-not-in-regular.s emulates the libc.so scenario, where ld.bfd and gold don't add DT_NEEDED for a.so

The relevant code in gold/resolve.cc:

  // If we have a non-WEAK reference from a regular object to a
  // dynamic object, mark the dynamic object as needed.
  if (to->is_from_dynobj() && to->in_reg() && !to->is_undef_binding_weak())
    to->object()->set_is_needed();

in_reg() appears to do something similar to IsUsedInRegularObj.

This patch makes lld do the similar thing, but moves the check from
addShared to a later stage MarkLive where all symbols are scanned.

Reviewers: ruiu, pcc, espindola

Reviewed By: ruiu

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 349849
2018-12-20 22:46:01 +00:00
Sean Fertile 367a7b7d66 [PPC64] Add toc-optimizations for got based relocations.
Differential Revision: https://reviews.llvm.org/D54907

llvm-svn: 349772
2018-12-20 17:00:33 +00:00
Rui Ueyama 392f0b2b71 Simplify. NFC.
Differential Revision: https://reviews.llvm.org/D55903

llvm-svn: 349697
2018-12-19 23:25:02 +00:00
George Rimar 751e6e1cf5 [LLD][ELF] - Report a location for symbols from the linker script when reporting an error.
When we report an error for symbols defined in the linker script,
we do not report the location properly.

For example:

ld.lld: error: relocation R_AARCH64_CALL26 cannot refer to absolute symbol: aliasto__text
>>> defined in <internal>
>>> referenced by rtoabs.o:(.text+0x4)

This patch fixes that.

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

llvm-svn: 349612
2018-12-19 10:19:40 +00:00
Rui Ueyama 2d7d128117 Use unique_ptr to manage a TarWriter instance. NFC.
llvm-svn: 349581
2018-12-18 23:50:37 +00:00
Rui Ueyama 5961809640 Fix error message.
Previously, this code printed out an error message like this

  ld.lld: error: --reproduce: failed to open /foo: cannot open /foo

Apparently "failed to open /foo:" part is redundant.

llvm-svn: 349571
2018-12-18 23:33:10 +00:00
Rui Ueyama a01246b7a7 Reject .so files if -static is given.
Previously, if you pass -static to lld, lld searches for only foo.a
and skips foo.so for -lfoo option. However, it didn't reject .so files
if you directly pass their pathnames via the command line, which is a bug.

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

llvm-svn: 349557
2018-12-18 22:30:23 +00:00
Fangrui Song 41031d97f2 [ELF] Place .note in the first page to ensure they are available in core files
Summary:
Other large sections (e.g. .rela.dyn .dynstr) may push .note.* off the
first page. They won't be available in core files if RLIMIT_CORE is
limited.

This patch gives priority to alloctable SHT_NOTE sections so that they
are assuredly in the first page and will be available in core files.
They are small and contain important information (e.g. .note.gnu.build-id
identifies the origin of the core, .note.tag stores NT_FREEBSD_ABI_TAG).

Note: gold Output_section_order has a similar rule:

  // Loadable read-only note sections come next so that the PT_NOTE
  // segment is on the first page of the executable.
  ORDER_RO_NOTE,

Reviewers: ruiu, pcc, espindola

Subscribers: emaste, arichardson, llvm-commits

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

llvm-svn: 349524
2018-12-18 19:16:37 +00:00
Sean Fertile 09a5bc0107 [PPC64] Support got-based relocations.
Differential Revison: https://reviews.llvm.org/D54859

llvm-svn: 349511
2018-12-18 17:34:26 +00:00
Reid Kleckner 0aa260d2c9 [COFF] Set the CPU string for LTO like ELF does
Fixes PR40043

llvm-svn: 349436
2018-12-18 01:59:33 +00:00
Reid Kleckner 53ce05960e [codeview] Align symbol records to save 441MB during linking clang.pdb
In PDBs, symbol records must be aligned to four bytes. However, in the
object file, symbol records may not be aligned. MSVC does not pad out
symbol records to make sure they are aligned. That means the linker has
to do extra work to insert the padding. Currently, LLD calculates the
required space with alignment, and copies each record one at a time
while padding them out to the correct size. It has a fast path that
avoids this copy when the records are already aligned.

This change fixes a bug in that codepath so that the copy is actually
saved, and tweaks LLVM's symbol record emission to align symbol records.
Here's how things compare when doing a plain clang Release+PDB build:
- objs are 0.65% bigger (negligible)
- link is 3.3% faster (negligible)
- saves allocating 441MB
- new LLD high water mark is ~1.05GB

llvm-svn: 349431
2018-12-18 01:14:05 +00:00
Peter Collingbourne 4ca86d289f ELF: AArch64: Fix errata patch address calculation.
The code here wants the output section offset of the instruction
requiring the errata patch, not the virtual address. Without this
change we can end up placing a patch out of range if the virtual
address of the code section is large enough.

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

llvm-svn: 349386
2018-12-17 20:15:12 +00:00
Peter Smith 6ece0ad429 [ELF][ARM] Add support for architecture v6m thunks
ARM Architecture v6m is used by the smallest microcontrollers such as the
cortex-m0. It is Thumb only (no Thumb 2) which prevents it from using the
existing Thumb 2 range extension thunks as these use the Thumb 2 movt/movw
instructions. Range extension thunks are not usually needed for
microcontrollers due to the small amount of flash and ram on the device,
however if code is copied from flash into ram then a range extension thunk
is required to call that code.

This change adds support for v6m range extension thunks. The procedure call
standard APCS permits a thunk to corrupt the intra-procedural scratch
register r12 (referred to as ip in the APCS). Most Thumb instructions do
not permit access to high registers (r8 - r15) so the thunks must spill
some low registers (r0 - r7) to perform the control transfer.

Fixes pr39922

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

llvm-svn: 349337
2018-12-17 10:33:47 +00:00
Peter Collingbourne ae15e7232a ELF: Handle R_ARM_V4BX correctly in PIC output files.
Previously we considered R_ARM_V4BX to be an absolute relocation,
which meant that we rejected it in read-only sections in PIC output
files. Instead, treat it as a hint relocation so that relocation
processing ignores it entirely.

Also fix a problem with the test case where it was never being run
because it has a .yaml extension and we don't run tests with that
extension.

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

llvm-svn: 349216
2018-12-15 00:20:17 +00:00
Michal Gorny fbed4e1dcf [test] Capture stderr from 'tar --version' call as well
Capture the stderr from 'tar --version' call as otherwise error messages
spill onto user's terminal unnecessarily (e.g. on NetBSD where tar does
not support long options).  While at it, refactor the code to use
communicate() instead of reinventing the wheel.

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

llvm-svn: 349204
2018-12-14 22:38:01 +00:00
Rui Ueyama 9f49990976 Add --plugin-opt=emit-llvm option.
`--plugin-opt=emit-llvm` is an option for LTO. It makes the linker to
combine all bitcode files and write the result to an output file without
doing codegen. Gold LTO plugin has this option.

This option is being used for some post-link code analysis tools that
have to see a whole program but don't need to see them in the native
machine code.

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

llvm-svn: 349198
2018-12-14 21:58:49 +00:00
Zachary Turner a05ae9db01 Correctly handle skewed streams in drop_front() method.
When calling BinaryStreamArray::drop_front(), if the stream
is skewed it means we must never drop the first bytes of the
stream since offsets which occur in records assume the existence
of those bytes.  So if we want to skip the first record in a
stream, then what we really want to do is just set the begin
pointer to the next record.  But we shouldn't actually remove
those bytes from the underlying view of the data.

llvm-svn: 349066
2018-12-13 18:11:33 +00:00
Peter Smith fe3015d164 [ELF][AArch64] Fix adrp to undefined weak reference.
In the ABI for the 64-bit Arm architecture the section on weak references
states:
During linking, the symbol value of an undefined weak reference is:
- Zero if the relocation type is absolute
- The address of the place if the relocation type is pc-relative.

The relocations associated with an ADRP are relative so we should resolve
the undefined weak reference to the place instead of 0. This matches GNU
ld.bfd behaviour.

fixes pr34928

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

llvm-svn: 349024
2018-12-13 11:13:01 +00:00
Sam Clegg e01c646dda [WebAssembly] Add "needed" list to dylink section
Differential Revision: https://reviews.llvm.org/D55613

llvm-svn: 348990
2018-12-12 23:44:59 +00:00
David Blaikie 84addb9037 Update for an llvm-dwarfdump change in output
llvm-svn: 348955
2018-12-12 18:46:43 +00:00
George Rimar 1f958ed269 [LLD][ELF] - Support discarding the .dynamic section.
This is a part of https://bugs.llvm.org/show_bug.cgi?id=39810.

Seems it turns out that supporting /DISCARD/ for the .dynamic section with the
linker script is something we can do easily. The patch does this.

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

llvm-svn: 348749
2018-12-10 09:24:49 +00:00
George Rimar ad667661c4 [ELF] - Allow discarding .dynsym from the linker script.
This is a part of https://bugs.llvm.org/show_bug.cgi?id=39810.
The patch allows discarding the .dynsym section using linker script.

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

llvm-svn: 348748
2018-12-10 09:13:36 +00:00
George Rimar 4af28e46ca [LLD][ELF] - Support discarding .dynstr section.
This is a part of https://bugs.llvm.org/show_bug.cgi?id=39810.
The patch allows discarding the .dynstr section using linker script.

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

llvm-svn: 348746
2018-12-10 09:07:30 +00:00
Heejin Ahn e915a71f18 [WebAssembly] Add support for the event section
Summary:
This adds support for the 'event section' specified in the exception
handling proposal.

Wasm exception handling binary model spec:
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model

Reviewers: sbc100, ruiu

Subscribers: dschuff, jgravelle-google, sunfish, llvm-commits

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

llvm-svn: 348703
2018-12-08 06:17:43 +00:00
Heejin Ahn 31975f601f clang-format LLVM.h (NFC)
Summary:
- LLVM style does not indent inside namespaces
- Alphabetize

Reviewers: ruiu

Subscribers: sbc100, llvm-commits

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

llvm-svn: 348652
2018-12-07 21:48:38 +00:00
Michal Gorny 80c32f05a7 [test] Fix reproduce-blackslash.s test with NetBSD tar
Unlike GNU tar and libarchive bsdtar, NetBSD 'tar -t' output does not
use C-style escapes and instead outputs paths literally.  Fix the test
to account both for escaped and literal backslash output.

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

llvm-svn: 348628
2018-12-07 18:57:09 +00:00
Michal Gorny 92dc7dce4a [test] Mark atime-based tests unsupported on NetBSD
Mark tests requiring 'touch' to set atime unsupported on NetBSD
due to kernel limitation preventing it from working with noatime.

llvm-svn: 348607
2018-12-07 16:21:08 +00:00
Zachary Turner a93458b050 [PDB] Move some code around. NFC.
llvm-svn: 348505
2018-12-06 17:49:15 +00:00
George Rimar e1fd3f940b [LLD][ELF] - Use auto. NFC.
This addresses the missed review comment.

llvm-svn: 348480
2018-12-06 10:56:11 +00:00
George Rimar b3be390f94 [ELF] - (-Map file) Implement printing of LMA for assignments outside of section declarations.
This was a missing piece.
We started to print LMAs and information about assignments,
but did not do that for assignments outside of section declarations yet.
The patch implements it.

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

llvm-svn: 348468
2018-12-06 09:04:52 +00:00
Diana Picus 35b7e12e66 Fixup r348306: Require x86 for test
The test breaks on buildbots that don't enable the x86 backend. Other
tests in this directory explicitly require x86, so this should do the
trick.

llvm-svn: 348466
2018-12-06 08:54:17 +00:00
George Rimar f49fe218c2 [LLD][ELF] - Linker script: accept using a file name without a list of sections.
This is a part of
https://bugs.llvm.org/show_bug.cgi?id=39885

Linker script specification says:
"You can specify a file name to include sections from a particular file. You would
do this if one or more of your files contain special data that needs to be at a
particular location in memory."

LLD did not accept this syntax. The patch implements it.

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

llvm-svn: 348463
2018-12-06 08:34:52 +00:00
Rui Ueyama c9c34bdc1a Do not use a hash table to uniquify mergeable strings.
Previously, we have a hash table containing strings and their offsets
to manage mergeable strings. Technically we can live without that, because
we can do binary search on a vector of mergeable strings to find a mergeable
strings.

We did have both the hash table and the binary search because we thought
that that is faster.

We recently observed that lld tend to consume more memory than gold when
building an output with debug info. A few percent of memory is consumed by
the hash table. So, we needed to reevaluate whether or not having the extra
hash table is a good CPU/memory tradeoff. I run a few benchmarks with and
without the hash table.

I got a mixed result for the benchmark. We observed a regression for some
programs by removing the hash table (that's what we expected), but we also
observed that performance imrpovements for some programs. This is perhaps
due to reduced memory usage.

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

llvm-svn: 348401
2018-12-05 19:13:31 +00:00
Fangrui Song 01fbb06b12 [ELF] Simplify getSectionPiece
Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: grimar, emaste, arichardson, llvm-commits

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

llvm-svn: 348311
2018-12-04 22:25:05 +00:00
Zachary Turner 7c6b19f49b [PDB] Emit S_UDT records in LLD.
Previously these were dropped.  We now understand them sufficiently
well to start emitting them.  From the debugger's perspective, this
now enables us to have debug info about typedefs (both global and
function-locally scoped)

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

llvm-svn: 348306
2018-12-04 21:48:46 +00:00
Rui Ueyama e84f14ee39 Remove unreachable code.
llvm-svn: 348294
2018-12-04 19:00:56 +00:00
Rui Ueyama a592aeb35a ELF: allow non allocated sections to go into allocated sections
Patch from Andrew Kelley.

For context, see https://bugs.llvm.org/show_bug.cgi?id=39862

The use case is embedded / OS programming where the kernel wants
access to its own debug info via mapped dwarf info. I have a proof of
concept of this working, using this linker script snippet:

  .rodata : ALIGN(4K) {
    *(.rodata)
    __debug_info_start = .;
    KEEP(*(.debug_info))
    __debug_info_end = .;
    __debug_abbrev_start = .;
    KEEP(*(.debug_abbrev))
    __debug_abbrev_end = .;
    __debug_str_start = .;
    KEEP(*(.debug_str))
    __debug_str_end = .;
    __debug_line_start = .;
    KEEP(*(.debug_line))
    __debug_line_end =
    .;
    __debug_ranges_start
    = .;
    KEEP(*(.debug_ranges))
    __debug_ranges_end
    = .;
  }

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

llvm-svn: 348291
2018-12-04 18:47:44 +00:00
Martell Malone 15b6c453b8 [ELF] Allow discarding of .rela.plt
When linking the linux kernel on ppc64le

ld.lld -EL -m elf64lppc -Bstatic --orphan-handling=warn --build-id -o
.tmp_vmlinux1 -T ./arch/powerpc/kernel/vmlinux.lds --whole-archive
built-in.a --no-whole-archive --start-group lib/lib.a --end-group
ld.lld: error: discarding .rela.plt section is not allowed

The linker script discards with the following matches
*(.glink .iplt .plt .rela* .comment)

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

llvm-svn: 348258
2018-12-04 12:37:56 +00:00
Martell Malone aa6086a64c [PPC][PPC64] PPC_REL14 and PPC64_REL14 relocations
When linking the linux kernel on ppc64 and ppc
ld.lld: error: unrecognized reloc 11
11 is PPC_REL14 and PPC64_REL14

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

llvm-svn: 348255
2018-12-04 12:26:21 +00:00
Sam Clegg 748f59caef [WebAssembly] Don't set a maximum size when importing the table
We shouldn't be setting setting a max size for a table that is
being imported.

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

llvm-svn: 348204
2018-12-03 22:37:55 +00:00
Rui Ueyama 3b6cd2c602 Show a proper error message if output file is too large.
At least on Linux, if a file size given to FileOutputBuffer is greater
than 2^63, it fails with "Invalid argument" error, which is not a
user-friendly error message. With this patch, lld prints out "output
file too large" instead.

llvm-svn: 348153
2018-12-03 17:42:57 +00:00
George Rimar 89230f7bc2 [LLD][ELF] - Remove the excessive condition. NFC.
There is no need to check that In.DynSymTab != nullptr,
because `includeInDynsym` already checks for `!Config->HasDynSymTab`
and `HasDynSymTab` is the pre-condition for In.DynSymTab creation.

llvm-svn: 348143
2018-12-03 14:44:02 +00:00
George Rimar c2bea66cf2 [LLD][ELF] - Improve the DWARF v5 suport for building .gdb_index.
Now LLD might build the broken/incomplete .gdb_index when some DWARF v5
sections (like .debug_rnglists and .debug_addr) are used.

Particularly, for the case above, we emit an empty address area. 
A test case is provided and patch fixes the issue.

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

llvm-svn: 348119
2018-12-03 10:48:57 +00:00
Rui Ueyama aea706083f Inline a function template that is used only once. NFC.
llvm-svn: 348013
2018-11-30 18:19:15 +00:00
Alexandre Ganea 66894975b2 [PDB] Quote linker arguments containing spaces (mimic MSVC)
Initial patch by Will Wilson (@lantictac)

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

llvm-svn: 348001
2018-11-30 16:36:40 +00:00
Rui Ueyama c310742dc3 Do not assume .idata is zero-initialized.
We initialize .text section with 0xcc (INT3 instruction), so we need to
explicitly write data even if it is zero if it can be in a .text section.
If you specify /merge:.rdata=.text, .rdata (which contains .idata) is put
to .text, so we need to do this.

Fixes https://bugs.llvm.org/show_bug.cgi?id=39826

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

llvm-svn: 348000
2018-11-30 16:34:56 +00:00
Sam Clegg 0f90191faa [WebAssembly] Allow undefined symbols when building shared libraries
Differential Revision: https://reviews.llvm.org/D55043

llvm-svn: 347909
2018-11-29 20:07:13 +00:00
Peter Smith fd8aeb2c2a [LLD][ELF] Error if _GLOBAL_OFFSET_TABLE_ is defined in input objects
The _GLOBAL_OFFSET_TABLE_ is a linker defined symbol that is placed at
some location relative to the .got, .got.plt or .toc section. On some
targets such as Arm the correctness of some code sequences using a
relocation to _GLOBAL_OFFSET_TABLE_ depend on the value of the symbol
being in the linker defined place. Follow the ld.gold example and give
a multiple symbol definition error. The ld.bfd behaviour is to ignore the
definition in the input object and redefine it, which seems like it could
be more surprising.

fixes pr39587

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

llvm-svn: 347854
2018-11-29 11:18:07 +00:00