c - 编译为 FDPIC ELF 时出现分段错误
问题描述
我有一个简单的 c helloworld 程序。
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
当我正常编译它时( arm-linux-gnueabi-gcc helloworld.c -o out.o
),它执行没有任何问题,但是当我尝试将它编译为 FDPIC 精灵( arm-linux-gnueabi-gcc -shared -fPIC -fPIE helloworld.c -o out.o
)时,它崩溃了。
$ qemu-arm -cpu cortex-a7 out.o
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault
解决方案
这个:
arm-linux-gnueabi-gcc -shared -fPIC -fPIE helloworld.c -o out.o
建立一个共享库。共享库缺少启动代码,无法正常执行。
也许您想构建一个 PIE 可执行文件?如果是这样,请执行以下操作:
arm-linux-gnueabi-gcc -pie -fPIE helloworld.c -o out.pie
推荐阅读
- python - 安装和运行 Selenium、Pycharm 时出错
- javascript - 反应 useContext useReducer 状态 Hooks 错误
- android - 如何提高像素绘制过程的性能?
- javascript - 为什么我的 flatlist 在过滤时不会再次呈现我的组件?
- mysql - 如何从一个表中选择不在其他表中的所有行?
- qt - 如何通过命令行升级Qt版本?
- palantir-foundry - 为什么代码工作簿中的“创建新模板”按钮是灰色的?
- mocha.js - 如果“it”部分之一失败,如何停止测试运行?
- javascript - React 将背景 url 转换为 base64 图像
- python - 当我尝试在 python 上安装模块时,错误不断出现