public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40490]  New: failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O
@ 2009-06-19  0:20 smcpeak at coverity dot com
  2009-06-21 18:32 ` [Bug middle-end/40490] " danglin at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: smcpeak at coverity dot com @ 2009-06-19  0:20 UTC (permalink / raw)
  To: gcc-bugs

The following input:

  class A {
  public:
    A();
    virtual void find() {}
  };

  static void foo(A &a)
  {
    a.find();
  }

  void bar()
  {
    A a;
    foo(a);
  }

when compiled with gcc-4.0.3, 4.0.4, 4.3.3 and 4.4.0 on HP-UX with -O
will produce assembly code that contains a call to find() but no
definition and no IMPORT:

  $ gcc-4.4.0/bin/g++ -S -O repro.cc
  $ grep 4find repro.s
          bl _ZN1A4findEv,%r2

Contrast with A::A(), which has both a call and an IMPORT:

  $ grep AC1 repro.s
          bl _ZN1AC1Ev,%r2
          .IMPORT _ZN1AC1Ev,CODE

The above input is approximately minimal; removing or changing any of
the features will make the problem disappear, typically by causing
find() to be completely inlined into the call site.

Interestingly, gcc-4.1.2 does not show a problem on this particular
input, although my recollection is it was showing the problem on a
larger variant.  I do not know where along the minimization process
gcc-4.1.2 stopped reproducing.

The lack of an IMPORT despite no definition is particularly nasty,
because 'nm' simply reports it as an undefined symbol, but the HP-UX
linker refuses to link the result into an executable when presented
with another object file that contains the definition:

  $ g++ -c -O repro.cc
  $ g++ -c -O rest.cc      # defines A::A() and main()
  $ g++ repro.o rest.o
  /usr/ccs/bin/ld: Unsatisfied symbols:
     A::find()    (first referenced in repro.o) (data)
  collect2: ld returned 1 exit status
  $ nm repro.o | grep 4find
           U _ZN1A4findEv
  $ nm rest.o | grep 4find
  00000000 W _ZN1A4findEv

The above is with GNU 'as' 2.15 and 2.17 (same result).  When using
the HP-UX assembler version "HP92453-03 UX.11.01.17 PA-RISC 2.0
Assembler" (which only accepts gcc-4.0.x output), it more helpfully
notices the missing IMPORT:

  as: error 7403: undefined label - _ZN1A4findEv (7403)

Of course, I didn't discover the IMPORT issue until after some hours
of searching for an explanation to the mysterious linker complaint.
It would be nice if GNU 'as' would realize that it is creating a .o
file that cannot be linked.

For completeness, the HP-UX linker version is "92453-07 linker linker
ld B.11.63 071126".

The IMPORT anomaly is specific to HP-UX, but the failure to emit a
definition of an inline is not.  On linux/x86_64 with gcc-4.0.3, for
example, repro.o again has a call but no definition, but is able to
link by using the definition from rest.o because there is no IMPORT
concept.  I find it suspicious that the compiler would ever choose to
emit a direct call to a defined inline function without also including
that function's definition; but the C++ ODR guarantees the compiler it
will see the class definition again, including the method body, in the
translation unit containing the definition of A::A(), so the omission
is not by itself necessarily indicative of a bug.

It's worth noting that the presence of a direct call to find() means
the compiler figured out it is A::find() being called, despite that
method being virtual.  I suspect the mechanism that does that may be
partly to blame.  That's the reason for including "resolved" in this
bug's title.


-- 
           Summary: failure to emit resolved inline virtual function
                    definition or IMPORT on HP-UX with -O
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: smcpeak at coverity dot com
 GCC build triplet: hppa2.0w-hp-hpux11.11
  GCC host triplet: hppa2.0w-hp-hpux11.11
GCC target triplet: hppa2.0w-hp-hpux11.11


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40490


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/40490] failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O
  2009-06-19  0:20 [Bug c++/40490] New: failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O smcpeak at coverity dot com
@ 2009-06-21 18:32 ` danglin at gcc dot gnu dot org
  2009-07-04 22:06 ` danglin at gcc dot gnu dot org
  2010-03-16 14:31 ` michael dot haubenwallner at salomon dot at
  2 siblings, 0 replies; 4+ messages in thread
From: danglin at gcc dot gnu dot org @ 2009-06-21 18:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from danglin at gcc dot gnu dot org  2009-06-21 18:32 -------
Changing to middle-end as it is responsible for determining which
calls are added to the list of pending assemble externals.


-- 

