tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] bug in tcc object files?


From: Damian M Gryski
Subject: [Tinycc-devel] bug in tcc object files?
Date: Thu, 10 Apr 2003 17:49:53 -0400
User-agent: Mutt/1.5.4i

/* Here is C code with comments that demonstrates the bug.

   bash$ tcc -c foo.c && gcc foo.o -o foo
   bash$ ./foo
   Segmentation fault (core dumped)
   bash$ nm foo.o
   00000000 d L.0
   00000020 T bar
   00000000 T baz
   00000058 T main
   0000000b T qux
   00000004 C zot
   bash$ gcc -c foo.c
   bash$ nm foo.o
   0000000f T bar
   00000000 T baz
   00000042 T main
   00000005 T qux
   00000000 b zot

   Notice that gcc puts zot in BSS, while tcc puts it in Common.

   The offending code is here;
   (gdb) disas bar
   Dump of assembler code for function bar:
   0x8048340 <bar>:        push   %ebp
   0x8048341 <bar+1>:      mov    %esp,%ebp
   0x8048343 <bar+3>:      sub    $0x0,%esp
   0x8048349 <bar+9>:      mov    $0x8049400,%eax
   0x804834e <bar+14>:     push   %eax
   0x804834f <bar+15>:     call   0x804832b <qux>
   0x8048354 <bar+20>:     add    $0x4,%esp
   0x8048357 <bar+23>:     mov    %eax,0x4
                                       ^^^
   0x804835d <bar+29>:     mov    0x4,%eax
                                  ^^^
   0x8048363 <bar+35>:     push   %eax
   0x8048364 <bar+36>:     call   0x8048320 <baz>
   0x8048369 <bar+41>:     add    $0x4,%esp
   0x804836c <bar+44>:     mov    $0x0,%eax
   0x8048371 <bar+49>:     jmp    0x8048376 <bar+54>
   0x8048376 <bar+54>:     leave  
   0x8048377 <bar+55>:     ret    
   End of assembler dump.
   (gdb) 

   Looks like the references to zot aren't getting relocated correctly.
   However, even though gcc is doing the linking, I'm inclined to blame
   tcc in this case.

   Is there a flag I'm missing to be able to link tcc-compiled code
   with gcc?

 */

static int *zot;

void baz(int *foo) { }

int *qux(char *s) { return 0; }

int *bar()
{
    zot = qux("");
    baz(zot);
    return 0;
}

int main()
{

    bar();
}

-- 
Damian Gryski          | "There is a crack, a crack in everything.
 address@hidden  |  That's how the light gets in."
  gnu / geek / juggler / coder / compsci / crypto / security

Attachment: pgpG4dn0rGdut.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]