Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

trip report: Tiny C Compiler 0.9.27 (Miscellaneous)

posted by bencollver Homepage, 05.02.2026, 18:34
(edited by bencollver on 05.02.2026, 19:01)

> Hello bencollver,
>
> > I believe the disassembly corresponds to the for(;;) loop body, probably
> at
> > "sym->next = last_sym". I am not sure i am ready to debug this one.
>
> __sym_malloc seems to be used to extend a pool of free
> struct Sym thingies (TCC can then allocate new struct
> Sym objects from this free pool). It is odd that the routine is
> crashing.

I also thought it was odd. tcc_malloc() should either return the requested memory, or it should end the program with an error.

> Anyway, here is the machine code output that I got for this routine after
> compiling tccgen.c on my end (on a Linux machine):
> ...
> (The R_386_PC32 and R_386_32 are ELF
> relocations.) If the compiler output something different on your end --
> modulo different instruction encodings -- then it might be a case of
> miscompilation.

Thank you for your help!

I compiled tccgen.c, used mingw objdump -D tccgen.o, and then zeroed out the address labels before comparing them to get this diff:

--- a   2026-02-05 09:17:52.125688241 -0800
+++ b   2026-02-05 09:20:17.973684566 -0800
@@ -2,53 +2,48 @@
      000:       55                      push   %ebp
      000:       89 e5                   mov    %esp,%ebp
      000:       81 ec 10 00 00 00       sub    $0x10,%esp
-     000:       b8 ec 1f 00 00          mov    $0x1fec,%eax
+     000:       90                      nop
+     000:       b8 e0 1f 00 00          mov    $0x1fe0,%eax
      000:       50                      push   %eax
-     000:       e8 fc ff ff ff          call   a28 <__sym_malloc+0x10>
-                        a28: R_386_PC32 tcc_malloc
+     000:       e8 fc ff ff ff          call   c5f <__sym_malloc+0x11>
      000:       83 c4 04                add    $0x4,%esp
-     000:       89 45 fc                mov    %eax,-0x4(%ebp)
-     000:       8b 45 fc                mov    -0x4(%ebp),%eax
+     000:       89 85 fc ff ff ff       mov    %eax,-0x4(%ebp)
+     000:       8b 85 fc ff ff ff       mov    -0x4(%ebp),%eax
      000:       50                      push   %eax
      000:       b8 00 00 00 00          mov    $0x0,%eax
-                        a37: R_386_32   nb_sym_pools
      000:       50                      push   %eax
      000:       b8 00 00 00 00          mov    $0x0,%eax
-                        a3d: R_386_32   sym_pools
      000:       50                      push   %eax
-     000:       e8 fc ff ff ff          call   a43 <__sym_malloc+0x2b>
-                        a43: R_386_PC32 dynarray_add
+     000:       e8 fc ff ff ff          call   c80 <__sym_malloc+0x32>
      000:       83 c4 0c                add    $0xc,%esp
      000:       8b 05 00 00 00 00       mov    0x0,%eax
-                        a4c: R_386_32   sym_free_first
-     000:       89 45 f4                mov    %eax,-0xc(%ebp)
-     000:       8b 45 fc                mov    -0x4(%ebp),%eax
-     000:       89 45 f8                mov    %eax,-0x8(%ebp)
+     000:       89 85 f4 ff ff ff       mov    %eax,-0xc(%ebp)
+     000:       8b 85 fc ff ff ff       mov    -0x4(%ebp),%eax
+     000:       89 85 f8 ff ff ff       mov    %eax,-0x8(%ebp)
      000:       b8 00 00 00 00          mov    $0x0,%eax
