replacement for “fvtable-gc” in GCC

2019-05-03 12:53发布

Is there any replacement for 'fvtable-gc' options in GCCv4.7.1 (it was supported in GCCv3.x)? I want to remove unused virtual functions during linkage process.

fvtable-gc 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.

1条回答
一纸荒年 Trace。
2楼-- · 2019-05-03 13:36

Looks like the feature was too buggy, so it has been removed several years ago. I don't think there is an equivalent replacement.

Though I haven't found an official statement, there are several comments that fvtable-gc is broken at least in the GCC 3.x series, maybe earlier. For example (source: cris.h; claiming to be part of GCC):

... When bugs are removed from -fvtable-gc (-fforce-addr causes invalid .vtable_entry asm in tinfo.cc and nothing at all works in GCC 3.0-pre) ...

Today, many years later, the compilers should be far more advanced. Maybe GCC's whole program optimizer is smart enough to detect and eliminate unused virtual functions, but I'm not sure.

查看更多
登录 后发表回答