Stefan Falk
Stefan Falk

Reputation: 25387

Undefined reference calling an assembly function in C

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

Upvotes: 0

Views: 4916

Answers (2)

aib
aib

Reputation: 46951

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

Upvotes: 2

Some programmer dude
Some programmer dude

Reputation: 409176

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());
}

Upvotes: 4

Related Questions