https://blog.csdn.net/qq_24402247/article/details/140617233
报错原理应该是和 这篇博客一样,因为两个函数最多只能+-2GB 空间。我这两个函数,都是在 32 位空间内(也就是整个 4G 空间),但这两个函数的距离超过了 2G 的距离(因为我 ld 脚本的写法)。
一些必要信息:
假设这两个函数是 A 和 B ,注释掉 A 函数里,对 B 函数的调用。则不会报错。A 和 B 函数,分别处于两个 c 文件里。查阅了 gcc 的 riscv 部分,只支持-mcmodel=medlow 和-mcmodel=medany如果是-mcmodel=medany ,那么报错 relocation trancated to fit R_RISCV_CALL against symbol xx in .text section如果是-mcmodel=medlow ,那么报错 relocation trancated to fit R_RISCV_H20 against .LC0 和 relocation trancated to fit R_RISCV_CALL against symbol xx in .text section一些猜想:我看了我编译出来的反汇编,大部分函数调用是 jal ,有很少的 jalr 。我理解 jalr ,就可以随便跳转了吧,为啥编译器不帮我 编译成使用 jalr 的汇编呢。
PS:问了大模型,搜了谷歌,还是没有帮助。