A strange error when link using tcc on a gcc compiled objected file

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

A strange error when link using tcc on a gcc compiled objected file

Jin Qian
I am trying to compile a code in MinGW gcc and link it with tcc (tiny C compiler), this is needed due to how a project is set up.
 But it's either give strange output or the resulted executable will "stop working".

c:\tcc> gcc -c te1.c
c:\tcc> objcopy -O elf64-x86-64 te1.o
c:\tcc> tcc te2.c te1.o
c:\tcc> te2.exe
567in dummy!!!

As you can see, the output is not "1234567in dummy!!!" as I had expected.   The command "objcopy" is necessary since the te1.o (from the output of gcc) 
is in COFF format.  After objcopy, it becomes ELF format which tcc can understand.

By the way, I used "readelf -a " to look at the elf from gcc/objcopy,  the relocation section has type R_X86_64_32.    If I compile te1.c with tcc, the resulted te1.o (in ELF format)
has relocation has type R_X86_64_RELATIVE.  Not sure it has anything to do with the error in the resulted executable (te2.exe). 

Any idea would be appreciated.  Thanks.

========file te1.c==================
#include <stdio.h>

void dummy () {
printf1("1234567in dummy!!!\n");

=======file te2.c======================
void printf1(char *p) {
extern void dummy();
int main(int argc, char *argv[]) {
return 0;

Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

You may change your MinGW Account Options or unsubscribe at:
Also: mailto:[hidden email]?subject=unsubscribe