one some systems GCC defaults to PIC/PIE code which is incompatible with a unannotated asm call to a function (getenv here). TCC doesn't support these PIC annotations (yet), so play some pre-processor games.
Unified · Split
| @@ -3358,7 +3358,13 @@ void test_asm_call(void) · 3357 unmodified lines | |||
| 3358 | would have a global symbol entry, not triggering the bug which is | 3358 | would have a global symbol entry, not triggering the bug which is |
| 3359 | tested here). */ | 3359 | tested here). */ |
| 3360 | /* two pushes so stack remains aligned */ | 3360 | /* two pushes so stack remains aligned */ |
| 3361 | asm volatile ("push %%rdi; push %%rdi; mov %0, %%rdi; call getenv; pop %%rdi; pop %%rdi" | 3361 | asm volatile ("push %%rdi; push %%rdi; mov %0, %%rdi;" |
| 3362 | #if 1 && !defined(__TINYC__) && (defined(__PIC__) || defined(__PIE__)) | ||
| 3363 | "call getenv@plt;" | ||
| 3364 | #else | ||
| 3365 | "call getenv;" | ||
| 3366 | #endif | ||
| 3367 | "pop %%rdi; pop %%rdi" | ||
| 3362 | : "=a" (s) : "r" (str)); | 3368 | : "=a" (s) : "r" (str)); |
| 3363 | printf("asmd: %s\n", s); | 3369 | printf("asmd: %s\n", s); |
| 3364 | #endif | 3370 | #endif |