Chinaunix首页 | 论坛 | 博客
  • 博客访问: 212758
  • 博文数量: 37
  • 博客积分: 3082
  • 博客等级: 中校
  • 技术积分: 387
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-14 13:59
文章分类
文章存档

2013年(1)

2012年(1)

2011年(2)

2010年(7)

2009年(1)

2008年(13)

2007年(12)

我的朋友

分类: LINUX

2010-05-11 11:51:57


原文如下

-------------------------------------------------------------------
Hi,

on Wed, 20 Mar 2002, Will Newton wrote:

> Is it valid to compile an executable with -fPIC?
> Can anyone tell me which architectures require -fPIC?

In general, you need to compile everything that could be mapped at
arbitrary addresses (in the process's virtual address space) with the
-fPIC option to make it position independent (whatever that means for the
target platform). Programs are loaded at a fixed address (for i386 Linux,
this is somewhere around 0x80000000), so they needn't be compiled with
-fPIC, while shared libraries can be mapped to different addresses in
different processes and thus need -fPIC. Static libraries are collections
of .o files, also called relocatable objects, which are not position
independent, but contain the information how to move them to a specified
position ("relocate", which basically means adding the start address to
all pointers). Thus, they don't need -fPIC either.

-fPIC is implemented in different ways for different architectures:

i386 doesn't have hardware support for PIC:

JSR label /* relative */
label: POP %reg /* now we have the address of "label" in %reg

m68k can address data relative to the current program counter, but only
for source addresses:

MOVE.L data(PC),%reg
[...]
LEA data(PC),%tmpreg
MOVE.L %reg,(%tmpreg)

As you can think for yourself, this is a performance penalty, especially
if you only have few registers, like on i386 (that's why i386 doesn't use
libperl in its perl interpreter -- 5% performance loss), however you
cannot avoid it for shared libraries.

For the "which architectures" question: Do not think about that.
Architectures which don't require -fPIC simply have compilers that ignore
it. :-)

Simon

阅读(1782) | 评论(0) | 转发(0) |
0

上一篇:dentry chain

下一篇:bit操作的坑

给主人留下些什么吧!~~