R_X86_64_32S 和 R_X86_64_64 重定位是什么意思? [英] What do R_X86_64_32S and R_X86_64_64 relocation mean?

查看:76
本文介绍了R_X86_64_32S 和 R_X86_64_64 重定位是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 64 位 FreeBSD 中编译 C 应用程序时出现以下错误:

Got the following error when I tried to compile a C application in 64-bit FreeBSD:

relocation R_X86_64_32S 制作共享对象时不能使用;用 -fPIC 重新编译

relocation R_X86_64_32S can not be used when making a shared object; recompile with -fPIC

什么是R_X86_64_32S重定位,什么是R_X86_64_64?

What is R_X86_64_32S relocation and what is R_X86_64_64?

我已经用谷歌搜索了这个错误,这可能是原因 - 如果有人能说出 R_X86_64_32S 的真正含义,那就太好了.

I've googled about the error, and it's possible causes - It'd be great if anyone could tell what R_X86_64_32S really means.

推荐答案

R_X86_64_32SR_X86_64_64 是重定位类型的名称,用于为 amd64 架构编译的代码.您可以在 amd64 ABI 中查找所有这些.据此,R_X86_64_64分解为:

The R_X86_64_32S and R_X86_64_64 are names of relocation types, for code compiled for the amd64 architecture. You can look all of them up in the amd64 ABI. According to it, R_X86_64_64 is broken down to:

  • R_X86_64 - 所有名称都以此为前缀
  • 64 - 直接 64 位重定位

R_X86_64_32S到:

  • R_X86_64 - 前缀
  • 32S - 将值截断为 32 位并进行符号扩展

在这两种情况下,这基本上意味着此重定位所指向的符号的值,加上任何加数".对于 R_X86_64_32S,链接器会验证生成的值是否符号扩展为原始 64 位值.

which basically means "the value of the symbol pointed to by this relocation, plus any addend", in both cases. For R_X86_64_32S the linker then verifies that the generated value sign-extends to the original 64-bit value.

现在,在一个可执行文件中,代码和数据段被赋予一个指定的虚拟基地址.可执行代码不共享,每个可执行文件都有自己的新地址空间.这意味着编译器确切地知道数据段的位置,并且可以直接引用它.另一方面,库只能知道它们的数据部分将位于距基地址的指定偏移量处;该基地址的值只能在运行时知道.因此,所有库都必须使用无论放在内存中的何处都可以执行的代码生成,称为位置无关代码(或简称 PIC).

Now, in an executable file, the code and data segments are given a specified virtual base address. The executable code is not shared, and each executable gets its own fresh address space. This means that the compiler knows exactly where the data section will be, and can reference it directly. Libraries, on the other hand, can only know that their data section will be at a specified offset from the base address; the value of that base address can only be known at runtime. Hence, all libraries must be produced with code that can execute no matter where it is put into memory, known as position independent code (or PIC for short).

现在在解决您的问题时,错误消息不言自明.

Now when it comes to resolving your problem, the error message speaks for itself.

这篇关于R_X86_64_32S 和 R_X86_64_64 重定位是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