This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: thread-local storage: c front end and generic backend patch


	The tls patch has changed GCC's behavior so that it no longer
emits uninitialize data in the common section, as the GCC Internals
documentation has stated would occur if BSS macros were not defined.

	* c-decl.c (start_decl): Do not set DECL_COMMON for tls variables.

-   if (!initialized && (! flag_no_common || ! TREE_PUBLIC (decl)))
+   if (TREE_CODE (decl) == VAR_DECL
+       && !initialized
+       && TREE_PUBLIC (decl)
+       && !DECL_THREAD_LOCAL (decl)
+       && !flag_no_common)
      DECL_COMMON (decl) = 1;
  
	This part of your patch from May did more than just change the
behavior for tls variables, it limited DECL_COMMON to variables marked
TREE_PUBLIC.  Prior to your patch, variables without TREE_PUBLIC flag were
marked DECL_COMMON.

At the point where varasm.c:assemble_variable() considers unitialized
data, it tests DECL_COMMON if no BSS macro is defined:


#ifndef ASM_EMIT_BSS
  /* If the target can't output uninitialized but not common global data
     in .bss, then we have to use .data.  */
  /* ??? We should handle .bss via select_section mechanisms rather than
     via special target hooks.  That would eliminate this special case.  */
  else if (!DECL_COMMON (decl))
    ;
#endif
  else if (DECL_INITIAL (decl) == 0
           || DECL_INITIAL (decl) == error_mark_node
           || (flag_zero_initialized_in_bss
               && initializer_zerop (DECL_INITIAL (decl))))
    {
...
      asm_emit_uninitialised (decl, name, size, rounded);
    }

The tm.texi section for ASM_OUTPUT_BSS states:

If this macro and @code{ASM_OUTPUT_ALIGNED_BSS} are not defined then
@code{ASM_OUTPUT_COMMON} or @code{ASM_OUTPUT_ALIGNED_COMMON} or
@code{ASM_OUTPUT_ALIGNED_DECL_COMMON} is used.

and BSS_SECTION_ASM_OP:

If not defined, and neither @code{ASM_OUTPUT_BSS} nor
@code{ASM_OUTPUT_ALIGNED_BSS} are defined, uninitialized global data will
be output in the data section if @option{-fno-common} is passed, otherwise
@code{ASM_OUTPUT_COMMON} will be used.


ASM_OUTPUT_COMMON no longer is used in the absence of -fno-common as
documented.  All systems without BSS definitions now are using initialized
data instead of common.  If that is intentional, all targets without BSS
definitions need to be updated.

David


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]