public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/33527] New: GCC doesn't protect %edi when using inline assembly
@ 2007-09-22 6:59 meng dot yan at gmail dot com
2007-09-22 7:27 ` [Bug c/33527] " ebotcazou at gcc dot gnu dot org
2007-09-22 10:22 ` ebotcazou at libertysurf dot fr
0 siblings, 2 replies; 3+ messages in thread
From: meng dot yan at gmail dot com @ 2007-09-22 6:59 UTC (permalink / raw)
To: gcc-bugs
OS: Ubuntu 7.04
GCC version: 4.2.1
I try to play the inline assembly function. Here I use "rep movsb" to copy a
string.
// Code begin
char input[] = {"GCC Version Number"};
char output[30];
int length = 28;
asm (
"cld\n\t"
"rep movsb"
:
: "c"(length), "S"(input), "D"(output));
printf("%s\n", output);
// Code end
While compiled without "-O", everything is okay. However, if compiled with
"-O", the compiler will generate incorrect code as if the %edi never changes
during the assembly code execution.
Compile with "-S" will see the corresponding generated assembly codes are:
// code begin
# APP
cld
rep movsb
# NO_APP
movl %edi, -4(%esp) # BAD CODE HERE
movl $.LC1, (%esp)
call printf
// code end
The problem is, movsb changes the value of %esi and %edi, and I told the
compiler about this in the "input" section in the asm directive. The compiler
didn't notice this and believe the value of %edi unchanged.
I think this is a bug.
--
Summary: GCC doesn't protect %edi when using inline assembly
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: meng dot yan at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33527
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/33527] GCC doesn't protect %edi when using inline assembly
2007-09-22 6:59 [Bug c/33527] New: GCC doesn't protect %edi when using inline assembly meng dot yan at gmail dot com
@ 2007-09-22 7:27 ` ebotcazou at gcc dot gnu dot org
2007-09-22 10:22 ` ebotcazou at libertysurf dot fr
1 sibling, 0 replies; 3+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2007-09-22 7:27 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from ebotcazou at gcc dot gnu dot org 2007-09-22 07:27 -------
> The problem is, movsb changes the value of %esi and %edi, and I told the
> compiler about this in the "input" section in the asm directive.
No, you didn't, you only told that %esi and %edi should be loaded on entry.
See section 5.35 of the manual, especially the paragraph starting with "Some
instructions clobber specific hard registers". Note that the provision "You
may not write a clobber description in a way that overlaps with an input or
output operand" will apply in this case, so 'volatile' will be required.
--
ebotcazou at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ebotcazou at gcc dot gnu dot
| |org
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33527
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/33527] GCC doesn't protect %edi when using inline assembly
2007-09-22 6:59 [Bug c/33527] New: GCC doesn't protect %edi when using inline assembly meng dot yan at gmail dot com
2007-09-22 7:27 ` [Bug c/33527] " ebotcazou at gcc dot gnu dot org
@ 2007-09-22 10:22 ` ebotcazou at libertysurf dot fr
1 sibling, 0 replies; 3+ messages in thread
From: ebotcazou at libertysurf dot fr @ 2007-09-22 10:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from ebotcazou at libertysurf dot fr 2007-09-22 10:22 -------
Subject: Re: GCC doesn't protect %edi when using inline assembly
> I've tried 'volatile', but it doesn't work.
#include <stdio.h>
int main(void)
{
char input[] = {"GCC Version Number"};
char output[30],*dummy;
int length = 28;
asm volatile (
"cld\n\t"
"rep movsb"
: "=S"(dummy),"=D"(dummy)
: "c"(length), "0"(input), "1"(output));
printf("%s\n", output);
return 0;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33527
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-09-22 10:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-22 6:59 [Bug c/33527] New: GCC doesn't protect %edi when using inline assembly meng dot yan at gmail dot com
2007-09-22 7:27 ` [Bug c/33527] " ebotcazou at gcc dot gnu dot org
2007-09-22 10:22 ` ebotcazou at libertysurf dot fr
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).