public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Why does gas put a stop bit in a bundle?
@ 2003-04-30 16:30 H. J. Lu
  2003-04-30 18:36 ` Jim Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2003-04-30 16:30 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

GAS adds a stop bit at the last bundle in the current section
automatically.

# gcc -c -o gcc.o bundle.s
# objdump -d gcc.o 
gcc.o:     file format elf64-ia64-little
 
Disassembly of section .text:
 
0000000000000000 <.text>:
   0:   0d 40 00 40 18 10       [MFI]       ld8 r8=[r32]
   6:   00 00 00 02 00 00                   nop.f 0x0
   c:   00 00 04 00                         nop.i 0x0;;
  10:   0d 30 00 04 18 10       [MFI]       ld8 r6=[r2]
  16:   00 00 00 02 00 00                   nop.f 0x0
  1c:   00 00 04 00                         nop.i 0x0;;

Why does gas do that? I'd like to turn it off.


H.J.

[-- Attachment #2: bundle.s --]
[-- Type: text/plain, Size: 233 bytes --]

      .text
      .align 16
	{ .mfi
      ld8  r8=[r32]
      nop.f 0x0
      nop.i 0x0
      }
      .data
      .align 16
      data8 0
      .text
      .align 16
	{ .mfi
      ld8  r6=[r2]
      nop.f 0x0
      nop.i 0x0
      }

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

* Re: Why does gas put a stop bit in a bundle?
  2003-04-30 16:30 Why does gas put a stop bit in a bundle? H. J. Lu
@ 2003-04-30 18:36 ` Jim Wilson
  2003-05-01 16:05   ` H. J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Wilson @ 2003-04-30 18:36 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

H. J. Lu wrote:
> GAS adds a stop bit at the last bundle in the current section
> automatically.
> Why does gas do that? I'd like to turn it off.

Because we can't do dependency violation checking across section 
switches.  Thus, in order to be safe, we must emit a stop bit when 
exiting the text section.  Doing otherwise will result in code that 
silently fails at run time.  Consider what happens if someone has C code 
with an extended asm that switches to an alternate code section and then 
back to text.

Section switching also causes problems for generation of unwind info. 
It also used to cause trouble for dwarf2 compaction, but I think Richard 
Henderson fixed that problem.

I believe the best long term solution for this is to modify IA-64 gas to 
insist on structured assembly language.  Gas should emit an error if it 
sees code that isn't inside a function.  Also, gas should emit an error 
if there is a section switch inside a function.  If we do this, then all 
of the dependency violation, unwind info, and dwarf2 problems go away. 
It isn't hard to follow these rules, it just takes a little thought. 
The IA-64 linux kernel is written this way for instance, because they 
have had problems in the past with secction switching in the middle of 
functions breaking DV checking and/or unwind info.

Jim


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

* Re: Why does gas put a stop bit in a bundle?
  2003-04-30 18:36 ` Jim Wilson
@ 2003-05-01 16:05   ` H. J. Lu
  2003-05-01 20:39     ` Jim Wilson
  0 siblings, 1 reply; 4+ messages in thread
From: H. J. Lu @ 2003-05-01 16:05 UTC (permalink / raw)
  To: Jim Wilson; +Cc: binutils

On Wed, Apr 30, 2003 at 11:37:03AM -0400, Jim Wilson wrote:
> H. J. Lu wrote:
> > GAS adds a stop bit at the last bundle in the current section
> > automatically.
> > Why does gas do that? I'd like to turn it off.
> 
> Because we can't do dependency violation checking across section 
> switches.  Thus, in order to be safe, we must emit a stop bit when 
> exiting the text section.  Doing otherwise will result in code that 
> silently fails at run time.  Consider what happens if someone has C code 
> with an extended asm that switches to an alternate code section and then 
> back to text.
> 
> Section switching also causes problems for generation of unwind info. 
> It also used to cause trouble for dwarf2 compaction, but I think Richard 
> Henderson fixed that problem.

Intel ia64 assembler doesn't add a stop bit. I consider it unfortunate
for gas. Can you create a testcase which shows dependency violation
doesn't with section switch? I'd like to add it to gas and I will take
a look at it when I find time.

Thanks.


H.J.

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

* Re: Why does gas put a stop bit in a bundle?
  2003-05-01 16:05   ` H. J. Lu
@ 2003-05-01 20:39     ` Jim Wilson
  0 siblings, 0 replies; 4+ messages in thread
From: Jim Wilson @ 2003-05-01 20:39 UTC (permalink / raw)
  To: H. J. Lu; +Cc: binutils

On Thu, 2003-05-01 at 12:05, H. J. Lu wrote:
> Intel ia64 assembler doesn't add a stop bit. I consider it unfortunate
> for gas. Can you create a testcase which shows dependency violation
> doesn't with section switch? I'd like to add it to gas and I will take
> a look at it when I find time.

First you have to patch gas to turn off this feature.

Index: tc-ia64.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-ia64.c,v
retrieving revision 1.82
diff -p -r1.82 tc-ia64.c
*** tc-ia64.c	21 Mar 2003 14:02:09 -0000	1.82
--- tc-ia64.c	1 May 2003 20:10:46 -0000
*************** ia64_flush_pending_output ()
*** 7064,7072 ****
--- 7064,7074 ----
    if (!md.keep_pending_output
        && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
      {
+ #if 0
        /* ??? This causes many unnecessary stop bits to be emitted.
  	 Unfortunately, it isn't clear if it is safe to remove this.  */
        insn_group_break (1, 0, 0);
+ #endif
        ia64_flush_insns ();
      }
  }

Here are two short examples.  Assemble the first one with as -x and you get
no DV warning even though the 1st and 3rd instructions conflict.  Assemble
the second one with as -x and you get a warning for a conflict between the
second and third one even though they are in different sections.

First example:
	.text
	add r3 = r2, r1
	.section .text2, "ax", @progbits
	add r6 = r4, r5
	;; 
	.text
	add r1 = r3, r2

Second example:
	.text
	add r3 = r2, r1
	;; 
	.section .text2, "ax", @progbits
	add r2 = r1, r3
	.text
	add r1 = r3, r2

Fixing this means all DV state needs to be associated with sections
instead of in a global variable, so that we can arbitrarily switch
between sections without losing state.

You mentioned that ias doesn't add a stop bit on section switches, but
how does it handle examples like this?  Does it get the right?  Or does
it give a warning/error?

The problem just isn't DV info.  The problem is all info that is synthesized
by the assembler.  This include DV info, but it also includes bundling info,
unwind info, and dwarf2 debug info.  All of the state for all of these things
would need to be section specific, otherwise we run into trouble.  The
complexity of doing this doesn't seem worth the benefit to me.

For the second example above, note that the two add instructions in text
go into two bundles, when they could have gone into one bundle.  This is
only a performance issue not a correctness issue, but it is a problem.
If people will get accidental hidden performance loss from section switching
then it is probably better to not let them do it, or at least warn them
about it.

I could also construct examples that show unwind info failures by
overlapping two function definitions.  This would be a correctness problem.
There is currently no solution for this.

Note that the xdata directives avoid a section switch, and this is
probably why it is there.

Another issue to consider is what happens when the linker merges text
sections together.  The linker isn't going to do DV checking.  This implies
that do need a stop bit at the end of each text section when we reach the
end of the input assembly file.

Jim


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

end of thread, other threads:[~2003-05-01 20:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-30 16:30 Why does gas put a stop bit in a bundle? H. J. Lu
2003-04-30 18:36 ` Jim Wilson
2003-05-01 16:05   ` H. J. Lu
2003-05-01 20:39     ` Jim Wilson

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