Closed llvmbot closed 7 years ago
Great, thanks for the confirmation! I think this one can be closed.
We do a round of dead-stripping on the index during the thin link, then mark for internalization any global values not reached by anything exported from the binary, which means they will be internalized and then deleted by the ThinLTO backends. Can you check what the final code looks like in the ThinLTO case, and confirm that is happening? You might need to compile with -O1 or up to get the full optimization pipeline to kick in BTW.
Yup - this does happen - the final binaries are stripped of unused functions/globals. Should I delete this bug now, since the pass is unnecessary?
We do a round of dead-stripping on the index during the thin link, then mark for internalization any global values not reached by anything exported from the binary, which means they will be internalized and then deleted by the ThinLTO backends. Can you check what the final code looks like in the ThinLTO case, and confirm that is happening? You might need to compile with -O1 or up to get the full optimization pipeline to kick in BTW.
Extended Description
// a.c int jj = 10;
int x() { return jj; }
int f(int x) { return x + 1; }
// b.c
extern int f(int);
int main(void) { return 1; }
///////////////////
=== THINLTO ===
$ ../build/bin/clang a.c b.c --for-linker=-mllvm --for-linker=-stats -flto=thin \ -fuse-ld=lld -o out &>&1 | grep globaldce
nothing
=== LTO ===
$ ../build/bin/clang a.c b.c --for-linker=-mllvm --for-linker=-stats -flto \ -fuse-ld=lld -o out &>&1 | grep globaldce 2 globaldce - Number of functions removed 1 globaldce - Number of global variables removed