Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error: ret #7

Closed
asdine opened this issue Jul 18, 2023 · 2 comments
Closed

Compilation error: ret #7

asdine opened this issue Jul 18, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@asdine
Copy link
Collaborator

asdine commented Jul 18, 2023

Once #2 is fixed, the same problematic code generates the following error:

void foo(float *a, float *res)
{
    *res = bar(a);
}

int bar(float *a)
{
    return *a + 10;
}

Error:

30: unexpected objectdump line: 4c:	c3                                              	ret

Objdump returns the following (the problem is the very last line):

Disassembly of section .text:

0000000000000000 <foo>:
   0:	55                                              	push   %rbp
   1:	48 89 e5                                        	mov    %rsp,%rbp
   4:	48 83 e4 f8                                     	and    $0xfffffffffffffff8,%rsp
   8:	c5 fa 10 07                                     	vmovss (%rdi),%xmm0
   c:	c5 fa 58 05 00 00 00 00                         	vaddss 0x0(%rip),%xmm0,%xmm0        # 14 <foo+0x14>
  14:	c5 fa 5b c0                                     	vcvttps2dq %xmm0,%xmm0
  18:	c5 f8 5b c0                                     	vcvtdq2ps %xmm0,%xmm0
  1c:	c5 fa 11 06                                     	vmovss %xmm0,(%rsi)
  20:	48 89 ec                                        	mov    %rbp,%rsp
  23:	5d                                              	pop    %rbp
  24:	c3                                              	ret
  25:	66 2e 0f 1f 84 00 00 00 00 00                   	cs nopw 0x0(%rax,%rax,1)
  2f:	90                                              	nop

0000000000000030 <bar>:
  30:	55                                              	push   %rbp
  31:	48 89 e5                                        	mov    %rsp,%rbp
  34:	48 83 e4 f8                                     	and    $0xfffffffffffffff8,%rsp
  38:	c5 fa 10 07                                     	vmovss (%rdi),%xmm0
  3c:	c5 fa 58 05 00 00 00 00                         	vaddss 0x0(%rip),%xmm0,%xmm0        # 44 <bar+0x14>
  44:	c5 fa 2c c0                                     	vcvttss2si %xmm0,%eax
  48:	48 89 ec                                        	mov    %rbp,%rsp
  4b:	5d                                              	pop    %rbp
  4c:	c3                                              	ret
@asdine asdine added the bug Something isn't working label Jul 18, 2023
@zhenghaoz
Copy link
Contributor

zhenghaoz commented Jul 20, 2023

This is caused by unexpected data section:

	.text
	.file	"foo.c"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2                               # -- Begin function foo
+ .LCPI0_0:
+	.long	0x41200000                      # float 10
	.text
	.globl	foo
	.p2align	4, 0x90
	.type	foo,@function
foo:                                    # @foo
# %bb.0:
	pushq	%rbp
	movq	%rsp, %rbp
	andq	$-8, %rsp
	vmovss	(%rdi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	vaddss	.LCPI0_0(%rip), %xmm0, %xmm0
	vcvttps2dq	%xmm0, %xmm0
	vcvtdq2ps	%xmm0, %xmm0
	vmovss	%xmm0, (%rsi)
	movq	%rbp, %rsp
	popq	%rbp
	retq
.Lfunc_end0:
	.size	foo, .Lfunc_end0-foo
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2                               # -- Begin function bar
.LCPI1_0:
	.long	0x41200000                      # float 10
	.text
	.globl	bar
	.p2align	4, 0x90
	.type	bar,@function
bar:                                    # @bar
# %bb.0:
	pushq	%rbp
	movq	%rsp, %rbp
	andq	$-8, %rsp
	vmovss	(%rdi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	vaddss	.LCPI1_0(%rip), %xmm0, %xmm0
	vcvttss2si	%xmm0, %eax
	movq	%rbp, %rsp
	popq	%rbp
	retq
.Lfunc_end1:
	.size	bar, .Lfunc_end1-bar
                                        # -- End function
	.ident	"Ubuntu clang version 14.0.0-1ubuntu1"
	.section	".note.GNU-stack","",@progbits
	.addrsig

GoAT doesn't support the data section yet. But it is possible to support it following https://go.dev/doc/asm

@asdine
Copy link
Collaborator Author

asdine commented Apr 23, 2024

Fixed by #2

@asdine asdine closed this as completed Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants