Commit Graph

3972 Commits

Author SHA1 Message Date
Rafael Espindola b5153ef7e8 Don't assume that size relocations are always constant.
llvm-svn: 321688
2018-01-03 03:58:58 +00:00
Rafael Espindola 4b2350d79b Produce relocations with weak undef if the section is RW.
If a section is RW there is no reason to drop a relocation with a weak
undefined symbol.

llvm-svn: 321684
2018-01-03 01:24:58 +00:00
Rafael Espindola 2640a0a5e5 Align SHT_NOBITS sections is they are the first on a PT_LOAD.
We normally want to ignore SHT_NOBITS sections when computing
offsets. The sh_offset of section itself seems to be irrelevant and

- If the section is in the middle of a PT_LOAD, it will make no
  difference on the computed offset of the followup section.

- If it is in the end of a PT_LOAD, we want to avoid its alignment
  changing the offset of the followup sections.

The issue is if it is at the start of the PT_LOAD. In that case we do
have to align it so that the following sections have congruent address
and offset module the page size. We were not handling this case.

This should fix freebsd kernel link.

llvm-svn: 321657
2018-01-02 16:46:30 +00:00
George Rimar edb61167e5 [ELF] - Add missing dynamic tags when producing output with IRelative relocations only.
This is "Bug 35751 - .dynamic relocation entries omitted if output
contains only IFUNC relocations"

We have InX::RelaPlt and InX::RelaIPlt synthetic sections for PLT relocations.
They are usually live in rela.plt section. Problem appears when InX::RelaPlt
section is empty. In that case we did not produce normal set of dynamic tags
required, because logic was written in the way assuming we always have
non-IRelative relocations in rela.plt.

Patch fixes the issue.

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

llvm-svn: 321600
2017-12-31 07:42:54 +00:00
Shoaib Meenai 0c958fba14 [ELF] Only scan executables for shlib undefined symbols
If using a version script with a `local: *` in it, symbols in shared
libraries will still get default visibility if another shared library on
the link line has an undefined reference to the symbol. This is quite
surprising. Neither bfd nor gold have this behavior when linking a
shared library, and none of LLD's tests fail without this behavior, so
it seems safe to limit scanShlibUndefined to executables.

As far as executables are concerned, gold doesn't do any automatic
default visibility marking, and bfd issues a link error about a shared
library having a reference to a hidden symbol rather than silently
giving that symbol default visibility. I think bfd's behavior here is
preferable to LLD's, but that's something to be considered in a
follow-up.

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

llvm-svn: 321578
2017-12-30 08:00:44 +00:00
Benjamin Kramer 61085ca999 Update lld tests after r321526.
llvm-svn: 321529
2017-12-28 17:20:41 +00:00
Bob Haarman e90ac016e7 [COFF] support /ignore:4217
Summary:
lld-link accepts link.exe's /ignore option, but used to ignore
it. This can lead to semantic differences when warnings are treated as
fatal errors. One such case is when we resolve an __imp_ symbol to a
local definition. We emit a warning in that case, which /wx turns into
a fatal. This change makes lld-link accept /ignore:4217 to suppress
that warning, so that code that links with link.exe /wx /ignore:4217
links with lld-link, too.

Fixes PR35762.

Reviewers: rnk, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

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

llvm-svn: 321512
2017-12-28 07:02:13 +00:00
Rafael Espindola 465e7c94ed Allow copy relocation with -z notext.
This makes adjustExpr a bit simpler too IMHO.

It seems that some of the complication around relocation processing
is that we are trying to create copy relocations too early. It seems
we could handle a few simple cases first and continue.

llvm-svn: 321507
2017-12-28 00:23:49 +00:00
Rafael Espindola e2e070c6c4 Don't try to preempt protected symbols with -z notext.
I will send a followup patch removing the FIXME this patch adds.

llvm-svn: 321499
2017-12-27 20:53:13 +00:00
George Rimar a0ab8d7a58 [ELF] - Allow relocation to a weak undefined symbol when -z notext is given.
Previously we failed to resolve them when produced executables:
"relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC"

Patch fixes it so that we resolve them to 0 for executables. 
And for -shared case we still should produce the relocation.

This finishes fixing PR35720.

DIfferential revision: https://reviews.llvm.org/D41551

