Bug 65074 - [5 Regression] r220674 broke C++ PIEs
Summary: [5 Regression] r220674 broke C++ PIEs
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 5.0
: P1 normal
Target Milestone: 5.0
Assignee: Richard Henderson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-15 22:27 UTC by Jakub Jelinek
Modified: 2015-02-19 15:50 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-02-16 00:00:00


Attachments
A patch (352 bytes, patch)
2015-02-15 23:31 UTC, H.J. Lu
Details | Diff
gcc5-pr65074-test.patch (339 bytes, patch)
2015-02-16 08:57 UTC, Jakub Jelinek
Details | Diff
second patch (461 bytes, patch)
2015-02-16 18:52 UTC, Richard Henderson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2015-02-15 22:27:35 UTC
namespace std
{
  template <typename _CharT> struct char_traits;
  template <typename _CharT, typename = char_traits <_CharT> > class basic_filebuf;
  template <typename _CharT, typename = char_traits <_CharT> > class basic_ifstream;
  typedef basic_ifstream <char> ifstream;
  enum _Ios_Openmode { _S_in };
  class basic_streambuf
  {
  };
  struct basic_ios
  {
    typedef char char_type;
    void init (void *);
    typedef _Ios_Openmode openmode;
  };
  template <typename _CharT> class __basic_file;
  template <> struct __basic_file <char>
  {
    __basic_file ();
    ~__basic_file ();
  };
  template <typename, typename _Traits> struct basic_filebuf : public basic_streambuf
  {
    __basic_file <char> _M_file;
    ~basic_filebuf () { this->close (); }
    void close ();
  };
  template <typename, typename _Traits> struct basic_ifstream : basic_ios
  {
    typedef _Traits traits_type;
    basic_filebuf <char_type, traits_type> _M_filebuf;
    basic_ifstream ();
    basic_ifstream (const char *, basic_ios::openmode = _S_in)
    {
      this->init (0);
    }
  };
  extern template class basic_filebuf <char>;
  ifstream f (0);
}

with -O2 -fpie starting with r220674 uses
call _ZNSt13basic_filebufIcSt11char_traitsIcEED1Ev
instead of
call _ZNSt13basic_filebufIcSt11char_traitsIcEED1Ev@PLT
that was used previously, despite that symbol being defined in libstdc++.so.6.
Comment 1 Jakub Jelinek 2015-02-15 22:29:30 UTC
This causes pdns-recursor link failure that without that would link fine.  The reduced testcase is reduced too much, so with added int main () {} it doesn't link even before r220674.
Comment 2 H.J. Lu 2015-02-15 23:31:26 UTC
Created attachment 34770 [details]
A patch

Please try this.
Comment 3 Jakub Jelinek 2015-02-16 08:57:14 UTC
Created attachment 34772 [details]
gcc5-pr65074-test.patch

Testcase for the testsuite.
Comment 4 Richard Henderson 2015-02-16 18:52:09 UTC
Created attachment 34785 [details]
second patch

I prefer to remove the test against node->definition entirely.
It appears to mean only that we have a definition that we could
emit, not that we're going to actually emit the symbol.

In particular, for functions, we'd have to also check cgraph_node::process.
At which point I suspect that DECL_EXTERNAL is sufficient.  Which means
that we can at least set defined_locally based on DECL_EXTERNAL even if
there is no symtab_node.  I don't know that we'd ever not have one, but
that's certainly not obvious from here.

Starting regression testing on several platforms...
Comment 5 Jan Hubicka 2015-02-17 17:12:07 UTC
Hi,
as Jakub noticed I just fixed the same bug independently by https://gcc.gnu.org/ml/gcc-patches/2015-02/msg01004.html

The fix is bit different. It adds DECL_EXTERNAL check in addition to node->definition.

Concerning discussion here, node->definition really just means that the definition is there at the time you check the flag.  It does not imply it will be output - it can be removed later by IPA optimization or it may be a definition of external variable or alias.

Using node->process flag is not a good idea, because these flags are set only while generating final assembler output, while we use binds_local_p during IPA optimization, too.

I see nothing wrong with dropping the use of ->definition flag as suggested by Richard. It is probably good cleanup compared to my change. The lto-cgraph.c and symtab.c parts of my change are still useful to fix some of nonsenses WRT definitions and ltrans partitions.

Honza
Comment 6 Richard Henderson 2015-02-19 15:14:56 UTC
Author: rth
Date: Thu Feb 19 15:14:24 2015
New Revision: 220816

URL: https://gcc.gnu.org/viewcvs?rev=220816&root=gcc&view=rev
Log:
PR middle-end/65074

 * varasm.c (default_binds_local_p_2): Don't test node->definition;
 test DECL_EXTERNAL independent of symtab_node.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/varasm.c
Comment 7 Richard Henderson 2015-02-19 15:49:22 UTC
Author: rth
Date: Thu Feb 19 15:48:50 2015
New Revision: 220817

URL: https://gcc.gnu.org/viewcvs?rev=220817&root=gcc&view=rev
Log:
PR middle-end/65074

 * g++.dg/opt/pr65074.C: New file.

Added:
    trunk/gcc/testsuite/g++.dg/opt/pr65074.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 8 Richard Henderson 2015-02-19 15:50:20 UTC
Fixed.