[Bug c/83220] New: modification of a global register variable while the function only reads from it
stefan at potyra dot de
gcc-bugzilla@gcc.gnu.org
Wed Nov 29 19:33:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83220
Bug ID: 83220
Summary: modification of a global register variable while the
function only reads from it
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: stefan at potyra dot de
Target Milestone: ---
Hi,
thanks for your work on gcc!
>> gcc --version
gcc (Debian 7.2.0-16) 7.2.0
(amd64 environment)
Compiling the following program code results in modification of rbp, even
though the function should only read from it:
struct cpssp {
union {
long double d;
unsigned long long mmx[2];
} fpregs[8];
unsigned int fpstt;
};
#define ST0(cpssp) (cpssp->fpregs[cpssp->fpstt].d)
#define ST(cpssp, n) (cpssp->fpregs[(cpssp->fpstt + (n)) & 7].d)
register struct cpssp *env asm ("rbp");
unsigned int PARAM1;
void op_fxchg_ST0_STN(void)
{
long double tmp;
tmp = ST(env, PARAM1);
ST(env, PARAM1) = ST0(env);
ST0(env) = tmp;
}
>> objdump -d test.o
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <op_fxchg_ST0_STN>:
0: 8b 95 80 00 00 00 mov 0x80(%rbp),%edx
6: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # c
<op_fxchg_ST0_STN+0xc>
c: 01 d0 add %edx,%eax
e: 48 c1 e2 04 shl $0x4,%rdx
12: 83 e0 07 and $0x7,%eax
15: 48 c1 e0 04 shl $0x4,%rax
19: 48 01 e8 add %rbp,%rax
1c: 48 01 d5 add %rdx,%rbp
1f: db 28 fldt (%rax)
21: db 6d 00 fldt 0x0(%rbp)
24: db 38 fstpt (%rax)
26: db 7d 00 fstpt 0x0(%rbp)
29: c3 retq
At offset 1c, rbp is modified, while the code should not change it.
Can you take a look?
If you need more information please ask.
P.S.: This is a (simplified) portion of code found in FAUmachine and Volkmar
Sieh found the actual problem. If you have a workaround, I am very happy to
hear it.
Cheers,
Stefan.
More information about the Gcc-bugs
mailing list