tinycc/tests/asm-c-connect-1.c
Michael Matz fbfe6209be macos: Fix asm-c-connect-test
via some heavy-handed hackery in the ASM symbol handling in case
C symbols get a leading underscore (but ASM symbols do not).
But this is now like clang and GCC on Darwin work: asm symbols are
undecorated, C symbols get a _ prepended, so to connect both some
trickery is involved for the ASM symbols that don't have a _ prepended.
They must be included in the C symbol table (because that's what we use
to lookup also ASM labels), but they also must not disturb the normal
C symbol (which don't have the _ prepended), so they need some mangling.

A bit unsatisfying, but well.  So, add asm-c-connect-test to the working
ones for Darwin as well.
2020-06-20 22:17:08 +02:00

67 lines
886 B
C

#include <stdio.h>
#if defined _WIN32 && !defined __TINYC__
# define _ "_"
#elif defined __APPLE__
# define _ "_"
#else
# define _
#endif
#ifdef __clang__
/* clang needs some help tp not throw functions away even at -O0 */
#define __USED __attribute__((__used__))
#else
#define __USED
#endif
static int __USED x1_c (void)
{
printf(" x1");
return 1;
}
asm(".text;"_"x1: call "_"x1_c; ret");
void callx4(void);
void callx5_again(void);
void x6()
{
printf(" x6-1");
}
int main(int argc, char *argv[])
{
printf("*");
asm("call "_"x1");
asm("call "_"x2");
asm("call "_"x3");
callx4();
asm("call "_"x5");
callx5_again();
x6();
printf(" *\n");
return 0;
}
static
int __USED x2(void)
{
printf(" x2");
return 2;
}
extern int x3(void);
void x4(void)
{
printf(" x4");
}
void x5(void);
void x5(void)
{
printf(" x5");
}