[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Calling curl_easy_setopt crashes on 64-bit Debian stable (SOLVED)

On 22.6.2010 15:39, Stephen Leake wrote:
> Tero Koskinen <tero.koskinen@iki.fi> writes:
>>    procedure printf (S : Interfaces.C.char_array; I : Interfaces.C.Int);
>>    pragma Import (C, printf, "printf");
> This is _not_ guaranteed to work;

Thanks. This indeed seem to be the issue.

I was comparing the assembly generated for Ada and C version of
printf call and noticed that for Ada GCC uses movl instruction
to move string location into register and for C GCC uses movq
instruction and in addition resets eax/rax to 0.

  movl .LC0, %edi
  movl $99999, %esi
  call printf

  movq .LC0, %rdi
  movl $99999, %esi
  movl $0, %eax
  call printf

"movl .LC0, %edi" is same as "movq .LC0, %rdi" when .LC0
resides on the lower half of the address space (like .rodata section
and NOT in stack). When the data is in the stack, GNAT correctly uses
movq. movl seems like some optimization done by GNAT, although I am not
sure is it always correct. (Can the .rodata sections appear on the upper
half of the address space?)

Adding "movl $0, %eax" to the Ada version of the code allowed
made the printf call work for Ada also, but I am really not into
inserting random assembly instructions in my code, so I'll probably
end up doing the wrapper for printf as the user guide suggests.


Reply to: