This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

statically linked PIEs without GOT


Dear GCC Experts,

I have a somewhat strange request. I would like to generate statically
linked position independent executables for I386 and AMD64. The source
language is C, I use ELF for the object files, and link them using GNU
ld with a custom linker script.

The code generated by GCC with -fpic uses the Global Offset Table to
resolve external symbols. Since my program will be statically linked, I
would like to avoid this, to simplify loading. All symbols will be
resolvable at link time.

Is there an option to avoid using a GOT?


----- example source code
extern int var;

int get_var(void)
{
        return var;
}
----- end


----- what I currently get
get_var:
        pushl   %ebp
        movl    %esp, %ebp
        call    __x86.get_pc_thunk.cx
        addl    $_GLOBAL_OFFSET_TABLE_, %ecx
        movl    var@GOT(%ecx), %eax
        movl    (%eax), %eax
        popl    %ebp
        ret

 Offset     Info    Type            Sym.Value  Sym. Name
00000004  00000b02 R_386_PC32        00000000   __x86.get_pc_thunk.cx
0000000a  00000c0a R_386_GOTPC       00000000   _GLOBAL_OFFSET_TABLE_
00000010  00000d03 R_386_GOT32       00000000   var
----- end


----- what I would like
get_var:
        pushl   %ebp
        movl    %esp, %ebp
        call    __x86.get_pc_thunk.cx
        movl    var-.(%ecx), %eax
        popl    %ebp
        ret

 Offset     Info    Type            Sym.Value  Sym. Name
00000004  00000702 R_386_PC32        00000000   __x86.get_pc_thunk.cx
0000000a  00000802 R_386_PC32        00000000   var
----- end


Kind regards,
Morten

-- 
Morten Shearman Kirkegaard <moki@fabletech.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]