public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ name mangling
@ 2013-12-13 12:04 Philip Herron
  2013-12-13 12:17 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Philip Herron @ 2013-12-13 12:04 UTC (permalink / raw)
  To: GCC

Hey

I never really looked into this much before but kind of just out of
curiosity where is it implemented. For example: C++ code:

int test (int)...

will generate the gimple:

int test(int) (int x)
{
  int D.2281;

  D.2281 = x + 1;
  return D.2281;
}

But then the aseembler name is:

_Z4testi:

I know you can do SET_DECL_ASSEMBLER_NAME on an fndecl. But not sure
how the mangling is done for C++ is there a convention to the c++
standard or is it compiler specific i imagine it must be some
standard. And where is it implemented in Rust you can do:

#[link_args = "-lreadline"]
extern {
    fn readline (p: *std::libc::c_char) -> * std::libc::c_char;
}

I would like to be able to do something like:

extern "c++" {
}

So then any rust program can call into c++ wrappers maybe? Maybe
leaving out templates and classes. Maybe i can do something like
SET_DECL_ASSEMBLER_NAME (cpp_mangle ("test"))

--Phil
--Phil

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

* Re: C++ name mangling
  2013-12-13 12:04 C++ name mangling Philip Herron
@ 2013-12-13 12:17 ` Jonathan Wakely
  2013-12-13 12:40   ` Philip Herron
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2013-12-13 12:17 UTC (permalink / raw)
  To: Philip Herron; +Cc: GCC

On 13 December 2013 12:04, Philip Herron wrote:
>
> I know you can do SET_DECL_ASSEMBLER_NAME on an fndecl. But not sure
> how the mangling is done for C++ is there a convention to the c++
> standard or is it compiler specific i imagine it must be some
> standard.

GCC follows the C++ ABI for Itanium, as specified at
http://www.codesourcery.com/cxx-abi/


> And where is it implemented in Rust you can do:
>
> #[link_args = "-lreadline"]
> extern {
>     fn readline (p: *std::libc::c_char) -> * std::libc::c_char;
> }
>
> I would like to be able to do something like:
>
> extern "c++" {
> }
>
> So then any rust program can call into c++ wrappers maybe? Maybe
> leaving out templates and classes. Maybe i can do something like
> SET_DECL_ASSEMBLER_NAME (cpp_mangle ("test"))

What do you expect "test" to mean?  To mangle a function name you have
to say the function signature, not just the name, that's the point of
mangling. "_Z4testi" is a function with one parameter of type int.
"test" is just a variable called "test" not a function.

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

* Re: C++ name mangling
  2013-12-13 12:17 ` Jonathan Wakely
@ 2013-12-13 12:40   ` Philip Herron
  0 siblings, 0 replies; 4+ messages in thread
From: Philip Herron @ 2013-12-13 12:40 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: GCC

Ah ok i see now. Thanks didnt realise that.

--Phil

On 13 December 2013 12:17, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 13 December 2013 12:04, Philip Herron wrote:
>>
>> I know you can do SET_DECL_ASSEMBLER_NAME on an fndecl. But not sure
>> how the mangling is done for C++ is there a convention to the c++
>> standard or is it compiler specific i imagine it must be some
>> standard.
>
> GCC follows the C++ ABI for Itanium, as specified at
> http://www.codesourcery.com/cxx-abi/
>
>
>> And where is it implemented in Rust you can do:
>>
>> #[link_args = "-lreadline"]
>> extern {
>>     fn readline (p: *std::libc::c_char) -> * std::libc::c_char;
>> }
>>
>> I would like to be able to do something like:
>>
>> extern "c++" {
>> }
>>
>> So then any rust program can call into c++ wrappers maybe? Maybe
>> leaving out templates and classes. Maybe i can do something like
>> SET_DECL_ASSEMBLER_NAME (cpp_mangle ("test"))
>
> What do you expect "test" to mean?  To mangle a function name you have
> to say the function signature, not just the name, that's the point of
> mangling. "_Z4testi" is a function with one parameter of type int.
> "test" is just a variable called "test" not a function.

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

* C++ name mangling
@ 2005-07-22  9:38 Helge Bahmann
  0 siblings, 0 replies; 4+ messages in thread
From: Helge Bahmann @ 2005-07-22  9:38 UTC (permalink / raw)
  To: gcc-help

Hello,

I would like to create symbol aliases from one symbol to another in an
object file. The way to do it with C symbols "appears" to be:

__asm__(".set foo, bar\n.globl foo\n")

Easy enough; for C++ this works as well, but I have to use the mangled
symbol name. Is there any way to obtain the mangled name of a symbol as
string? The documentation appears to indicate there is none, but I thought
I'd ask nevertheless...

Thanks and best regards
-- 
Helge Bahmann <hcb@chaoticmind.net>                     /| \__
The past: Smart users in front of dumb terminals       /_|____\
                                                     _/\ |   __)
$ ./configure                                        \\ \|__/__|
checking whether build environment is sane... yes     \\/___/ |
checking for AIX... no (we already did this)            |

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

end of thread, other threads:[~2013-12-13 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-13 12:04 C++ name mangling Philip Herron
2013-12-13 12:17 ` Jonathan Wakely
2013-12-13 12:40   ` Philip Herron
  -- strict thread matches above, loose matches on Subject: below --
2005-07-22  9:38 Helge Bahmann

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