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

Add -fno-builtin compile flag #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niwis
Copy link

@niwis niwis commented Oct 5, 2020

Using the latest version of riscv-gcc, the benchmarks compile incorrectly: memset() is compiled with a recursive call, just as described in riscvarchive/riscv-gcc#197. This leads to an infinite recursion and ultimately to a crash due to a stack overflow. Here is the corresponding part of dhrystone.riscv.dump compiled with the latest versions of riscv-tests and riscv-gcc:

0000000080002774 <memset>:
    80002774:	1141                	addi	sp,sp,-16
    80002776:	00c567b3          	or	a5,a0,a2
    8000277a:	e022                	sd	s0,0(sp)
    8000277c:	e406                	sd	ra,8(sp)
    8000277e:	8b9d                	andi	a5,a5,7
    80002780:	842a                	mv	s0,a0
    80002782:	00c506b3          	add	a3,a0,a2
    80002786:	cf81                	beqz	a5,8000279e <memset+0x2a>
    80002788:	00d57663          	bgeu	a0,a3,80002794 <memset+0x20>
    8000278c:	0ff5f593          	andi	a1,a1,255
    80002790:	fe5ff0ef          	jal	ra,80002774 <memset>  // recursion
    80002794:	60a2                	ld	ra,8(sp)
    80002796:	8522                	mv	a0,s0
    80002798:	6402                	ld	s0,0(sp)
    8000279a:	0141                	addi	sp,sp,16
    8000279c:	8082                	ret
    8000279e:	0ff5f593          	andi	a1,a1,255
    800027a2:	00859713          	slli	a4,a1,0x8
    800027a6:	8f4d                	or	a4,a4,a1
    800027a8:	01071593          	slli	a1,a4,0x10
    800027ac:	8f4d                	or	a4,a4,a1
    800027ae:	02071793          	slli	a5,a4,0x20
    800027b2:	8f5d                	or	a4,a4,a5
    800027b4:	fed570e3          	bgeu	a0,a3,80002794 <memset+0x20>
    800027b8:	87aa                	mv	a5,a0
    800027ba:	07a1                	addi	a5,a5,8
    800027bc:	fee7bc23          	sd	a4,-8(a5)
    800027c0:	fed7ede3          	bltu	a5,a3,800027ba <memset+0x46>
    800027c4:	60a2                	ld	ra,8(sp)
    800027c6:	8522                	mv	a0,s0
    800027c8:	6402                	ld	s0,0(sp)
    800027ca:	0141                	addi	sp,sp,16
    800027cc:	8082                	ret

As suggested in riscvarchive/riscv-gcc#197, compiling with -fno-builtin resolves this issue. However, I could not check how this impacts performance across platforms.

Signed-off-by: Nils Wistoff <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant