I have a simple piece of assembly code that works correctly on Mac OS X (x86-64) but not on Linux (x86-64):
.data
.align 4
foo: .quad 1,2
.text
.globl fun
fun:
movapd foo(%rip), %xmm1
ret
Called from a simple C program:
int main(void){
fun();
return 0;
}
What happens on the Mac is that the xmm1 register is filled with the data at location foo i.e. in GDB:
(gdb) p $xmm1
$2 = {
...
v2_int64 = {2, 1},
uint128 = 0x00000000000000020000000000000001
}
When I run the same code under Linux it segfaults - it seems that the foo label corresponds to 0x0:
> objdump -d asm.o
...
Disassembly of section .text:
0000000000000000 <fun>:
0: 66 0f 28 0d 00 00 00 movapd 0x0(%rip),%xmm1
...
Can someone explain why this occurs and what I can do to avoid it?
Cheers
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…