public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101010] New: Feature request: add builtins to provide mangled symbols, optionally with a prefix
@ 2021-06-10  8:28 hedayat.fwd at gmail dot com
  2021-06-10  8:36 ` [Bug c++/101010] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hedayat.fwd at gmail dot com @ 2021-06-10  8:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101010
           Summary: Feature request: add builtins to provide mangled
                    symbols, optionally with a prefix
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hedayat.fwd at gmail dot com
  Target Milestone: ---

Currently, there is no method to generate mangled symbol as an string or as a
symbol. 

A mangled symbol as string is useful in many cases for GCC itself, e.g. to use
with alias or ifunc attributes. Currently, you should find the mangled name
yourself and use it there, which is both inconvenient and also might change in
future (or it might be even different for example when compiled with mingw). 

Having a mangled symbol with a prefix (not as a string), is useful when using
the '--wrap' option to ld, to generate __real_SYMBOL and __wrap_SYMBOLs.
Actually, I'm more interested in this one, but found that the former one
(mangled name as string) is also useful. 

Sample intended usage:
void __builtin_mangled_symbol(__wrap_, &MyClass::member)(MyClass *mc_this, int
a)
{
   if (call_real)
       __builtin_mangled_symbol(__real_, &MyClass::member)(mc_this, a);
   else
   {...}
}

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

* [Bug c++/101010] Feature request: add builtins to provide mangled symbols, optionally with a prefix
  2021-06-10  8:28 [Bug c++/101010] New: Feature request: add builtins to provide mangled symbols, optionally with a prefix hedayat.fwd at gmail dot com
@ 2021-06-10  8:36 ` pinskia at gcc dot gnu.org
  2021-06-10 17:39 ` msebor at gcc dot gnu.org
  2021-06-10 21:08 ` hedayat.fwd at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-10  8:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug c++/101010] Feature request: add builtins to provide mangled symbols, optionally with a prefix
  2021-06-10  8:28 [Bug c++/101010] New: Feature request: add builtins to provide mangled symbols, optionally with a prefix hedayat.fwd at gmail dot com
  2021-06-10  8:36 ` [Bug c++/101010] " pinskia at gcc dot gnu.org
@ 2021-06-10 17:39 ` msebor at gcc dot gnu.org
  2021-06-10 21:08 ` hedayat.fwd at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-06-10 17:39 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Does the type_info::name() string match what you're looking for?

$ cat t.C && g++ t.C && ./a.out
#include <typeinfo>

struct MyClass
{
  void member (MyClass*, int);
};

int main ()
{
  __builtin_puts (typeid (&MyClass::member).name ());
}
M7MyClassFvPS_iE

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

* [Bug c++/101010] Feature request: add builtins to provide mangled symbols, optionally with a prefix
  2021-06-10  8:28 [Bug c++/101010] New: Feature request: add builtins to provide mangled symbols, optionally with a prefix hedayat.fwd at gmail dot com
  2021-06-10  8:36 ` [Bug c++/101010] " pinskia at gcc dot gnu.org
  2021-06-10 17:39 ` msebor at gcc dot gnu.org
@ 2021-06-10 21:08 ` hedayat.fwd at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: hedayat.fwd at gmail dot com @ 2021-06-10 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Hedayat Vatankhah <hedayat.fwd at gmail dot com> ---
(In reply to Martin Sebor from comment #1)
> Does the type_info::name() string match what you're looking for?

No, not at all. Looks like I've not clearly described my intent. 

First of all, type_info::name() is a runtime function. Both builtins I asked
are compile-time builtins: they should be replaced at compile time with the
desired string or symbol.

Also, I want the symbol name of the referred function or variable, not its
type. What your sample program outputs is the mangled name of type "void
(MyClass::*)(MyClass*, int)", but what I want is the mangled name of symbol
"void MyClass::member(MyClass*, int)". 

Finally, I asked about two distinct type of builtins:
1. The first kind is replaced at compile time with the mangled name as a
string. This kind, makes the following possible (note that probably dropping &
makes it more clear):
void f() __attribute__ ((weak, alias (__builtin_mangle(MyClass::member))));
Should become same as the following:
void f() __attribute__ ((weak, alias ("_ZN7MyClass6memberEi")));


2. The second kind, does not generate a "string"; It generates a symbol at
compile time. Consider the example I provided in comment 0, it should be
converted to the following at compile time:

void __wrap__ZN7MyClass6memberEi(MyClass *mc_this, int a)
{
   if (call_real)
       __real__ZN7MyClass6memberEi(mc_this, a);
   else
   {...}
}

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

end of thread, other threads:[~2021-06-10 21:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10  8:28 [Bug c++/101010] New: Feature request: add builtins to provide mangled symbols, optionally with a prefix hedayat.fwd at gmail dot com
2021-06-10  8:36 ` [Bug c++/101010] " pinskia at gcc dot gnu.org
2021-06-10 17:39 ` msebor at gcc dot gnu.org
2021-06-10 21:08 ` hedayat.fwd at gmail dot com

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