LLVM:目标文件重定位被截断以适合:R_X86_64_32S 反对`.rodata'

问题描述

我有一个 LLVM 程序可以评估指令并构建 IR。然后我使用 LLVMTargetMachineEmitToFile 发出模块。当与 ld 链接时,我得到一个输出

test:(.text+0x61): relocation truncated to fit: R_X86_64_32S against `.rodata'
test:(.text+0x6d): relocation truncated to fit: R_X86_64_32S against `.rodata'+4
collect2: error: ld returned 1 exit status

这个错误的原因来自于我在程序中创建的一个全局变量输出 IR 时,您会看到:

@const.array = private unnamed_addr constant [6 x i8] c"\05\06\07\08\09\0A",align 16

我用来输出目标文件代码

LLVMTargetRef t;
LLVMGetTargetFromTriple(LLVMGetDefaultTargetTriple(),&t,&error);
if (error)
    printf("%s\n",error);

LLVMTargetMachineRef target = LLVMCreateTargetMachine(t,LLVMGetDefaultTargetTriple(),LLVMGetTargetName(t),LLVMGetHostcpuFeatures(),LLVMCodeGenLevelNone,LLVMRelocStatic,LLVMcodemodelDefault);
strcpy(file_name + len,".o\0");
LLVMTargetMachineEmitToFile(target,mod,file_name,LLVMObjectFile,&error);

我正在使用 cygwin 提供的 ld。如果我在 WSL 中使用 ld 它链接正常。此外,我尝试将 -m 选项与 ld 一起使用,但出于某种原因,cygwin 版本似乎只支持 i386。我在 LLVMCreateTargetMachine 中尝试了不同的重定位模式,但这似乎没有任何作用。我该如何解决这个问题?

还有一个附带问题:当使用 LLVMConsArray 时,它会生成一个 ascii 字符串,如上所示,但是当我在 clang 中为 c 文件发出 IR 代码时,它使用实际数组。这能解决吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)