Commit Graph

3617 Commits

Author SHA1 Message Date
Fangrui Song 213d1849a4 [ELF] Improve sh_info=0 and sh_info>=num_sections diagnostic for SHT_REL/SHT_RELA
PR52408 reported an sh_info=0 instance. I have seen sh_info=0
independently before.

sh_info>=num_sections is probably very rare. Just use one diagnostic for
the two types of errors.

Delete invalid-relocations.test which is covered by invalid/bad-reloc-target.test

Differential Revision: https://reviews.llvm.org/D113466
2021-11-09 09:54:12 -08:00
Fangrui Song cebb0a64b4 [ELF][ARM] Improve error message for unknown relocation
Like rLLD354040.

Before: `error: unrecognized relocation Unknown (254)`
Now:    `error: unknown relocation (254) against symbol foo`
2021-11-08 12:39:08 -08:00
Fangrui Song 26a8ceba3e [llvm-readobj] Display DT_RELRSZ/DT_RELRENT as " (bytes)"
to match RELSZ/RELENT.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D113206
2021-11-05 10:02:49 -07:00
Fangrui Song 9f8ffaaa0b [ELF] Replace "symbol '...' has no type" diagnostic with "relocation ... cannot be used against symbol '...'"
The "symbol 'foo' has no type" diagnostic tries to inform that copy
relocation/canonical PLT entry cannot be used, but the diagnostic is often
incorrect and confusing.
2021-10-31 13:12:26 -07:00
Fangrui Song 55e69ece72 [ELF] Remove -Wl,-z,notext hint
The hint does not pull its weight:

* adding -Wl,-z,notext often won't work (relocation types other than `symbolRel`, e.g. `R_AARCH64_LDST32_ABS_LO12_NC`)
* for pure (no assembly) C/C++ projects, the "-fPIC" hint is sufficient
2021-10-31 12:10:43 -07:00
Fangrui Song e39c138f45 [ELF] Implement TLSDESC for x86-32
`-z rela` is also supported.

Tested with:

```
cat > ./a.c <<eof
#include <assert.h>
int foo();
int bar();
int main() {
  assert(foo() == 2);
  assert(foo() == 4);
  assert(bar() == 2);
  assert(bar() == 4);
}
eof

cat > ./b.c <<eof
#include <stdio.h>
__thread int tls0;
extern __thread int tls1;
int foo() { return ++tls0 + ++tls1; }
static __thread int tls2, tls3;
int bar() { return ++tls2 + ++tls3; }
eof

echo '__thread int tls1;' > ./c.c

sed 's/        /\t/' > ./Makefile <<'eof'
.MAKE.MODE = meta curDirOk=true

CC := gcc -m32 -g -fpic -mtls-dialect=gnu2
LDFLAGS := -m32 -Wl,-rpath=.

all: a0 a1 a2

run: all
        ./a0 && ./a1 && ./a2

c.so: c.o; ${LINK.c} -shared $> -o $@
bc.so: b.o c.o; ${LINK.c} -shared $> -o $@
b.so: b.o c.so; ${LINK.c} -shared $> -o $@

a0: a.o b.o c.o; ${LINK.c} $> -o $@
a1: a.o b.so; ${LINK.c} $> -o $@
a2: a.o bc.so; ${LINK.c} $> -o $@
eof
```
and glibc `elf/tst-gnu2-tls1`.

`/usr/local/bin/ld` points to the freshly built `lld`.

`bmake run && bmake CFLAGS=-O1 run` => ok.

Differential Revision: https://reviews.llvm.org/D112582
2021-10-28 17:52:03 -07:00
Fangrui Song 2b1e32410c [ELF] Change common diagnostics to report both object file location and source file location
Many diagnostics use `getErrorPlace` or `getErrorLocation` to report a location.
In the presence of line table debug information, `getErrorPlace` uses a source
file location and ignores the object file location. However, the object file
location is sometimes more useful.

This patch changes "undefined symbol" and "out of range" diagnostics to report
both object/source file locations. Other diagnostics can use similar format if
needed.

The key idea is to let `InputSectionBase::getLocation` report the object file
location and use `getSrcMsg` for source file/line information. `getSrcMsg`
doesn't leverage `STT_FILE` information yet, but I think the temporary lack of
the functionality is ok.

