public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98436] New: issue with casting member function on linux32 bit only
@ 2020-12-24  9:19 samuel_benjamin at mentor dot com
  2020-12-24 10:04 ` [Bug c++/98436] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: samuel_benjamin at mentor dot com @ 2020-12-24  9:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

            Bug ID: 98436
           Summary: issue with casting member function on linux32 bit only
           Product: gcc
           Version: 7.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: samuel_benjamin at mentor dot com
  Target Milestone: ---

Created attachment 49840
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49840&action=edit
TestCase

There is an issue with gcc 7.4.0 linux32 bit only, I tried the example below
with 4.7.4 , 5.3.0. 6.3.0 , all are working fine for both 32bit and 64 bit
except gcc-7.4.0 linux32.

The issue is i have an un-implemented member function in a class , and the
implementation is inside another stub file.

The main exe loads two shared librares ( systemc.so ) and (systemc_stubs.so) ,
the issue arrives when i casts the undefined member function pointer is :

on gcc-7.4.0- 32 bit :

(gdb) p tmp
$1 = &virtual table offset -134397620


on gcc-7.4.0 - 64 bit and many other gcc versions : 
$1 = (void (functor::*)(functor * const)) 0x7ffff7e4c15a
     <_ZN7MyClass17myUndefinedMethodEv()>


Files are below :
Class.h --> basic class
testbench.cpp --> this is the main file for the fist so ( systemc.so)
stub.cpp --> systemc_stubs.so
main.cpp --> main exe which loads the 2 so and executes the entry point.

Compilation :
g++ -shared -o systemc.so -Wl,-E -Wl,-Bsymbolic -lm testbench.cpp -g
g++ -shared -o systemc_stubs.so -Wl,-E -Wl,-Bsymbolic -lm stub.cpp -g
g++ main.cpp -g -ldl -o testmain

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
@ 2020-12-24 10:04 ` pinskia at gcc dot gnu.org
  2020-12-24 10:14 ` samuel_benjamin at mentor dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-12-24 10:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think you have a problem _ZN7MyClass17myUndefinedMethodEv is not correct.  It
has an argument passed to it which you don't take into account.

Also what you are doing is undefined as the "this" argument does not have to
passed as the same as a normal arugment.

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
  2020-12-24 10:04 ` [Bug c++/98436] " pinskia at gcc dot gnu.org
@ 2020-12-24 10:14 ` samuel_benjamin at mentor dot com
  2020-12-24 11:15 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: samuel_benjamin at mentor dot com @ 2020-12-24 10:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

Samuel Benjamin <samuel_benjamin at mentor dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #2 from Samuel Benjamin <samuel_benjamin at mentor dot com> ---
Hi,
_ZN7MyClass17myUndefinedMethodEv is the decorated name i got out from nm.
It is working with all the gcc versions except 7.4.0 32 bit, what do you
suggest here ?

The stub.cpp is automatically generated file to handle undefined refs.

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
  2020-12-24 10:04 ` [Bug c++/98436] " pinskia at gcc dot gnu.org
  2020-12-24 10:14 ` samuel_benjamin at mentor dot com
@ 2020-12-24 11:15 ` pinskia at gcc dot gnu.org
  2020-12-24 12:13 ` samuel_benjamin at mentor dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-12-24 11:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Again you missed the 'this' argument. Read my whole comment again on why this
is invalid. This has nothing to do with the name of the function but rather the
function being incorrectly defined.

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
                   ` (2 preceding siblings ...)
  2020-12-24 11:15 ` pinskia at gcc dot gnu.org
@ 2020-12-24 12:13 ` samuel_benjamin at mentor dot com
  2020-12-24 12:18 ` samuel_benjamin at mentor dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: samuel_benjamin at mentor dot com @ 2020-12-24 12:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

--- Comment #4 from Samuel Benjamin <samuel_benjamin at mentor dot com> ---
I got your point, But why is this working with 64bit and other gcc versions
other than 7.4.0 - 32 bit ?

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
                   ` (3 preceding siblings ...)
  2020-12-24 12:13 ` samuel_benjamin at mentor dot com
@ 2020-12-24 12:18 ` samuel_benjamin at mentor dot com
  2020-12-24 15:52 ` redi at gcc dot gnu.org
  2020-12-25  0:20 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: samuel_benjamin at mentor dot com @ 2020-12-24 12:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

Samuel Benjamin <samuel_benjamin at mentor dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #5 from Samuel Benjamin <samuel_benjamin at mentor dot com> ---
C++ Standard 5.4 "Explicit type conversion",
clause 7: a pointer to member of derived class type may be explicitly converted
to a pointer to member of an unambiguous non-virtual base class type.

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
                   ` (4 preceding siblings ...)
  2020-12-24 12:18 ` samuel_benjamin at mentor dot com
@ 2020-12-24 15:52 ` redi at gcc dot gnu.org
  2020-12-25  0:20 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-24 15:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Samuel Benjamin from comment #4)
> I got your point, But why is this working with 64bit and other gcc versions
> other than 7.4.0 - 32 bit ?

Undefined behaviour means anything can happen, including appearing to work as
you expect.

Implementing C++ member functions as non-member functions is indeed undefined
behaviour. Even naming your function "_ZN7MyClass17myUndefinedMethodEv" is
undefined, because that's a reserved name.

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

* [Bug c++/98436] issue with casting member function on linux32 bit only
  2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
                   ` (5 preceding siblings ...)
  2020-12-24 15:52 ` redi at gcc dot gnu.org
@ 2020-12-25  0:20 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-12-25  0:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98436

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Samuel Benjamin from comment #4)
> I got your point, But why is this working with 64bit and other gcc versions
> other than 7.4.0 - 32 bit ?

Because the ABI for x86_64 and i?86 are different.  One passes the this
arugment via the stack (i?86) while the other passes it via a register.  In the
case for x86_64, the register can be safely ignored.

Again this is undefined code and just happens to work on x86_64.

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

end of thread, other threads:[~2020-12-25  0:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24  9:19 [Bug c++/98436] New: issue with casting member function on linux32 bit only samuel_benjamin at mentor dot com
2020-12-24 10:04 ` [Bug c++/98436] " pinskia at gcc dot gnu.org
2020-12-24 10:14 ` samuel_benjamin at mentor dot com
2020-12-24 11:15 ` pinskia at gcc dot gnu.org
2020-12-24 12:13 ` samuel_benjamin at mentor dot com
2020-12-24 12:18 ` samuel_benjamin at mentor dot com
2020-12-24 15:52 ` redi at gcc dot gnu.org
2020-12-25  0:20 ` pinskia at gcc dot gnu.org

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).