danglin at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |danglin at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
          Component|target                      |middle-end
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-06-21 18:32:03
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40490


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/40490] failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O
  2009-06-19  0:20 [Bug c++/40490] New: failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O smcpeak at coverity dot com
  2009-06-21 18:32 ` [Bug middle-end/40490] " danglin at gcc dot gnu dot org
@ 2009-07-04 22:06 ` danglin at gcc dot gnu dot org
  2010-03-16 14:31 ` michael dot haubenwallner at salomon dot at
  2 siblings, 0 replies; 4+ messages in thread
From: danglin at gcc dot gnu dot org @ 2009-07-04 22:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from danglin at gcc dot gnu dot org  2009-07-04 22:05 -------
Breakpoint 6, assemble_external (decl=0x7ae86f80)
    at ../../gcc/gcc/varasm.c:2304
2304      gcc_assert (asm_out_file);
(gdb) p debug_tree (decl)
 <function_decl 7ae86f80 find
    type <method_type 7ae85f08
        type <void_type 7adf74e0 void VOID
            align 8 symtab 0 alias set -1 canonical type 7adf74e0
            pointer_to_this <pointer_type 7adf7548>>
        SI
        size <integer_cst 7ade07a0 constant 32>
        unit size <integer_cst 7ade0540 constant 4>
        align 32 symtab 0 alias set -1 canonical type 7ae85f08 method basetype
<record_type 7ae85d00 A>
        arg-types <tree_list 7ae8c7e0 value <pointer_type 7ae85f70>
            chain <tree_list 7adfa1a0 value <void_type 7adf74e0 void>>>
        pointer_to_this <pointer_type 7ae8e3a8>>
    addressable used nothrow public static weak autoinline no-static-chain
virtual decl_5 SI defer-output file pr40490.cc line 4 col 16 align 32 context
<record_type 7ae85d00 A> initial <error_mark 7ade0500>
    arguments <parm_decl 7adf65a0 this
        type <pointer_type 7ae8e000 type <record_type 7ae85d00 A>
            readonly unsigned SI size <integer_cst 7ade07a0 32> unit size
<integer_cst 7ade0540 4>
            align 32 symtab 0 alias set -1 canonical type 7ae8e000>
        readonly unsigned SI file pr40490.cc line 4 col 21 size <integer_cst
7ade07a0 32> unit size <integer_cst 7ade0540 4>
        align 32 context <function_decl 7ae86f80 find> arg-type <pointer_type
7ae8e000>>
    result <result_decl 7adf66e0 D.1717 type <void_type 7adf74e0 void>
        ignored VOID file pr40490.cc line 4 col 23
        align 8 context <function_decl 7ae86f80 find>>
    pending-inline-info 7ae8bd90
    (mem:SI (symbol_ref/v/i:SI ("@_ZN1A4findEv") [flags 0x1] <function_decl
7ae86f80 find>) [0 S4 A32])>
$10 = void

DECL_EXTERNAL (decl) is 0, so the symbol is not imported.  Probably, the
component should be changed to c++.


-- 

danglin at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark at codesourcery dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40490


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/40490] failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O
  2009-06-19  0:20 [Bug c++/40490] New: failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O smcpeak at coverity dot com
  2009-06-21 18:32 ` [Bug middle-end/40490] " danglin at gcc dot gnu dot org
  2009-07-04 22:06 ` danglin at gcc dot gnu dot org
@ 2010-03-16 14:31 ` michael dot haubenwallner at salomon dot at
  2 siblings, 0 replies; 4+ messages in thread
From: michael dot haubenwallner at salomon dot at @ 2010-03-16 14:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from michael dot haubenwallner at salomon dot at  2010-03-16 14:30 -------
While the input from comment#0 indeed seems to work with gcc-4.2.4 too, this
one has the same problem with 4.2.4, 4.3.1 and 4.4.3 (each hp-gcc):

  class A
  {
  public:
    virtual ~A();
    virtual void find() {}
  };

  void foo()
  {
    A a;
    A* pa = &a;
    pa->find();
  }


-- 

michael dot haubenwallner at salomon dot at changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |michael dot haubenwallner at
                   |                            |salomon dot at


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40490


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-03-16 14:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-19  0:20 [Bug c++/40490] New: failure to emit resolved inline virtual function definition or IMPORT on HP-UX with -O smcpeak at coverity dot com
2009-06-21 18:32 ` [Bug middle-end/40490] " danglin at gcc dot gnu dot org
2009-07-04 22:06 ` danglin at gcc dot gnu dot org
2010-03-16 14:31 ` michael dot haubenwallner at salomon dot at

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).