This patch is pending review for trunk. Please see if this is ok to commit to google/gcc-4_8 branch. Please see this for more details:
https://gcc.gnu.org/ml/gcc-patches/2014-05/msg01215.html Patch attached. Thanks Sri
Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 210728) +++ config/i386/i386.c (working copy) @@ -12540,7 +12540,10 @@ legitimate_pic_address_disp_p (rtx disp) /* TLS references should always be enclosed in UNSPEC. */ if (SYMBOL_REF_TLS_MODEL (op0)) return false; - if (!SYMBOL_REF_FAR_ADDR_P (op0) && SYMBOL_REF_LOCAL_P (op0) + if (!SYMBOL_REF_FAR_ADDR_P (op0) + && (SYMBOL_REF_LOCAL_P (op0) + || (TARGET_64BIT && ix86_ld_pie_copyrelocs && flag_pie + && !SYMBOL_REF_FUNCTION_P (op0))) && ix86_cmodel != CM_LARGE_PIC) return true; break; Index: config/i386/i386.opt =================================================================== --- config/i386/i386.opt (revision 210728) +++ config/i386/i386.opt (working copy) @@ -198,6 +198,10 @@ mfancy-math-387 Target RejectNegative Report InverseMask(NO_FANCY_MATH_387, USE_FANCY_MATH_387) Save Generate sin, cos, sqrt for FPU +mld-pie-copyrelocs +Target Report Var(ix86_ld_pie_copyrelocs) Init(0) +Use linker copy relocs for pie + mforce-drap Target Report Var(ix86_force_drap) Always use Dynamic Realigned Argument Pointer (DRAP) to realign stack Index: testsuite/gcc.target/i386/ld-pie-copyrelocs-1.c =================================================================== --- testsuite/gcc.target/i386/ld-pie-copyrelocs-1.c (revision 0) +++ testsuite/gcc.target/i386/ld-pie-copyrelocs-1.c (revision 0) @@ -0,0 +1,13 @@ +/* Test if -mld-pie-copyrelocs does the right thing. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fpie -mld-pie-copyrelocs" } */ + +extern int glob_a; + +int foo () +{ + return glob_a; +} + +/* glob_a should never be accessed with a GOTPCREL */ +/* { dg-final { scan-assembler-not "glob_a\\@GOTPCREL" { target { x86_64-*-* } } } } */ Index: testsuite/gcc.target/i386/ld-pie-copyrelocs-2.c =================================================================== --- testsuite/gcc.target/i386/ld-pie-copyrelocs-2.c (revision 0) +++ testsuite/gcc.target/i386/ld-pie-copyrelocs-2.c (revision 0) @@ -0,0 +1,13 @@ +/* Test if -mno-ld-pie-copyrelocs does the right thing. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fpie -mno-ld-pie-copyrelocs" } */ + +extern int glob_a; + +int foo () +{ + return glob_a; +} + +/* glob_a should always be accessed via GOT */ +/* { dg-final { scan-assembler "glob_a\\@GOT" { target { x86_64-*-* } } } } */