本文介绍了为什么fPIC绝对需要64位而不是32位平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近收到了一个:

错误。



现在解决这个问题并不困难(用-fPIC重新编译所有依赖项),但经过一番研究后发现,这个问题只存在于x86-64平台上。在32位上,任何依赖位置的代码仍然可以通过动态加载器重新定位。



最好的我能找到的是:

但是我觉得这不够。如果重定位破坏了共享库的概念,为什么它可以在32位平台上完成?另外,如果需要对ELF格式进行更改以支持64位,那么为什么并非所有的字段都增加以容纳?



这可能是小问题,但它的动机是:a)有问题的代码是一个科学代码,不用担心会有性能问题,而且b)这些信息在第一时间是不可能找到的! / p>



@awoodlands 可能是最好的'文字回答',@servn ,最终是一个 (请参见第68页)
]

解决方案
据我所知,问题是x86-64似乎引入了新的,相对于指令指针来说,引用数据的速度更快,而x86-32则不存在。

/code/c/amd64-pic.htmlrel =noreferrer>本文对其进行了深入分析,并给出了以下内容摘要:

即, -fPIC 寻址为寻址增加了一个额外的抽象层,以使通常寻址方式中以前可能的(以及理想的特性)仍然适用于新的体系结构。 / p>

I recently received a:

error while trying to compile a program as a shared library.

Now the solution to this is not too difficult (recompile all dependencies with -fPIC), but after some research it turns out that this problem is only present on x86-64 platforms. On 32bit any position dependent code can still be relocated by the dynamic loader.

The best answer I could find is:

But I don't find this quite adequate. If it is the case that relocations spoil the concept of shared libraries, why can it be done on 32bit platforms? Also, if there were changes that needed to be made to the ELF format to support 64bit, then why were not all fields increased in size to accommodate?

This may be a minor point, but it is motivated by the fact that a) the code in question is a scientific code and it would be nice not to have to take a performance hit and b) this information was nye impossible to find in the first place!

[Edit: 'The Answer'

@awoodlands answer is probably the best 'literal answer', @servn added some good information.

In a search to find more about different types of relocations I found this and ultimately an x86_64 ABI reference (see page 68)]

解决方案

As I understand it the problem is x86-64 seems to introduce a new, faster way of referencing data relative to the instruction pointer, which did not exist for x86-32.

This article has a nice in-depth analysis of it, and gives the following executive summary:

I.e. -fPIC addressing adds an extra layer of abstraction to addressing, to make what was previously possible (and a desirable feature) in the usual addressing style still work with the newer architecture.

这篇关于为什么fPIC绝对需要64位而不是32位平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:24