Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-10

Wrong assembler generated?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Haines

Hi,

I was experimenting with gtk3 a bit and a simple program was failing to execute properly.

It's very simple:

gtk_init(@argc, @argv);
WType := gtk_window_get_type();
WinClass := g_type_class_ref( WType );

assembler is like so:
WType is -0x20(%rbp)

1 00000000004AD18E e875eafeff callq 0x49bc08
2 00000000004AD193 e8a0e5ffff callq 0x4ab738
3 00000000004AD198 488945e0 mov %rax,-0x20(%rbp) 4 00000000004AD19C 488b75e0 mov -0x20(%rbp),%rsi 5 00000000004AD1A0 488d7dd8 lea -0x28(%rbp),%rdi 6 00000000004AD1A4 e85f4bffff callq 0x4a1d08
7 00000000004AD1A9 488b45d8 mov -0x28(%rbp),%rax 8 00000000004AD1AD 488945f0 mov %rax,-0x10(%rbp) 9 00000000004AD1B1 488b45f0 mov -0x10(%rbp),%rax

shouldn't line 4 be "mov -0x20(%rbp),%rdi"
Line 5 shouldn't be there?
Line 7 overwrites the returned value before we've copied it anywhere?

Here's part of the assembly fpc generated:

# [39] begin
subq $280,%rsp
.Lc7:
# Var Win located in register rax
# Var WinClass located in register rax
# Var P2 located in register rsi
# Var WType located in register rsi
movq %rbx,264(%rsp)
movq %r12,272(%rsp)
.Ll12:
# [40] gtk_init(@argc, @argv);
movq $operatingsystem_parameter_argv,%rsi
movq $operatingsystem_parameter_argc,%rdi
call gtk_init
.Ll13:
# [41] WType := gtk_window_get_type();
call gtk_window_get_type
movq %rax,%rsi
.Ll14:
# [42] WinClass:=PGtkWindowClass(g_type_class_ref(WType)); movq %rsp,%rdi
call g_type_class_ref
movq (%rsp),%rax

I've got the same problem with fpc 2.5.1 and 2.7.1. I'll try 2.4.4 as soon as it's downloaded.

Same result with 2.4.4

Regards,

Andrew Haines

Reply by email

Jonas Maebe
to Andrew Haines
Andrew Haines wrote
I was experimenting with gtk3 a bit and a simple program was failing to execute properly. It's very simple:

It's very difficult. The reason is that you are not showing a complete compilable program including all the declarations of the external functions you are calling and the types you are using. And moreover the two assembler blocks you are showing have been compiled with different optimization levels.

Jonas

Reply by email

Andrew Haines
to Jonas Maebe
Jonas Maebe wrote 11 lines
On 22 Oct 2011, at 05:20, Andrew Haines wrote: > I was experimenting with gtk3 a bit and a simple program was failing to > execute properly. > > It's very simple: It's very difficult. The reason is that you are not showing a complete compilable program including all the declarations of the external functions you are calling and the types you are using. And moreover the two assembler blocks you are showing have been compiled with different optimization levels.

Sorry, I had tried with several different versions and optimization levels.

I found the problem. g_type_class_ref was declared to return TGTypeClass instead of PGTypeClass.

My fault.

Regards,

Andrew Haines

Reply by email