How to get the address of the asm function in c

I have an asm file (I use gas) and a c file. My asm file contains a function, something like this

.global myfunc
.type myfunc, @function

myfunc:
   pusha
   .
   .
   .

now I want to get the address of the myfunc label from my c file, so I wrote

extern uintptr_t _myfunc asm("myfunc");

my program links are no problem, but when I execute my program, the _myfunc variable does not contain the correct address.

Change 1

it may be useful to know that this piece of code is part of a simple program

Edit 2

using prototype function solved problem

void function() asm("myfunc");

uintptr_t _myfunc = (uintptr_t)&myfunc;
+4
source share
1 answer

You should be able to declare your asm function in C using the same character that you use in the declaration .global:

extern void myfunc(void);

. , asm, myfunc, C undefined.

ABI (a.out ELF) _myfunc myfunc extern.

+4

All Articles