Example source:
void f1(long foo, long bar) {/*empty*/}
void f2(long foo, ...) {/*empty*/}

void _start()
{
        f1(-1, -2); //both correct
        f2(-1, -2); //-1 correct, -2 becomes 0x00000000FFFFFFFE
        f2(0xffffffffffffffff, 0xfffffffffffffffe); //both correct
}


$ amd64-elf-gcc -ffreestanding -nodefaultlibs -nostdlib -nostartfiles -o
standalone.bin standalone.c

$ amd64-elf-gcc -v
Using built-in specs.
Target: amd64-elf
Configured with: /elf/src/gcc-4.1.1/configure --target=amd64-elf --prefix=/elf
-
-exec-prefix=/elf/amd64-pc-cygwin --with-gnu-as --with-gnu-ld --without-headers
Thread model: single
gcc version 4.1.1


$ amd64-elf-objdump -d standalone.bin

<snipped f1 & f2>

000000000040014a <_start>:
  40014a:       55                      push   %rbp
  40014b:       48 89 e5                mov    %rsp,%rbp
  40014e:       48 c7 c6 fe ff ff ff    mov    $0xfffffffffffffffe,%rsi
  400155:       48 c7 c7 ff ff ff ff    mov    $0xffffffffffffffff,%rdi
  40015c:       e8 4f ff ff ff          callq  4000b0 <f1>

  400161:       be fe ff ff ff          mov    $0xfffffffe,%esi    <-- should
be  qword move
  400166:       48 c7 c7 ff ff ff ff    mov    $0xffffffffffffffff,%rdi
  40016d:       b8 00 00 00 00          mov    $0x0,%eax
  400172:       e8 47 ff ff ff          callq  4000be <f2>

  400177:       48 c7 c6 fe ff ff ff    mov    $0xfffffffffffffffe,%rsi
  40017e:       48 c7 c7 ff ff ff ff    mov    $0xffffffffffffffff,%rdi
  400185:       b8 00 00 00 00          mov    $0x0,%eax
  40018a:       e8 2f ff ff ff          callq  4000be <f2>
  40018f:       c9                      leaveq
  400190:       c3                      retq

It should emit the 0x48 prefixed version as in the 3rd call. My guess is that
"movl" instead of "movq" or "mov ..., esi" instead of "mov ..., rsi" is being
passed to as.


-- 
           Summary: Negative numbers in varargs incorrect on AMD64
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wulf at ignmail dot com
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: amd64-pc-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28931

Reply via email to