fixes the problem in the testcase. A symbolic reference from asm, which remains undefined at the end of processing is always a global reference, not a static (STB_LOCAL) one. This also affected the linux kernel.
Unified · Split
| @@ -75,8 +75,6 @@ ST_FUNC Sym* get_asm_sym(int name, Sym *csym) · 74 unmodified lines | ||
| 75 | 75 | sym->type.t &= ~VT_EXTERN; |
| 76 | 76 | /* Mark that this asm symbol doesn't need to be fed back. */ |
| 77 | 77 | sym->a.dllimport = 1; |
| 78 | − } else { | |
| 79 | − sym->type.t |= VT_STATIC; | |
| 80 | 78 | } |
| 81 | 79 | } |
| 82 | 80 | return sym; |
| @@ -3345,6 +3345,25 @@ void test_asm_dead_code(void) · 3344 unmodified lines | ||
| 3345 | 3345 | })); |
| 3346 | 3346 | } |
| 3347 | 3347 | |
| 3348 | +void test_asm_call(void) | |
| 3349 | +{ | |
| 3350 | +#if defined __x86_64__ && !defined _WIN64 | |
| 3351 | + static char str[] = "PATH"; | |
| 3352 | + char *s; | |
| 3353 | + /* This tests if a reference to an undefined symbol from an asm | |
| 3354 | + block, which isn't otherwise referenced in this file, is correctly | |
| 3355 | + regarded as global symbol, so that it's resolved by other object files | |
| 3356 | + or libraries. We chose getenv here, which isn't used anywhere else | |
| 3357 | + in this file. (If we used e.g. printf, which is used we already | |
| 3358 | + would have a global symbol entry, not triggering the bug which is | |
| 3359 | + tested here). */ | |
| 3360 | + /* two pushes so stack remains aligned */ | |
| 3361 | + asm volatile ("push %%rdi; push %%rdi; mov %0, %%rdi; call getenv; pop %%rdi; pop %%rdi" | |
| 3362 | + : "=a" (s) : "r" (str)); | |
| 3363 | + printf("asmd: %s\n", s); | |
| 3364 | +#endif | |
| 3365 | +} | |
| 3366 | + | |
| 3348 | 3367 | void asm_test(void) |
| 3349 | 3368 | { |
| 3350 | 3369 | char buf[128]; |
| @@ -3431,6 +3450,7 @@ void asm_test(void) · 80 unmodified lines | ||
| 3431 | 3450 | test_high_clobbers(); |
| 3432 | 3451 | trace_console(8, 8); |
| 3433 | 3452 | test_asm_dead_code(); |
| 3453 | + test_asm_call(); | |
| 3434 | 3454 | return; |
| 3435 | 3455 | label1: |
| 3436 | 3456 | goto label2; |