llvm-svn: 321473
2017-12-27 07:29:55 +00:00
Rafael Espindola a9c490b71d Allow relocations in rw sections to create plt entries.
If a relocation cannot be implemented by the dynamic linker and the
section is rw, allow creating a plt entry to use as the function
address as if the section was ro.

This matches bfd and gold. It also matches our behavior with -z
notext.

llvm-svn: 321430
2017-12-24 19:02:10 +00:00
Rafael Espindola 6a97f80755 Fix output section offset and contents when linker script uses memory region and data commands.
Advance the memory region offset when handling a linker script data
command such as BYTE or LONG.  Failure to advance the offset results
in corrupted output with overlapping sections.

Update tests to check for this combination of both a) memory regions
and b) data commands.

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

Patch by Owen Shaw!

llvm-svn: 321418
2017-12-24 03:46:35 +00:00
George Rimar 3bdf6baa25 [ELF] - Allow using PLT relocations when "-z notext" is given.
This is part of PR35720.

Currently LLD allows dynamic relocations against text when -z notext is given.
Though for non-PIC relocations like R_X86_64_PC32 that does not work,
we produce "relocation R_X86_64_PC32 cannot be used against shared object;"
error because they may overflow in runtime.

Solution implemented is to use PLT for them.

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

llvm-svn: 321400
2017-12-23 09:00:37 +00:00
Rafael Espindola 9cbb6dd1fc Result of subtracting two symbols should be absolute.
When two linker script symbols are subtracted, the result should be absolute.

This is the behavior of binutils' ld.

Patch by Erick Reyes!

llvm-svn: 321390
2017-12-22 21:55:28 +00:00
Sam Clegg 5cfffbc875 [WebAssembly] Increase test coverage for weak aliases
LLVM-side is now fixed

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

llvm-svn: 321385
2017-12-22 20:35:19 +00:00
Sam Clegg 86109f63c8 [WebAssembly] Add extra test for weak global symbols
Summary:
Currently the test only checks behaviour for weak function symbols.

Should be good to merge straight away?

Reviewers: sbc100

Reviewed By: sbc100

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

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

llvm-svn: 321308
2017-12-21 21:15:00 +00:00
Sam Clegg 1cf31bbca5 [WebAssmebly] Fix references to weak aliases
Corresponding LLVM change: https://reviews.llvm.org/D41472

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

llvm-svn: 321244
2017-12-21 02:43:39 +00:00
Sam Clegg c6e4d73f31 [WebAssembly] Improve weak alias tests cases
Based on: https://github.com/WebAssembly/tool-conventions/issues/34

Currently weak-alias-overide.ll exhibits incorrect
behaviour in that call_direct() calls the wrong function.

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

llvm-svn: 321241
2017-12-21 02:30:09 +00:00
Igor Kudrin 5966d15943 [ELF] Fix an assignment command at the end of an .ARM.exidx section.
The value of the symbol in the assignment should include the sentinel entry.

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

llvm-svn: 321154
2017-12-20 08:56:10 +00:00
Martin Storsjo 6528fb8691 [COFF] Don't set the thumb bit in address table entries for data symbols
The thumb bit should only be set for executable code.

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

llvm-svn: 321149
2017-12-20 06:50:45 +00:00
Sam Clegg 7075d3fc1c [WebAssembly] Add test of indirect call to an otherwise unused type
In this case we are calling a function pointer which
a type that doesn't otherwise exist in the code.
Clearly this code can't would trap if it was ever
called (because there is not such function that
the pointer can resolve to).

But it should valid and compile and link and validation
time.

llvm-svn: 321134
2017-12-20 01:17:45 +00:00
Sam Clegg 0d0dd39159 [WebAssembly] Add support for writing out init functions in linking section
This change add support for init functions in the linking
section, but only in -r/--relocatable mode.

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

llvm-svn: 321088
2017-12-19 17:09:45 +00:00
Rafael Espindola 4e125de4a6 Use # instead of // for comments in a test.
The test was using both // and # before.

llvm-svn: 321049
2017-12-19 00:53:06 +00:00
Sam Clegg bd0416d0c0 [WebAssemlby] Fix typo in target triple used in tests
llvm-svn: 321044
2017-12-19 00:18:16 +00:00
Craig Topper 9dbd6cc823 Adjust test to account for llvm change where an empty CPU string will no longer generate a long nop on x86.
Long nops aren't supported by all x86 CPUs. So if no CPU is specified we have to use a single byte nop.

