> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c > index cff26909292..7dee311051d 100644 > --- a/gcc/config/i386/i386.c > +++ b/gcc/config/i386/i386.c > @@ -10312,13 +10312,17 @@ darwin_local_data_pic (rtx disp) > } > > /* True if the function symbol operand X should be loaded from GOT. > + If CALL_P is true, X is a call operand. > + > + NB: -fno-direct-extern-access doesn't force load from GOT for > + call. > > NB: In 32-bit mode, only non-PIC is allowed in inline assembly > statements, since a PIC register could not be available at the > call site. */ > > bool > -ix86_force_load_from_GOT_p (rtx x) > +ix86_force_load_from_GOT_p (rtx x, bool call_p) > { > return ((TARGET_64BIT || (!flag_pic && HAVE_AS_IX86_GOT32X)) > && !TARGET_PECOFF && !TARGET_MACHO > @@ -10326,11 +10330,12 @@ ix86_force_load_from_GOT_p (rtx x) > && ix86_cmodel != CM_LARGE > && ix86_cmodel != CM_LARGE_PIC > && GET_CODE (x) == SYMBOL_REF > - && SYMBOL_REF_FUNCTION_P (x) > - && (!flag_plt > - || (SYMBOL_REF_DECL (x) > - && lookup_attribute ("noplt", > - DECL_ATTRIBUTES (SYMBOL_REF_DECL > (x))))) > + && ((!call_p && !flag_direct_extern_access) > + || (SYMBOL_REF_FUNCTION_P (x) > + && (!flag_plt > + || (SYMBOL_REF_DECL (x) > + && lookup_attribute ("noplt", > + DECL_ATTRIBUTES > (SYMBOL_REF_DECL (x))))))) > && !SYMBOL_REF_LOCAL_P (x)); > } > > @@ -10596,7 +10601,8 @@ legitimate_pic_address_disp_p (rtx disp) > } > else if (!SYMBOL_REF_FAR_ADDR_P (op0) > && (SYMBOL_REF_LOCAL_P (op0) > - || (HAVE_LD_PIE_COPYRELOC > + || (flag_direct_extern_access > + && HAVE_LD_PIE_COPYRELOC > && flag_pie > && !SYMBOL_REF_WEAK (op0) > && !SYMBOL_REF_FUNCTION_P (op0))) > @@ -13498,7 +13504,7 @@ ix86_print_operand (FILE *file, rtx x, int code) > > if (code == 'P') > { > - if (ix86_force_load_from_GOT_p (x)) > + if (ix86_force_load_from_GOT_p (x, true)) > { > /* For inline assembly statement, load function address > from GOT with 'P' operand modifier to avoid PLT. */ > @@ -21935,10 +21941,10 @@ int > asm_preferred_eh_data_format (int code, int global) > { > /* PE-COFF is effectively always -fPIC because of the .reloc section. */ > - if (flag_pic || TARGET_PECOFF) > + if (flag_pic || TARGET_PECOFF || !flag_direct_extern_access) > { > int type = DW_EH_PE_sdata8; > - if (!TARGET_64BIT > + if (ptr_mode == SImode > || ix86_cmodel == CM_SMALL_PIC > || (ix86_cmodel == CM_MEDIUM_PIC && (global || code))) > type = DW_EH_PE_sdata4; > @@ -23028,10 +23034,21 @@ ix86_atomic_assign_expand_fenv (tree *hold, tree > *clear, tree *update) > static bool > ix86_binds_local_p (const_tree exp) > { > - return default_binds_local_p_3 (exp, flag_shlib != 0, true, true, > - (!flag_pic > - || (TARGET_64BIT > - && HAVE_LD_PIE_COPYRELOC != 0))); > + return default_binds_local_p_3 (exp, flag_shlib != 0, true, > + flag_direct_extern_access, > + (flag_direct_extern_access > + && (!flag_pic > + || (TARGET_64BIT > + && HAVE_LD_PIE_COPYRELOC != 0)))); > +}
Hope we can get rid of HAVE_LD_PIE_COPYRELOC unconditionally, probably separately. Patch is here: https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570139.html