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.

Reply via email to