Sorry, I made a mistake about this problem.
The problem is, on MacOS, it will automatically add _
prefix to all function, except our own assembly code.
So when calling test_func()
in the main()
, it is actually calling to _test_func()
.
I will edit this to previous question.
Then we can keep all the function in c file unchanged, and define the assembly code like this:
#ifdef __APPLE__
#define DEFINE_FUNC(func) \
.global _##func; \
_##func
#define END_FUNC(...) /*_*/
#else
#define DEFINE_FUNC(func)\
.global func; \
.type func,%function; \
func
#define END_FUNC(func)\
.size func,.-func;
#endif
DEFINE_FUNC(test_func):
mov x0, x1
ret
END_FUNC(test_func)
So now I think I solved this problem elegantly. If there is a better way, please post your idea without any hesitation.