public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: Fix DWARF2 section lossage
@ 2001-04-24 18:55 Mark Mitchell
  2001-04-25 12:35 ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Mitchell @ 2001-04-24 18:55 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill; +Cc: gcc

This patch fixes PR1964, a regression from GCC 2.95.x.  The problem
comes from the fact that the x86 back-end now emits PIC stubs at the
end of the file.  At this point, the DWARF2 code has changed the
current section around, but hasn't told varasm.c about what it's done.
As a result, when the x86 back-end calls text_section, varasm.c thinks
that we are already in the text section, and does nothing.  Then, we
end up emitting the PIC stub into the middle of the .debug_aranges
section.

The patch fixes the problem by forcibly synchronizing varasm.c's
notion of the current section with reality.

The real problem, however, is that dwarf2out.c is doing things behind
the back of the rest of the compiler.  In particular, dwaf2out.c uses
ASM_OUTPUT_SECTION throughout -- a macro that can be overridden by the
target machine, but which is not documented in the TeXinfo
documentation.  Using this macro doesn't updated in_section in
varasm.c.

Instead, the dwaf2out.c code should be using named_section; the
routine that is supposed to switch among sections.  However, just
making that change doesn't work on i686-pc-linux-gnu; the definition
of ASM_OUTPUT_SECTION_NAME (which *is* documented) used there does:

  .section debug_aranges,"aw",@progbits

and the linker then proceeds to issue error messages.  Presumably
ASM_OUTPUT_SECTION_NAME needs some tweaking to handle the .debug_*
sections appropriately.

The attached patch should do the trick on the branch, but the mainline
should get a better fix, via the use of named_section.  Or someone
should tell me I misapprehend the situation. :-)

Jason, would you care to take a whack at this, since you're an expert
on this code?

Tested on i686-pc-linux-gnu, committed on the branch.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-04-24  Mark Mitchell  <mark@codesourcery.com>

	* dwarf2out.c (dwarf2out_finish): Forcibly return to the data
	section after emitting information.

Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.242.2.7
diff -c -p -r1.242.2.7 dwarf2out.c
*** dwarf2out.c	2001/04/23 16:37:15	1.242.2.7
--- dwarf2out.c	2001/04/25 01:39:28
*************** dwarf2out_finish ()
*** 11922,11926 ****
--- 11922,11940 ----
        ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
        output_aranges ();
      }
+ 
+   /* At this point, we've switched sections like mad, but we've done
+      so behind the back of varasm.c.  Unfortunately, used
+      named_section to switch sections doesn't work either; GAS 2.9.5
+      is not pleased by:
+ 
+        .section debug_aranges,"a",@progbits
+ 
+      on i686-pc-linux-gnu.  
+ 
+      By calling force_data_section, we get varasm.c synched back up
+      with reality.  That makes subsequent calls to text_section and
+      such make sense.  */
+   force_data_section ();
  }
  #endif /* DWARF2_DEBUGGING_INFO */

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Fix DWARF2 section lossage
  2001-04-24 18:55 PATCH: Fix DWARF2 section lossage Mark Mitchell
@ 2001-04-25 12:35 ` Richard Henderson
  2001-04-25 13:16   ` Mark Mitchell
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2001-04-25 12:35 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: gcc-patches, Jason Merrill, gcc

On Tue, Apr 24, 2001 at 06:54:50PM -0700, Mark Mitchell wrote:
> Presumably ASM_OUTPUT_SECTION_NAME needs some tweaking to handle
> the .debug_* sections appropriately.

Yep.  The current definition cannot create non-allocated sections.


r~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Fix DWARF2 section lossage
  2001-04-25 12:35 ` Richard Henderson
@ 2001-04-25 13:16   ` Mark Mitchell
  2001-04-25 13:32     ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Mitchell @ 2001-04-25 13:16 UTC (permalink / raw)
  To: rth; +Cc: gcc-patches, jason, gcc

>>>>> "Richard" == Richard Henderson <rth@redhat.com> writes:

    Richard> On Tue, Apr 24, 2001 at 06:54:50PM -0700, Mark Mitchell
    Richard> wrote:
    >> Presumably ASM_OUTPUT_SECTION_NAME needs some tweaking to
    >> handle the .debug_* sections appropriately.

    Richard> Yep.  The current definition cannot create non-allocated
    Richard> sections.

Is simply looking for `.debug_*' and then emitting `.section x' good
enough?  If so, I can certainly implement that.  I don't know if all
the .debug-prefixed sections are reserved for DWARF2, or whether to be
pedantically correct we'd have to explicitly enumerate all of them.

