[fpc-devel] Wrong assembler generated?

Andrew Haines AndrewD207 at aol.com
Sat Oct 22 05:20:20 CEST 2011


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 <gtk_init at plt>
2 00000000004AD193 e8a0e5ffff  callq  0x4ab738 <gtk_window_get_type at plt>
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 <g_type_class_ref at plt>
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
	




More information about the fpc-devel mailing list