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 tkchia Homepage, 05.02.2026, 16:44

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.

Anyway, here is the machine code output that I got for this routine after compiling tccgen.c on my end (on a Linux machine):

00000a18 <__sym_malloc>:
     a18:       55                      push   %ebp
     a19:       89 e5                   mov    %esp,%ebp
     a1b:       81 ec 10 00 00 00       sub    $0x10,%esp
     a21:       b8 ec 1f 00 00          mov    $0x1fec,%eax
     a26:       50                      push   %eax
     a27:       e8 fc ff ff ff          call   a28 <__sym_malloc+0x10>
                        a28: R_386_PC32 tcc_malloc
     a2c:       83 c4 04                add    $0x4,%esp
     a2f:       89 45 fc                mov    %eax,-0x4(%ebp)
     a32:       8b 45 fc                mov    -0x4(%ebp),%eax
     a35:       50                      push   %eax
     a36:       b8 00 00 00 00          mov    $0x0,%eax
                        a37: R_386_32   nb_sym_pools
     a3b:       50                      push   %eax
     a3c:       b8 00 00 00 00          mov    $0x0,%eax
                        a3d: R_386_32   sym_pools
     a41:       50                      push   %eax
     a42:       e8 fc ff ff ff          call   a43 <__sym_malloc+0x2b>
                        a43: R_386_PC32 dynarray_add
     a47:       83 c4 0c                add    $0xc,%esp
     a4a:       8b 05 00 00 00 00       mov    0x0,%eax
                        a4c: R_386_32   sym_free_first
     a50:       89 45 f4                mov    %eax,-0xc(%ebp)
     a53:       8b 45 fc                mov    -0x4(%ebp),%eax
     a56:       89 45 f8                mov    %eax,-0x8(%ebp)
     a59:       b8 00 00 00 00          mov    $0x0,%eax
     a5e:       89 45 f0                mov    %eax,-0x10(%ebp)
     a61:       8b 45 f0                mov    -0x10(%ebp),%eax
     a64:       81 f8 e3 00 00 00       cmp    $0xe3,%eax
     a6a:       0f 83 2e 00 00 00       jae    a9e <__sym_malloc+0x86>
     a70:       e9 0b 00 00 00          jmp    a80 <__sym_malloc+0x68>
     a75:       8b 45 f0                mov    -0x10(%ebp),%eax
     a78:       89 c1                   mov    %eax,%ecx
     a7a:       40                      inc    %eax
     a7b:       89 45 f0                mov    %eax,-0x10(%ebp)
     a7e:       eb e1                   jmp    a61 <__sym_malloc+0x49>
     a80:       8b 45 f8                mov    -0x8(%ebp),%eax
     a83:       83 c0 18                add    $0x18,%eax
     a86:       8b 4d f4                mov    -0xc(%ebp),%ecx
     a89:       89 08                   mov    %ecx,(%eax)
     a8b:       8b 45 f8                mov    -0x8(%ebp),%eax
     a8e:       89 45 f4                mov    %eax,-0xc(%ebp)
     a91:       8b 45 f8                mov    -0x8(%ebp),%eax
     a94:       89 c1                   mov    %eax,%ecx
     a96:       83 c0 24                add    $0x24,%eax
     a99:       89 45 f8                mov    %eax,-0x8(%ebp)
     a9c:       eb d7                   jmp    a75 <__sym_malloc+0x5d>
     a9e:       8b 45 f4                mov    -0xc(%ebp),%eax
     aa1:       89 05 00 00 00 00       mov    %eax,0x0
                        aa3: R_386_32   sym_free_first
     aa7:       8b 45 f4                mov    -0xc(%ebp),%eax
     aaa:       c9                      leave
     aab:       c3                      ret


(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!

---
https://codeberg.org/tkchia · https://disroot.org/tkchia · 😴 "MOV AX,0D500H+CMOS_REG_D+NMI"

 

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