Question

I am trying to convert my .c file to a .s file using TCC, however, I get the error: tcc: cannot specify multiple files with -c

tcc.exe main.c -c main.S

What should I do?

Was it helpful?

Solution

tcc, as far as I can tell, does not have an option to generate an assembly listing.

tcc -c foo.c takes the C source file foo.c as input and generates a binary object file foo.o.

It can also take assembly files as input:

tcc -c asm.S preprocesses and assembles the assembly source in the existing asm.S file and generates an object file asm.o.

tcc -c asm.s is similar, but it doesn't preprocess the input file before assembling it.

The man page says:

TCC options are a very much like gcc options. The main difference is that TCC can also execute directly the resulting program and give it runtime arguments.

If tcc had an option to generate an assembly listing, then surely it would use the same option that gcc (and many other Unix-based compilers) use, namely -S -- but:

$ tcc -S foo.c
tcc: error: invalid option -- '-S'
$

You can get an assembly listing of sorts using objdump:

$ cat foo.c
#include <stdio.h>
int main(void) {
    puts("hello");
}
$ tcc -c foo.c
$ objdump -d foo.o

foo.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 81 ec 00 00 00 00    sub    $0x0,%rsp
   b:   48 8d 05 fc ff ff ff    lea    -0x4(%rip),%rax        # e <main+0xe>
  12:   48 89 c7                mov    %rax,%rdi
  15:   b8 00 00 00 00          mov    $0x0,%eax
  1a:   e8 fc ff ff ff          callq  1b <main+0x1b>
  1f:   c9                      leaveq 
  20:   c3                      retq   
$ 

but as you can see you lose some information that you'd get from a compiler-generated assembly listing. (Playing with objdump options might give you more information.)

I'm using tcc version 0.9.25 on a Linux x86_64 system.

(remyabel posted a similar but less detailed answer but deleted it, I'm not sure why.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top