History

Don't make forard asm symbols static by default

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.

Michael Matz committed 9 years ago

Commit a8ece0f1 parent 348dd9f2 files · +20 −2Browse files

Unified · Split

2 files
  1. tccasm.c +0 −2
  2. tests/tcctest.c +20 −0
tccasm.c+0−2
@@ -75,8 +75,6 @@ ST_FUNC Sym* get_asm_sym(int name, Sym *csym) · 74 unmodified lines
7575 sym->type.t &= ~VT_EXTERN;
7676 /* Mark that this asm symbol doesn't need to be fed back. */
7777 sym->a.dllimport = 1;
78− } else {
79− sym->type.t |= VT_STATIC;
8078 }
8179 }
8280 return sym;
tests/tcctest.c+20−0
@@ -3345,6 +3345,25 @@ void test_asm_dead_code(void) · 3344 unmodified lines
33453345 }));
33463346 }
33473347
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+
33483367 void asm_test(void)
33493368 {
33503369 char buf[128];
@@ -3431,6 +3450,7 @@ void asm_test(void) · 80 unmodified lines
34313450 test_high_clobbers();
34323451 trace_console(8, 8);
34333452 test_asm_dead_code();
3453+ test_asm_call();
34343454 return;
34353455 label1:
34363456 goto label2;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t