This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Link problems with section anchors
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org, David Edelsohn <dje at watson dot ibm dot com>, Steven Munroe <munroesj at us dot ibm dot com>, richard at codesourcery dot com
- Date: Wed, 9 Aug 2006 09:27:19 -0400
- Subject: Re: Link problems with section anchors
- References: <44D2755E.9020600@us.ibm.com> <20060804013032.GB23605@bubble.grove.modra.org> <87y7u427or.fsf@talisman.home> <200608041354.k74DsG832840@makai.watson.ibm.com> <87lkq41tx5.fsf@talisman.home> <200608041411.k74EBg832682@makai.watson.ibm.com> <20060809041155.GE6370@bubble.grove.modra.org> <87u04mctj1.fsf@talisman.home> <44D9B448.7070505@codesourcery.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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