Commit Graph

12435 Commits

Author SHA1 Message Date
Martin Storsjo 0e5530abfc [MinGW] Correct handling different forms of a few options
Support the equals form of the long --entry=<symbol> option,
add a test for the -e<symbol> form.

Add tests for single dash forms of -exclude-all-symbols and
-export-all-symbols.

Support single-dash forms of -out-implib and -output-def, support
the equals form of --output-def=<file>. (We previously had a test
to explicitly disallow -out-implib, but it turns out that GNU ld
actually does support it just fine, despite also matching the
-o<file> option.)

Disallow the double-dashed --u form, add a test for -u<symbol>.

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

llvm-svn: 368816
2019-08-14 09:35:44 +00:00
Martin Storsjo ce26ad7a9d [MinGW] Restructure Options.td to use multiclass where sensible. NFC.
Differential Revision: https://reviews.llvm.org/D66065

llvm-svn: 368815
2019-08-14 09:35:40 +00:00
Martin Storsjo df7ec1ff7b [MinGW] Remove stray/inconsistent comment chars in test file. NFC.
Test directives don't need to be in comments in this file.

llvm-svn: 368814
2019-08-14 09:35:36 +00:00
Fangrui Song f1d538cce5 [ELF] Initialize 2 fields of Symbol in SymbolTable::insert
A new symbol is added to elf::symtab in 3 steps:

1) SymbolTable::insert creates a placeholder.
2) Symbol::mergeProperties
3) Symbol::replace

Fields referenced by steps 2) and 3) should be initialized in
SymbolTable::insert.  `traced` and `referenced` were missed previously.
This did not cause problems because compilers generated code that
initialized them (bit fields) to 0.

Reviewed By: grimar

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

llvm-svn: 368784
2019-08-14 01:52:47 +00:00
Sam Clegg 7185a7301e [lld][WebAssembly] Allow linking of pic code into static binaries
Summary: See https://github.com/emscripten-core/emscripten/issues/9013

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

Tags: #llvm

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

llvm-svn: 368719
2019-08-13 17:02:02 +00:00
Jordan Rupprecht 7859641626 [lld][test] Update test to print ELF note description data
llvm-svn: 368710
2019-08-13 16:11:09 +00:00
Fangrui Song dc06b0bc9a [ELF] Don't special case symbolic relocations with 0 addend to ifunc in writable locations
Currently the following 3 relocation types do not trigger the creation
of a canonical PLT (which changes STT_GNU_IFUNC to STT_FUNC and
redirects all references):

1) GOT-generating (`needsGot`)
2) PLT-generating (`needsPlt`)
3) R_ABS with 0 addend in a writable location. This is used for
  for ifunc function pointers in writable sections such as .data and .toc.

This patch deletes case 3) to simplify the R_*_IRELATIVE generating
logic added in D57371. Other advantages:

* It is guaranteed no more than 1 R_*_IRELATIVE is created for an ifunc.
* PPC64: no need to special case ifunc in toc-indirect to toc-relative relaxation. See D65755

The deleted elf::addIRelativeRelocs demonstrates that one-pass scan
through relocations makes several optimizations difficult. This is
something we can think about in the future.

Reviewed By: peter.smith

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

llvm-svn: 368661
2019-08-13 09:43:40 +00:00
Fangrui Song c6cd62352c [ELF] Simplify handling of exportDynamic and isPreemptible
In Writer::includeInDynSym(), exportDynamic is used by a Defined with
protected or default visibility, to record whether it is required to be
exported into .dynsym. It is set when any of the following conditions
hold:

1) There is an interposable symbol from a DSO (Undefined or SharedSymbol with default visibility)
2) If -shared or --export-dynamic is specified, any symbol in an object file/bitcode sets this property, unless suppressed by canBeOmittedFromSymbolTable().
3) --dynamic-list when producing an executable

4) protected symbol from a DSO preempted by copy relocation/canonical PLT when
  --ignore-{data,function}-address-equality is specified
5) ifunc is exported when -z ifunc-noplt is specified

Bullet points 4) and 5) are irrelevant in this patch.

Bullet 3) does not play well with 1) and 2). When -shared is specified,
exportDynamic of most symbols is true. This makes it incapable to record
--dynamic-list marked symbols. We thus have obscure:

    if (!config->shared)
      b->exportDynamic = true;
    else if (b->includeInDynsym())
      b->isPreemptible = true;

This patch adds another bit `Symbol::inDynamicList` to record
3). We can thus simplify handleDynamicList() by unifying the DSO and
  executable cases. It also allows us to simplify isPreemptible - now
the field is only used in finalizeSections() and later stages.

Reviewed By: peter.smith

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

llvm-svn: 368659
2019-08-13 09:12:52 +00:00
Fangrui Song ab04ad6af7 [ELF] Rename odd variable names "New" after r365730. NFC
New -> newSym or newFlags

Reviewed By: atanasyan

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

llvm-svn: 368651
2019-08-13 06:19:39 +00:00
Fangrui Song 892cdc73be [ELF][test] Add dynamic-list-preempt2.s
When producing a DSO, the isPreemptible property of a Defined with
default or protected visibility is affected by the --dynamic-list file,
but not by interposable symbols in other DSOs.

llvm-svn: 368649
2019-08-13 05:08:46 +00:00
Bob Haarman 6e18c7f8d4 [lld] Remove unnecessary "class Lazy"
llvm-svn: 368644
2019-08-13 01:02:30 +00:00
Fangrui Song 3cafdfddcb [ELF] Remove unnecessary assignment to `isPreemptible` in replaceWithDefined()
After r368535, it is no longer used in the handling of VER_NDX_LOCAL.
Drop it.

llvm-svn: 368550
2019-08-12 10:01:17 +00:00
Fangrui Song cfdd4589f1 [ELF] Remove redundant isDefined() in Symbol::computeBinding() and delete one redundant call site
After r367869, VER_NDX_LOCAL can only be assigned to Defined and
CommonSymbol.  CommonSymbol becomes Defined after replaceCommonSymbols(),
thus `versionId == VER_NDX_LOCAL` will imply `isDefined()`.

In maybeReportUndefined(), computeBinding() is called when the symbol is
unknown to be Undefined. computeBinding() != STB_LOCAL will always be
true.

llvm-svn: 368536
2019-08-11 17:03:00 +00:00
Fangrui Song 635eda8bb0 [ELF] Remove redundant !isPreemptible in Symbol::computeBinding()
!isPreemptible was added in r343668 to fix PR39104: symbols redefined by
replaceWithDefined() might be incorrectly considered STB_LOCAL if a
version script specified `local: *;`.

After r367869 (`config->defaultSymbolVersion` was removed), we will
assign VER_NDX_LOCAL to only regular Defined and CommonSymbol, not
Defined created by replaceWithDefined() (because scanVersionScript() is
called before scanRelocations()). The !isPreemptible is thus redundant
and can be deleted.

llvm-svn: 368535
2019-08-11 16:12:07 +00:00
Fangrui Song 38c5788548 [ELF] Remove unnecessary assignment to `used` in replaceWithDefined
`Symbol::used` is used by Undefined and SharedSymbol to record if a
.symtab entry is needed. It is of no use for Defined.

llvm-svn: 368533
2019-08-11 13:32:46 +00:00
Igor Kudrin b65016ddac [ELF] For VS-style diagnostics, prefer printing full paths in the header.
The filename part in the message header is used by Visual Studio
to fill Error List so that a user can click on an item and jump
to the mentioned location. If we use only the name of a source file
and not the full path, Visual Studio might be unable to find the right
file or, even worse, show a wrong one.

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

llvm-svn: 368409
2019-08-09 08:29:03 +00:00
Fangrui Song 179dc276eb [ELF] Expand regions for gaps due to explicit address
If the dot gets moved by an explicit section address, an empty gap between sections could be created. The encompassing region for the section being parsed needs to be expanded to include the gap.

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

Patch by Gabriel Smith!

llvm-svn: 368379
2019-08-09 01:25:49 +00:00
David Blaikie 84b55e61dd DebugInfo: Explicitly handle errors when parsing unit DIEs
This ensures these errors produce a non-zero exit and improves the
context (providing the name of the input object and section being
parsed).

llvm-svn: 368378
2019-08-09 01:14:36 +00:00
Peter Collingbourne 1fa1cd200b ELF: Move sections referred to by __start_/__stop_ symbols into the main partition.
In the case where C identifier sections have SHF_LINK_ORDER they will most
likely be placed in the same partition as the section that they are associated
with. But unless this happens to be the main partition, this will cause them
to be excluded from the range covered by the __start_ and __stop_ symbols,
which may lead to incorrect program behaviour. So we need to move them
all into the main partition so that they will be covered by the __start_
and __stop_ symbols.

We may want to refine this approach later and allow different __start_/__stop_
symbol values for different partitions. This would only make sense for
relocations from SHT_NOTE sections since they are duplicated into each
partition.

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

llvm-svn: 368375
2019-08-09 00:57:54 +00:00
Sam Clegg dbfea28219 [lld][WebAssembly] Don't create optional symbols when outputing an object file
Summary: This was a bug in rL368310.  I'm working on a test case now.

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

llvm-svn: 368369
2019-08-08 23:56:21 +00:00
Guanzhong Chen c5ccbf52ad [WebAssembly][lld] control __data_end export with config->shared
Summary:
Emscripten expects `__data_end` to show up in PIC code as long as it's not
linked with `--shared`.

Currently, Emscripten breaks with latest LLVM because `__data_end` is controlled
by `config->isPic` instead of `config->shared`.`

Reviewers: tlively, sbc100

Reviewed By: sbc100

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

Tags: #llvm

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

llvm-svn: 368361
2019-08-08 22:40:04 +00:00
Sam Clegg ad1cc145e8 [lld][WebAssembly] Use createGlobalVariable helper function. NFC.
Differential Revision: https://reviews.llvm.org/D65911

llvm-svn: 368325
2019-08-08 18:22:03 +00:00
Sam Clegg caa0db1318 [lld][WebAssembly] Add optional symbols after input file handling
This allows undefined references in input files be resolved by the
optional symbols.  Previously we were doing this before input file
reading which means it was working only for command line symbols
references (i.e. -u or --export).

Also use addOptionalDataSymbol for __dso_handle and make all optional
symbols hidden by default.

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

llvm-svn: 368310
2019-08-08 16:58:36 +00:00
Fangrui Song ba4bda657e [ELF][AArch64] Delete two unused RUN lines from aarch64-movw-tprel.s after D65882
llvm-svn: 368298
2019-08-08 13:57:53 +00:00
Peter Smith d4695e1d75 [ELF][AArch64] Support for movz, movk tprel relocations
This patch Implements the R_AARCH64_TLSLE_MOVW_TPREL_G*[_NC]. These are
logically the same calculation as the existing TLSLE relocations with
the result written back to mov[nz] and movk instructions. A typical code
sequence is:
movz x0, #:tprel_g2:foo    // bits [47:32] of R_TLS with overflow check
movk x0, #:tprel_g1_nc:foo // bits [31:16] of R_TLS with no overflow check
movk x0, #:tprel_g0_nc:foo // bits [15:0] of R_TLS with no overflow check

This type of code sequence is usually used with a large code model.

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

Fixes: PR42853
llvm-svn: 368293
2019-08-08 13:38:09 +00:00
David Blaikie 8a480d2cbf gdb-index: Wire up str_offsets section to avoid incorrect error message about offsets_base
There's still a need for a deeper fix to the way libDebugInfoDWARF error
messages are propagated up to lld - if lld had exited non-zero on this
error message we would've found the issue sooner.

llvm-svn: 368229
2019-08-07 22:49:14 +00:00
David Blaikie 77ddf6af2b Add a test demonstrating DWARF parse failures are not causing lld to exit non-zero
This bug was/is masking other issues - committing this to demonstrate
the problem/track fixing it.

llvm-svn: 368220
2019-08-07 22:05:33 +00:00
David Blaikie fa2f4395e9 API update for change to LLVM's lib/DebugInfo/DWARF
llvm-svn: 368190
2019-08-07 17:18:18 +00:00
Igor Kudrin 0e1fea6754 Try to fix windows build bots after r368153.
llvm-svn: 368169
2019-08-07 13:22:29 +00:00
Igor Kudrin da41e2107e [ELF] Fix splitting messages for duplicate symbols.
D65213 (rL367536) does not work for the case when a source file path
includes subdirectories.

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

llvm-svn: 368153
2019-08-07 11:32:43 +00:00
Rui Ueyama e6a33e1f11 Handle /align option.
Differential Revision: https://reviews.llvm.org/D65736

llvm-svn: 368145
2019-08-07 10:16:21 +00:00
Rui Ueyama 6c5fc94093 Simplify error message output. NFC.
Differential Revision: https://reviews.llvm.org/D65855

llvm-svn: 368144
2019-08-07 10:11:24 +00:00
Fangrui Song 5ebee2558b [ELF][X86] Add --no-show-raw-insn and -soname to some i386 tests
llvm-svn: 368142
2019-08-07 09:43:54 +00:00
Rui Ueyama cac8df1ab9 Re-submit r367649: Improve raw_ostream so that you can "write" colors using operator<<
The original patch broke buildbots, perhaps because it changed the
default setting whether colors are enabled or not.

llvm-svn: 368131
2019-08-07 08:08:17 +00:00
Guanzhong Chen 0cb776e61a [WebAssembly] Fix null pointer in createInitTLSFunction
Summary:
`createSyntheticSymbols`, which creates `WasmSym::InitTLS`, is only called
when `!config->relocatable`, but this condition is not checked when calling
`createInitTLSFunction`.

This diff checks `!config->relocatable` before calling `createInitTLSFunction`.

Fixes https://github.com/emscripten-core/emscripten/issues/9155.

Reviewers: tlively, aheejin, kripken, sbc100

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

Tags: #llvm

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

llvm-svn: 368078
2019-08-06 20:09:04 +00:00
Fangrui Song c55c0598f9 [ELF][PPC] Don't relax ifunc toc-indirect accesses to toc-relative
Fixes PR42759.

```
// If ifunc is taken address in -fPIC code, it may have a toc entry
.section .toc,"aw",@progbits
  .quad ifunc

