Index: lib/Target/X86/X86Subtarget.cpp =================================================================== --- lib/Target/X86/X86Subtarget.cpp +++ lib/Target/X86/X86Subtarget.cpp @@ -83,8 +83,15 @@ } else if (!isTargetWin64()) { assert(isTargetELF() && "Unknown rip-relative target"); - // Extra load is needed for all externally visible globals. - if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility()) + // Extra load is needed for all externally visible globals except with + // PIE as the definition of the global in an executable is not + // overridden. + + bool isPIEDefinition = + GV->hasExactDefinition() && TM.Options.PositionIndependentExecutable; + + if (!GV->hasLocalLinkage() && GV->hasDefaultVisibility() && + !isPIEDefinition) return X86II::MO_GOTPCREL; } Index: test/CodeGen/X86/emutls-pie.ll =================================================================== --- test/CodeGen/X86/emutls-pie.ll +++ test/CodeGen/X86/emutls-pie.ll @@ -47,7 +47,7 @@ ; X32-NEXT: popl %ebx ; X32-NEXT: retl ; X64-LABEL: f1: -; X64: movq __emutls_v.i@GOTPCREL(%rip), %rdi +; X64: leaq __emutls_v.i(%rip), %rdi ; X64-NEXT: callq __emutls_get_address@PLT ; X64-NEXT: movl (%rax), %eax ; X64-NEXT: popq %rcx @@ -64,7 +64,7 @@ ; X32-NEXT: movl %eax, (%esp) ; X32-NEXT: calll __emutls_get_address@PLT ; X64-LABEL: f2: -; X64: movq __emutls_v.i@GOTPCREL(%rip), %rdi +; X64: leaq __emutls_v.i(%rip), %rdi ; X64-NEXT: callq __emutls_get_address@PLT entry: