On Tue, May 19, 2015 at 9:11 AM, Xinliang David Li wrote: >> >> Hm. But which options are unsafe? Also wouldn't it be better to simply >> _not_ have unsafe options produce comdats but always make local clones >> for them (thus emit the comdat with "unsafe" flags dropped)? > > Always localize comdat functions may lead to text size increase. It > does not work if the comdat function is a virtual function for > instance. Based on Richard's suggestion, I have a patch to localize comdat functions which seems like a very effective solution to this problem. The text size increase is limited to the extra comdat copies generated for the specialized modules (modules with unsafe options) which is usually only a few. Since -fweak does something similar for functions, I have called the new option -fweak-comdat-functions. This does not apply to virtual comdat functions as their addresses can always be leaked via the vtable. Using this flag with virtual functions generates a warning. To summarize, this is the intended usage of this option. Modules which use unsafe code options, like -m for multiversioning, to generate code that is meant to run only on a subset of CPUs can generate comdats with specialized instructions which when picked by the linker can get run unconditionally causing SIGILL on unsupported platforms. This flag hides these comdats to be local to these modules and not make them available publicly, with the caveat that it does not apply to virtual comdats. Could you please review? * c-family/c.opt (fweak-comdat-functions): New option. * cp/decl2.c (comdat_linkage): Implement new option. Warn when virtual comdat functions are seen. * doc/invoke.texi: Document new option. * testsuite/g++.dg/no-weak-comdat-functions-1.C: New test. Thanks Sri > > David > > >> >> Richard. >> >>> >>> Thanks >>> Sri