For the ARM "branch and link relocation" diagnostic, I arbitrarily place the
source file location at the end of the line. The diagnostic is not very common
so its formatting doesn't need to be pretty.

Differential Revision: https://reviews.llvm.org/D112518
2021-10-28 09:38:45 -07:00
Fangrui Song 35c3f5610c [ELF][X86] Write R_X86_64_TLSDESC addends with -z rel
Similar to D100544 for AArch64.

Reviewed By: arichardson

Differential Revision: https://reviews.llvm.org/D112592
2021-10-27 09:35:30 -07:00
Fangrui Song 25da870057 [ELF] Remove irrelevant group signature hack working around old gold -r 2021-10-25 15:09:08 -07:00
Fangrui Song 43753f8f9d [ELF] Remove irrelevant SHT_INIT_ARRAY/SHT_FINI_ARRAY hack
The hack is irrelevant for two reasons:

* binutils 2.24 is quite old and cannot handle R_X86_64_REX_GOTPCRELX from 2016 onwards anyway
* `canMergeToProgbits` allows combining SHT_INIT_ARRAY/SHT_FINI_ARRAY into SHT_PROGBITS
2021-10-25 14:23:05 -07:00
Fangrui Song 6506907a0a [ELF] Update comments/diagnostics for -defsym and -image-base to use the canonical two-dash form 2021-10-25 14:01:36 -07:00
Fangrui Song ca8105b76c [ELF][X86] Support R_X86_64_PLTOFF64
For a function call (using the default `-fplt`), GCC `-mcmodel=large` generates an assembly modifier which
leads to an R_X86_64_PLTOFF64 relocation. In real world,
http://git.ageinghacker.net/jitter (used by GNU poke) uses `-mcmodel=large`.

R_X86_64_PLTOFF64's formula is (if preemptible) `L - GOT + A` or (if non-preemptible) `S - GOT + A`
where `GOT` is (confusingly) the address of `.got.plt`

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D112386
2021-10-25 13:05:17 -07:00
Fangrui Song bf6e259b21 [ELF] Update comments/diagnostics for some long options to use the canonical two-dash form
Rewrite some comments as appropriate.
2021-10-25 12:52:06 -07:00
Fangrui Song 4ae1c2c6f1 [ELF] Delete unneeded hack for discarding empty name local symbol
This actually improves GNU ld compatibility.
Correct assemblers don't create such symbols.

Also simplify the code.
2021-10-25 11:55:31 -07:00
Fangrui Song 815a1207bf [ELF] Remove ignored options that likely nobody uses
GNU ld doesn't support `--no-pic-executable`.

`-p` has been removed from likely the only use case (Linux kernel) for over 2.5 years: https://git.kernel.org/linus/091bb549f7722723b284f63ac665e2aedcf9dec9

`--no-add-needed` was the pre-binutils-2.23 spelling for `--no-copy-dt-needed-entries`.
The legacy alias is irrelevant in 2021.
2021-10-24 18:29:45 -07:00
Igor Kudrin 1302fdc233 [ELF] Avoid adding an orphan section to a less suitable segment
If segments are defined in a linker script, placing an orphan section
before the found closest-rank section can result in adding it in a
previous segment and changing flags of that segment. This happens if
the orphan section has a lower sort rank than the found section. To
avoid that, the patch forces orphan sections to be moved after the
found section if segments are explicitly defined.

Differential Revision: https://reviews.llvm.org/D111717
2021-10-21 11:38:39 +07:00
gbreynoo f2c144fc18 [LLD][TEST] Add testing for negative addends for R_X86_64_32 and R_X86_64_PC32 relocations
This change is derived from a test case we have locally but I could not
see an equivalent in LLD's testing.

Differential Revision: https://reviews.llvm.org/D111803
2021-10-18 16:38:33 +01:00
Fangrui Song f8ee74fc13 [ELF] Require two-dash form for --pack-dyn-relocs
LLD specific options can be more rigid.
Also add a test.
2021-10-15 15:36:30 -07:00
Andrew Ng 649cc160e3 [ELF][test] Add testing for dynamic TLS relocations in .debug_info
Differential Revision: https://reviews.llvm.org/D111436
2021-10-12 10:54:52 +01:00
Ben Dunbobbin aaeba6483f [LLD] [TEST] Add test case for patching an absolute relocation to a weak undef
I noticed that we had this case in our internal testsuite but couldn't find it in LLD's tests.

This adds that case.

Differential Revision: https://reviews.llvm.org/D110716
2021-10-11 13:14:45 +01:00
Andrew Ng 3334b9d70b [ELF][test] Enhance relative dynamic relocation tests
Add checking of the value of the relocation with an addend. Also check
all relocation offsets.

Differential Revision: https://reviews.llvm.org/D111071
2021-10-05 11:32:22 +01:00
Igor Kudrin 65c284a7be [ELF][test][NFC] Make a test standard compliant
PT_LOAD segments in the program header must be sorted by their virtual
addresses, so they should be defined in a similar order as the
associated sections.

Differential Revision: https://reviews.llvm.org/D111068
2021-10-05 11:40:02 +07:00
Andrew Ng 39f3f7c08f [ELF][test] Fix several LLD ICF tests
A number of the ICF tests were not updated to use --print-icf-sections
instead of --verbose and various '-NOT' checks were not updated to the
latest output format of --print-icf-sections. Because these are all
'negative' tests, these issues have gone unnoticed.

Differential Revision: https://reviews.llvm.org/D110353
2021-10-04 11:10:10 +01:00
Shoaib Meenai f9b3c18e74 [CodeGen] Fix wrapping personality symbol on ARM
The ARM backend was explicitly setting global binding on the personality
symbol. This was added without any comment in a7ec2dcefd, which
introduced EHABI support (back in 2011). None of the other backends do
anything equivalent, as far as I can tell.