// ifunc may be defined as STT_GNU_IFUNC in another object file
.type ifunc, %gnu_indirect_function
```

If ifunc is non-preemptable (e.g. when linking an executable), the toc
entry will be relocated by R_PPC64_IRELATIVE.

R_*_IRELATIVE represents the symbolic value of a
non-preemptable ifunc (not associated with a canonical PLT) in a writable location. It has an unknown value at
link time, so we cannot apply toc-indirect to toc-relative relaxation.

Reviewed By: luporl, sfertile

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

llvm-svn: 368057
2019-08-06 16:57:54 +00:00
Peter Smith 7f320d4bf0 [ELF][ARM] Fix /DISCARD/ of section with .ARM.exidx section
The combineEhSections runs, by design, before processSectionCommands so
that input exception sections like .ARM.exidx and .eh_frame are not assigned
to OutputSections. Unfortunately if /DISCARD/ removes InputSections that
have associated .ARM.exidx sections without discarding the .ARM.exidx
synthetic section then we will end up crashing when trying to sort the
InputSections in ascending address order.

We fix this by filtering out the sections that have been discarded prior
to processing the InputSections in finalizeContents().

fixes pr42890

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

llvm-svn: 368041
2019-08-06 14:13:38 +00:00
Fangrui Song e49c417ed1 [ELF] Make binding (weak or non-weak) logic consistent for Undefined and SharedSymbol
This is a case missed by D64136. If %t1.o has a weak reference on foo,
and %t2.so has a non-weak reference on foo:

```
0. ld.lld %t1.o %t2.so          # ok; STB_WEAK; accepted since D64136
1. ld.lld %t2.so %t1.o          # undefined symbol: foo; STB_GLOBAL
2. gold %t1.o %t2.so            # ok; STB_WEAK
3. gold %t2.so %t1.o            # undefined reference to 'foo'; STB_GLOBAL
4. ld.bfd %t1.o %t2.so          # undefined reference to `foo'; STB_WEAK
5. ld.bfd %t2.so %t1.o          # undefined reference to `foo'; STB_WEAK
```

It can be argued that in both cases, the binding of the undefined foo
should be set to STB_WEAK, because the binding should not be affected by
referenced from shared objects.

--allow-shlib-undefined doesn't suppress errors (3,4,5), but -shared or
--noinhibit-exec allows ld.bfd/gold to produce a binary:

```
3. gold -shared %t2.so %t1.o    # ok; STB_GLOBAL
4. ld.bfd -shared %t2.so %t1.o  # ok; STB_WEAK
5. ld.bfd -shared %t1.o %t1.o   # ok; STB_WEAK
```

If %t2.so has DT_NEEDED entries, ld.bfd will load them (lld/gold don't
have the behavior). If one of the DSO defines foo and it is in the
link-time search path (e.g. DT_NEEDED entry is an absolute path, via
-rpath=, via -rpath-link=, etc),
`ld.bfd %t1.o %t2.so` and `ld.bfd %t1.o %t2.so` will not error.

In this patch, we make Undefined and SharedSymbol share the same binding
computing logic. Case 1 will be allowed:

```
0. ld.lld %t1.o %t2.so          # ok; STB_WEAK; accepted since D64136
1. ld.lld %t2.so %t1.o          # ok; STB_WEAK; changed by this patch
```

In the future, we can explore the option that turns both (0,1) into
errors if --no-allow-shlib-undefined (default when linking an
executable) is in action.

Reviewed By: ruiu

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

llvm-svn: 368038
2019-08-06 14:03:45 +00:00
Igor Kudrin 5978c9249b [MachO] Update LLD to use 64-bit offsets with DataExtractor (3/5)
Differential Revision: https://reviews.llvm.org/D65639

llvm-svn: 368032
2019-08-06 13:37:34 +00:00
Fangrui Song 8981dc3058 [ELF][test] Reorganize some tls-*.s tests
Some tls-*.s tests do not test generic TLS behavior but rather are x86 specific.
Rename them to i386-*.s or x86-64-*.s

Delete tls-static.s: covered by tls-opt.s
Delete tls-opt-no-plt.s: add --implicit-check-not=.plt to x86-64-tls-gdie.s to cover it

Rename tls-dynamic-i686.s to i386-tls-dynamic.s
Rename tls-i686.s to i386-tls-le.s
Rename tls-opt-i686.s to i386-tls-opt.s
Rename tls-opt-iele-i686-nopic.s to i386-tls-opt-iele-nopic.s

Rename tls-dynamic.s to x86-64-tls-dynamic.s . IE should be split off in the future.
Rename tls-error.s to x86-64-reloc-tpoff32-error.s
Rename tls-opt-gdie.s to x86-64-tls-gdie.s
Rename tls-opt-x86_64-noplt.s to x86-64-tls-opt-noplt.s
Rename tls-opt-local.s => x86-64-tls-ie-opt-local.s . It can be merged with x86-64-tls-ie-local.s in the future.

llvm-svn: 367877
2019-08-05 15:34:01 +00:00
Fangrui Song e28a70daf4 [ELF] Consistently prioritize non-* wildcards overs "*" in version scripts
We prioritize non-* wildcards overs VER_NDX_LOCAL/VER_NDX_GLOBAL "*".
This patch generalizes the rule to "*" of other versions and thus fixes PR40176.
I don't feel strongly about this GNU linkers' behavior but the
generalization simplifies code.

Delete `config->defaultSymbolVersion` which was used to special case
VER_NDX_LOCAL/VER_NDX_GLOBAL "*".

In `SymbolTable::scanVersionScript`, custom versions are handled the same
way as VER_NDX_LOCAL/VER_NDX_GLOBAL. So merge
`config->versionScript{Locals,Globals}` into `config->versionDefinitions`.
Overall this seems to simplify the code.

In `SymbolTable::assign{Exact,Wildcard}Versions`,
`sym->verdefIndex == config->defaultSymbolVersion` is changed to
`verdefIndex == UINT32_C(-1)`.
This allows us to give duplicate assignment diagnostics for
`{ global: foo; };` `V1 { global: foo; };`

In test/linkerscript/version-script.s:
  vs_index of an undefined symbol changes from 0 to 1. This doesn't matter (arguably 1 is better because the binding is STB_GLOBAL) because vs_index of an undefined symbol is ignored.

Reviewed By: ruiu

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

llvm-svn: 367869
2019-08-05 14:31:39 +00:00
Nilanjana Basu da60fc813c Changing representation of .cv_def_range directives in Codeview debug info assembly format for better readability
llvm-svn: 367867
2019-08-05 14:16:58 +00:00
Nilanjana Basu b5e4d7de17 Revert "Changing representation of .cv_def_range directives in Codeview debug info assembly format for better readability"
This reverts commit a885afa9fa.

llvm-svn: 367861
2019-08-05 13:55:21 +00:00
Nilanjana Basu a885afa9fa Changing representation of .cv_def_range directives in Codeview debug info assembly format for better readability
llvm-svn: 367850
2019-08-05 13:11:51 +00:00
Martin Storsjo c92b3563c6 [MinGW] Add an lld specific option for requesting to delay load libraries
With GNU tools, delayload is handled completely differently. (One
creates a specific delayload import library using dlltool and then
links against it instead of the normal import library.)

Instead of requiring using -Xlink=-delayload:lib.dll, we can provide
an lld specific option for this.

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

llvm-svn: 367837
2019-08-05 11:57:06 +00:00
Martin Storsjo a0cbe16ed5 [COFF] Omit automatically imported symbols from the symbol table
These symbols actually point to the symbol's IAT entry, which
obviously is different from the symbol itself (which is imported
from a different module and doesn't exist in the current one).

Omitting this symbol helps gdb inspect automatically imported
symbols, see https://sourceware.org/bugzilla/show_bug.cgi?id=24574
for discussion on the matter.

Surprisingly, those extra symbols don't seem to be an issue for
gdb when the sources have been built with clang, only with gcc.
The actual logic in gdb that this depends on still is unknown, but
omitting these symbols from the symbol table is the right thing to
do in any case.

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

llvm-svn: 367836
2019-08-05 11:57:00 +00:00
Fangrui Song d9b948b6eb Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFC
F_{None,Text,Append} are kept for compatibility since r334221.

llvm-svn: 367800
2019-08-05 05:43:48 +00:00
Fangrui Song 8f6cf97bee [ELF][test] Delete redundant version-script-*.s tests
Delete version-script-missing.s: it is covered by version-script-noundef.s
Delete version-script-anonymous-local.s: it is covered by version-script-{glob,weak}.s etc
Delete version-script-no-warn{,2}.s: add --fatal-warnings to some version-script.s commands instead

llvm-svn: 367778
2019-08-04 09:05:21 +00:00
Fangrui Song 25ab1c6471 [ELF] Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn unless --pack-dyn-relocs=android[+relr]
An R_*_IRELATIVE represents the address of a STT_GNU_IFUNC symbol
(redirected at runtime) which is non-preemptable and is not associated
with a canonical PLT (associated with a symbol with a section index of
SHN_UNDEF but a non-zero st_value).

.rel[a].plt [DT_JMPREL, DT_JMPREL+DT_JMPRELSZ) contains relocations that
can be lazily resolved. R_*_IRELATIVE are always eagerly resolved, so
conceptually they do not belong to .rela.plt. "iplt" is mostly a misnomer.

glibc powerpc and powerpc64 do not resolve R_*_IRELATIVE if they are in .rela.plt.

    // a.o - synthesized PLT call stub has an R_*_IRELATIVE
    void ifunc(); int main() { ifunc(); }
    // b.o
    static void real() {}
    asm (".type ifunc, %gnu_indirect_function");
    void *ifunc() { return &real; }

The lld-linked executable crashes. ld.bfd places R_*_IRELATIVE in
.rela.dyn and the executable works.

glibc i386, x86_64, and aarch64 have logic
(glibc/sysdeps/*/dl-machine.h:elf_machine_lazy_rel) to eagerly resolve
R_*_IRELATIVE in .rel[a].plt so the lld-linked executable works.

Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn to fix the crashes on
glibc powerpc/powerpc64. This also helps simplifying ifunc
implementation in FreeBSD rtld-elf powerpc64.

If --pack-dyn-relocs=android[+relr] is specified, the Android packed
dynamic relocation format is used for .rela.dyn. We cannot name
in.relaIplt ".rela.dyn" because the output section will have mixed
formats. This can be improved in the future.

Reviewed By: pcc

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

llvm-svn: 367745
2019-08-03 02:26:52 +00:00
Martin Storsjo 397a516a52 [COFF] Clarify a comment. NFC.
It's the __delayLoadHelper2 function that overwrites the jump table
slot, not this thunk.

llvm-svn: 367674
2019-08-02 11:08:15 +00:00
Martin Storsjo 5f0077d238 [COFF] Avoid loading objects for mingw autoimport, when a defined alias exists
This avoids a spurious and confusing log message in cases where
both e.g. "alias" and "__imp_alias" exist.

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

llvm-svn: 367673
2019-08-02 11:02:34 +00:00
Rui Ueyama 4d41c332ef Revert r367649: Improve raw_ostream so that you can "write" colors using operator<<
This reverts commit r367649 in an attempt to unbreak Windows bots.

llvm-svn: 367658
2019-08-02 07:22:34 +00:00
Rui Ueyama c1981b2b26 Add an assert() to catch possible regexp errors.
llvm-svn: 367651
2019-08-02 05:11:19 +00:00
Rui Ueyama 96a7a225f5 Add a comment for --vs-diagnostics.
llvm-svn: 367650
2019-08-02 05:04:27 +00:00
Rui Ueyama a52f982f1c Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to
the termina with colors. Previously, in order to change and reset
color, you had to call `changeColor` and `resetColor` functions,
respectively.

So, if you print out "error: " in red, for example, you had to do
something like this:

  OS.changeColor(raw_ostream::RED);
  OS << "error: ";
  OS.resetColor();

With this patch, you can write the same code as follows:

  OS << raw_ostream::RED << "error: " << raw_ostream::RESET;

2. Add a boolean flag to raw_ostream so that you can disable colored
output. If you disable colors, changeColor, operator<<(Color),
resetColor and other color-related functions have no effect.

Most LLVM tools automatically prints out messages using colors, and
you can disable it by passing a flag such as `--disable-colors`.
This new flag makes it easy to write code that works that way.

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

llvm-svn: 367649
2019-08-02 04:48:30 +00:00
Rui Ueyama 966b9a3b9d Fix an unused variable warning.
llvm-svn: 367643
2019-08-02 02:51:20 +00:00
Martin Storsjo 90b4388f56 [COFF] Fix wholearchive with thin archives
The Archive object created when loading an archive specified with
wholearchive got cleaned up immediately, when the owning std::unique_ptr
went out of scope, even if persisted StringRefs pointed to memory that
belonged to the archive, which no longer was mapped in memory.

This hasn't been an issue with regular (as opposed to thin) archives,
as references to the member objects has kept the mapping for the whole
archive file alive - but with thin archives, all such references point
to other files.

Add the std::unique_ptr to the arena allocator, to retain it as long
as necessary.

This fixes (the last issue raised in) PR42388.

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

llvm-svn: 367599
2019-08-01 18:47:27 +00:00
Fangrui Song 5391f158c2 [ELF] Add -z separate-code and pad the last page of last PF_X PT_LOAD with traps only if -z separate-code is specified
This patch

1) adds -z separate-code and -z noseparate-code (default).
2) changes the condition that the last page of last PF_X PT_LOAD is
 padded with trap instructions.
 Current condition (after D33630): if there is no `SECTIONS` commands.
 After this change: if -z separate-code is specified.

-z separate-code was introduced to ld.bfd in 2018, to place the text
segment in its own pages. There is no overlap in pages between an
executable segment and a non-executable segment:

1) RX cannot load initial contents from R or RW(or non-SHF_ALLOC).
2) R and RW(or non-SHF_ALLOC) cannot load initial contents from RX.

lld's current status:

- Between R and RX: in `Writer<ELFT>::fixSectionAlignments()`, the start of a
  segment is always aligned to maxPageSize, so the initial contents loaded by R
  and RX do not overlap. I plan to allow overlaps in D64906 if -z noseparate-code
  is in effect.
- Between RX and RW(or non-SHF_ALLOC if RW doesn't exist):
  we currently unconditionally pad the last page to commonPageSize
  (defaults to 4096 on all targets we support).
  This patch will make it effective only if -z separate-code is specified.

-z separate-code is a dubious feature that intends to reduce the number
of ROP gadgets (which is actually ineffective because attackers can find
plenty of gadgets in the text segment, no need to find gadgets in
non-code regions).

With the overlapping PT_LOAD technique D64906, -z noseparate-code
removes two more alignments at segment boundaries than -z separate-code.
This saves at most defaultCommonPageSize*2 bytes, which are significant
on targets with large defaultCommonPageSize (AArch64/MIPS/PPC: 65536).

Issues/feedback on alignment at segment boundaries to help understand
the implication:

* binutils PR24490 (the situation on ld.bfd is worse because they have
  two R-- on both sides of R-E so more alignments.)

* In binutils, the 2018-02-27 commit "ld: Add --enable-separate-code" made -z separate-code the default on Linux.
  d969dea983
  In musl-cross-make, binutils is configured with --disable-separate-code
  to address size regressions caused by -z separate-code. (lld actually has the same
  issue, which I plan to fix in a future patch. The ld.bfd x86 status is
  worse because they default to max-page-size=0x200000).

* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=237676 people want
  smaller code size. This patch will remove one alignment boundary.

* Stef O'Rear: I'm opposed to any kind of page alignment at the
  text/rodata line (having a partial page of text aliased as rodata and
  vice versa has no demonstrable harm, and I actually care about small
  systems).

So, make -z noseparate-code the default.

Reviewed By: ruiu

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

llvm-svn: 367537
2019-08-01 09:58:25 +00:00
Igor Kudrin 07ceadda25 [ELF] With --vs-diagnostics, print a separate message for each location of a duplicate symbol.
We extract and print the source location in the message header so that
Visual Studio is able to parse it and jump there. As duplicate symbols
are defined in several locations, it is more convenient to have separate
error messages, which allows a user to easily access all the locations.

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

llvm-svn: 367536
2019-08-01 09:58:03 +00:00
Fangrui Song 0cfa72eaec [ELF][X86] Improve tests
* Add --no-show-raw-insn to llvm-objdump -d tests
* When linking an executable with %t.so, the path %t.so will be recorded
  in the DT_NEEDED entry if %t.so doesn't have DT_SONAME. .dynstr will
  have varying lengths on different systems. Add -soname so that the
  string in .dynstr is of fixed length to make tests more robust.
* Rename i386-tls-initial-exec-local.s to i386-tls-ie-local.s
* Refactor tls-initial-exec-local.s to x86-64-tls-ie-local.s

llvm-svn: 367533
2019-08-01 09:25:34 +00:00
Igor Kudrin 510086b5e5 [ELF] Fix finding locations in messages for undefined hidden symbols.
Previously, when `--vs-diagnostics` was used, the linker printed
something like

  hidden(undef.s): error: undefined hidden symbol: foo
  >>> referenced by undef.s:15

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

llvm-svn: 367515
2019-08-01 05:23:45 +00:00
Rui Ueyama d524c17029 Return early. NFC.
llvm-svn: 367200
2019-07-29 05:24:51 +00:00
Bob Haarman 51dcb292cc [lld-link] diagnose undefined symbols before LTO when possible
Summary:
This allows reporting undefined symbols before LTO codegen is
run. Since LTO codegen can take a long time, this improves user
experience by avoiding that time spend if the link is going to
fail with undefined symbols anyway.

Fixes PR32400.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: mehdi_amini, steven_wu, dexonsmith, mstorsjo, llvm-commits

Tags: #llvm

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

llvm-svn: 367136
2019-07-26 17:56:45 +00:00
Fangrui Song d6c448244b [ELF] Simplify with dyn_cast_or_null. NFC
llvm-svn: 367126
2019-07-26 16:29:15 +00:00
Fangrui Song 3d51d4ed6d [ELF] Detemplate maybeReportUndefined and copySectionsIntoPartitions
llvm-svn: 367117
2019-07-26 14:57:53 +00:00
Fangrui Song 3e023a6dbc [ELF][MIPS] Improve tests
* Add --no-show-raw-insn to llvm-objdump -d tests
* When linking an executable with %t.so, the path %t.so will be recorded
  in the DT_NEEDED entry if %t.so doesn't have DT_SONAME. .dynstr will
  have varying lengths on different systems. Add -soname to make tests
  more robust.

llvm-svn: 366988
2019-07-25 07:12:23 +00:00
Guanzhong Chen 87186b2447 [WebAssembly] Set __tls_align to 1 when there is no TLS
Summary:
We want the tool conventions to state that `__tls_align` will be a power of 2.
It makes sense to not have an exception for when there is no TLS.

Reviewers: tlively, sunfish

Reviewed By: tlively

Subscribers: dschuff, sbc100, jgravelle-google, aheejin, llvm-commits

Tags: #llvm

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

llvm-svn: 366948
2019-07-24 21:48:14 +00:00
Alexander Richardson a8104b4927 [LLD] Do not print additional newlines after reaching error limit
Summary:
This could previously happen if errors that are emitted after reaching the
error limit. In that case, the flag inside the newline() function will be
set to true which causes the next call to print a newline even though the
actual message will be discarded.

Reviewers: ruiu, grimar, MaskRay, espindola

Reviewed By: ruiu

Subscribers: emaste, llvm-commits

Tags: #llvm

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

llvm-svn: 366944
2019-07-24 20:56:23 +00:00
Simon Atanasyan 5adbfdda2d [mips] Assign R_TLS type to the R_MIPS_TLS_TPREL_XXX relocations. NFC
That allows to remove duplicated code which subtracts 0x7000 from the
R_MIPS_TLS_TPREL_XXX relocations values in the `MIPS::relocateOne`
function.

llvm-svn: 366888
2019-07-24 11:37:13 +00:00
Nico Weber 9c0716f116 ld.lld: Demangle symbols from archives in diagnostics
This ports r366573 from COFF to ELF.

There are now to toString(Archive::Symbol), one doing MSVC demangling
in COFF and one doing Itanium demangling in ELF, so rename these two
to toCOFFString() and to toELFString() to not get a duplicate symbol.

Nothing ever passes a raw Archive::Symbol to CHECK(), so these not
being part of the normal toString() machinery seems ok.

There are two code paths in the ELF linker that emits this type of
diagnostic:

1. The "normal" one in InputFiles.cpp. This is covered by the tweaked test.

2. An additional one that's only used for libcalls if there's at least
   one bitcode in the link, and if the libcall symbol is lazy, and
   lazily loaded from an archive (i.e. not from a lazy .o file).
   (This code path was added in r339301.) Since all libcall names so far
   are C symbols and never mangled, the change there is not observable
   and hence not covered by tests.

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

llvm-svn: 366836
2019-07-23 19:00:01 +00:00
Martin Storsjo b95fcf09c0 [test] Fix the test from the previous commit when run on windows. NFC.
Apparently the escaped dollar sign didn't work the same way in "echo -e"
on windows buildbots.

llvm-svn: 366784
2019-07-23 07:28:23 +00:00
Martin Storsjo 341a68ca2f [COFF] Unbreak sorting of mingw comdat .tls sections after SVN r363457
Code built for mingw with -fdata-sections will store each TLS variable
in a comdat section, named .tls$$<varname>. Normal TLS variables are
stored in sections named .tls$ with a trailing dollar, which are
sorted after a starter marker (in a later linked object file) in a
section named ".tls" (with no dollar suffix), before an ending marker
in a section named ".tls$ZZZ".

The mingw comdat section suffix stripping introduced in SVN r363457
broke sorting of such tls sections, ending up sorting the stripped
.tls$$<varname> sections (stripped to ".tls") before the start marker
in the section named ".tls".

We could add exceptions to the section name suffix stripping for
.tls (and .CRT, where suffixes always should be honored), but the
more conservative option is probably the reverse; to only apply the
stripping for the normal sections where sorting shouldn't have any
effect.

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

llvm-svn: 366780
2019-07-23 06:38:04 +00:00
Fangrui Song 5d4bc1293c [ARM][test] Improve tests
Delete trailing 2>&1 that is not piped to another command.
Add --no-show-raw-insn to objdump -d commands.

llvm-svn: 366676
2019-07-22 11:37:03 +00:00
Petr Hosek ae4c30a4be [ELF] Support explicitly overriding relocation model in LTO
lld currently selects the relocation model automatically depending on
the link flags specified, but in some cases it'd be useful to allow
explicitly overriding the relocation model using a flag.

llvm-svn: 366644
2019-07-20 21:59:47 +00:00
Guanzhong Chen 5204f7611f [WebAssembly] Compute and export TLS block alignment
Summary:
Add immutable WASM global `__tls_align` which stores the alignment
requirements of the TLS segment.

Add `__builtin_wasm_tls_align()` intrinsic to get this alignment in Clang.

The expected usage has now changed to:

    __wasm_init_tls(memalign(__builtin_wasm_tls_align(),
                             __builtin_wasm_tls_size()));

Reviewers: tlively, aheejin, sbc100, sunfish, alexcrichton

Reviewed By: tlively

Subscribers: dschuff, jgravelle-google, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

llvm-svn: 366624
2019-07-19 23:34:16 +00:00
Nico Weber cb2c50028d lld-link: Demangle symbols from archives in diagnostics
Also add test coverage for thin archives (which are the only way I could
come up with to test at least some of the diagnostic changes).

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

llvm-svn: 366573
2019-07-19 13:29:10 +00:00
Fangrui Song 3628d948f5 [ELF][test] Fix aarch64-condb-reloc.s
llvm-svn: 366534
2019-07-19 08:00:22 +00:00
Fangrui Song c2a5459d52 [ELF][AArch64] Improve some aarch64-*.s tests
* Delete aarch64-tls-static.s: it is covered by aarch64-tlsdesc.c
* Add --no-show-raw-insn to llvm-objdump -d tests
* When linking an executable with %t.so, the path %t.so will be recorded in the DT_NEEDED entry if %t.so doesn't have DT_SONAME. The DT_NEEDED has varying lengths on different systems.
  Add -soname to make tests more robust. This issue will become outstanding if we allow overlapping PT_LOAD (D64930).

llvm-svn: 366532
2019-07-19 06:33:36 +00:00
Thomas Lively 6a6f28f7b7 [WebAssembly] Use passive segments by default when memory is shared
Summary:
This change makes it so that passing --shared-memory is all a user
needs to do to get proper multithreaded code. This default can still
be explicitly overridden for any reason using --passive-segments and
--active-segments.

Reviewers: sbc100, quantum

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

Tags: #llvm

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

llvm-svn: 366504
2019-07-18 21:50:24 +00:00
Guanzhong Chen 21aafc2e0c [WebAssembly] fix bug in finding .tdata segment
Summary: Fix bug in `wasm-ld`'s `Writer::createInitTLSFunction` that only finds `.tdata` if it's the first section.

Reviewers: tlively, aheejin, sbc100

Reviewed By: sbc100

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

Tags: #llvm

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

llvm-svn: 366500
2019-07-18 21:18:24 +00:00
Peter Collingbourne c2ccf4ccba ELF: Add support for remaining R_AARCH64_MOVW* relocations.
Differential Revision: https://reviews.llvm.org/D64685

llvm-svn: 366466
2019-07-18 17:12:50 +00:00
Peter Collingbourne 311131dafc ELF: Simplify test. NFCI.
Avoid splitting the test into multiple files and use zero for the value of
the symbol with addends at relocations so that it's clear what value is
being used at relocations.

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

llvm-svn: 366463
2019-07-18 16:57:06 +00:00
Peter Collingbourne cb2d8e9125 ELF: Allow forward references to linked sections.
It's possible to create IR that uses !associated to refer to a global that
appears later in the module, which can result in these types of forward
references being generated. Unfortunately our assembler does not currently
accept the resulting .s so I needed to use yaml2obj to test this.

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

llvm-svn: 366460
2019-07-18 16:47:29 +00:00
Jonas Devlieghere a5359b1b07 [CMake] Don't set Python_ADDITIONAL_VERSIONS
Until recently, Python_ADDITIONAL_VERSIONS was used to limit LLVM's
Python support to 2.7. Now that both LLVM and LLDB both support Python
3, there's no longer a need to put an arbitrary limit on this.

However, instead of removing the variable, r365692 expanded the list,
which has the (presumably unintentional) side-effect of expression
preference for Python 3.

Instead, as Michal proposed in the original code review, we should just
not set the list at all, and let CMake pick whatever Python interpreter
you have in your path.

This patch removes the Python_ADDITIONAL_VERSIONS variable in llvm,
clang and lld. I've also updated the docs with the default behavior and
how to force a different Python version to be used.

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

llvm-svn: 366447
2019-07-18 15:17:42 +00:00
Fangrui Song f286fa3088 [ELF][PPC] Delete ppc64-dynamic-relocations.s
I forgot to delete it in r366424.

llvm-svn: 366445
2019-07-18 15:07:42 +00:00
Hans Wennborg 8f5b44aead Bump the trunk version to 10.0.0svn
and clear the release notes.

llvm-svn: 366427
2019-07-18 11:51:05 +00:00
Fangrui Song 782390258b [ELF][PPC] Refactor some ppc64 tests
Merge ppc64-dynamic-relocations.s into ppc64-plt-stub.s
Add ppc64-tls-ie.s: covers ppc64-initial-exec-tls.s and ppc64-tls-ie-le.s
Add ppc64-tls-gd.s: covers ppc64-general-dynamic-tls.s, ppc64-gd-to-ie.s, ppc64-tls-gd-le.s, and ppc64-tls-gd-le-small.s

llvm-svn: 366424
2019-07-18 10:43:07 +00:00
Chris Jackson 0b03429a91 [lld] Fix vs-diagnostics-version-script test. NFC.
Removed unnecessary llvm-mc call.

llvm-svn: 366418
2019-07-18 09:17:11 +00:00
Diana Picus f26706fa1c Fixup r366333 (require x86 in test)
Seems to be required for the other added tests too.

llvm-svn: 366416
2019-07-18 08:27:44 +00:00
Alex Bradbury 44deaf7e54 [DWARF][RISCV] Add support for RISC-V relocations needed for debug info
When code relaxation is enabled many RISC-V fixups are not resolved but
instead relocations are emitted. This happens even for DWARF debug
sections. Therefore, to properly support the parsing of DWARF debug info
we need to be able to resolve RISC-V relocations. This patch adds:

* Support for RISC-V relocations in RelocationResolver
* DWARF support for two relocations per object file offset
* DWARF changes to support relocations in more DIE fields

The two relocations per offset change is needed because some RISC-V
relocations (used for label differences) come in pairs.

Relocations can also be emitted for DWARF fields where relocations were
not yet evaluated. Adding relocation support for some of these fields is
essencial. On the other hand, LLVM currently emits RISC-V relocations
for fixups that could be safely evaluated, since they can never be
affected by code relaxations. This patch also adds relocation support
for the fields affected by those extraneous relocations (the DWARF unit
entry Length, and the DWARF debug line entry TotalLength and
PrologueLength), for testing purposes.

Differential Revision: https://reviews.llvm.org/D62062
Patch by Luís Marques.

llvm-svn: 366402
2019-07-18 05:22:55 +00:00
Fangrui Song 1d5cbb7557 [ELF][test] Merge/rename some basic*.s tests
basic64be.s is a big-endian powerpc64 test that just duplicates what
basic-ppc64.s does. Extend basic-ppc64.s to add big-endian tests.
Delete basic64be.s

Rename basic32.s to basic-i386.s

llvm-svn: 366401
2019-07-18 04:54:58 +00:00
Sam Clegg accad76c14 [lld][WebAssembly] Fix handling of comdat functions in init array.
When hidden symbols are discarded by comdat rules we still want to
create a local defined symbol, otherwise `Symbol::isDiscarded()` relies
on begin able to check `getChunk->discarded`.

This is a followup on rL362769. The comdat.ll test was previously GC'ing
the `__wasm_call_ctors` functions so `do_init` was not actually being
included in the link.  Once that function was included in triggered the
crash bug that this change addresses.

Fixes: https://github.com/emscripten-core/emscripten/issues/8981

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

llvm-svn: 366358
2019-07-17 18:43:36 +00:00
Chris Jackson 87886299b4 [lld] Add Visual Studio compatible diagnostics
Summary:
Add a --vs-diagnostics flag that alters the format of diagnostic output
to enable source hyperlinks in Visual Studio.

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

Reviewed by: ruiu

llvm-svn: 366333
2019-07-17 14:54:02 +00:00
Fangrui Song 2be0ebb0d8 [ELF] Delete redundant pageAlign at PT_GNU_RELRO boundaries after D58892
Summary:
After D58892 split the RW PT_LOAD on the PT_GNU_RELRO boundary, the new
layout is:

PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)) PT_LOAD(.data. .bss)

The two pageAlign() calls at PT_GNU_RELRO boundaries are redundant due
to the existence of PT_LOAD.

Reviewers: grimar, peter.smith, ruiu, espindola

Reviewed By: ruiu

Subscribers: sfertile, atanasyan, emaste, arichardson, llvm-commits

Tags: #llvm

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

llvm-svn: 366307
2019-07-17 09:23:04 +00:00
Reid Kleckner fa57583922 Add REQUIRES: x86 to safeseh-no.s test for x86
llvm-svn: 366273
2019-07-16 22:01:30 +00:00
Guanzhong Chen 42bba4b852 [WebAssembly] Implement thread-local storage (local-exec model)
Summary:
Thread local variables are placed inside a `.tdata` segment. Their symbols are
offsets from the start of the segment. The address of a thread local variable
is computed as `__tls_base` + the offset from the start of the segment.

`.tdata` segment is a passive segment and `memory.init` is used once per thread
to initialize the thread local storage.

`__tls_base` is a wasm global. Since each thread has its own wasm instance,
it is effectively thread local. Currently, `__tls_base` must be initialized
at thread startup, and so cannot be used with dynamic libraries.

`__tls_base` is to be initialized with a new linker-synthesized function,
`__wasm_init_tls`, which takes as an argument a block of memory to use as the
storage for thread locals. It then initializes the block of memory and sets
`__tls_base`. As `__wasm_init_tls` will handle the memory initialization,
the memory does not have to be zeroed.

To help allocating memory for thread-local storage, a new compiler intrinsic
is introduced: `__builtin_wasm_tls_size()`. This instrinsic function returns
the size of the thread-local storage for the current function.

The expected usage is to run something like the following upon thread startup:

    __wasm_init_tls(malloc(__builtin_wasm_tls_size()));

Reviewers: tlively, aheejin, kripken, sbc100

Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

llvm-svn: 366272
2019-07-16 22:00:45 +00:00
Reid Kleckner 11dc3d3711 Mark new test as requiring an x86 backend for LTO native object generation
llvm-svn: 366245
2019-07-16 18:34:46 +00:00
Reid Kleckner 4b6f69fe90 Fix linkrepro.test after safeseh:no change
Add the @feat.00 flag to the input.

llvm-svn: 366244
2019-07-16 18:33:13 +00:00
Reid Kleckner fe44a531e0 [COFF] Implement /safeseh:no and check @feat.00 flags by default
Summary:
Fixes PR41828. Before this, LLD always emitted SafeSEH chunks and
defined __safe_se_handler_table & size. Now, /safeseh:no leaves those
undefined.

Additionally, we were checking for the safeseh @feat.00 flag in two
places: once to emit errors, and once during safeseh table construction.
The error was set up to be off by default, but safeseh is supposed to be
on by default. I combined the two checks, so now LLD emits an error if
an input object lacks @feat.00 and safeseh is enabled. This caused the
majority of 32-bit LLD tests to fail, since many test input object files
lack @feat.00 symbols. I explicitly added -safeseh:no to those tests to
preserve behavior.

Finally, LLD no longer sets IMAGE_DLL_CHARACTERISTICS_NO_SEH if any
input file wasn't compiled for safeseh.

Reviewers: mstorsjo, ruiu, thakis

Reviewed By: ruiu, thakis

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 366238
2019-07-16 18:17:33 +00:00
Fangrui Song 2e2038b647 [COFF] Rename variale references in comments after VariableName -> variableName change
llvm-svn: 366193
2019-07-16 08:26:38 +00:00
Fangrui Song 33fdf82dda [WebAssembly] Rename variale references in comments after VariableName -> variableName change
llvm-svn: 366192
2019-07-16 08:08:17 +00:00
Puyan Lotfi 3e10905c49 [NFC][test] Fix for riscv tests.
Following tests need updating for: https://reviews.llvm.org/D55277

llvm-svn: 366183
2019-07-16 05:58:03 +00:00
Fangrui Song 47cfe8f321 [ELF] Fix variable names in comments after VariableName -> variableName change
Also fix some typos.

llvm-svn: 366181
2019-07-16 05:50:45 +00:00
Rui Ueyama 49a3ad21d6 Fix parameter name comments using clang-tidy. NFC.
This patch applies clang-tidy's bugprone-argument-comment tool
to LLVM, clang and lld source trees. Here is how I created this
patch:

$ git clone https://github.com/llvm/llvm-project.git
$ cd llvm-project
$ mkdir build
$ cd build
$ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \
    -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \
    -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm
$ ninja
$ parallel clang-tidy -checks='-*,bugprone-argument-comment' \
    -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \
    ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h}

llvm-svn: 366177
2019-07-16 04:46:31 +00:00
Jonas Devlieghere ca16d280f7 Re-land "[DebugInfo] Move function from line table to the prologue (NFC)"
In LLDB, when parsing type units, we don't need to parse the whole line
table. Instead, we only need to parse the "support files" from the line
table prologue.

To make that possible, this patch moves the respective functions from
the LineTable into the Prologue. Because I don't think users of the
LineTable should have to know that these files come from the Prologue,

I've left the original methods in place, and made them redirect to the
LineTable.

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

llvm-svn: 366164
2019-07-16 01:21:25 +00:00
Heejin Ahn 9f96a58ccc [WebAssembly] Rename except_ref type to exnref
Summary:
We agreed to rename `except_ref` to `exnref` for consistency with other
reference types in
https://github.com/WebAssembly/exception-handling/issues/79. This also
renames WebAssemblyInstrExceptRef.td to WebAssemblyInstrRef.td in order
to use the file for other reference types in future.

Reviewers: dschuff

Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits

Tags: #llvm

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

llvm-svn: 366145
2019-07-15 22:49:25 +00:00
Reid Kleckner 3e7c314b03 Reland "[COFF] Add null check in case of symbols defined in LTO blobs"
This reverts r365990 (git commit 1a6053ebc6)

The test no longer depends on the Visual C++ libraries. I confirmed that
the crash still reproduces with the new test case if I remove the null
check.

llvm-svn: 366095
2019-07-15 17:51:02 +00:00
George Rimar 8d9b9f6bf2 [LLD][ELF] - Minor simplification. NFC.
This removes a call to `object::getSymbol<ELFT>`.
We used this function in a next way: it was given an
array of symbols and index and returned either a symbol
at the index given or a error.

This function was removed in D64631. 
(rL366052, but was reverted because of LLD compilation error
that I didn't know about).

It does not make much sense to keep this function on LLVM side
only for LLD, because having only a list of symbols and the index it
is not able to produce a valueable error message about context anyways.

llvm-svn: 366057
2019-07-15 11:47:54 +00:00
Petr Hosek 1a6053ebc6 Revert "[COFF] Add null check in case of symbols defined in LTO blobs"
This reverts commit r365979: COFF/undefined-symbol-lto.test is failing.

llvm-svn: 365990
2019-07-13 05:31:48 +00:00
Reid Kleckner 0291d30929 [COFF] Add null check in case of symbols defined in LTO blobs
The test case could probably be improved further if the failure path was
better understood.

Fixes PR42536

llvm-svn: 365979
2019-07-13 00:20:34 +00:00
Thomas Lively 26a6b95da9 [WebAssembly] i32.const operands should be signed
Summary:
This was causing large addresses to be emitted as negative numbers,
which rightfully caused crashes in binaryen.

Reviewers: aheejin, dschuff

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

Tags: #llvm

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

llvm-svn: 365930
2019-07-12 17:55:07 +00:00
Rui Ueyama 332fc712c6 Fix odd variable names.
llvm-svn: 365875
2019-07-12 06:12:27 +00:00
Simon Atanasyan 5dd5541d9f [mips] Simplify test case. NFC
Before rL295040 the linker just crashed when a GOT relocation (R_MIPS_GOT16)
comes from a merge section. To ensure that this bug still fixed it's enough
to check that the linker does not crash and create GOT entries.

llvm-svn: 365834
2019-07-11 21:55:56 +00:00
Martin Storsjo 6bd26db06a [COFF] Share the tail in delayimport symbol thunks
E.g. for x86_64, previously each symbol's thunk was 87 bytes. Now
there's a 12 byte thunk per symbol, plus a shared 83 byte tail
function.

This is similar to what both MS link.exe and GNU tools do for
delay imports.

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

llvm-svn: 365823
2019-07-11 21:19:11 +00:00
Bob Haarman 5011b83237 [lld-link] implement -thinlto-{prefix,object-suffix}-replace
Summary:
Adds the following two options to lld-link:

-thinlto-prefix-replace: allows replacing a prefix in paths generated
for ThinLTO. This can be used to ensure index files and native object
files are stored in unique directories, allowing multiple distributed
ThinLTO links to proceed concurrently.

-thinlto-object-suffix-replace: allows replacing a suffix in object
file paths involved in ThinLTO. This allows minimized index files to
be used for the thin link while storing the paths to the full bitcode
files for subsequent steps (code generation and final linking).

Reviewers: ruiu, tejohnson, pcc, rnk

Subscribers: mehdi_amini, steven_wu, dexonsmith, llvm-commits

Tags: #llvm

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

llvm-svn: 365807
2019-07-11 18:48:58 +00:00
Bob Haarman 63efb28f47 [lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.

Reviewers: ruiu, tejohnson, pcc, rnk

Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits

Tags: #llvm

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

llvm-svn: 365800
2019-07-11 18:03:14 +00:00
Sam Clegg fd11ce32bb [WebAssembly] Import __stack_pointer when building -pie binaries
The -pie binary doesn't know that layout ahead of time so needs to
import the stack pointer from the embedder, just like we do already
for shared libraries.

This change is needed in order to address:
https://github.com/emscripten-core/emscripten/issues/8915

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

llvm-svn: 365771
2019-07-11 13:13:25 +00:00
Fangrui Song e1ee3837ac [ELF] Handle non-glob patterns before glob patterns in version scripts & fix a corner case of --dynamic-list
This fixes PR38549, which is silently accepted by ld.bfd.
This seems correct because it makes sense to let non-glob patterns take
precedence over glob patterns.

lld issues an error because
`assignWildcardVersion(ver, VER_NDX_LOCAL);` is processed before `assignExactVersion(ver, v.id, v.name);`.

Move all assignWildcardVersion() calls after assignExactVersion() calls
to fix this.

Also, move handleDynamicList() to the bottom. computeBinding() called by
includeInDynsym() has this cryptic rule:

    if (versionId == VER_NDX_LOCAL && isDefined() && !isPreemptible)
      return STB_LOCAL;

Before the change:

* foo's version is set to VER_NDX_LOCAL due to `local: *`
* handleDynamicList() is called
  - foo.computeBinding() is STB_LOCAL
  - foo.includeInDynsym() is false
  - foo.isPreemptible is not set (wrong)
* foo's version is set to V1

After the change:

* foo's version is set to VER_NDX_LOCAL due to `local: *`
* foo's version is set to V1
* handleDynamicList() is called
  - foo.computeBinding() is STB_GLOBAL
  - foo.includeInDynsym() is true
  - foo.isPreemptible is set (correct)

Reviewed By: ruiu

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

llvm-svn: 365760
2019-07-11 11:16:51 +00:00
Fangrui Song be8275753f [ELF] Warn rather than error when duplicate version assignments occur
In lvm2, libdevmapper.so is linked with a version script with duplicate
version assignments:

    DM_1_02_138 { global: ... dm_bitset_parse_list; ... };
    DM_1_02_129 { global: ... dm_bitset_parse_list; ... };

ld.bfd silently accepts this while gold issues a warning. We currently
error, thus inhibit producing the executable. Change the error to
warning to allow this case, and improve the message.

There are some cases where ld.bfd error
`anonymous version tag cannot be combined with other version tags`
but we just warn. It is probably OK for now.

Reviewed By: grimar, ruiu

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

llvm-svn: 365759
2019-07-11 11:16:44 +00:00
Rui Ueyama 77565f7690 Fix build breakage on Win32.
llvm-svn: 365737
2019-07-11 06:56:44 +00:00
Rui Ueyama f4954b52e4 Fix build breakage on Darwin.
llvm-svn: 365734
2019-07-11 06:12:18 +00:00
Rui Ueyama bfaf64ae57 Update comments for r365730. NFC.
llvm-svn: 365733
2019-07-11 06:08:54 +00:00
Rui Ueyama 76c3f6cdff Fix build breakage on Win32.
llvm-svn: 365732
2019-07-11 06:00:40 +00:00
Rui Ueyama 136d27ab4d [Coding style change][lld] Rename variables for non-ELF ports
This patch does the same thing as r365595 to other subdirectories,
which completes the naming style change for the entire lld directory.

With this, the naming style conversion is complete for lld.

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

llvm-svn: 365730
2019-07-11 05:40:30 +00:00
Nikola Prica 6522bedefe Revert "[ELF] Update test case due to llvm r365618"
Reverting du to reverting r365618

This reverts commit b1e76d1d41c2303f70b53e352bdefbff2a2a9d37.

llvm-svn: 365686
2019-07-10 18:58:29 +00:00
Peter Collingbourne d37edd0c79 ELF: Add support for R_AARCH64_ADR_PREL_PG_HI21_NC relocation.
Differential Revision: https://reviews.llvm.org/D64456

llvm-svn: 365662
2019-07-10 16:42:20 +00:00
George Rimar c44a23f8f4 [LLD][ELF] - Linkerscript: fix FILL() expressions handling.
D64130 introduced a bug described in the following message:
https://reviews.llvm.org/D64130#1571560

The problem can happen with the following script:

SECTIONS {
  .out : {
...
   FILL(0x10101010)
   *(.aaa)
...
}

The current code tries to read (0x10101010) as an expression and
does not break when meets *, what results in a script parsing error.

In this patch, I verify that FILL command's expression always wrapped in ().
And at the same time =<fillexp> expression can be both wrapped or unwrapped.
I checked it matches to bfd/gold.

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

llvm-svn: 365635
2019-07-10 14:36:48 +00:00
Nikola Prica fcd978b0a6 [ELF] Update test case due to llvm r365618
llvm-svn: 365619
2019-07-10 11:19:44 +00:00
Rui Ueyama 7e296adec7 Make functions and member variables distinguishable even after the name style change. NFC.
llvm-svn: 365605
2019-07-10 09:10:01 +00:00
Rui Ueyama 3837f4273f [Coding style change] Rename variables so that they start with a lowercase letter
This patch is mechanically generated by clang-llvm-rename tool that I wrote
using Clang Refactoring Engine just for creating this patch. You can see the
source code of the tool at https://reviews.llvm.org/D64123. There's no manual
post-processing; you can generate the same patch by re-running the tool against
lld's code base.

Here is the main discussion thread to change the LLVM coding style:
https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html
In the discussion thread, I proposed we use lld as a testbed for variable
naming scheme change, and this patch does that.

I chose to rename variables so that they are in camelCase, just because that
is a minimal change to make variables to start with a lowercase letter.

Note to downstream patch maintainers: if you are maintaining a downstream lld
repo, just rebasing ahead of this commit would cause massive merge conflicts
because this patch essentially changes every line in the lld subdirectory. But
there's a remedy.

clang-llvm-rename tool is a batch tool, so you can rename variables in your
downstream repo with the tool. Given that, here is how to rebase your repo to
a commit after the mass renaming:

1. rebase to the commit just before the mass variable renaming,
2. apply the tool to your downstream repo to mass-rename variables locally, and
3. rebase again to the head.

Most changes made by the tool should be identical for a downstream repo and
for the head, so at the step 3, almost all changes should be merged and
disappear. I'd expect that there would be some lines that you need to merge by
hand, but that shouldn't be too many.

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

llvm-svn: 365595
2019-07-10 05:00:37 +00:00
Sam Clegg 9abe8c4805 [lld][WebAssembly] Report undefined symbols during scanRelocations
This puts handling of undefined symbols in a single location.  Its
also more in line with the ELF backend which only reports undefined
symbols based on relocations.

One side effect is that we no longer report undefined symbols that are
only referenced in GC'd sections.

This also fixes a crash reported in the emscripten toolchain:
https://github.com/emscripten-core/emscripten/issues/8930.

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

llvm-svn: 365553
2019-07-09 20:45:20 +00:00
Sam Clegg 51c2b99eff [lld][WebAssembly] Fix name of data section in PIC mode
This should always have been ".data".  Without this we treat the
section as a user-defined section in other places (such as the
generation of __start/__stop symbols).

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

llvm-svn: 365547
2019-07-09 19:47:32 +00:00
Nico Weber e7a67bf8ce lld-link: Stop accepting /natvis and /fastfail in .drectve sections
link.exe doesn't accept them either.

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

llvm-svn: 365478
2019-07-09 13:30:03 +00:00
Fangrui Song 50e7f45b28 [ELF] Assert sizeof(SymbolUnion) <= 80
Reviewed By: ruiu

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

llvm-svn: 365443
2019-07-09 07:12:58 +00:00
Fangrui Song c117be6fc6 [ELF][test] Rename tail-merge-string-align2.s to merge-string-align2.s
This test was added by D64200/r365139 to check we don't merge
SHF_MERGE|SHF_STRINGS sections with different alignments (that wastes
space and can make MergeTailAlignment::Builder out of sync).

It has nothing to do with tail merge (-O2), so rename it.

llvm-svn: 365442
2019-07-09 06:10:21 +00:00
Denis Bakhvalov 92fb5f2e47 [LLD] NFC: Fixed GCC warning in ELF/Arch/RISCV.cpp
GCC emits warning on this line:
error: enumeral and non-enumeral type in conditional
expression [-Werror=extra]

Change-Id: I04969cc32e27e310968b88ebaa4e1c4894528d74
llvm-svn: 365434
2019-07-09 03:56:44 +00:00
Nico Weber e3f06b478c Let unaliased Args track which Alias they were created from, and use that in Arg::getAsString() for diagnostics
With this, `clang-cl /source-charset:utf-16 test.cc` now prints `invalid
value 'utf-16' in '/source-charset:utf-16'` instead of `invalid value
'utf-16' in '-finput-charset=utf-16'` before, and several other clang-cl
flags produce much less confusing output as well.

Fixes PR29106.

Since an arg and its alias can have different arg types (joined vs not)
and different values (because of AliasArgs<>), I chose to give the Alias
its own Arg object. For convenience, I just store the alias directly in
the unaliased arg – there aren't many arg objects at runtime, so that
seems ok.

Finally, I changed Arg::getAsString() to use the alias's representation
if it's present – that function was already documented as being the
suitable function for diagnostics, and most callers already used it for
diagnostics.

Implementation-wise, Arg::accept() previously used to parse things as
the unaliased option. The core of that switch is now extracted into a
new function acceptInternal() which parses as the _aliased_ option, and
the previously-intermingled unaliasing is now done as an explicit step
afterwards.

(This also changes one place in lld that didn't use getAsString() for
diagnostics, so that that one place now also prints the flag as the user
wrote it, not as it looks after it went through unaliasing.)

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

llvm-svn: 365413
2019-07-09 00:34:08 +00:00
Bill Wendling 858e35160e Add parentheses to silence warnings.
llvm-svn: 365397
2019-07-08 22:05:02 +00:00
Sam Clegg 556ec990e9 [lld] Use -o /dev/null in test when output is not needed.
Fix for feedback nit from rL364998

llvm-svn: 365310
2019-07-08 11:14:10 +00:00
Sam Clegg 15006469bf [lld][WebAssembly] Fix __start/__stop symbols when combining input segments
We should be generating one __start/__stop pair per output segment
not per input segment.  The test wasn't catching this because it was
only linking a single object file.

Fixes PR41565

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

llvm-svn: 365308
2019-07-08 10:35:08 +00:00
Sam Clegg d0e1d00397 [lld][WebAssembly] Fix typo in error message
Differential Revision: https://reviews.llvm.org/D64315

llvm-svn: 365304
2019-07-08 09:34:30 +00:00
Fangrui Song 34958d12c9 [WebAssembly] Add static_assert(sizeof(SymbolUnion) <= 96)
On Windows, the bitfield layout rule places `ussigned Referenced : 1` at
byte offset 40, instead of byte offset 37 on *NIX. The consequence is that
sizeof(SymbolUnion) == 104 on Windows while 96 on *NIX.

To eliminate this difference, change these unsigned bitfields to bool.

Reviewed By: ruiu

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

llvm-svn: 365296
2019-07-08 07:30:07 +00:00
Nico Weber a780276301 lld, llvm-dlltool, llvm-lib: Use getAsString() instead of getSpelling() for printing unknown args
Since OPT_UNKNOWN args never have any values and consist only of
spelling (and are never aliased), this doesn't make any difference in
practice, but it's more consistent with Arg's guidance to use
getAsString() for diagnostics, and it matches what clang does.

Also tweak two tests to use an unknown option that contains '=' for
additional coverage while here. (The new tests pass fine with the old
code too though.)

llvm-svn: 365200
2019-07-05 12:31:32 +00:00
Nico Weber cf1a11ded2 Make joined instances of JoinedOrSeparate flags point to the unaliased args, like all other arg types do
This fixes an 8-year-old regression. r105763 made it so that aliases
always refer to the unaliased option – but it missed the "joined" branch
of JoinedOrSeparate flags. (r162231 then made the Args classes
non-virtual, and r169344 moved them from clang to llvm.)

Back then, there was no JoinedOrSeparate flag that was an alias, so it
wasn't observable. Now /U in CLCompatOptions is a JoinedOrSeparate alias
in clang, and warn_slash_u_filename incorrectly used the aliased arg id
(using the unaliased one isn't really a regression since that warning
checks if the undefined macro contains slash or backslash and only then
emits the warning – and no valid use will pass "-Ufoo/bar" or similar).

Also, lld has many JoinedOrSeparate aliases, and due to this bug it had
to explicitly call `getUnaliasedOption()` in a bunch of places, even
though that shouldn't be necessary by design. After this fix in Option,
these calls really don't have an effect any more, so remove them.

No intended behavior change.

(I accidentally fixed this bug while working on PR29106 but then
wondered why the warn_slash_u_filename broke. When I figured it out, I
thought it would make sense to land this in a separate commit.)

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

llvm-svn: 365186
2019-07-05 11:45:24 +00:00
George Rimar c9a5c631fe [LLD][ELF] - Update a test after LLVM change.
Error reporting changed in r365183

llvm-svn: 365184
2019-07-05 11:29:04 +00:00
Nico Weber fdef18b42d lld-link: Make /debugtype: option work better
- The code tried to pass false to split()'s KeepEmpty parameter, but
  instead passed it to MaxSplit. As a result, it would never split on
  commas. This has been broken since the flag was added in r278056.

- The code used getSpelling() for getting the argument's values, but
  getSpelling() always returns the `/debugtype:` prefix without any
  values. So if any /debugtype: flag was passed, it always resulted in
  an "unknown option:" warning. (The warning code then used the correct
  getValue() for printing the invalid option, so the warning looked
  kind of like it made sense.) This regressed in r342894.

Slightly improve the test coverage of this feature (but since I don't
know what this flag actually does, there's still no test for the correct
semantics), and add a comment to getSpelling() explaining what it does.

llvm-svn: 365182
2019-07-05 11:28:31 +00:00
Fangrui Song c4339f1051 [WebAssembly] Delete static_assert(sizeof(SymbolUnion) <= 96) to fix Windows builds
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/47944/steps/stage%201%20build/logs/stdio

Needs to figure out later the size on Windows.

llvm-svn: 365171
2019-07-05 01:45:12 +00:00
Fangrui Song 3d0193909b [WebAssembly] Reorder Symbol fields to make it smaller
On 64-bit systems, this decreases sizeof(SymbolUnion) from 112 to 96.

Add a static_assert to avoid accidental increases in future.

Reviewed By: sbc100

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

llvm-svn: 365169
2019-07-05 01:27:39 +00:00
George Rimar 0810f16fb9 [LLD][ELF] - Linkerscript: add a support for expressions for section's filling
Imagine the script:

.section: {
...
} = FILL_EXPR
LLD assumes that FILL_EXPR is a number, and does not allow
it to be an expression. Though that is allowed by specification:
https://sourceware.org/binutils/docs-2.32/ld/Output-Section-Fill.html

This patch adds a support for cases when FILL_EXPR is simple math expression.

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

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

llvm-svn: 365143
2019-07-04 14:17:31 +00:00
Fangrui Song 5c4bbc2746 [ELF] Allow placing non-string SHF_MERGE sections with different alignments into the same MergeSyntheticSection
The difference from D63432/r365015 is that this patch does not place
SHF_STRINGS sections with different alignments into the same
MergeSyntheticSection. Doing that would:

(1) create unnecessary padding and thus waste space.
  Add a test tail-merge-string-align2.s to check no extra padding is created.
(2) make some input sections unaligned when tail merge (-O2) is enabled.
  The alignment of MergeTailAlignment::Builder was out of sync in D63432.
  MOVAPS on such unaligned strings can raise SIGSEGV.

This should fix PR42289: the Linux kernel has a use case that input
files have .rodata.cst32 sections with different alignments. The
expectation (and what ld.bfd and gold do) is that in the -r link, there
is only one .rodata.cst32 (SHF_MERGE sections with different alignments
can be combined), but lld currently creates one for each different
alignment.

The current merging strategy:

1) Group SHF_MERGE sections by (name, sh_flags, sh_entsize and
   sh_addralign). Merging is performed among a group, even if -O0 is specified.
2) Create one output section for each group. This is a special case in
   addInputSec().

This patch changes 1) to:

1) Group SHF_MERGE sections by (name, sh_flags, sh_entsize).
   Merging is performed among a group, even if -O0 is specified.

We will thus create just one .rodata.cst32 . This also improves merging
efficiency when sections with the same name but different alignments are
combined.

Reviewed By: peter.smith

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

llvm-svn: 365139
2019-07-04 13:33:27 +00:00