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: Link problems with section anchors


On Wed, Aug 09, 2006 at 11:09:12AM +0100, Mark Mitchell wrote:
> Richard Sandiford wrote:
> 
> > I really think recognising ".gnu.linkonce" as a magic string is a bad
> > idea.  There was talk on #gcc at the time about adding a new attribute
> > specifically for making something link-once.  I still think that's the
> > right way to go.
> 
> I agree with both points.
> 
> I think everyone agrees that, for ELF, it's unfortunate that there's as
> much code as there is throughout the toolchain relying on section names.
>  We should in general try to avoid adding more.  (Furthermore, the
> special .gnu.linkonce semantics only apply if you're using the GNU
> assembler (or perhaps GNU linker?) on an ELF system, so even if we did
> recognize the string, we'd need to do it conditionally.)
> 
> In short, I, too, think an attribute would be much better.
> 
> I also think that DECL_ONE_ONLY should definitely apply only to
> declarations with external linkage, i.e., with TREE_PUBLIC set.
> Otherwise, we're squandering a valuable bit in the tree representation
> for other declarations.

But DECL_ONE_ONLY vs. non-DECL_ONE_ONLY semantics of a section specified
in a section attribute is just one of the attributes of a section
that a user should be able to tell to GCC.  Other such attributes include
e.g. stuff GCC internally encodes with the SECCAT_* constants (read-only vs.
writable, @progbits vs. @nobits, mergeable vs. non-mergeable, code vs. data
vs. bss, small vs. non-small, tls vs. non-tls, data rel ro type), for
mergeable sections also the entity size.
Lack of this forces glibc and other programs do ugly things behind
GCC's back, like:
# ifdef HAVE_SECTION_QUOTES
#  define __sec_comment "\"\n\t#\""
# else
#  define __sec_comment "\n\t#"
# endif
# ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
#  define __make_section_unallocated(section_string)    \
  asm (".section " section_string "\n\t.previous");
# elif defined HAVE_ASM_POPSECTION_DIRECTIVE
#  define __make_section_unallocated(section_string)    \
  asm (".pushsection " section_string "\n\t.popsection");
# else
#  define __make_section_unallocated(section_string)
# endif
# define link_warning(symbol, msg) \
  __make_section_unallocated (".gnu.warning." #symbol) \
  static const char __evoke_link_warning_##symbol[]     \
    __attribute__ ((used, section (".gnu.warning." #symbol __sec_comment))) \
    = msg;
# define libc_freeres_ptr(decl) \
  __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
  decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))

where an assembly comment char just comments out what GCC appends
after the section name in .section directive, so that it doesn't override
what was specified in assembly.

	Jakub


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