0

I just cannot find the solution to this issue..

What I'm trying to do is calling an assembly function using gcc. Just take a look:

// Somewhere in start.s
global _start_thread
_start_thread:
  ; ...


// Somewhere in UserThread.cpp
extern void _start_thread( pointer );

static void UserMainHack()
{
    _start_thread(((UserThread*)currentThread)->getUserMain());
}

Thanks for any help..

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378

2 Answers2

4

Did you know that many C linkers automatically adds the leading underscore when looking for identifiers? So in the C source (not the assembler source), just remove the leading underscore:

extern void start_thread( pointer );

static void UserMainHack()
{
    start_thread(((UserThread*)currentThread)->getUserMain());
}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • @elyashiv: the name-mangling system is up to the implementation (although the dll format has a say), and it's the mangled name rather than the unmangled name that you have to implement in assembly. So the reason the linker adds the `_` is just that it mangles the name. The reason that (for example) Win32 sticks a wart on the front of mangled names even in C is to indicate which calling convention the function uses, so that you never accidentally link against a function using the wrong convention. Win64 doesn't do it, because there's only one calling convention. – Steve Jessop Oct 17 '12 at 12:35
2

Give your function [declaration] assembly linkage by using an "Asm Label":

extern void start_thread(pointer) __asm__("start_thread");

(and have the .global on the asm side match it.)

It works much like extern "C" in that it can be used for both functions and variables, and that it's one-sided (but on the C side this time).

aib
  • 45,516
  • 10
  • 73
  • 79