Bug 49538

Summary: [4.7 regression] Revision 175341 causes segfaults
Product: gcc Reporter: Markus Trippelsdorf <octoploid>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: hubicka, jarro.2783, jason
Priority: P3 Keywords: wrong-code
Version: 4.7.0   
Target Milestone: 4.7.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 49533    
Attachments: fix logical thinko

Description Markus Trippelsdorf 2011-06-27 07:17:26 UTC
After building "konsole" with the latest gcc I see this:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f6ea97 in ?? () from /usr/lib64/libkonsoleprivate.so
(gdb) bt
#0  0x00007ffff7f6ea97 in ?? () from /usr/lib64/libkonsoleprivate.so
#1  0x00007ffff7ab376f in __cxa_finalize (d=0x7ffff7fb90a0) at cxa_finalize.c:56
#2  0x00007ffff7f125e3 in ?? () from /usr/lib64/libkonsoleprivate.so
#3  0x00007fffffffd8e0 in ?? ()
#4  0x00007ffff7dec1da in _dl_fini () at dl-fini.c:244
Backtrace stopped: frame did not save the PC

I've bisected this to:
c85c2c3f3bb4e66026354b08d5fc29e7330297ad is the first bad commit
commit c85c2c3f3bb4e66026354b08d5fc29e7330297ad
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jun 23 16:52:56 2011 +0000

        * optimize.c (maybe_clone_body): Set linkage flags before
        cgraph_same_body_alias.

http://gcc.gnu.org/ml/gcc-cvs/2011-06/msg00832.html
http://gcc.gnu.org/viewcvs?view=revision&revision=175341

Reverting the commit above "solves" the problem.
Comment 1 Markus Trippelsdorf 2011-06-27 16:12:04 UTC
ld.bfd links libkonsoleprivate.so without errors, gold however fails:

Linking CXX shared library ../../lib/libkonsoleprivate.so
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/ColorScheme.o: requires dynamic R
_X86_64_PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/EditProfileDialog.o: requires dyn
amic R_X86_64_PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/KeyboardTranslator.o: requires dy
namic R_X86_64_PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/ProcessInfo.o: requires dynamic R
_X86_64_PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/Profile.o: requires dynamic R_X86
_64_PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/Pty.o: requires dynamic R_X86_64_
PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/Pty.o: requires dynamic R_X86_64_
PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: CMakeFiles/konsoleprivate.dir/SessionManager.o: requires dynami
c R_X86_64_PC32 reloc against 'QList<QString>::~QList()' which may overflow at runtime; recompile with -fPIC
CMakeFiles/konsoleprivate.dir/ColorScheme.o:ColorScheme.cpp:function Konsole::ColorSchemeManager::loadAllColorSchemes(): warning: relocation refers t
o discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/ColorScheme.o:ColorScheme.cpp:function Konsole::ColorSchemeManager::loadAllColorSchemes(): warning: relocation refers t
o discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/ColorScheme.o:ColorScheme.cpp:function Konsole::ColorSchemeManager::loadAllColorSchemes(): warning: relocation refers t
o discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/ColorScheme.o:ColorScheme.cpp:function Konsole::ColorSchemeManager::loadAllColorSchemes(): warning: relocation refers t
o discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/EditProfileDialog.o:EditProfileDialog.cpp:function Konsole::EditProfileDialog::updateKeyBindingsList(bool): warning: re
location refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/EditProfileDialog.o:EditProfileDialog.cpp:function Konsole::EditProfileDialog::updateKeyBindingsList(bool): warning: re
location refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/KeyboardTranslator.o:KeyboardTranslator.cpp:function Konsole::KeyboardTranslatorManager::findTranslators(): warning: re
location refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/ProcessInfo.o:ProcessInfo.cpp:function Konsole::ProcessInfo::formatCommand(QString const&, QVector<QString> const&, Kon
sole::ProcessInfo::CommandFormat) const: warning: relocation refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/ProcessInfo.o:ProcessInfo.cpp:function Konsole::ProcessInfo::formatShortDir(QString const&) const: warning: relocation 
refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/Profile.o:Profile.cpp:function Konsole::Profile::namesForProperty(Konsole::Profile::Property): warning: relocation refe
rs to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/Pty.o:Pty.cpp:function Konsole::Pty::addEnvironmentVariables(QStringList const&): warning: relocation refers to discard
ed section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/Pty.o:Pty.cpp:function Konsole::Pty::start(QString const&, QStringList const&, QStringList const&, unsigned long, bool,
 QString const&, QString const&): warning: relocation refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/Pty.o:Pty.cpp:function QList<QString>::mid(int, int) const: warning: relocation refers to discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
CMakeFiles/konsoleprivate.dir/SessionManager.o:SessionManager.cpp:function Konsole::SessionManager::loadAllProfiles(): warning: relocation refers to 
discarded section
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: hidden symbol 'QList<QString>::~QList()' is not defined locally
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libkonsoleprivate.so] Error 1



