c - 如何为 GCC 运行链接描述文件
问题描述
我正在尝试运行一个简单的链接器脚本以了解链接的工作原理以及如何使用链接器脚本实现函数重新排序
这是我的 C 代码
void A(){
printf("A\n");
}
void B(){
printf("B\n");
}
void main(){
B();
A();
}
这是链接器脚本
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}
当我尝试使用这个外部链接器脚本进行编译时,它给了我这个错误
/usr/lib64/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x14): undefined reference to `__init_array_start'
/usr/lib64/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
(.text+0x1c): undefined reference to `__init_array_end'
/usr/bin/ld: cl: hidden symbol `__init_array_end' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
我的编译命令是这样的
gcc -Wl,-no-whole-archive -ffunction-sections -T simple.ld cache_ex.c -o cl
你能告诉我我做错了什么吗?
解决方案
推荐阅读
- swift - NavigationLink 绑定问题
- ios - 如何为 iPhone 8 屏幕与 iPhone X 及更高版本的底部锚点设置不同的常量?
- java - 以编程方式添加 imageview 约束问题
- python - 如何将(纬度,经度)坐标转换为 tkinter 画布的坐标
- python-3.x - 如何使用 kivy 访问 iPhone 的位置?
- python - 我究竟做错了什么?“TypeError:不能将序列乘以‘str’类型的非整数”
- video - YOLO 用于视频(图像序列)
- php - PHP XPath 获取属性值的一部分
- json - 如何在 Python 中获取 JSON 值的索引?
- python - 如何修复 - '文件不包含节标题错误?