Files
clang-p2996/lld/test/ELF/version-symbol-undef.s
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

60 lines
1.8 KiB
ArmAsm

// REQUIRES: x86
// RUN: echo ".data; \
// RUN: .quad \"basename\"; \
// RUN: .quad \"basename@FBSD_1.0\"; \
// RUN: .quad \"basename@FBSD_1.1\" " > %t.s
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t.s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t2.o
// RUN: echo "FBSD_1.0 { global: basename; local: *; }; FBSD_1.1 { basename; };" > %t2.ver
// RUN: ld.lld --shared --version-script %t2.ver %t2.o -o %t2.so
// RUN: echo "FBSD_1.0 { }; FBSD_1.1 { }; LIBPKG_1.3 { };" > %t.ver
// RUN: ld.lld --shared %t.o --version-script %t.ver %t2.so -o %t.so
// RUN: llvm-readobj --dyn-symbols -r %t.so | FileCheck %s
// Test that each relocation points to the correct version.
// CHECK: Section ({{.*}}) .rela.dyn {
// CHECK-NEXT: R_X86_64_64 basename@FBSD_1.1 0x0
// CHECK-NEXT: R_X86_64_64 basename@FBSD_1.0 0x0
// CHECK-NEXT: R_X86_64_64 basename@FBSD_1.1 0x0
// CHECK-NEXT: }
// CHECK: DynamicSymbols [
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name:
// CHECK-NEXT: Value:
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding:
// CHECK-NEXT: Type:
// CHECK-NEXT: Other:
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: basename@FBSD_1.1
// CHECK-NEXT: Value:
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding:
// CHECK-NEXT: Type:
// CHECK-NEXT: Other:
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: basename@FBSD_1.0
// CHECK-NEXT: Value:
// CHECK-NEXT: Size:
// CHECK-NEXT: Binding:
// CHECK-NEXT: Type:
// CHECK-NEXT: Other:
// CHECK-NEXT: Section:
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: basename@FBSD_1.1
.global "basename@FBSD_1.0"
"basename@FBSD_1.0":
.global "basename@@FBSD_1.1"
"basename@@FBSD_1.1":