llvm-svn: 321040
2017-12-18 23:32:18 +00:00
Rafael Espindola 4c74feffd4 Don't write preemptible symbol values to the .got.
It is not necessary and matches what bfd and gold do.

This was a regression from r315658.

llvm-svn: 321023
2017-12-18 20:35:15 +00:00
Rafael Espindola dfe160bcd2 Add another test.
This also changed in r315658. The new result is the correct one.

llvm-svn: 321021
2017-12-18 20:29:00 +00:00
Dimitry Andric e4f5d01033 Fix more inconsistent line endings. NFC.
llvm-svn: 321016
2017-12-18 19:46:56 +00:00
Rafael Espindola 6c0858e414 Add a test.
This changed in r315658, but it was missing a test.

llvm-svn: 320995
2017-12-18 17:36:28 +00:00
Peter Smith 3c73a41128 [ELF] Optimize Arm PLT sequences
A more efficient PLT sequence can be used when the distance between the
.plt and the end of the .plt.got is less than 128 Megabytes, which is
frequently true. We fall back to the old sequence when the offset is larger
than 128 Megabytes. This gives us an alternative to forcing the longer
entries with --long-plt as we gracefully fall back to it as needed. 

See ELF for the ARM Architecture Appendix A for details of the PLT sequence.

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

llvm-svn: 320987
2017-12-18 14:46:27 +00:00
Vitaly Buka a5376f393e [LTO] Make processing of combined module more consistent
Summary:
1. Use stream 0 only for combined module. Previously if combined module was not
processes ThinLTO used the stream for own output. However small changes in input,
could trigger combined module  and shuffle outputs making life of llvm::LTO harder.

2. Always process combined module and write output to stream 0. Processing empty
combined module is cheap and allows llvm::LTO users to avoid implementing processing
which is already done in llvm::LTO.

Subscribers: mehdi_amini, inglorion, eraman, hiraditya

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

llvm-svn: 320905
2017-12-16 02:10:00 +00:00
Shoaib Meenai a1f6fba4d1 [COFF] Clean up debug option handling
/debug and /debug:dwarf are orthogonal. An object file can contain both
CodeView and DWARF debug info, so the combination of /debug:dwarf and
/debug should generate both DWARF and a PDB, rather than /debug:dwarf
always suppressing PDB creation.

/nopdb is now redundant and can be removed. /debug /nopdb was previously
used to support DWARF, but specifying /debug:dwarf is entirely
equivalent to that combination now.

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

llvm-svn: 320896
2017-12-16 00:23:24 +00:00
Sam Clegg c018115480 [WebAssembly] Don't include lazy symbols in import table
This bug was introduced in: https://reviews.llvm.org/D41304.
Add a test for this case.

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

llvm-svn: 320872
2017-12-15 22:17:15 +00:00
Martin Storsjo a1e9b6e3d2 [COFF] Set the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag automatically
This seems to match how link.exe sets it.

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

llvm-svn: 320860
2017-12-15 20:53:03 +00:00
Peter Smith cbc9bb9ffd [ELF] Reduce size of ELF file produced by test
We only need to exceed 128 Megabytes to provoke the generation of a range
extension thunk. This brings the file size down to just over 128 Megabytes.

llvm-svn: 320821
2017-12-15 15:30:00 +00:00
Rafael Espindola 9b332d997f Delete a really large test output.
llvm-svn: 320818
2017-12-15 14:56:01 +00:00
Rafael Espindola 75ebe9a3bf Handle a VersymIndex of 0 as an error.
I noticed that the continue this patch deletes was not tested. Trying
to add a test I realized that we never put a VER_NDX_LOCAL symbol in
the dynamic symbol table. There doesn't seem to be any reason for a
linker to use VER_NDX_LOCAL for a defined shared symbol.

llvm-svn: 320817
2017-12-15 14:52:40 +00:00
Peter Smith 96ca4f5e91 [ELF] Remove Duplicate .ARM.exidx sections
The ARM.exidx section contains a table of 8-byte entries with the first
word of each entry an offset to the function it describes and the second
word instructions for unwinding if an exception is thrown from that
function. The SHF_LINK_ORDER processing will order the table in ascending
order of the functions described by the exception table entries. As the
address range of an exception table entry is terminated by the next table
entry, it is possible to merge consecutive table entries that have
identical unwind instructions.

