Closed
Description
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.