public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Fāng-ruì Sòng" <maskray@google.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH v3 1/2] Add -f[no-]direct-extern-access
Date: Sun, 11 Jul 2021 23:24:43 -0700	[thread overview]
Message-ID: <CAFP8O3KP8NX00qZ1LZ5XDr+E6JPd=Oz5iXnzPMSCkihjDt57WA@mail.gmail.com> (raw)
In-Reply-To: <20210709145014.1350564-2-hjl.tools@gmail.com>

> 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

  parent reply	other threads:[~2021-07-12  6:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 14:50 [PATCH v3 0/2] Implement indirect external access H.J. Lu
2021-07-09 14:50 ` [PATCH v3 1/2] Add -f[no-]direct-extern-access H.J. Lu
2021-07-12  6:13   ` Richard Biener
2021-07-12 12:13     ` H.J. Lu
2021-08-04 22:03       ` PING^1 " H.J. Lu
2021-07-12  6:24   ` Fāng-ruì Sòng [this message]
2021-07-09 14:50 ` [PATCH v3 2/2] Add TARGET_ASM_EMIT_GNU_PROPERTY_NOTE H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFP8O3KP8NX00qZ1LZ5XDr+E6JPd=Oz5iXnzPMSCkihjDt57WA@mail.gmail.com' \
    --to=maskray@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=jakub@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).