bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gold/18296] gold fails to properly handle R_386_GOTOFF


From: hjl.tools at gmail dot com
Subject: [Bug gold/18296] gold fails to properly handle R_386_GOTOFF
Date: Wed, 22 Apr 2015 12:58:55 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=18296

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
>From a82bef932ec11cc16f205427f8a056c3c0ea517d Mon Sep 17 00:00:00 2001
From: Sriraman Tallam <address@hidden>
Date: Tue, 13 May 2014 10:51:48 -0700
Subject: [PATCH] With -pie and x86, the linker complains if it sees a
 PC-relative relocation to access a global as it expects a GOTPCREL
 relocation.  This is really not necessary as the linker could use a copy
 relocation to get around it.  This patch enables copy relocations with pie.

Context:
This is useful because currently the GCC compiler with option -fpie makes
every extern global access go through the GOT. That is because the compiler
cannot tell if a global will end up being defined in the executable or not
and is conservative. This ends up hurting performance when the binary is linked
as mostly static where most of the globals do end up being defined in the
executable.  By allowing copy relocs with fPIE, the compiler need not generate
a GOTPCREL(GOT access) for any global access.  It can safely assume that all
globals will be defined in the executable and generate a PC-relative access
instead.  Gold can then create a copy reloc for only the undefined globals.

assumes that PC-relative data access is used in PIE for copy reloc.  But it
isn't true for i386 which doesn't have PC-relative data access.  For i386,
gold should check R_386_GOTOFF like:

>From d5597ebccca6761fb641b7fc99b6e8b56fbac6e2 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <address@hidden>
Date: Wed, 22 Apr 2015 05:24:54 -0700
Subject: [PATCH] i386: Allow copy relocs for building PIE

This patch allows copy relocs for R_386_GOTOFF relocations in PIE.  For

extern int glob_a;
int foo ()
{
  return glob_a;
}

compiler now can optimize it from

    call    __x86.get_pc_thunk.ax
    addl    $_GLOBAL_OFFSET_TABLE_, %eax
    movl    address@hidden(%eax), %eax
    movl    (%eax), %eax
    ret

to

    call    __x86.get_pc_thunk.ax
    addl    $_GLOBAL_OFFSET_TABLE_, %eax
    movl    address@hidden(%eax), %eax
    ret

testsuite/pie_copyrelocs_test.cc doesn't catch the error since it relies on
compiler to generate proper relocation and compiler doesn't generate it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]