For this implementation we define a table entry to be identical if:
- Both entries are the special EXIDX_CANTUNWIND.
- Both entries have the same inline unwind instructions.
We do not attempt to establish if table entries that are references to
.ARM.extab sections are identical.

This implementation works at a granularity of a single .ARM.exidx
InputSection. If all entries in the InputSection are identical to the
previous table entry we can remove the InputSection. A more sophisticated
but more complex implementation would rewrite InputSection contents so that
duplicates within a .ARM.exidx InputSection can be merged.

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

llvm-svn: 320803
2017-12-15 11:09:41 +00:00
Peter Smith f60cdce087 [ELF] Add missing test from r320800
Forgot to svn add the additional test for the commit. Adding with this one.

llvm-svn: 320802
2017-12-15 11:02:50 +00:00
Peter Smith cf354873c1 [ELF] Complete implementation of --fix-cortex-a53-843419
This patch provides the mechanism to fix instances of the instruction
sequence that may trigger the cortex-a53 843419 erratum. The fix is
provided by an alternative instruction sequence to remove one of the
erratum conditions. To reach this alternative instruction sequence we
replace the original instruction with a branch to the alternative
sequence. The alternative sequence is responsible for branching back to
the original.

As there is only erratum to fix the implementation is specific to
AArch64 and the specific erratum conditions. It should be generalizable
to other targets and erratum if needed.

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

llvm-svn: 320800
2017-12-15 10:32:34 +00:00
Shoaib Meenai ed46ccbb7a Repair Windows buildbots after r320792
Windows paths have colons in them, so the regex will fail there. Just
match for any character; the rest of the message will restrict the match
to the path anyway.

llvm-svn: 320793
2017-12-15 08:08:26 +00:00
Shoaib Meenai d0bd40294d [COFF] Warn for locally imported symbols
Locally imported symbols are a very surprising linker feature. link.exe
warns for them, and we should warn too.

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

llvm-svn: 320792
2017-12-15 07:49:21 +00:00
Rui Ueyama 476a73924e Do not create an unnecessary object file in a test.
llvm-svn: 320773
2017-12-15 00:17:04 +00:00
Rui Ueyama 29ceba7961 Fix error messages.
llvm-svn: 320772
2017-12-15 00:07:15 +00:00
Rui Ueyama fbe68a3584 Use warn() instead of error() to report a bad symbol in a DSO.
Specifically, libwidevinecdm.so in Chrome has such bad symbol.
It seems the BFD linker handles them as local symbols, so instead
of inserting them to the symbol table, we should skip them too.

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

llvm-svn: 320770
2017-12-15 00:01:33 +00:00
Zachary Turner 0d07a8e948 [COFF] Teach LLD to use the COFF .debug$H section.
This adds the /DEBUG:GHASH option to LLD which will look for
the existence of .debug$H sections in linker inputs and use them
to accelerate type merging.  The clang-cl side has already been
added, so this completes the work necessary to begin experimenting
with this feature.

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

llvm-svn: 320719
2017-12-14 18:07:04 +00:00
Martin Storsjo 94d72b89d6 [COFF] Error out if 20 bit thumb branches are out of range
This is similar to what was added in SVN r277838 for 24 bit
branch instructions.

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

llvm-svn: 320677
2017-12-14 08:56:36 +00:00
Martin Storsjo 9603b8e3f5 [COFF] Sort .pdata for arm64
This works for linking the output from the MSVC compiler.
The pdata entries for arm64 seem to be 8 bytes in the same
(or at least similar) form to arm.

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

llvm-svn: 320676
2017-12-14 08:56:29 +00:00
Igor Kudrin f01caab4b7 [ELF] Prevent crash in writing an .ARM.exidx sentinel entry.
We might crash in 'ARMExidxSentinelSection::writeTo()' because it expected
the sentinel entry to be put in the same 'InputSectionDescription' as
the last real entry. This assumption fails if the last output section command
for .ARM.exidx is anything but an input section description, because in this
case 'OutputSection::addSection()' creates a new 'InputSectionDescription'.

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

llvm-svn: 320668
2017-12-14 06:23:50 +00:00
Rafael Espindola b308cace84 Fix crash on invalid.
We would fail an assert if a shared library had a local symbol after
sh_info.

llvm-svn: 320667
2017-12-14 05:01:49 +00:00