This causes problems when attempting to wrap the personality symbol.
Wrapped symbols are marked as weak inside LTO to inhibit IPO (see
https://reviews.llvm.org/D33621). When we wrap the personality symbol,
it initially gets weak binding, and then the ARM backend attempts to
change the binding to global, which causes an error in MC because of
attempting to change the binding of a symbol from non-global to global
(the error was added in https://reviews.llvm.org/D90108).

Simply drop the ARM backend's explicit global binding setting to fix
this. This matches all the other backends, and a large internal
application successfully linked and ran with this change, so it
shouldn't cause any problems. Test via LLD, since wrapping is required
to exhibit the issue.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D110609
2021-09-28 15:01:05 -07:00
Fangrui Song 74a47e54be [llvm-objdump] Fix -R display and support ET_EXEC
* Add a newline before `DYNAMIC RELOCATION RECORDS` (see D101796)
* Add the missing `OFFSET TYPE VALUE` line
* Align columns

Note: llvm-readobj/ELFDumper.cpp `loadDynamicTable` has sophisticated PT_DYNAMIC
code which is unavailable in llvm-objdump.

Reviewed By: jhenderson, Higuoxing

Differential Revision: https://reviews.llvm.org/D110595
2021-09-28 09:58:27 -07:00
Fangrui Song 2bf06d9345 [ELF] Support symbol names with space in linker script expressions
Fix PR51961

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D110490
2021-09-27 09:50:42 -07:00
Fangrui Song a892c0e49e [ELF][test] Improve test coverage 2021-09-25 11:57:54 -07:00
Fangrui Song 19d53d45f2 [ELF][AArch64] Refine and fix the condition when BTI/PAC PLT needs bti c
(As I mentioned in https://reviews.llvm.org/D62609#1534158 ,
the condition for using bti c for executable can be loosened.)

In two cases the address of a PLT may escape:

* canonical PLT entry for a STT_FUNC
* non-preemptible STT_GNU_IFUNC which is converted to STT_FUNC

The first case can be detected with `needsPltAddr`.

The second case is not straightforward to detect because for the Relocations.cpp
created `directSym`, it's difficult to know whether the associated `sym` has
exercised the `!needsPlt(expr)` code path. Just use the conservative `isInIplt`
condition. A non-preemptible ifunc not referenced by non-GOT-generating
non-PLT-generating relocations will have an unneeded `bti c`, but the cost is acceptable.

The second case fixes a bug as well: a -shared link may have non-preemptible ifunc.
Before the patch we did not emit `bti c` and could be wrong if the PLT address escaped.
GNU ld doesn't handle the case: `relocation R_AARCH64_ADR_PREL_PG_HI21 against STT_GNU_IFUNC symbol 'ifunc2' isn't handled by elf64_aarch64_final_link_relocate` (https://sourceware.org/bugzilla/show_bug.cgi?id=28370)

For -shared, if BTI is enabled but PAC is disabled, the PLT entry size increases
from 16 to 24 because we have to select the PLT scheme early, but the cost is
acceptable.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D110217
2021-09-22 11:51:09 -07:00
Hongtao Yu d9b511d8e8 [CSSPGO] Set PseudoProbeInserter as a default pass.
Currenlty PseudoProbeInserter is a pass conditioned on a target switch. It works well with a single clang invocation. It doesn't work so well when the backend is called separately (i.e, through the linker or llc), where user has always to pass -pseudo-probe-for-profiling explictly. I'm making the pass a default pass that requires no command line arg to trigger, but will be actually run depending on whether the CU comes with `llvm.pseudo_probe_desc` metadata.

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D110209
2021-09-22 09:09:48 -07:00
Andrew Ng 05b1303421 [ELF][test] Restore important part of ICF alignment test
Restore the checking of addresses in ICF test which was testing the
behaviour of ICF with regards to different alignments of otherwise
identical sections. Also make the test more robust to layout changes.

Differential Revision: https://reviews.llvm.org/D110090
2021-09-22 14:15:33 +01:00
Fangrui Song a954bb18b1 [ELF] Add --why-extract= to query why archive members/lazy object files are extracted
Similar to D69607 but for archive member extraction unrelated to GC. This patch adds --why-extract=.

Prior art:

GNU ld -M prints
```
Archive member included to satisfy reference by file (symbol)

a.a(a.o)                      main.o (a)
b.a(b.o)                      (b())
```

-M is mainly for input section/symbol assignment <-> output section mapping
(often huge output) and the information may appear ad-hoc.

Apple ld64
```
__Z1bv forced load of b.a(b.o)
_a forced load of a.a(a.o)
```

It doesn't say the reference file.

Arm's proprietary linker
```
Selecting member vsnprintf.o(c_wfu.l) to define vsnprintf.
...
Loading member vsnprintf.o from c_wfu.l.
              definition:  vsnprintf
              reference :  _printf_a
```

---

--why-extract= gives the user the full data (which is much shorter than GNU ld
-Map). It is easy to track a chain of references to one archive member with a
one-liner, e.g.

```
% ld.lld main.o a_b.a b_c.a c.a -o /dev/null --why-extract=- | tee stdout
reference       extracted       symbol
main.o  a_b.a(a_b.o)    a
a_b.a(a_b.o)    b_c.a(b_c.o)    b()
b_c.a(b_c.o)    c.a(c.o)        c()

% ruby -ane 'BEGIN{p={}}; p[$F[1]]=[$F[0],$F[2]] if $.>1; END{x="c.a(c.o)"; while y=p[x]; puts "#{y[0]} extracts #{x} to resolve #{y[1]}"; x=y[0] end}' stdout
b_c.a(b_c.o) extracts c.a(c.o) to resolve c()
a_b.a(a_b.o) extracts b_c.a(b_c.o) to resolve b()
main.o extracts a_b.a(a_b.o) to resolve a
```

Archive member extraction happens before --gc-sections, so this may not be a live path
under --gc-sections, but I think it is a good approximation in practice.

* Specifying a file avoids output interleaving with --verbose.
* Required `=` prevents accidental overwrite of an input if the user forgets `=`. (Most of compiler drivers' long options accept `=` but not ` `)

Differential Revision: https://reviews.llvm.org/D109572
2021-09-20 09:52:30 -07:00
Fangrui Song d001ab82e4 [ELF] Don't fall back to .text for e_entry
We have the rule to simulate
(https://sourceware.org/binutils/docs/ld/Entry-Point.html),
but the behavior is questionable
(https://sourceware.org/pipermail/binutils/2021-September/117929.html).

gold doesn't fall back to .text.
The behavior is unlikely relied by projects (there is even a warning for
executable links), so let's just delete this fallback path.

Reviewed By: jhenderson, peter.smith

Differential Revision: https://reviews.llvm.org/D110014
2021-09-20 09:35:12 -07:00
Fangrui Song aa4dfba522 [ELF] Infer EM_HEXAGON in getBitcodeMachineKind 2021-09-07 20:46:37 -07:00
Fangrui Song abd80ecf6e [ELF][test] Improve gitBitcodeMachineKind tests 2021-09-07 11:38:43 -07:00
Sid Manning 0d7e5daedc [lld][Hexagon] Add checks for instructions that can have TLS relocations
Several instructions with potential TLS relocations were missing.  This
issue was found when building the Canadian LLVM toolchain.
2021-09-01 13:15:18 -07:00
Fangrui Song f9277caffc [ELF][test] Fix R_AARCH64_ADR_PREL_PG_HI21 typo
Found by redfast00
2021-08-31 13:09:55 -07:00
Pirama Arumuga Nainar 9632ce14e4 [lld/test/ELF] Test fetch from archive to resolve undefined symbols in shared libs
Add missing test coverage uncovered in review of D108006.

Differential Revision: https://reviews.llvm.org/D108328
2021-08-27 14:17:32 -07:00
Fangrui Song 54e76cb17a [split-file] Default to --no-leading-lines
It turns out that the --leading-lines may be a bad default.
[[#@LINE+-num]] is rarely used.
2021-08-16 19:23:11 -07:00
Yolanda Chen 8fa16cc628 [LTO][lld] Add lto-pgo-warn-mismatch option
When enable CSPGO for ThinLTO, there are profile cfg mismatch warnings that will cause lld-link errors (with /WX)
due to source changes (e.g. `#if` code runs for profile generation but not for profile use)
To disable it we have to use an internal "/mllvm:-no-pgo-warn-mismatch" option.
In contrast clang uses option ”-Wno-backend-plugin“ to avoid such warnings and gcc has an explicit "-Wno-coverage-mismatch" option.

Add "lto-pgo-warn-mismatch" option to lld COFF/ELF to help turn on/off the profile mismatch warnings explicitly when build with ThinLTO and CSPGO.

Differential Revision: https://reviews.llvm.org/D104431
2021-08-11 09:45:55 -07:00
Wang, Pengfei 6c4809825d Revert "[lld] Add lto-pgo-warn-mismatch option"
This reverts commit 0cfb00a1c9.
2021-08-11 16:25:42 +08:00
Yolanda Chen 0cfb00a1c9 [lld] Add lto-pgo-warn-mismatch option
When enable CSPGO for ThinLTO, there are profile cfg mismatch warnings that will cause lld-link errors (with /WX).
To disable it we have to use an internal "/mllvm:-no-pgo-warn-mismatch" option.
In contrast clang uses option ”-Wno-backend-plugin“ to avoid such warnings and gcc has an explicit "-Wno-coverage-mismatch" option.

Add this "lto-pgo-warn-mismatch" option to lld to help turn on/off the profile mismatch warnings explicitly when build with ThinLTO and CSPGO.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D104431
2021-08-11 14:43:26 +08:00
Fangrui Song 76093b1739 [InlineAdvisor] Add single quotes around caller/callee names
Clang diagnostics refer to identifier names in quotes.
This patch makes inline remarks conform to the convention.
New behavior:

```
% clang -O2 -Rpass=inline -Rpass-missed=inline -S a.c
a.c:4:25: remark: 'foo' inlined into 'bar' with (cost=-30, threshold=337) at callsite bar:0:25; [-Rpass=inline]
int bar(int a) { return foo(a); }
                        ^
```

Reviewed By: hoy

Differential Revision: https://reviews.llvm.org/D107791
2021-08-10 11:51:31 -07:00
Ben Dunbobbin 8392e8c007 [LLD][Test] Add thin archives to map file test
This adds thin archives to the map file test.
I noticed that we had this test-case in our downstream
testsuite but it wasn't in the upstream testing.

Differential revision: https://reviews.llvm.org/D107555
2021-08-10 10:24:01 +01:00
Simon Atanasyan 454f69bcc1 [LLD] Add required `ppc` target to the test cases. NFC 2021-08-07 13:29:59 +03:00
Simon Atanasyan c6ebc651b6 [LLD] Support compressed input sections on big-endian targets
This patch enables compressed input sections on big-endian targets by
checking the target endianness and selecting an appropriate `Chdr`
structure.

Fixes PR51369

Differential Revision: https://reviews.llvm.org/D107635
2021-08-07 13:20:13 +03:00
Fangrui Song 72d070b4db [ELF] Support copy relocation on non-default version symbols
Copy relocation on a non-default version symbol is unsupported and can crash at
runtime. Fortunately there is a one-line fix which works for most cases:
ensure `getSymbolsAt` unconditionally returns `ss`.

If two non-default version symbols are defined at the same place and both
are copy relocated, our implementation will copy relocated them into different
addresses. The pointer inequality is very unlikely an issue. In GNU ld, copy
relocating version aliases seems to create more pointer inequality problems than
us.

(
In glibc, sys_errlist@GLIBC_2.2.5 sys_errlist@GLIBC_2.3 sys_errlist@GLIBC_2.4
are defined at the same place, but it is unlikely they are all copy relocated in
one executable. Even if so, the variables are read-only and pointer inequality
should not be a problem.
)

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D107535
2021-08-05 10:32:14 -07:00
Fangrui Song 00809c8889 [ELF] Apply version script patterns to non-default version symbols
Currently version script patterns are ignored for .symver produced
non-default version (single @) symbols. This makes such symbols
not localizable by `local:`, e.g.

```
.symver foo3_v1,foo3@v1
.globl foo_v1
foo3_v1:

ld.lld --version-script=a.ver -shared a.o
```

This patch adds the support:

* Move `config->versionDefinitions[VER_NDX_LOCAL].patterns` to `config->versionDefinitions[versionId].localPatterns`
* Rename `config->versionDefinitions[versionId].patterns` to `config->versionDefinitions[versionId].nonLocalPatterns`
* Allow `findAllByVersion` to find non-default version symbols when `includeNonDefault` is true. (Note: `symtab` keys do not have `@@`)
* Make each pattern check both the unversioned `pat.name` and the versioned `${pat.name}@${v.name}`
* `localPatterns` can localize `${pat.name}@${v.name}`. `nonLocalPatterns` can prevent localization by assigning `verdefIndex` (before `parseSymbolVersion`).

---

If a user notices new `undefined symbol` errors with a version script containing
`local: *;`, the issue is likely due to a missing `global:` pattern.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D107234
2021-08-04 23:52:56 -07:00
Fangrui Song a533eb7423 Revert "[ELF] Apply version script patterns to non-default version symbols"
This reverts commit 7ed22a6fa9.

buf is not cleared so the commit misses some cases.
2021-08-04 23:52:55 -07:00
Fangrui Song 66d4430492 [ELF] Combine foo@v1 and foo with the same versionId if both are defined
Due to an assembler design flaw (IMO), `.symver foo,foo@v1` produces two symbols `foo` and `foo@v1` if `foo` is defined.

* `v1 {};` produces both `foo` and `foo@v1`, but GNU ld only produces `foo@v1`
* `v1 { foo; };` produces both `foo@@v1` and `foo@v1`, but GNU ld only produces `foo@v1`
* `v2 { foo; };` produces both `foo@@v2` and `foo@v1`, matching GNU ld. (Tested by symver.s)

This patch implements the GNU ld behavior by reusing the symbol redirection mechanism
in D92259. The new test symver-non-default.s checks the first two cases.

Without the patch, the second case will produce `foo@v1` and `foo@@v1` which
looks weird and makes foo unnecessarily default versioned.

Note: `.symver foo,foo@v1,remove` exists but the unfortunate `foo` will not go
away anytime soon.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D107235
2021-08-04 09:06:05 -07:00
Fangrui Song 7ed22a6fa9 [ELF] Apply version script patterns to non-default version symbols
Currently version script patterns are ignored for .symver produced
non-default version (single @) symbols. This makes such symbols
not localizable by `local:`, e.g.

```
.symver foo3_v1,foo3@v1
.globl foo_v1
foo3_v1:

ld.lld --version-script=a.ver -shared a.o
# In a.out, foo3@v1 is incorrectly exported.
```

This patch adds the support:

* Move `config->versionDefinitions[VER_NDX_LOCAL].patterns` to `config->versionDefinitions[versionId].localPatterns`
* Rename `config->versionDefinitions[versionId].patterns` to `config->versionDefinitions[versionId].nonLocalPatterns`
* Allow `findAllByVersion` to find non-default version symbols when `includeNonDefault` is true. (Note: `symtab` keys do not have `@@`)
* Make each pattern check both the unversioned `pat.name` and the versioned `${pat.name}@${v.name}`
* `localPatterns` can localize `${pat.name}@${v.name}`. `nonLocalPatterns` can prevent localization by assigning `verdefIndex` (before `parseSymbolVersion`).

---

If a user notices new `undefined symbol` errors with a version script containing
`local: *;`, the issue is likely due to a missing `global:` pattern.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D107234
2021-08-04 09:02:11 -07:00