[PATCH] Provide new macro TARGET_SUPPORTS_WEAK

Richard Guenther richard.guenther@gmail.com
Mon Oct 11 16:07:00 GMT 2010


On Mon, Oct 11, 2010 at 5:19 PM, John David Anglin
<dave@hiauly1.hia.nrc.ca> wrote:
> On Thu, 30 Sep 2010, Joseph S. Myers wrote:
>
>> As with HARD_FRAME_POINTER_IS_FRAME_POINTER and
>> HARD_FRAME_POINTER_IS_ARG_POINTER, and with the powerpc64-linux fix
>> (r164764), if a target macro is used in preprocessor conditionals then it
>> must not depend on command-line options, and if it does at present you
>> need to define a new macro that does not.  Such dependencies have never
>> made much logical sense, but now they break the build rather than quietly
>> treating target_flags as 0.
>
> The enclosed patch defines a new macro, TARGET_SUPPORTS_WEAK, to decouple
> uses a preprocessor constant and a C expression.  The uses as a C expression
> are renamed to use the new macro TARGET_SUPPORTS_WEAK.
>
> In reviewing these changes, I noticed that the define for USE_LINKONCE_INDIRECT
> was broken as SUPPORTS_ONE_ONLY is always defined.  This is corrected.
>
> Tested on hppa2.0w-hp-hpux11.11 and hppa64-hp-hpux11.11.  An earlier
> version was tested on hppa-unknown-linux-gnu.
>
> OK?

Ok.  But please leave Joseph time to comment.

Thanks,
Richard.

> Dave
> --
> J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
> National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)
>
> 2010-10-11  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
>
>        PR middle-end/45862
>        * doc/tm.texi.in (SUPPORTS_WEAK): Update.
>        (TARGET_SUPPORTS_WEAK): New.
>        * doc/tm.texi: Regenerate.
>        * defaults.h (SUPPORTS_WEAK): Update comment.
>        (TARGET_SUPPORTS_WEAK): New.
>        * dwarf2asm.c (USE_LINKONCE_INDIRECT): Update define.
>        * varasm.c (assemble_external): Use TARGET_SUPPORTS_WEAK instead of
>        SUPPORTS_WEAK.
>        (merge_weak, declare_weak, do_assemble_alias, supports_one_only,
>        make_decl_one_only): Likewise.
>        * config/pa/som.h (SUPPORTS_WEAK): Rename defines to
>        TARGET_SUPPORTS_WEAK.
>        (SUPPORTS_ONE_ONLY, MAKE_DECL_ONE_ONLY): Use TARGET_SUPPORTS_WEAK
>        instead of SUPPORTS_WEAK.
>
> Index: doc/tm.texi.in
> ===================================================================
> --- doc/tm.texi.in      (revision 165311)
> +++ doc/tm.texi.in      (working copy)
> @@ -7909,15 +7909,23 @@
>  @end defmac
>
>  @defmac SUPPORTS_WEAK
> -A C expression which evaluates to true if the target supports weak symbols.
> +A preprocessor constant expression which evaluates to true if the target
> +supports weak symbols.
>
>  If you don't define this macro, @file{defaults.h} provides a default
>  definition.  If either @code{ASM_WEAKEN_LABEL} or @code{ASM_WEAKEN_DECL}
> -is defined, the default definition is @samp{1}; otherwise, it is
> -@samp{0}.  Define this macro if you want to control weak symbol support
> -with a compiler flag such as @option{-melf}.
> +is defined, the default definition is @samp{1}; otherwise, it is @samp{0}.
>  @end defmac
>
> +@defmac TARGET_SUPPORTS_WEAK
> +A C expression which evaluates to true if the target supports weak symbols.
> +
> +If you don't define this macro, @file{defaults.h} provides a default
> +definition.  The default definition is @samp{(SUPPORTS_WEAK)}.  Define
> +this macro if you want to control weak symbol support with a compiler
> +flag such as @option{-melf}.
> +@end defmac
> +
>  @defmac MAKE_DECL_ONE_ONLY (@var{decl})
>  A C statement (sans semicolon) to mark @var{decl} to be emitted as a
>  public symbol such that extra copies in multiple translation units will
> Index: doc/tm.texi
> ===================================================================
> --- doc/tm.texi (revision 165311)
> +++ doc/tm.texi (working copy)
> @@ -7923,15 +7923,23 @@
>  @end defmac
>
>  @defmac SUPPORTS_WEAK
> -A C expression which evaluates to true if the target supports weak symbols.
> +A preprocessor constant expression which evaluates to true if the target
> +supports weak symbols.
>
>  If you don't define this macro, @file{defaults.h} provides a default
>  definition.  If either @code{ASM_WEAKEN_LABEL} or @code{ASM_WEAKEN_DECL}
> -is defined, the default definition is @samp{1}; otherwise, it is
> -@samp{0}.  Define this macro if you want to control weak symbol support
> -with a compiler flag such as @option{-melf}.
> +is defined, the default definition is @samp{1}; otherwise, it is @samp{0}.
>  @end defmac
>
> +@defmac TARGET_SUPPORTS_WEAK
> +A C expression which evaluates to true if the target supports weak symbols.
> +
> +If you don't define this macro, @file{defaults.h} provides a default
> +definition.  The default definition is @samp{(SUPPORTS_WEAK)}.  Define
> +this macro if you want to control weak symbol support with a compiler
> +flag such as @option{-melf}.
> +@end defmac
> +
>  @defmac MAKE_DECL_ONE_ONLY (@var{decl})
>  A C statement (sans semicolon) to mark @var{decl} to be emitted as a
>  public symbol such that extra copies in multiple translation units will
> Index: defaults.h
> ===================================================================
> --- defaults.h  (revision 165311)
> +++ defaults.h  (working copy)
> @@ -286,7 +286,8 @@
>  #endif
>  #endif
>
> -/* This determines whether or not we support weak symbols.  */
> +/* This determines whether or not we support weak symbols.  SUPPORTS_WEAK
> +   must be a preprocessor constant.  */
>  #ifndef SUPPORTS_WEAK
>  #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
>  #define SUPPORTS_WEAK 1
> @@ -295,6 +296,12 @@
>  #endif
>  #endif
>
> +/* This determines whether or not we support weak symbols during target
> +   code generation.  TARGET_SUPPORTS_WEAK can be any valid C expression.  */
> +#ifndef TARGET_SUPPORTS_WEAK
> +#define TARGET_SUPPORTS_WEAK (SUPPORTS_WEAK)
> +#endif
> +
>  /* This determines whether or not we support the discriminator
>    attribute in the .loc directive.  */
>  #ifndef SUPPORTS_DISCRIMINATOR
> Index: dwarf2asm.c
> ===================================================================
> --- dwarf2asm.c (revision 165311)
> +++ dwarf2asm.c (working copy)
> @@ -798,8 +798,8 @@
>
>  static GTY(()) int dw2_const_labelno;
>
> -#if defined(HAVE_GAS_HIDDEN) && defined(SUPPORTS_ONE_ONLY)
> -# define USE_LINKONCE_INDIRECT 1
> +#if defined(HAVE_GAS_HIDDEN)
> +# define USE_LINKONCE_INDIRECT (SUPPORTS_ONE_ONLY)
>  #else
>  # define USE_LINKONCE_INDIRECT 0
>  #endif
> Index: varasm.c
> ===================================================================
> --- varasm.c    (revision 165311)
> +++ varasm.c    (working copy)
> @@ -2053,7 +2053,7 @@
>   /* We want to output annotation for weak and external symbols at
>      very last to check if they are references or not.  */
>
> -  if (SUPPORTS_WEAK
> +  if (TARGET_SUPPORTS_WEAK
>       && DECL_WEAK (decl)
>       /* TREE_STATIC is a weird and abused creature which is not
>         generally the right test for whether an entity has been
> @@ -5027,7 +5027,7 @@
>  {
>   if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
>     {
> -      if (DECL_WEAK (newdecl) && SUPPORTS_WEAK)
> +      if (DECL_WEAK (newdecl) && TARGET_SUPPORTS_WEAK)
>         {
>           tree *pwd;
>           /* We put the NEWDECL on the weak_decls list at some point
> @@ -5064,7 +5064,7 @@
>        warning (0, "weak declaration of %q+D after first use results "
>                  "in unspecified behavior", newdecl);
>
> -      if (SUPPORTS_WEAK)
> +      if (TARGET_SUPPORTS_WEAK)
>        {
>          /* We put the NEWDECL on the weak_decls list at some point.
>             Replace it with the OLDDECL.  */
> @@ -5098,7 +5098,7 @@
>     error ("weak declaration of %q+D must be public", decl);
>   else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
>     error ("weak declaration of %q+D must precede definition", decl);
> -  else if (!SUPPORTS_WEAK)
> +  else if (!TARGET_SUPPORTS_WEAK)
>     warning (0, "weak declaration of %q+D not supported", decl);
>
>   mark_weak (decl);
> @@ -5344,7 +5344,7 @@
>                          IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
>                          IDENTIFIER_POINTER (target));
>  #else
> -      if (!SUPPORTS_WEAK)
> +      if (!TARGET_SUPPORTS_WEAK)
>        {
>          error_at (DECL_SOURCE_LOCATION (decl),
>                    "weakref is not supported in this configuration");
> @@ -5636,7 +5636,7 @@
>  {
>   if (SUPPORTS_ONE_ONLY)
>     return 1;
> -  return SUPPORTS_WEAK;
> +  return TARGET_SUPPORTS_WEAK;
>  }
>
>  /* Set up DECL as a public symbol that can be defined in multiple
> @@ -5662,7 +5662,7 @@
>     DECL_COMMON (decl) = 1;
>   else
>     {
> -      gcc_assert (SUPPORTS_WEAK);
> +      gcc_assert (TARGET_SUPPORTS_WEAK);
>       DECL_WEAK (decl) = 1;
>     }
>  }
> Index: config/pa/som.h
> ===================================================================
> --- config/pa/som.h     (revision 165311)
> +++ config/pa/som.h     (working copy)
> @@ -272,11 +272,13 @@
>  #define ALWAYS_STRIP_DOTDOT 1
>
>  /* If GAS supports weak, we can support weak when we have working linker
> -   support for secondary definitions and are generating code for GAS.  */
> +   support for secondary definitions and are generating code for GAS.
> +   This is primarily for one-only support as SOM doesn't allow undefined
> +   weak symbols.  */
>  #ifdef HAVE_GAS_WEAK
> -#define SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS)
> +#define TARGET_SUPPORTS_WEAK (TARGET_SOM_SDEF && TARGET_GAS)
>  #else
> -#define SUPPORTS_WEAK 0
> +#define TARGET_SUPPORTS_WEAK 0
>  #endif
>
>  /* CVS GAS as of 4/28/04 supports a comdat parameter for the .nsubspa
> @@ -289,7 +291,7 @@
>  #endif
>
>  /* We can support one only if we support weak or comdat.  */
> -#define SUPPORTS_ONE_ONLY (SUPPORTS_WEAK || SUPPORTS_SOM_COMDAT)
> +#define SUPPORTS_ONE_ONLY (TARGET_SUPPORTS_WEAK || SUPPORTS_SOM_COMDAT)
>
>  /* We use DECL_COMMON for uninitialized one-only variables as we don't
>    have linkonce .bss.  We use SOM secondary definitions or comdat for
> @@ -300,7 +302,7 @@
>         && (DECL_INITIAL (DECL) == 0                                   \
>             || DECL_INITIAL (DECL) == error_mark_node))                        \
>       DECL_COMMON (DECL) = 1;                                          \
> -    else if (SUPPORTS_WEAK)                                            \
> +    else if (TARGET_SUPPORTS_WEAK)                                     \
>       DECL_WEAK (DECL) = 1;                                            \
>   } while (0)
>
>



More information about the Gcc-patches mailing list