llvm / llvm/llvm-project

[lld][ELF][RISC-V] Imported undefined variant-CC symbol loses STO_RISCV_VARIANT_CC when resolved by plain DSO

Open
#203,471 5 comments 0 reactions 0 assignees View on GitHub
lld:ELF
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Title: [lld][ELF][RISC-V] Preserve STO_RISCV_VARIANT_CC when undefined regular symbol is resolved by plain DSO

ld.lld drops `STO_RISCV_VARIANT_CC` from an undefined regular RISC-V symbol when that symbol is resolved by a shared library definition that is not marked variant-CC.

The output still imports the symbol through the PLT, but the dynamic symbol loses `[VARIANT_CC]` and `DT_RISCV_VARIANT_CC` is not emitted.

Reproducer:

`main.s`
```asm
.text
.globl main
.type main, @function
main:
call target
ret
```

`variant-decl.s`
```asm
.text
.globl target
.type target, @function
.variant_cc target
```

`provider.s`
```asm
.text
.globl target
.type target, @function
target:
ret
```

Current result:

`llvm-readelf -Ws out.so` shows `target` as a plain undefined dynamic symbol, without `[VARIANT_CC]`.

`llvm-readelf -d out.so` does not show `RISCV_VARIANT_CC`.

`llvm-readelf -r out.so` still shows a PLT relocation for `target`.

Expected result:

The imported dynamic symbol should keep `STO_RISCV_VARIANT_CC`, and the output should contain `DT_RISCV_VARIANT_CC`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.