Commit Graph

11293 Commits

Author SHA1 Message Date
Alexandre Ganea 149de8de19 [LLD][COFF] Fix ordering of CRT global initializers in COMDAT sections
(patch by Benoit Rousseau)

This patch fixes a bug where the global variable initializers were sometimes not invoked in the correct order when it involved a C++ template instantiation.

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

llvm-svn: 343847
2018-10-05 12:56:46 +00:00
Ed Maste bf378b808a ReleaseNotes: remove superfluous 's' in 'can promotes'
llvm-svn: 343820
2018-10-04 21:37:32 +00:00
Sid Manning 261eec5fa5 [ELF][HEXAGON] Add support for GOT relocations.
The GOT is referenced through the symbol _GLOBAL_OFFSET_TABLE_ .

The relocation added calculates the offset into the global offset table for
the entry of a symbol.  In order to get the correct TargetVA I needed to
create an new relocation expression, HEXAGON_GOT.  It does
Sym.getGotVA() - In.GotPlt->getVA().

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

llvm-svn: 343784
2018-10-04 14:54:17 +00:00
George Rimar f76dffb90f [ELF] - Simplify. NFCI.
Assign the `Link` to parent directly.

llvm-svn: 343762
2018-10-04 09:31:15 +00:00
Matt Morehouse 8d53ab5e7a Use std::make_pair rather than brace initialization.
r343732 broke the Windows bot.  Seems like the compiler on that bot
doesn't like brace initialization.

llvm-svn: 343749
2018-10-04 00:35:24 +00:00
Shoaib Meenai 509230f68d [ELF] Fix typo. NFC
llvm-svn: 343748
2018-10-04 00:07:59 +00:00
Shoaib Meenai 6883d882f1 [ELF] Fix crash on invalid undefined local symbols
r320770 made LLD handle invalid DSOs where local symbols were found in
the global part of the symbol table. Unfortunately, it didn't handle the
case where those local symbols were also undefined, and r326242 exposed
an assertion failure in that case. Just warn on that case instead of
crashing, by moving the local binding check before the undefined symbol
addition.

The input file for the test is crafted by hand, since I don't know of
any tool that would produce such a broken DSO. I also don't understand
what it even means for a symbol to be undefined but have STB_LOCAL
binding - I don't think that combination makes any sense - but we have
found broken DSOs of this nature that we were linking against. I've
included detailed instructions on how to produce the DSO in the test.

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

llvm-svn: 343745
2018-10-03 23:53:11 +00:00
Jordan Rupprecht dd0f98972d [llvm-nm] Update lld tests based on changed llvm-nm output
llvm-svn: 343743
2018-10-03 23:39:59 +00:00
Derek Schuff 371842b853 [WebAssembly] Refactor use of signatures
Update use of WebAssemblySignature to go along with D52580

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

llvm-svn: 343734
2018-10-03 22:25:32 +00:00
Rui Ueyama 3ed33eade0 Minor refacotring of Relocations.cpp. NFC.
This patch splits ThunkCreator::mergeThunks into two smaller functions.
Also adds blank lines to various places so that the code doesn't look
too dense.

llvm-svn: 343732
2018-10-03 22:20:26 +00:00
Sean Fertile 98da20f0fb [PPC64] Test documenting toc-restore after interposable recursive call. [NFC]
A test verifying that toc restores are properly inserted following recursive
calls, as well as briefly describing why they are needed.

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

llvm-svn: 343729
2018-10-03 21:58:44 +00:00
Sean Fertile 7cbe41f2c7 [PPC64] Add test documenting toc-restore when linking with -Bsymbolic. [NFC]
Differential Revision: https://reviews.llvm.org/D52523

llvm-svn: 343728
2018-10-03 21:58:42 +00:00
Martin Storsjo 2657200274 [COFF] Cope with weak aliases produced by GNU tools
When GNU tools create a weak alias, they produce a strong symbol
named .weak.<weaksymbol>.<relatedstrongsymbol>.

