as/i386 compiles 4+(%esp) to 0(%esp)

Number:rdar://5828463 Date Originated:28-Mar-2008 02:50 PM
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
28-Mar-2008 10:50 AM Alexander Strange:
int a(int v)
    int temp[4];
    asm volatile("mov %0, 4+%1"
                 : "r"(v), "o"(*temp));
    return temp[1];

gcc/llvm will output 'mov %eax, 4+(%esp)'. Under other systems, this compiles to '4(%esp)', but Darwin compiles to 0(%esp), which is wrong.

Steps to Reproduce:
1. Under some other i386 system: gcc -O -fomit-frame-pointer -c asm-offset.c (attached)
2. Check with objdump -d:
Disassembly of section .text:

00000000 <a>:
   0:   83 ec 10                sub    $0x10,%esp
   3:   8b 44 24 14             mov    0x14(%esp),%eax
   7:   89 44 24 04             mov    %eax,0x4(%esp)
   b:   8b 44 24 04             mov    0x4(%esp),%eax
   f:   83 c4 10                add    $0x10,%esp
  12:   c3                      ret    

3. Under Darwin: gcc -arch i386 -O -fomit-frame-pointer -c asm-offset.c (attached)
4. Check the output with otool -tv.

Expected results:
The same assembly.

Actual results:
00000000	subl	$0x1c,%esp
00000003	movl	0x20(%esp),%eax
00000007	movl	%eax,0x00(%esp)
0000000b	movl	0x04(%esp),%eax
0000000f	addl	$0x1c,%esp
00000012	ret

Checked with:
Apple Computer, Inc. version cctools-667.3~112, GNU assembler version 1.38
GNU assembler version 2.18 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.18

There seems to be a problem with the definition of "o" constraints in gcc - shouldn't it always output 0(%esp) in this case?


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!