-fvtable-gc for Clang?

I recently stumbled on -fvtable-gc which in gcc 3 did the following:

Emit special relocations for vtables and virtual function references so that the linker can identify unused virtual functions and zero out vtable slots that refer to them. This is most useful with -ffunction-sections and -Wl,--gc-sections, in order to also discard the functions themselves.
This optimization requires GNU as and GNU ld. Not all systems support this option. -Wl,--gc-sections is ignored without -static.

Abstractly, removing unused virtual functions seems pretty good, but it looks like this feature was removed some time back for maintenance reasons. I was wondering if it would be worthwhile re-implementing this for clang. Some things I think would be nice to know are what type of relocation was emitted, and I guess what made the original feature buggy.

I wonder how it worked exactly. @MaskRay have you seen this?

1 Like

Isn’t this what the R_*_GNU_VTINHERIT and R_*_GNU_VTENTRY relocations are for?

There’s the frontend flag -fvirtual-function-elimination. It has some correctness issues and the author reported performance issues as well, but might be able to be improved.