http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51663
--- Comment #8 from Jan Hubicka <hubicka at gcc dot gnu.org> 2012-03-25 13:50:39 UTC --- The inconsistency should be solved. The question however is what kind of behaviour we want at -O0 from LTO. It seems to me that at -O0 the LTO/non-LTO output should be as close as possible and thus LTO should not privatize symbols and break more silly debuggers/tools (this is especially important for SLIM mode). We still do renaming of statics and other nasty things, but we should not do more than neccesary. On the the other hand, I think -fwhole-program should still do privatization. This patch implements it. In addition to this it drops more unobvious transformation from -fwhole-program where we bring local COMDAT virtual tables and functions w/o address taken since we know duplicating them does not hurt. Does this look sane? Honza Index: ipa.c =================================================================== --- ipa.c (revision 185777) +++ ipa.c (working copy) @@ -616,7 +616,8 @@ cgraph_externally_visible_p (struct cgra if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && lookup_attribute ("dllexport", DECL_ATTRIBUTES (node->decl))) return true; - if (node->resolution == LDPR_PREVAILING_DEF_IRONLY) + if (node->resolution == LDPR_PREVAILING_DEF_IRONLY + && optimize) return false; /* When doing LTO or whole program, we can bring COMDAT functoins static. This improves code quality and we know we will duplicate them at most twice @@ -624,11 +625,13 @@ cgraph_externally_visible_p (struct cgra implementing same COMDAT) */ if ((in_lto_p || whole_program) && DECL_COMDAT (node->decl) + && optimize && cgraph_comdat_can_be_unshared_p (node)) return false; /* When doing link time optimizations, hidden symbols become local. */ if (in_lto_p + && optimize && (DECL_VISIBILITY (node->decl) == VISIBILITY_HIDDEN || DECL_VISIBILITY (node->decl) == VISIBILITY_INTERNAL) /* Be sure that node is defined in IR file, not in other object @@ -681,7 +684,8 @@ varpool_externally_visible_p (struct var This is needed for i.e. references from asm statements. */ if (varpool_used_from_object_file_p (vnode)) return true; - if (vnode->resolution == LDPR_PREVAILING_DEF_IRONLY) + if (vnode->resolution == LDPR_PREVAILING_DEF_IRONLY + && optimize) return false; /* As a special case, the COMDAT virutal tables can be unshared. @@ -690,6 +694,7 @@ varpool_externally_visible_p (struct var is faster for dynamic linking. Also this match logic hidding vtables from LTO symbol tables. */ if ((in_lto_p || flag_whole_program) + && optimize && !vnode->force_output && DECL_COMDAT (vnode->decl) && DECL_VIRTUAL_P (vnode->decl)) return false;