GNU ld allows many such weak alternatives for the same weak symbol, and
the linker picks the first one encountered.

This can't be reproduced by assembling from .s files, since llvm-mc
produces symbols named .weak.<weaksymbol>.default in these cases.

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

llvm-svn: 343704
2018-10-03 18:31:53 +00:00
Nico Weber d377826277 lld-link: Several tweaks to default entry point selection.
Three related changes:

1. link.exe uses the presence of main and wmain to decide if it should call
   mainCRTStartup or wmainCRTStartup, even if /nodefaultlib is passed. For
   compatibility, remove FindMain logic.

2. Default to the non-wide entrypoint if main is not found. This has two effects:

2a. In normal links, lld-link now prints

        lld-link: error: undefined symbol: _main
        >>> referenced by f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:78
        >>>               libcmt.lib(exe_main.obj):("int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ))
        >>> referenced by f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
        >>>               libcmt.lib(exe_main.obj):("int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ))

    instead of

        lld-link: error: entry point must be defined

    This is arguably a better error message, since it now mentions that _main is
    missing. (This matches link.exe's diagnostic in this case.)

2b. With /nodefautlib, we now default to mainCRTStartup if no main() is
    present, again matching link.exe. This makes r337407 obsolete.

This means if you have a cc file containing both mainCRTStartup and
wmainCRTStartup and you pass /nodefaultlib /subsystem:console, lld-link will
now call mainCRTStartup, matching link.exe

3. Print a warning if both main and wmain are present, similar to link.exe's
   LNK4067.

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

llvm-svn: 343698
2018-10-03 17:01:39 +00:00
George Rimar db2e641fd7 [ELF] - Fix BB after r343668
This stops testing the value of .rela.plt section offset.

Also makes _start global to eliminate
'cannot find entry symbol _start' warning.

llvm-svn: 343669
2018-10-03 09:59:08 +00:00
George Rimar f79a8ef2ae [ELF] - Do not forget to include to .dymsym symbols that were converted to Defined.
This is the fix for
"Bug 39104 - LLD links incorrect ELF executable if version script contains "local: *;"
(https://bugs.llvm.org/show_bug.cgi?id=39104).

The issue happens when we have non-PIC program call to function in a shared library.
(for example, the PR above has R_X86_64_PC32 relocation against __libc_start_main)

LLD converts symbol to Defined in that case with the use of replaceWithDefined()

The issue is that after above we create a broken relocation because do not
include the symbol into .dynsym.

That happens when the version script is used because we treat the symbol as
STB_LOCAL if the following condition match:
VersionId == VER_NDX_LOCAL && isDefined() and do not include it to
.dynsym because of that. Patch fixes the issue.

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

llvm-svn: 343668
2018-10-03 09:33:00 +00:00
George Rimar 3832d7c25d [LLD] - Do not crash when reporting errors when .debug_line_str (DWARF5) is used
Imagine we have the following code:

int foo();
int main() { return foo(); }

It will crash if you try to compile it with
`clang -O0 -gdwarf-5 test.cpp -o test -g -fuse-ld=lld`

The crash happens inside the LLVM DWARF parser because LLD does not provide
the .debug_line_str section. At the same time for correct parsing and reporting,
we anyways need to provide this section from our side.

The patch fixes the issue.

llvm-svn: 343667
2018-10-03 08:59:46 +00:00
Ali Tamur 63830b2794 Introduce a flag to warn when ifunc symbols are used with text relocations.
Summary:
This patch adds a new flag, --warn-ifunc-textrel, to work around a glibc bug. When a code with ifunc symbols is used to produce an object file with text relocations, lld always succeeds. However, if that object file is linked using an old version of glibc, the resultant binary just crashes with segmentation fault when it is run (The bug is going to be corrected as of glibc 2.19).

Since there is no way to tell beforehand what library the object file will be linked against in the future, there does not seem to be a fool-proof way for lld to give an error only in cases where the binary will crash. So, with this change (dated 2018-09-25), lld starts to give a warning, contingent on a new command line flag that does not have a gnu counter part. The default value for --warn-ifunc-textrel is false, so lld behaviour will not change unless the user explicitly asks lld to give a warning. Users that link with a glibc library with version 2.19 or newer, or does not use ifunc symbols, or does not generate object files with text relocations do not need to take any action. Other users may consider to start passing warn-ifunc-textrel to lld to get early warnings.

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: grimar, MaskRay, markj, emaste, arichardson, llvm-commits

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

llvm-svn: 343628
2018-10-02 20:30:22 +00:00
Diogo N. Sampaio a35e55eff9 [NFC][BUG-FIX][ARM] Add missing data symbol
llvm rL343594: [ARM] Emmit data symbol
for constant pool data fixed a bug that ommited
required data symbols.
Such change breaked a test case in lld:
test/ELF/arm-thunk-largesection.s

llvm-svn: 343604
2018-10-02 16:53:12 +00:00
Michael J. Spencer 8222f902ca [ELF] Read the call graph profile from object files.
This uses the call graph profile embedded in the object files to construct the call graph.

This is read from a SHT_LLVM_CALL_GRAPH_PROFILE (0x6fff4c02) section as (uint32_t, uint32_t, uint64_t) tuples as (from symbol index, to symbol index, weight).

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

llvm-svn: 343552
2018-10-02 00:17:15 +00:00
Sid Manning 490429d069 [ELF] [HEXAGON] Add support for PLT_B22_PCREL and HEX_32_PCREL
Update testcase.

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

llvm-svn: 343515
2018-10-01 18:27:26 +00:00
Rui Ueyama 1e591d807b Add an explanation about cross linking.
Differential Revision: https://reviews.llvm.org/D52567

llvm-svn: 343495
2018-10-01 16:41:58 +00:00
James Henderson 194a4eb8f7 Fix typo in LLD man page
llvm-svn: 343449
2018-10-01 09:57:20 +00:00
Martin Storsjo 0f8f0d6d1d [COFF] In MinGW mode, ignore relocations against a discarded section
When GCC produces a jump table as part of a comdat function, the
jump table itself is produced as plain non-comdat rdata section. When
linked with ld.bfd, all of those rdata sections are kept, with
relocations unchanged in the sections that refer to discarded comdat
sections.

This has been observed with at least GCC 5.x and 7.x.

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

llvm-svn: 343422
2018-09-30 18:31:03 +00:00
Alexandre Ganea 91def5cc6a [LLD][COFF] Fix pdb loading when the path points to a removable device
Differential Revision: https://reviews.llvm.org/D52666

llvm-svn: 343366
2018-09-28 21:53:40 +00:00
Sam Clegg 8b0b48f343 [WebAssembly] Preserve function signatures during LTO
With LTO when and undefined function (with a known signature)
in replaced by a defined bitcode function we were loosing the
signature information (since bitcode functions don't have
signatures).

With this change we preserve the original signature from the
undefined function and verify that the post LTO compiled
function has the correct signature.

This change improves the error handling in the case where
there is a signature mismatch with a function defined in
a bitcode file.

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

llvm-svn: 343340
2018-09-28 16:50:14 +00:00
Sid Manning fc50e63a2a [ELF][HEXAGON] Add support for dynamic libraries
Write out the PLT header and stub.
Hexagon uses RELA relocations.

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

llvm-svn: 343320
2018-09-28 14:09:16 +00:00
Sam Clegg 305b0343ce [WebAssembly] Add --[no]-export-dynamic to replace --export-default
In a very recent change I introduced a --no-export-default flag
but after conferring with others it seems that this feature already
exists in gnu GNU ld and lld in the form the --export-dynamic flag
which is off by default.

This change replaces export-default with export-dynamic and also
changes the default to match the traditional linker behaviour.

Now, by default, only the entry point is exported.  If other symbols
are required by the embedder then --export-dynamic or --export can
be used to export all visibility hidden symbols or individual
symbols respectively.

This change touches a lot of tests that were relying on symbols
being exported by default.  I imagine it will also effect many
users but do think the change is worth it match of the traditional
behaviour and flag names.

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

llvm-svn: 343265
2018-09-27 21:06:25 +00:00
Peter Smith fb5a5d09fe [COFF] Add missing Requires x86 to fix buildbot
Add REQUIRES: x86 to pdb-debug-f.s as this is causing the Arm and
AArch64 buildbots to fail as they do not have the x86 backend.

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

llvm-svn: 343196
2018-09-27 12:07:47 +00:00
Sam Clegg 4aad12ce0b [WebAssembly] Update Config member to match command line option
Subscribers: dschuff, jgravelle-google, aheejin, sunfish, llvm-commits

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

llvm-svn: 343157
2018-09-27 00:46:54 +00:00
Sam Clegg bd37e09355 Revert "[WebAssembly] Update docs"
This change reverts rL343155.  It broke the builtbot, even though
it works for me locally:
http://lab.llvm.org:8011/builders/lld-sphinx-docs/builds/26336

Must be a sphinx version issue I guess.

llvm-svn: 343156
2018-09-27 00:42:49 +00:00
Sam Clegg 77ab7c1b30 [WebAssembly] Update docs
Differential Revision: https://reviews.llvm.org/D52048

llvm-svn: 343155
2018-09-27 00:22:24 +00:00
Fangrui Song dbaeec6892 [ELF] llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, mgrang, llvm-commits

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

llvm-svn: 343146
2018-09-26 20:54:42 +00:00
Ryan Prichard ed5bb932a2 Allow later -z name=<int> args to override earlier args
Summary:
lld already gives later -z options precedence in getZFlag().

This matches the behavior of ld.bfd and ld.gold, where later options
override earlier ones. (I tested with -z max-page-size and -z stack-size.)

Reviewers: ruiu, espindola, grimar

Reviewed By: ruiu, grimar

Subscribers: grimar, emaste, arichardson, llvm-commits

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

llvm-svn: 343145
2018-09-26 20:50:39 +00:00
Ryan Prichard b7c8d2d405 [AArch64] Fix range check of R_AARCH64_TLSLE_ADD_TPREL_HI12
Summary:
An AArch64 LE relocation is a positive ("variant 1") offset. This
relocation is used to write the upper 12 bits of a 24-bit offset into an
add instruction:

    add x0, x0, :tprel_hi12:v1

The comment in the ARM docs for R_AARCH64_TLSLE_ADD_TPREL_HI12 is:

"Set an ADD immediate field to bits [23:12] of X; check 0 <= X < 2^24."

Reviewers: javed.absar, espindola, ruiu, peter.smith, zatrazz

Reviewed By: ruiu

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

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

llvm-svn: 343144
2018-09-26 20:50:38 +00:00
Fangrui Song 5dffc95b26 [ELF][test] Use llvm-readelf's short option -r instead of -relocations and remove ignored --wide
Reviewers: ruiu, sfertile, espindola

Reviewed By: ruiu

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

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

llvm-svn: 343135
2018-09-26 19:48:07 +00:00
George Rimar 95aae4c59d [ELF] - Do not fail on R_*_NONE relocations when parsing the debug info.
This is https://bugs.llvm.org//show_bug.cgi?id=38919.

Currently, LLD may report "unsupported relocation target while parsing debug info"
when parsing the debug information.

At the same time LLD does that for zeroed R_X86_64_NONE relocations,
which obviously has "invalid" targets.

The nature of R_*_NONE relocation assumes them should be ignored.
This patch teaches LLD to stop reporting the debug information parsing errors for them.

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

llvm-svn: 343078
2018-09-26 08:11:34 +00:00
Martin Storsjo 32e651e169 [COFF] Don't do autoexport of symbols from GNU import libraries
This involves adding more generic list of symbol suffixes/prefixes
to ignore for autoexport; adding a few other entries to these lists
as well from the corresponding lists in binutils.

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

llvm-svn: 343070
2018-09-26 06:13:47 +00:00
Martin Storsjo 2bfa125fd6 [COFF] Allow automatic dllimport from gnu import libraries
Don't assume that the IAT chunk will be a DefinedImportData, it can
just as well be a DefinedRegular for gnu import libraries.

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

llvm-svn: 343069
2018-09-26 06:13:39 +00:00
Sam Clegg 4e62418b25 [WebAssembly] Add --export-default/--no-export-default options
These option control weather or not symbols marked as visibility
default are exported in the output binary.

By default this is true, but emscripten prefers to control the
exported symbol list explicitly at link time and ignore the
symbol attributes.

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

llvm-svn: 343034
2018-09-25 21:50:15 +00:00
Rui Ueyama 378a028d91 Update a --help message and add -execute-only to the man page.
llvm-svn: 343032
2018-09-25 21:39:08 +00:00
Rui Ueyama 12ef7a9575 De-template VersionDefinitionSection. NFC.
When we write a struct to a mmap'ed buffer, we usually use
write16/32/64, but we didn't for VersionDefinitionSection, so
we needed to template that class.

llvm-svn: 343024
2018-09-25 20:37:51 +00:00
Rui Ueyama 4e247522ac Reset input section pointers to null on each linker invocation.
Previously, if you invoke lld's `main` more than once in the same process,
the second invocation could fail or produce a wrong result due to a stale
pointer values of the previous run.

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

llvm-svn: 343009
2018-09-25 19:26:58 +00:00
Rui Ueyama ae34348354 Fix an error message. It must start with a lowercase letter.
llvm-svn: 342992
2018-09-25 17:12:50 +00:00
Rui Ueyama 7d053709d4 Parallelize .gdb_index string table writes.
When we are creating a large .gdb_index, this change makes a difference.

llvm-svn: 342978
2018-09-25 14:34:56 +00:00
Martin Storsjo 57ddec0dd1 [COFF] Add support for creating range extension thunks for ARM
This is a feature that MS link.exe lacks; it currently errors out on
such relocations, just like lld did before.

This allows linking clang.exe for ARM - practically, any image over
16 MB will likely run into the issue.

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

llvm-svn: 342962
2018-09-25 10:59:29 +00:00
George Rimar b5a6538b07 [ELF] - Add -z global option to manual.
This was requested during review of D49374,
but for some unknown reason was not in the final commit.

llvm-svn: 342954
2018-09-25 09:32:31 +00:00
Yury Delendik d66aabc6d7 [WebAssembly] Move .debug_line section address of dead function outside section range
Summary:
Currently we are pointing all debug information that refer removed function code
to the beginning of the code section (offset = 0). A debugger may want to
resolve code offset to the debug information, which will collide with offsets
of the live functions.

Moving offsets of dead functions outside code section range.

Reviewers: sbc100

Reviewed By: sbc100

Subscribers: dblaikie, ruiu, alexcrichton, dschuff, aprantl, jgravelle-google, aheejin, sunfish, JDevlieghere, llvm-commits

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

llvm-svn: 342930
2018-09-24 23:50:55 +00:00
Will Wilson 3cb18346d7 [lld-link] Generalize handling of /debug and /debug:{none,full,fastlink,ghash,symtab}
Implement final argument precedence if multiple /debug arguments are passed on the command-line to match expected link.exe behavior.
Support /debug:none and emit warning for /debug:fastlink with automatic fallback to /debug:full.
Emit error if last /debug:option is unknown.
Emit warning if last /debugtype:option is unknown.

https://reviews.llvm.org/D50404

llvm-svn: 342894
2018-09-24 15:28:03 +00:00
Ed Maste c8ec7a9e1e Correct RISC-V link in release notes
llvm-svn: 342887
2018-09-24 14:47:56 +00:00