-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[ELF] Unused symbol is not being garbage-collected #84730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
partaror
added a commit
to partaror/llvm-project
that referenced
this issue
Mar 11, 2024
Previously, linker was unnecessarily including a PROVIDE symbol which was referenced by another unused PROVIDE symbol. For example, if a linker script contained the below code and 'not_used_sym' provide symbol is not included, then linker was still unnecessarily including 'foo' PROVIDE symbol because it was referenced by 'not_used_sym'. This commit fixes this behavior. PROVIDE(not_used_sym = foo) PROVIDE(foo = 0x1000) This commit fixes this behavior by using dfs-like algorithm to find all the symbols referenced in provide expressions of included provide symbols. This commit also fixes the issue of unused section not being garbage-collected if a symbol of the section is referenced by an unused PROVIDE symbol. Closes llvm#74771 Closes llvm#84730
@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 >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 |
partaror
added a commit
to partaror/llvm-project
that referenced
this issue
Mar 18, 2024
Previously, linker was unnecessarily including a PROVIDE symbol which was referenced by another unused PROVIDE symbol. For example, if a linker script contained the below code and 'not_used_sym' provide symbol is not included, then linker was still unnecessarily including 'foo' PROVIDE symbol because it was referenced by 'not_used_sym'. This commit fixes this behavior. PROVIDE(not_used_sym = foo) PROVIDE(foo = 0x1000) This commit fixes this behavior by using dfs-like algorithm to find all the symbols referenced in provide expressions of included provide symbols. This commit also fixes the issue of unused section not being garbage-collected if a symbol of the section is referenced by an unused PROVIDE symbol. Closes llvm#74771 Closes llvm#84730
partaror
added a commit
to partaror/llvm-project
that referenced
this issue
Mar 25, 2024
Previously, linker was unnecessarily including a PROVIDE symbol which was referenced by another unused PROVIDE symbol. For example, if a linker script contained the below code and 'not_used_sym' provide symbol is not included, then linker was still unnecessarily including 'foo' PROVIDE symbol because it was referenced by 'not_used_sym'. This commit fixes this behavior. PROVIDE(not_used_sym = foo) PROVIDE(foo = 0x1000) This commit fixes this behavior by using dfs-like algorithm to find all the symbols referenced in provide expressions of included provide symbols. This commit also fixes the issue of unused section not being garbage-collected if a symbol of the section is referenced by an unused PROVIDE symbol. Closes llvm#74771 Closes llvm#84730
partaror
added a commit
to partaror/llvm-project
that referenced
this issue
Mar 25, 2024
Previously, linker was unnecessarily including a PROVIDE symbol which was referenced by another unused PROVIDE symbol. For example, if a linker script contained the below code and 'not_used_sym' provide symbol is not included, then linker was still unnecessarily including 'foo' PROVIDE symbol because it was referenced by 'not_used_sym'. This commit fixes this behavior. PROVIDE(not_used_sym = foo) PROVIDE(foo = 0x1000) This commit fixes this behavior by using dfs-like algorithm to find all the symbols referenced in provide expressions of included provide symbols. This commit also fixes the issue of unused section not being garbage-collected if a symbol of the section is referenced by an unused PROVIDE symbol. Closes llvm#74771 Closes llvm#84730
partaror
added a commit
to partaror/llvm-project
that referenced
this issue
Mar 25, 2024
Previously, linker was unnecessarily including a PROVIDE symbol which was referenced by another unused PROVIDE symbol. For example, if a linker script contained the below code and 'not_used_sym' provide symbol is not included, then linker was still unnecessarily including 'foo' PROVIDE symbol because it was referenced by 'not_used_sym'. This commit fixes this behavior. PROVIDE(not_used_sym = foo) PROVIDE(foo = 0x1000) This commit fixes this behavior by using dfs-like algorithm to find all the symbols referenced in provide expressions of included provide symbols. This commit also fixes the issue of unused section not being garbage-collected if a symbol of the section is referenced by an unused PROVIDE symbol. Closes llvm#74771 Closes llvm#84730 Co-authored-by: Fangrui Song <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LLD is not garbage collecting an unused symbol that is referenced by an unused provide symbol.
Reproducible example:
The section
.text.bar
can be garbage-collected but remains uncollected.The text was updated successfully, but these errors were encountered: