我试图将二进制blob嵌入到exe文件中.我正在使用mingw gcc.
我像这样制作目标文件:
ld -r -b binary -o binary.o input.txt
Run Code Online (Sandbox Code Playgroud)
然后我看objdump输出来获取符号:
objdump -x binary.o
Run Code Online (Sandbox Code Playgroud)
它给出了符号:
_binary_input_txt_start
_binary_input_txt_end
_binary_input_txt_size
Run Code Online (Sandbox Code Playgroud)
然后我尝试在我的C程序中访问它们:
#include <stdlib.h>
#include <stdio.h>
extern char _binary_input_txt_start[];
int main (int argc, char *argv[])
{
char *p;
p = _binary_input_txt_start;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我这样编译:
gcc -o test.exe test.c binary.o
Run Code Online (Sandbox Code Playgroud)
但我总是得到:
undefined reference to _binary_input_txt_start
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?
当我看到C应用程序的汇编代码时,如下所示:
emacs hello.c
clang -S -O hello.c -o hello.s
cat hello.s
Run Code Online (Sandbox Code Playgroud)
函数名称以下划线为前缀(例如callq _printf).为什么要这样做,它有什么优势?
例:
你好ç
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *myString = malloc(strlen("Hello, World!") + 1);
memcpy(myString, "Hello, World!", strlen("Hello, World!") + 1);
printf("%s", myString);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
hello.s
_main: ; Here
Leh_func_begin0:
pushq %rbp
Ltmp0:
movq %rsp, %rbp
Ltmp1:
movl $14, %edi
callq _malloc ; Here
movabsq $6278066737626506568, %rcx
movq %rcx, (%rax)
movw $33, 12(%rax)
movl $1684828783, 8(%rax)
leaq L_.str1(%rip), %rdi
movq …Run Code Online (Sandbox Code Playgroud) 出于好奇心的考虑,我试图看看用最少的汇编语言制作C程序的最小.我想看看我是否可以使用动态链接的OpenGL和GLUT进行简单的OpenGL演示(即演示场景),而无需标准库.但是,我遇到了最基本的问题.
我创建了一个包含的测试main.c文件
void newStart() {
//Do stuff here...
asm("movl $1, %eax;"
"xorl %ebx, %ebx;"
"int $0x80;");
}
Run Code Online (Sandbox Code Playgroud)
我正在制作它
gcc main.c -nostdlib -e newStart -o min
Run Code Online (Sandbox Code Playgroud)
使用此StackOverflow问题建议的'-e'选项.我尝试编译时遇到以下错误:
ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
ld: entry point (newStart) undefined. for architecture x86_64
Run Code Online (Sandbox Code Playgroud)
我正在运行OS X 10.7(Lion).谁能帮我吗?
我正在使用GCC在Linux环境中学习OS开发.我在Bran的内核开发中了解到,编译时C中的所有函数和变量名都在其相应的汇编源文件中以"_"(下划线)开头.但是当我浏览已编译的C程序的汇编源代码时,我甚至找不到"_main"函数.我执行了以下操作.
cpp sample.c sample.i
gcc -S sample.I