llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[ELF] Unused symbol is not being garbage-collected

Open partaror opened this issue 2 years ago • 1 comments

LLD is not garbage collecting an unused symbol that is referenced by an unused provide symbol.

Reproducible example:

#!/usr/bin/env bash

cat >1.c <<\EOF
int foo() { return 1; }
int bar() { return 3; }

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

cat >script.t <<\EOF
PROVIDE(unused = bar);
EOF

clang-15 -o 1.o 1.c -c -ffunction-sections
ld.lld -o 1.elf 1.o -T script.t --gc-sections --print-gc-sections -e main

The section .text.bar can be garbage-collected but remains uncollected.

partaror avatar Mar 11 '24 08:03 partaror

@llvm/issue-subscribers-lld-elf

Author: None (partaror)

LLD is not garbage collecting an unused symbol that is referenced by an unused provide symbol.

Reproducible example:

#!/usr/bin/env bash

cat &gt;1.c &lt;&lt;\EOF
int foo() { return 1; }
int bar() { return 3; }

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

cat &gt;script.t &lt;&lt;\EOF
PROVIDE(unused = bar);
EOF

clang-15 -o 1.o 1.c -c -ffunction-sections
ld.lld -o 1.elf 1.o -T script.t --gc-sections --print-gc-sections -e main

The section .text.bar can be garbage-collected but remains uncollected.

llvmbot avatar Mar 11 '24 14:03 llvmbot