|
| Charles Curley - Software Engineer, Writer | << | < | > | >> + Larger Font | - Smaller Font |
Charles Curley |
This is a memo I emailed out to other software engineers describing a bug I had found in a compiler routine. I had to document it in detail in order to be sure the other engineers were seeing this and not something else. It turned out that no-one else in the company was using the ANSI C standard's method of copying structures.
Also, even though the project was written entirely in ANSI C, my skills with assembly language helped me to identify this bug precisely. The assembler is Motorola 68hc11, by the way.
The names have been change to protect the guilty.
I may have come across a bug in Xyz Compiler's code routines, and want
to know if anyone else has seen this.
The problem shows up when you
a) have structures large enough that the compiler lays down a block
move instead of using registers, and
b) have auto variables on the stack which are used after the first
structure move described by a).
The compiler lays down a jsr to an assembly routine, c_movstr, to copy
a structure. If you are using memcpy(), you won't see it because
memcpy() and c_movestr don't share any code. The bug appears to be in
how c_movestr saves the processor registers:
c_movestr:
pshx
pshy
blah, blah....
pulx
puly
rts
This has the effect of swapping the x and y registers, which going in
to the routine contain the stack frame and the destination,
respectively. So if you never refer to any stack variables after using
this routine, the error doesn't show up. It may not show up under
certain other circumstances, such as the destination being the lowest
variable on the stack frame.
The work-around is to use memcpy(). This is why I checked to see that
c_movstr and memcpy() don't share any code. If you have
struct foo {
stuff;
nonsense;
} bar, baz;
....
baz = bar;
substitute
memcpy (&baz, &bar, sizeof(struct foo));
Has anyone else seen this? I'd like to confirm this before I squawk at
Xyz Company.
-- C^2
|
| << | <
| > | >>
| Welcome
| Software
| Communications
| Classes
| Resume
| Sample Code
| Thomas Jefferson: Patron Saint of the Internet
| Yum Repository Notes
| NFS and Firewalls on Fedora Core
| Netiquette
| NT Emacs Installation
| My .emacs File
| Notes on OpenSSH
| Bare Metal Recovery
| Fn
| Rms
| Dump
| Register
| Atexit
| Graphics Tree Walker
| which.nvidia
| buildiso
| wallpaper2
| gps
| Fedora Gpsdrive RPMs
| Single Source Frames
| Notes
| A Bug Notification
| Helpful Little Paperclip
| Linux on Lenovo R51
| Wyoming Travel
|