History

Fix another corner case with C/asm symtable

See testcase (from grischka). If the asm has no .globl, but there's a (non-static) C definition the symbol should be exported, even if the first reference comes from asm.

Michael Matz committed 8 years ago

Commit cc6cb7f1 parent 529b44c4 files · +29 −3Browse files

Unified · Split

4 files
  1. tccasm.c +3 −2
  2. tests/Makefile +8 −1
  3. tests/asm-c-connect-1.c +9 −0
  4. tests/asm-c-connect-2.c +9 −0
tccasm.c+3−2
@@ -422,9 +422,10 @@ ST_FUNC void asm_free_labels(TCCState *st) · 421 unmodified lines
422422 for(s = st->asm_labels; s != NULL; s = s1) {
423423 ElfSym *esym = elfsym(s);
424424 s1 = s->prev;
425− /* Possibly update binding and visibility from asm directives. */
425+ /* Possibly update binding and visibility from asm directives
426+ if the symbol has no C decl (type is VT_VOID).*/
426427 s->type.t &= ~VT_EXTERN;
427− if (esym) {
428+ if (esym && s->type.t == VT_VOID) {
428429 if (!s->a.asmexport && esym->st_shndx != SHN_UNDEF)
429430 s->type.t |= VT_STATIC;
430431 if (s->a.visibility)
tests/Makefile+8−1
@@ -235,9 +235,16 @@ vla_test-run: vla_test$(EXESUF) · 234 unmodified lines
235235 asm-c-connect$(EXESUF): asm-c-connect-1.c asm-c-connect-2.c
236236 $(TCC) -o $@ $^
237237
238−asm-c-connect-test: asm-c-connect$(EXESUF)
238+asm-c-connect-%.o: asm-c-connect-%.c
239+ $(TCC) -c -o $@ $<
240+
241+asm-c-connect-sep$(EXESUF): asm-c-connect-1.o asm-c-connect-2.o
242+ $(TCC) -o $@ $^
243+
244+asm-c-connect-test: asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF)
239245 @echo ------------ $@ ------------
240246 ./asm-c-connect$(EXESUF)
247+ ./asm-c-connect-sep$(EXESUF)
241248
242249 cross-test :
243250 @echo ------------ $@ ------------
tests/asm-c-connect-1.c+9−0
@@ -15,12 +15,15 @@ static int x1_c(void) · 14 unmodified lines
1515 asm(".text;"_"x1: call "_"x1_c; ret");
1616
1717 void callx4(void);
18+void callx5_again(void);
1819 int main(int argc, char *argv[])
1920 {
2021 asm("call "_"x1");
2122 asm("call "_"x2");
2223 asm("call "_"x3");
2324 callx4();
25+ asm("call "_"x5");
26+ callx5_again();
2427 return 0;
2528 }
2629
@@ -37,3 +40,9 @@ void x4(void) · 10 unmodified lines
3740 {
3841 printf("x4\n");
3942 }
43+
44+void x5(void);
45+void x5(void)
46+{
47+ printf("x5\n");
48+}
tests/asm-c-connect-2.c+9−0
@@ -6,5 +6,14 @@ int x3(void) · 5 unmodified lines
66 return 3;
77 }
88
9+/* That callx4 is defined globally (as if ".globl callx4")
10+ is a TCC extension. GCC doesn't behave like this. */
911 void callx4(void);
1012 __asm__("callx4: call x4; ret");
13+
14+extern void x5(void);
15+void callx5_again(void);
16+void callx5_again(void)
17+{
18+ x5();
19+}

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