简体   繁体   English

搬迁被截断以适应:R_X86_64_32

[英]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: 有两种解决方法:

  1. 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]访问该地址上的数据。

  2. 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.

相关问题 使用简单的链接描述文件将“重新定位到适合的位置:R_X86_64_32S” - Using simple linker script gives “relocation truncated to fit: R_X86_64_32S” “relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_Sleep'”的问题 - Problem with “ relocation truncated to fit: R_X86_64_PC32 against symbol `__imp_Sleep' ” 截断重定位以适合:R_X86_64_PC32针对未定义符号`cfree&#39; - relocation truncated to fit: R_X86_64_PC32 against undefined symbol `cfree' C编译:重定位被截断以适合R_X86_64_PC32针对符号 - C compiling: relocation truncated to fit R_X86_64_PC32 against symbol 在制作共享对象时,不能使用针对`.data&#39;的重定位R_X86_64_32; - relocation R_X86_64_32 against `.data' can not be used when making a shared object; cygwin 64库:未定义引用,重定位被截断以适合:R_X86_64_PC32对未定义的符号 - cygwin 64 library: undefined reference, relocation truncated to fit: R_X86_64_PC32 against undefined symbol 错误:c:87 :(。text + 0x247):重定位被截断以适合:R_X86_64_PC32针对未定义的符号“ course_insert” - Error: c:87:(.text+0x247): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `course_insert' gcc 编译错误:/usr/bin/ld: gfx.o: 重定位 R_X86_64_32 against `.rodata' cannot be used when make a PIE object; 使用 -fPIE 重新编译 - gcc compile error: /usr/bin/ld: gfx.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE R_X86_64_32S 和 R_X86_64_64 重定位是什么意思? - What do R_X86_64_32S and R_X86_64_64 relocation mean? 从内联汇编调用函数时,对符号重新定位R_X86_64_PC32 - Relocation R_X86_64_PC32 against symbol when calling function from inline assembly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM