public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32
@ 2014-07-29 16:23 hjl.tools at gmail dot com
  2014-07-30  0:18 ` [Bug ada/61954] " hjl.tools at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-07-29 16:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61954

            Bug ID: 61954
           Summary: Ada fails to properly pass pointer arguments on x32
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com

Pointers in x32 are 32 bits.  When 32-bit pointers passed as argument
in register, they must be zero-extended to 64 bits.  Flush_Buffer in
output.adb has

           if Cur_Indentation = 0
              or else Cur_Indentation + Len > Buffer_Max
              or else Buffer (1 .. Len) = (1 => ASCII.LF)
            then
               Write_Buffer (Buffer (1 .. Len));

which is compiled into:

   0x00797849 <+169>:    lea    -0x40(%rbp),%edi
   0x0079784c <+172>:    movl   $0x1,-0x40(%ebp)
   0x00797854 <+180>:    shl    $0x20,%rdi
   0x00797858 <+184>:    mov    %eax,-0x3c(%ebp)
   0x0079785c <+188>:    mov    $0x1cddf80,%eax
   0x00797861 <+193>:    or     %rax,%rdi
   0x00797864 <+196>:    mov    -0x48(%ebp),%eax
   0x00797868 <+200>:    mov    %rax,-0x60(%ebp)
   0x0079786d <+205>:    mov    $0x1335fd8,%eax
   0x00797872 <+210>:    mov    %rax,-0x50(%ebp)
   0x00797877 <+215>:    mov    $0x1335ff0,%eax
   0x0079787c <+220>:    mov    %rax,-0x58(%ebp)
   0x00797881 <+225>:    callq  0x797530 <output__flush_buffer__write_buffer>

DI register is used to pass a pointer, which should be zero-extended
from 32 bits to 64 bits.  But we got

(gdb) si
0x00797849    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) si
0x0079784c    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) p/x $rdi
$14 = 0xffffcba0
(gdb) si
0x00797854    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) si
0x00797858    136                   Write_Buffer (Buffer (1 .. Len));
(gdb) p/x $rdi
$15 = 0xffffcba000000000
(gdb) 

RTL expand looks strange:

;; D.3473.P_BOUNDS = &D.3474;

(insn 143 142 144 (parallel [
            (set (reg:SI 156)
                (plus:SI (reg/f:SI 78 virtual-stack-vars)
                    (const_int -64 [0xffffffffffffffc0])))
            (clobber (reg:CC 17 flags))
        ]) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 144 143 145 (set (reg:DI 157)
        (zero_extend:DI (reg:SI 156)))
/export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 145 144 146 (parallel [
            (set (reg:DI 158)
                (ashift:DI (reg:DI 157)
                    (const_int 32 [0x20])))
            (clobber (reg:CC 17 flags))
        ]) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 147 146 148 (parallel [
            (set (reg:DI 160)
                (ior:DI (reg:DI 159)
                    (reg:DI 158)))
            (clobber (reg:CC 17 flags))
        ]) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

(insn 148 147 0 (set (reg:DI 120 [ D.3473 ])
        (reg:DI 160)) /export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))

;; output.flush_buffer.write_buffer (D.3473);

(insn 149 148 150 (set (reg:DI 5 di)
        (reg:DI 120 [ D.3473 ]))
/export/gnu/import/git/gcc/gcc/ada/output.adb:136 -1
     (nil))


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug ada/61954] Ada fails to properly pass pointer arguments on x32
  2014-07-29 16:23 [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32 hjl.tools at gmail dot com
@ 2014-07-30  0:18 ` hjl.tools at gmail dot com
  2014-07-30  0:34 ` hjl.tools at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-07-30  0:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61954

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
Ada seems to use a struct for pointers, something
like

struct pointer
{
  void *p;
  void *b;
};

But it fails to properly zero-extend pointers when calling
C functions:

[hjl@gnu-6 tmp]$ cat p.c
struct pointer
{
  void *p;
  void *b;
};

extern void foo (struct pointer);
extern void bar (void *p);

void
xxx (struct pointer p)
{
  foo (p);
}

void
yyy (struct pointer p)
{
  bar (p.p);
}
[hjl@gnu-6 tmp]$ gcc -mx32 -O2 p.c -S
[hjl@gnu-6 tmp]$ cat p.s
    .file    "p.c"
    .text
    .p2align 4,,15
    .globl    xxx
    .type    xxx, @function
xxx:
.LFB0:
    .cfi_startproc
    jmp    foo
    .cfi_endproc
.LFE0:
    .size    xxx, .-xxx
    .p2align 4,,15
    .globl    yyy
    .type    yyy, @function
yyy:
.LFB1:
    .cfi_startproc
    movl    %edi, %edi
    jmp    bar
    .cfi_endproc
.LFE1:
    .size    yyy, .-yyy

It treats C functions, like

       ssize_t write(int fd, const void *buf, size_t count);

as Ada functions.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug ada/61954] Ada fails to properly pass pointer arguments on x32
  2014-07-29 16:23 [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32 hjl.tools at gmail dot com
  2014-07-30  0:18 ` [Bug ada/61954] " hjl.tools at gmail dot com