-     000:       89 45 f0                mov    %eax,-0x10(%ebp)
-     000:       8b 45 f0                mov    -0x10(%ebp),%eax
-     000:       81 f8 e3 00 00 00       cmp    $0xe3,%eax
-     000:       0f 83 2e 00 00 00       jae    a9e <__sym_malloc+0x86>
-     000:       e9 0b 00 00 00          jmp    a80 <__sym_malloc+0x68>
-     000:       8b 45 f0                mov    -0x10(%ebp),%eax
+     000:       89 85 f0 ff ff ff       mov    %eax,-0x10(%ebp)
+     000:       8b 85 f0 ff ff ff       mov    -0x10(%ebp),%eax
+     000:       83 f8 cc                cmp    $0xffffffcc,%eax
+     000:       0f 83 4c 00 00 00       jae    d05 <__sym_malloc+0xb7>
+     000:       e9 14 00 00 00          jmp    cd2 <__sym_malloc+0x84>
+     000:       8b 85 f0 ff ff ff       mov    -0x10(%ebp),%eax
      000:       89 c1                   mov    %eax,%ecx
      000:       40                      inc    %eax
-     000:       89 45 f0                mov    %eax,-0x10(%ebp)
-     000:       eb e1                   jmp    a61 <__sym_malloc+0x49>
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
+     000:       89 85 f0 ff ff ff       mov    %eax,-0x10(%ebp)
+     000:       e9 d8 ff ff ff          jmp    caa <__sym_malloc+0x5c>
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax
      000:       83 c0 18                add    $0x18,%eax
-     000:       8b 4d f4                mov    -0xc(%ebp),%ecx
+     000:       8b 8d f4 ff ff ff       mov    -0xc(%ebp),%ecx
      000:       89 08                   mov    %ecx,(%eax)
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
-     000:       89 45 f4                mov    %eax,-0xc(%ebp)
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax
+     000:       89 85 f4 ff ff ff       mov    %eax,-0xc(%ebp)
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax
      000:       89 c1                   mov    %eax,%ecx
-     000:       83 c0 24                add    $0x24,%eax
-     000:       89 45 f8                mov    %eax,-0x8(%ebp)
-     000:       eb d7                   jmp    a75 <__sym_malloc+0x5d>
-     000:       8b 45 f4                mov    -0xc(%ebp),%eax
+     000:       83 c0 28                add    $0x28,%eax
+     000:       89 85 f8 ff ff ff       mov    %eax,-0x8(%ebp)
+     000:       e9 b9 ff ff ff          jmp    cbe <__sym_malloc+0x70>
+     000:       8b 85 f4 ff ff ff       mov    -0xc(%ebp),%eax
      000:       89 05 00 00 00 00       mov    %eax,0x0
-                        aa3: R_386_32   sym_free_first
-     000:       8b 45 f4                mov    -0xc(%ebp),%eax
-     000:       c9                      leave
-     000:       c3                      ret
+     000:       8b 85 f4 ff ff ff       mov    -0xc(%ebp),%eax
+     000:       c9                      leave 
+     000:       c3                      ret


I don't see the elf relocations in mingw's objdump output.

For the three instructions in the crash error message, the only difference is that on my win32 version the instructions have "ff ff ff" appended to them:

      000:       89 08                   mov    %ecx,(%eax)
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
-     000:       89 45 f4                mov    %eax,-0xc(%ebp)
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax
+     000:       89 85 f4 ff ff ff       mov    %eax,-0xc(%ebp)
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax


p.s.

I compared the output of the official win32 build of tcc 0.9.27 to my watcom bootstrapped build:

      000:       89 08                   mov    %ecx,(%eax)
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
-     000:       89 45 f4                mov    %eax,-0xc(%ebp)
-     000:       8b 45 f8                mov    -0x8(%ebp),%eax
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax
+     000:       89 85 f4 ff ff ff       mov    %eax,-0xc(%ebp)
+     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax


The only place i saw ELF relocations was in your disassembly.

I guess i could try and figure out where those extra "ff ff ff" bytes are coming from.

 

Complete thread:

Back to the forum
Board view  Mix view
23153 Postings in 2179 Threads, 404 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum