Skip to content

[ELF] Unused symbol is not being garbage-collected #84730

Closed
@partaror

Description

@partaror

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions