[英]Relocation truncated to fit: R_X86_64_32
I have a C
driver file which declares an extern
function in order to use it in my asm
file. 我有一个
C
驱动程序文件,该文件声明一个extern
函数以便在我的asm
文件中使用它。 I am on a Windows 7 x64 machine. 我在Windows 7 x64计算机上。
I assembled the asm
file with NASM
with this command: 我使用以下命令与
NASM
组装了asm
文件:
nasm avxmain.asm -f win64 -o avxmain.o
nasm avxmain.asm -f win64 -o avxmain.o
Then I compiled the C
file like this: 然后我像这样编译
C
文件:
gcc avxdriver.c -c -m64 -o avxdriver.o
gcc avxdriver.c -c -m64 -o avxdriver.o
Linking it all together, I ran: 将它们链接在一起,我运行:
gcc avxdriver.o avxmain.o -o final
gcc avxdriver.o avxmain.o -o final
Here are the errors I am getting: 这是我遇到的错误:
avxmain.o:G:\\Desktop\\CPSC240:(.text+0x50): relocation truncated to fit: R_X86_64_32 against `.bss'
avxmain.o:G:\\ Desktop \\ CPSC240 :(。text + 0x50):重定位被截断以适合:R_X86_64_32针对.bss
avxmain.o:G:\\Desktop\\CPSC240:(.text+0xb9): relocation truncated to fit: R_X86_64_32 against `.data'
avxmain.o:G:\\ Desktop \\ CPSC240 :(。text + 0xb9):重定位被截断以适合:R_X86_64_32针对`.data'
avxmain.o:G:\\Desktop\\CPSC240:(.text+0xc2): relocation truncated to fit: R_X86_64_32 against `.data'
avxmain.o:G:\\ Desktop \\ CPSC240 :(。text + 0xc2):截断以适应:R_X86_64_32针对.data
avxmain.o:G:\\Desktop\\CPSC240:(.text+0x14e): relocation truncated to fit: R_X86_64_32 against `.bss'
avxmain.o:G:\\ Desktop \\ CPSC240 :(。text + 0x14e):截断为适合的位置:R_X86_64_32针对.bss
collect2: error: ld returned 1 exit status
collect2:错误:ld返回1退出状态
avxdriver.c
file: avxdriver.c
文件: #include <stdio.h>
#include <stdint.h>
extern double avxdemo();
int main()
{
double return_code = -99.9;
printf("%s","This program will test for the presence of AVX (Advanced Vector Extensions) also known as state component number 2.\n");
return_code = avxdemo();
printf("%s %1.12lf\n","The value returned to the driver is ", return_code);
printf("%s","The driver program will next send a zero to the operating system. Enjoy your programming.\n");
return 0;
}
avxmain.asm
file: avxmain.asm
文件: http://pastebin.com/CfnjbpXM http://pastebin.com/CfnjbpXM
I posted it here because it is very long due to comments provided by the professor. 我把它张贴在这里是因为由于教授的评论很长。
I have tried running the -fPIC
and -mcmodel=medium
option. 我尝试运行
-fPIC
和-mcmodel=medium
选项。 I still get the same errors. 我仍然遇到相同的错误。 I'm completely lost and confused since this is the sample project I am supposed to run for my class.
我完全迷糊了,因为这是我应该为我的课程运行的示例项目。 This subject is brand new to me.
这个主题对我来说是全新的。 I've spent about half my day searching these errors and trying different things.
我花了大约半天的时间搜索这些错误并尝试其他操作。 I just need to be pointed in the right direction.
我只需要指出正确的方向。
The problem is that general x64 instructions do not allow direct 64-bit addresses in their encodings. 问题在于常规的x64指令在其编码中不允许直接的64位地址。 There are two ways around this:
有两种解决方法:
Use the movabs rax, symbolNameHere
instruction to set rax
to the address, then use [rax]
to access data at that address. 使用
movabs rax, symbolNameHere
指令将rax
设置为该地址,然后使用[rax]
访问该地址上的数据。
Use [rel symbolNameHere]
as the operand; 使用
[rel symbolNameHere]
作为操作数; this creates a PC-relative reference to symbolNameHere
. 这将创建一个相对于PC的对
symbolNameHere
引用。 It's encoded as a 32-bit signed offset from whatever rip
will be when that instruction is executed. 它被编码为与执行该指令时的任何
rip
应的32位有符号偏移量。
Method 1 allows you to encode the absolute address in the instruction, whereas method 2 is smaller code (you can always do lea rax, [rel symbolNameHere]
to get the same effect as method 1). 方法1允许您对指令中的绝对地址进行编码,而方法2是较小的代码(您可以始终使用
lea rax, [rel symbolNameHere]
来获得与方法1相同的效果)。
You should use objdump -d
on avxmain.o
to find out which statements the linker is complaining about. 您应该在
avxmain.o
上使用objdump -d
找出链接器抱怨的语句。 However it's pretty clear which instructions are the problem: 但是,很明显问题是哪些指令:
xrstor [backuparea]
vmovupd ymm0, [testdata]
vmovupd ymm1, [testdata+32]
xsave [backuparea]
The problem, as Drew McGowen explained, is that the 64-bit instruction set has no way of encoding these addresses a 64-bit values in an instruction. 正如Drew McGowen所解释的那样,问题在于64位指令集无法将这些地址编码为指令中的64位值。 Instead they become 32-bit signed displacements that are signed extended to 64-bits to create the effective address.
取而代之的是,它们变成32位带符号位移,将其符号扩展到64位以创建有效地址。 As apparently Windows loads 64-bit drivers in the address range starting at
0xFFFFF88`00000000
the truncated 32-bit displacements won't get sign extended back to the correct value. 由于Windows显然在地址范围
0xFFFFF88`00000000
加载64位驱动程序,因此,被截断的32位位移不会使符号扩展回正确的值。
You should be able to use RIP relative addressing, like Drew McGowen suggested, to work around the problem. 您应该能够像Drew McGowen建议的那样使用RIP相对寻址来解决此问题。 In that case the assembler should generate PC relative (RIP relative) relocations that the linker won't complain about:
在那种情况下,汇编器应生成链接器不会抱怨的PC相对(RIP相对)重定位:
xrstor [rel backuparea]
vmovupd ymm0, [rel testdata]
vmovupd ymm1, [rel + testdata+32]
xsave [rel backuparea]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.