@ 2014-07-30  0:34 ` hjl.tools at gmail dot com
  2014-07-30 16:03 ` hjl.tools at gmail dot com
  2014-08-06 16:30 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-07-30  0:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61954

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Maybe Ada fails to tell the backend that a parameter is a pointer:

[hjl@gnu-6 tmp]$ cat p2.c
struct pointer
{
  int p;
  int b;
};

extern void bar (int p);

void
xxx (struct pointer p)
{
  foo (p);
}
[hjl@gnu-6 tmp]$ gcc -mx32 -O2 p2.c -S
[hjl@gnu-6 tmp]$ cat p2.s
    .file    "p2.c"
    .text
    .p2align 4,,15
    .globl    xxx
    .type    xxx, @function
xxx:
.LFB0:
    .cfi_startproc
    xorl    %eax, %eax
    jmp    foo
    .cfi_endproc
.LFE0:
    .size    xxx, .-xxx


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug ada/61954] Ada fails to properly pass pointer arguments on x32
  2014-07-29 16:23 [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32 hjl.tools at gmail dot com
  2014-07-30  0:18 ` [Bug ada/61954] " hjl.tools at gmail dot com
  2014-07-30  0:34 ` hjl.tools at gmail dot com
@ 2014-07-30 16:03 ` hjl.tools at gmail dot com
  2014-08-06 16:30 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-07-30 16:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61954

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
s-os_lib.adb has

   function Write
     (FD : File_Descriptor;
      A  : System.Address;
      N  : Integer) return Integer
   is   
   begin
      return
        Integer (System.CRTL.write
                   (System.CRTL.int (FD),
                    System.CRTL.chars (A), 
                    System.CRTL.size_t (N)));
   end Write;

It is compiled into

jmp    write

'A' should be a pointer, not integer.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug ada/61954] Ada fails to properly pass pointer arguments on x32
  2014-07-29 16:23 [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32 hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2014-07-30 16:03 ` hjl.tools at gmail dot com
@ 2014-08-06 16:30 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2014-08-06 16:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61954

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-08-06
                 CC|                            |ebotcazou at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> Maybe Ada fails to tell the backend that a parameter is a pointer:

Yes, there are known issues in this area for ABIs that treat pointers and
integers of the same size differently, e.g. the Linux ABI for m68K.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-06 16:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-29 16:23 [Bug ada/61954] New: Ada fails to properly pass pointer arguments on x32 hjl.tools at gmail dot com
2014-07-30  0:18 ` [Bug ada/61954] " hjl.tools at gmail dot com
2014-07-30  0:34 ` hjl.tools at gmail dot com
2014-07-30 16:03 ` hjl.tools at gmail dot com
2014-08-06 16:30 ` ebotcazou at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).