With c85c2c3f3bb4e reverted, gold links without any error.
Comment 2 Markus Trippelsdorf 2011-06-28 14:49:18 UTC
Created attachment 24618 [details]
fix logical thinko

This patch fixes the issue.
It was a simple logical thinko.
It also fixes Bug 49533.
Comment 3 Markus Trippelsdorf 2011-06-28 20:32:14 UTC
Haha, that patch doesn't work. It's identical to:

#if 0
      if (!in_charge_parm_used
	  && fns[0]
	  && idx == 1
	  && !flag_use_repository
	  && DECL_INTERFACE_KNOWN (fns[0])
	  && (SUPPORTS_ONE_ONLY || !DECL_WEAK (fns[0]))
	  && (!DECL_ONE_ONLY (fns[0])
	      || (HAVE_COMDAT_GROUP
		  && DECL_WEAK (fns[0])))
	  && (flag_syntax_only
	      /* Set linkage flags appropriately before
		 cgraph_create_function_alias looks at them.  */
	      && (expand_or_defer_fn_1 (clone)
		  || cgraph_same_body_alias (cgraph_get_node (fns[0]),
					     clone, fns[0]))))
	{
	  alias = true;
	  if (DECL_ONE_ONLY (fns[0]))
	    {
	      /* For comdat base and complete cdtors put them
		 into the same, *[CD]5* comdat group instead of
		 *[CD][12]*.  */
	      comdat_group = cdtor_comdat_group (fns[1], fns[0]);
	      DECL_COMDAT_GROUP (fns[0]) = comdat_group;
	    }
	}
#endif

So back to square one. But everything points to commit c70f46b057cd12973:

Author: hubicka 
Date:   Sat Jun 11 13:01:53 2011 +0000

        * lto-symtab.c (lto_cgraph_replace_node): Kill same body alias code.
        (lto_symtab_resolve_can_prevail_p): Likewise.
...
Comment 4 Markus Trippelsdorf 2011-07-07 12:49:55 UTC
No, c70f46b057cd12973 is fine.
I've tested tested:
git reset --hard c70f46b057cd12973d33c01c8fa0da5c14ba3944
and then applied Jason's patch on top of this and
everything is fine.
Comment 5 Markus Trippelsdorf 2011-07-07 14:08:08 UTC
OK I've finally found the commit in question:

% git bisect start
$ git bisect bad
% git bisect good c70f46b057cd12973d33c01c8fa0da5c14ba3944
...
(test and repeat always with Jason's patch applied on top)
...
% git bisect bad
f30e87e922bda64571abe28fca8edab3bdc42918 is the first bad commit
commit f30e87e922bda64571abe28fca8edab3bdc42918
Author: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Jun 13 15:34:59 2011 +0000

        * ipa-inline.c (reset_edge_caches): Walk aliases.
        (update_caller_keys): Do not test inlinability of aliases.
        * ipa-inline-analysis.c (do_estimate_edge_time): Look through alias.
        (do_estimate_growth): Fix typo.
    
    
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174992 138bc75d-0d04-0410-961f-82ee72b054a4
Comment 6 Markus Trippelsdorf 2011-07-07 14:43:49 UTC
It's the first hunk that causes the problem:

diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index 43e0f81..b008f05 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -2079,7 +2079,7 @@ do_estimate_edge_time (struct cgraph_edge *edge)
   struct inline_edge_summary *es = inline_edge_summary (edge);
 
   gcc_checking_assert (edge->inline_failed);
-  estimate_node_size_and_time (edge->callee,
+  estimate_node_size_and_time (cgraph_function_or_thunk_node (edge->callee, NULL),
                               evaluate_conditions_for_edge (edge, true),
                               &size, &time);
Comment 7 Jarryd Beck 2011-07-07 21:55:06 UTC
I just wanted to comment here that I have also found this problem. I bisected it to the same revision using my own project. I reported it as bug [[49587]].
Comment 8 Jarryd Beck 2011-07-07 21:58:45 UTC
Sorry I linked that wrongly, it's bug 49587.
Comment 9 Markus Trippelsdorf 2011-07-09 10:53:20 UTC
Commit dabebf7ecc90b fixes the problem for me.
Thanks Jason.
 
commit dabebf7ecc90b59b0603d2428cf465fe1f0d642b
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Sat Jul 9 03:33:44 2011 +0000

    gcc/
        * cgraph.c (cgraph_add_to_same_comdat_group): New.
        * cgraph.h: Declare it.
        * ipa.c (function_and_variable_visibility): Make sure thunks
        have the right visibility.
    gcc/cp/
        * method.c (use_thunk): Use cgraph_add_to_same_comdat_group.
        * optimize.c (maybe_clone_body): Likewise.
        * semantics.c (maybe_add_lambda_conv_op): Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@176071
Comment 10 Jarryd Beck 2011-07-10 12:20:26 UTC
*** Bug 49587 has been marked as a duplicate of this bug. ***