Clang LTO with ASM symbol fails..

I’m trying to build coro.c using Clang+LTO.

When I link together the final binary, I get the following error:

Global is external, but doesn't have external or weak linkage!
void ()* @coro_transfer

The symbol is defined in coro.h as:

#if __i386__ || __x86_64__
extern void __attribute__ ((__noinline__, __regparm__(2)))
#else
extern void __attribute__ ((__noinline__))
#endif
coro_transfer (coro_context *prev, coro_context *next);

and in coro.c as:

  asm (
       "\t.text\n"
       #if _WIN32 || __CYGWIN__ || __MACH__
       "\t.globl _coro_transfer\n"
       "_coro_transfer:\n"
       #else
       "\t.globl coro_transfer\n"
       "coro_transfer:\n"
       #endif

It seems to me that it does have (or should) have global linkage. Is this a bug with LTO, or is there something wrong with the assembly definition?

I checked with nm and noticed the symbol was first undefined and then defined. I guess that’s because of the declaration in the header but it’s not technically a C function in the implementation.

coro.c.o:
         U abort
00000000 T coro_create
00000000 T coro_stack_alloc
00000000 T coro_stack_free
         U coro_transfer
00000000 T coro_transfer
         U mmap
         U mprotect
         U munmap
         U sysconf

Could this be causing the problem?

Thanks for any ideas or suggestions.

Kind regards,
Samuel

It’s complaining about the declaration. As far as I can tell, your declaration does appear to have external linkage, so I am not sure what is triggering this issue.

What version of clang? What linker?

Teresa