我正在尝试使用tcc(版本0.9.26)针对gcc生成的.o文件编译源代码,但它有奇怪的行为.gcc(版本5.3.0)来自MinGW 64位.
更具体地说,我有以下两个文件(te1.c te2.c).我在windows7框上执行了以下命令
c:\tcc> gcc -c te1.c
c:\tcc> objcopy -O elf64-x86-64 te1.o #this is needed because te1.o from previous step is in COFF format, tcc only understand ELF format
c:\tcc> tcc te2.c te1.o
c:\tcc> te2.exe
567in dummy!!!
Run Code Online (Sandbox Code Playgroud)
请注意,它从字符串中删除了4个字节1234567in dummy!!!\n.想知道什么可能出错.
谢谢金
========文件te1.c ===========
#include <stdio.h>
void dummy () {
printf1("1234567in dummy!!!\n");
}
Run Code Online (Sandbox Code Playgroud)
========文件te2.c ===========
#include <stdio.h>
void printf1(char *p) {
printf("%s\n",p);
}
extern void dummy();
int main(int argc, char *argv[]) {
dummy();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
更新1
看到te1.o(由tcc编译的te1.c)和te1_gcc.o(由gcc编译的te1.c)之间的汇编有所不同.在编译的tcc中,我看到lea …
我pow()在C编程语言中使用整数强制转换函数时遇到了一些问题.我正在使用的编译器是Windows平台的Tiny C编译器(tcc版本0.9.24).执行以下代码时,它会输出意外结果100, 99:
#include <stdio.h>
#include <math.h>
int main(void)
{
printf("%d, ", (int) pow(10, 2));
printf("%d", (int) pow(10, 2));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,在这个在线编译器中,输出符合预期:100, 100.我不知道是什么导致了这种行为.有什么想法吗?我编程错误,编译错误?
有没有人在OS X上成功编译过TCC?
据我所知它应该是可能的但是当我运行make时我得到以下错误:
$ make
gcc -o tcc tcc.c -DTCC_TARGET_I386 -O2 -g -Wall -fno-strict-aliasing -mpreferred-stack- boundary=2 -march=i386 -falign-functions=0 -Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0 -lm -ldl
tcc.c:1: error: CPU you selected does not support x86-64 instruction set
tcc.c:1: error: CPU you selected does not support x86-64 instruction set
tcc.c:1: error: -mpreferred-stack-boundary=2 is not between 4 and 12
make: *** [tcc] Error 1
Run Code Online (Sandbox Code Playgroud)
./configure 运行正常,并提供以下输出:
$ ./configure
Binary directory /usr/local/bin
TinyCC directory /usr/local/lib/tcc
Library directory /usr/local/lib
Include directory /usr/local/include
Manual directory /usr/local/man …Run Code Online (Sandbox Code Playgroud) 有人可以解释为什么这个代码:
#include <stdio.h>
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当使用tcc使用tcc编译时,生成这个asm:
00401000 |. 55 PUSH EBP
00401001 |. 89E5 MOV EBP,ESP
00401003 |. 81EC 00000000 SUB ESP,0
00401009 |. 90 NOP
0040100A |. B8 00000000 MOV EAX,0
0040100F |. E9 00000000 JMP fmt_vuln1.00401014
00401014 |. C9 LEAVE
00401015 |. C3 RETN
Run Code Online (Sandbox Code Playgroud)
我猜可能是
00401009 |. 90 NOP
Run Code Online (Sandbox Code Playgroud)
也许有一些内存对齐,但是怎么样
0040100F |. E9 00000000 JMP fmt_vuln1.00401014
00401014 |. C9 LEAVE
Run Code Online (Sandbox Code Playgroud)
我的意思是为什么编译器会插入跳转到下一条指令的近跳转,LEAVE会执行呢?
我在64位Windows上使用TCC 0.9.26生成32位可执行文件.
我正在尝试将历史功能语言解释器(EMAS的KRC)移植到现代系统(C for Unix),并且它有一个垃圾收集器,希望能够扫描堆栈以获取指向堆的指针,以了解它必须重新定位哪些指针在GC期间移动堆中的对象时.为此,必须在堆栈中找到指向堆的所有函数参数和局部变量.
现在,有一段时间"注册"关键字意味着"如果你愿意,你可以把这个变量放在寄存器中",否则它就在堆栈上,但现在所有(GCC,Clang,Tinyc/tcc)C编译器似乎无论如何都将局部变量放入寄存器中,无法禁用此行为,结果是GC错过了属于正在进行的函数的某些值,无法保留它们并破坏堆.
有没有办法告诉任何这些编译器使用原始的C语义,除非你说"注册",否则所有局部变量都在堆栈中?
我有一些狡猾的"解决方案":
这似乎都改善了问题,但是非常黑客和不可靠.
是否有更好的方法来实现所需的结果,确保所有函数参数和局部变量都在堆栈中?
我使用clang,, gcc和tcc,我希望能够区分共同标题中的三个.
从他们的宏观转储来看,我预计宏的存在
__clang__将唯一地识别铿锵声.
我无法获得宏转储tcc($compiler -x c -E -dM /dev/null在其情况下不起作用).
什么是唯一标识gcc(可能还有tcc)的宏(如果有的话)?
我可以使用TCC的套接字库吗?我在include目录中找不到对winsock或sys/socket.h的任何引用.
如果我没记错的话,winsock是windows平台SDK的一部分(?)如果可以,我可以将它与TCC联系起来吗?
如何修复从源代码构建 TinyCCompiler(TCC) 中 crt1.o,crti.o 的错误?
https://github.com/LuaDist/tcc
我在我的桌面系统(ubuntu)上测试这个,也在服务器(centos)上测试。在两个操作系统上,都显示错误。
tcc: file '/usr/lib/crt1.o' not found
tcc: file '/usr/lib/crti.o' not found
Run Code Online (Sandbox Code Playgroud)
来宾@Base:~/Gits/tcc-compiler$ ./configure --prefix=build
Binary directory build/bin
TinyCC directory build/lib/tcc
Library directory build/lib
Include directory build/include
Manual directory build/man
Doc directory build/share/doc/tcc
Target root prefix
Source path /home/guest/Gits/tcc-compiler
C compiler gcc
CPU x86-64
Big Endian no
gprof enabled no
cross compilers no
use libgcc no
Creating config.mak and config.h
config.h is unchanged
Run Code Online (Sandbox Code Playgroud)
来宾@Base:~/Gits/tcc-compiler$ sudo make
....
....
Run Code Online (Sandbox Code Playgroud)
来宾@Base:~/Gits/tcc-compiler$ sudo make …
我正在尝试从 C++ 运行 libtcc 以使用 C 作为运行时脚本语言。运行时编译的代码必须能够运行外部代码中的函数。当传递整数时,这工作得很好,但是当将结构从 tcc 代码传递到 gcc 代码时,会发生奇怪的事情。
最小运行示例:
#include <libtcc.h>
#include <stdio.h>
struct Vec {
int x;
};
void tmp(struct Vec test) {
printf("got %x\n",test.x);
}
int main() {
TCCState* tcc; tcc = tcc_new();
tcc_set_output_type(tcc, TCC_OUTPUT_MEMORY);
tcc_add_symbol(tcc, "tmp", (void*)&tmp);
tcc_compile_string(tcc, "\
struct Vec {int x;};\
void tmp(struct Vec test);\
void fun() {\
struct Vec x = {0};\
tmp(x);\
}");
tcc_relocate(tcc, TCC_RELOCATE_AUTO);
void (*fun)(void) = (void(*)())tcc_get_symbol(tcc, "fun");
fun();
}
Run Code Online (Sandbox Code Playgroud)
运行:
gcc -ltcc -ldl test.c && ./a.out
> …Run Code Online (Sandbox Code Playgroud) 我正在尝试从名为 的小型 cc (tcc-0.9.26-win64-bin.zip)运行该示例libtcc_test.c。
我已将libtcc.hfrom libtccintoinclude复制libtcc.def到lib.
然后我运行tcc ./examples/libtcc_test.c并收到链接错误:/
tcc: error: undefined symbol 'tcc_new'
tcc: error: undefined symbol 'tcc_set_lib_path'
tcc: error: undefined symbol 'tcc_set_output_type'
tcc: error: undefined symbol 'tcc_compile_string'
tcc: error: undefined symbol 'tcc_add_symbol'
tcc: error: undefined symbol 'tcc_relocate'
tcc: error: undefined symbol 'tcc_get_symbol'
tcc: error: undefined symbol 'tcc_delete'
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
更多信息:
P:\cpp\tcc>tcc ./examples/libtcc_test.c -vv
tcc version 0.9.26 (i386 Win32)
-> ./examples/libtcc_test.c
-> p:/cpp/tcc/include/stdlib.h
-> p:/cpp/tcc/include/_mingw.h
-> …Run Code Online (Sandbox Code Playgroud)