public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* varasm.cc: how to hook in assemble_variable ?
@ 2023-12-19 11:16 Georg-Johann Lay
  0 siblings, 0 replies; only message in thread
From: Georg-Johann Lay @ 2023-12-19 11:16 UTC (permalink / raw)
  To: gcc

The avr backend supports variable attributes like the following that
allow to define symbols:

__attribute__((address(1234))
char a_symbol;

would produce assembly

.global a_symbol
a_symbol = 1234

This works except for -fdata-sections -fno-common (PR112952), and I am
struggling to find a fix.

Currently, the asm out happens in ASM_OUTPUT_ALIGNED_DECL_LOCAL and
ASM_OUTPUT_ALIGNED_DECL_COMMON, which is bypassed with above options.

With -fdata-sections -fno-common there is no way to output the code
in the way as required by the attributes.

The only way I found is to output in TARGET_ENCODE_SECTION_INFO
(resp. cache for later output) and set TREE_ASM_WRITTEN(decl) = 1
in order to bypass the rest of assemble_variable().

However, varasm.cc::assemble_variable() would require an extension:
The function currently reads something like below, where lines
marked with ! are needed to make it work:


void
assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
		   int at_end ATTRIBUTE_UNUSED, int dont_output_data)
{
   ...

   /* The first declaration of a variable that comes through this function
      decides whether it is global (in C, has external linkage)
      or local (in C, has internal linkage).  So do nothing more
      if this function has already run.  */

   if (TREE_ASM_WRITTEN (decl))
     return;

   /* Make sure targetm.encode_section_info is invoked before we set
      ASM_WRITTEN.  */
   decl_rtl = DECL_RTL (decl);

   TREE_ASM_WRITTEN (decl) = 1;

!  /* Allow targetm.encode_section_info to output all of decl
!     including alignment, globalizing and initializer its own
!     way.  */
!  if (TREE_ASM_WRITTEN (decl))
!    return;

   /* Do no output if -fsyntax-only.  */
   if (flag_syntax_only)
     return;


What's the proposed way to fix this?

Thanks in advance,

Johann


FYI, what won't work is to set TREE_ASM_WRITTEN in insert_attributes
for several reasons.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-19 11:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 11:16 varasm.cc: how to hook in assemble_variable ? Georg-Johann Lay

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).