public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* c++ symbol name
@ 2005-03-27 23:35 Martin Stecklum
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Stecklum @ 2005-03-27 23:35 UTC (permalink / raw)
  To: gcc-help

Hello,
I need to define a specific symbol name for a function in the resulting 
object file. example:

test.cpp:

int test();

int test()
{
	//do something
	return 0;
}

I compiled the file using:
gcc -c -fno-rtti -fno-builtin -fno-exceptions -nostdinc++ test.cpp -o test.o

(Yes, I want to create a freestanding application!)

The symbol name for the test() function in the resulting test.o file is 
"_Z4testv":
readelf -s test.o

Symbol table '.symtab' contains 8 entries:
    Num:    Value  Size Type    Bind   Vis      Ndx Name
      0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
      1: 00000000     0 FILE    LOCAL  DEFAULT  ABS test.cpp
      2: 00000000     0 SECTION LOCAL  DEFAULT    1
      3: 00000000     0 SECTION LOCAL  DEFAULT    2
      4: 00000000     0 SECTION LOCAL  DEFAULT    3
      5: 00000000     0 SECTION LOCAL  DEFAULT    4
      6: 00000000     0 SECTION LOCAL  DEFAULT    5
      7: 00000000    10 FUNC    GLOBAL DEFAULT    1 _Z4testv

So here comes my question. How can I define the symbol name for the 
test() function for example to _test?

Bye
	Martin Stecklum

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

* Re: c++ symbol name
@ 2005-03-28  6:52 Martin Stecklum
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Stecklum @ 2005-03-28  6:52 UTC (permalink / raw)
  To: gcc-help

Hello again,
Murphy's law! As soon as you write to a mailing list you find the answer 
yourself :)
If anyone is interested in the solution:

int test() __asm__ ("_new_symbol_name");

int test()
{
	//do something
	return 0;
}

And the result in the object file:

Symbol table '.symtab' contains 8 entries:
    Num:    Value  Size Type    Bind   Vis      Ndx Name
      0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
      1: 00000000     0 FILE    LOCAL  DEFAULT  ABS test.cpp
      2: 00000000     0 SECTION LOCAL  DEFAULT    1
      3: 00000000     0 SECTION LOCAL  DEFAULT    2
      4: 00000000     0 SECTION LOCAL  DEFAULT    3
      5: 00000000     0 SECTION LOCAL  DEFAULT    4
      6: 00000000     0 SECTION LOCAL  DEFAULT    5
      7: 00000000    10 FUNC    GLOBAL DEFAULT    1 _new_symbol_name

Bye
	Martin Stecklum

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

end of thread, other threads:[~2005-03-27 23:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-27 23:35 c++ symbol name Martin Stecklum
2005-03-28  6:52 Martin Stecklum

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