Thanks,

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Fix DWARF2 section lossage
  2001-04-25 13:16   ` Mark Mitchell
@ 2001-04-25 13:32     ` Richard Henderson
  2001-04-25 13:36       ` Mark Mitchell
  2001-04-25 14:46       ` Jakub Jelinek
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Henderson @ 2001-04-25 13:32 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: gcc-patches, jason, gcc

On Wed, Apr 25, 2001 at 01:16:39PM -0700, Mark Mitchell wrote:
> Is simply looking for `.debug_*' and then emitting `.section x' good
> enough?

I wouldn't think so.  This would affect __attribute__((section)) as well.
Perhaps enumerating all of the known sections would be ok, but I certainly
don't like it.

What I'd really like to see is 

enum section_flags
{
  SECT_EXECUTABLE = 1,
  SECT_WRITABLE = 2,
  SECT_LOADED = 4,
  SECT_SHORT = 8,
  SECT_COMDAT = 16,
};

#define ASM_OUTPUT_SECTION_NAME (FILE, NAME, DECL, FLAGS)

At present we have a _lot_ of replicated logic to look at a DECL
and figure out what the section flags ought to be.  It'd be really
nice to factor that out into common code.


r~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Fix DWARF2 section lossage
  2001-04-25 13:32     ` Richard Henderson
@ 2001-04-25 13:36       ` Mark Mitchell
  2001-04-25 14:46       ` Jakub Jelinek
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Mitchell @ 2001-04-25 13:36 UTC (permalink / raw)
  To: rth; +Cc: gcc-patches, jason, gcc

>>>>> "Richard" == Richard Henderson <rth@redhat.com> writes:

    Richard> At present we have a _lot_ of replicated logic to look at
    Richard> a DECL and figure out what the section flags ought to be.
    Richard> It'd be really nice to factor that out into common code.

Ok, that sounds good.

That's a bit of work, so I'll not do anything, since this only affects
the mainline at this point; hopefully someone else will get a chance.

Back to GNATS...

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: PATCH: Fix DWARF2 section lossage
  2001-04-25 13:32     ` Richard Henderson
  2001-04-25 13:36       ` Mark Mitchell
@ 2001-04-25 14:46       ` Jakub Jelinek
  1 sibling, 0 replies; 6+ messages in thread
From: Jakub Jelinek @ 2001-04-25 14:46 UTC (permalink / raw)
  To: Richard Henderson, Mark Mitchell, gcc-patches, jason, gcc

On Wed, Apr 25, 2001 at 01:32:15PM -0700, Richard Henderson wrote:
> On Wed, Apr 25, 2001 at 01:16:39PM -0700, Mark Mitchell wrote:
> > Is simply looking for `.debug_*' and then emitting `.section x' good
> > enough?
> 
> I wouldn't think so.  This would affect __attribute__((section)) as well.
> Perhaps enumerating all of the known sections would be ok, but I certainly
> don't like it.
> 
> What I'd really like to see is 
> 
> enum section_flags
> {
>   SECT_EXECUTABLE = 1,
>   SECT_WRITABLE = 2,
>   SECT_LOADED = 4,
>   SECT_SHORT = 8,
>   SECT_COMDAT = 16,
> };

We should then IMHO extend __attribute__((section)) syntax so that the
programmer could specify that as well (say __attribute__((section("awx")))
). The letters could be borrowed say from ELF .section command and for other
targets the ASM_OUTPUT_* macros would just map that manually to
corresponding syntax. __attribute__((section(""))) could mean just keep the
section attributes which have been given already.
With this, linux kernel could get rid of tons of warnings and glibc could
kill ugly workarounds:
/* Tacking on "\n\t#" to the section name makes gcc put it's bogus
   section attributes on what looks like a comment to the assembler.  */
#  ifdef HAVE_SECTION_QUOTES
#   define link_warning(symbol, msg) \
  __make_section_unallocated (".gnu.warning." #symbol) \
  static const char __evoke_link_warning_##symbol[]     \
    __attribute__ ((section (".gnu.warning." #symbol "\"\n\t#\""))) = msg;
#  else
#   define link_warning(symbol, msg) \
  __make_section_unallocated (".gnu.warning." #symbol) \
  static const char __evoke_link_warning_##symbol[]     \
    __attribute__ ((section (".gnu.warning." #symbol "\n\t#"))) = msg;
#  endif

	Jakub

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-04-25 14:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-24 18:55 PATCH: Fix DWARF2 section lossage Mark Mitchell
2001-04-25 12:35 ` Richard Henderson
2001-04-25 13:16   ` Mark Mitchell
2001-04-25 13:32     ` Richard Henderson
2001-04-25 13:36       ` Mark Mitchell
2001-04-25 14:46       ` Jakub Jelinek

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