Skip to content

Call ABI broken for >=7 arguments with commit ae26b7e4e! (LLVM-73) #26

Closed
@arjanmels

Description

@arjanmels

With the latest commit ae26b7e, the call abi got broken for functions with 7 or more arguments.

Rust example:

#[no_mangle]
#[inline(never)]
fn CALLING_CONVENTION(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32, g: u32) -> u32 {
    a + b + c + d + e + f + g
}

#[no_mangle]
#[inline(never)]
fn CALL_CALLING_CONVENTION() -> u32 {
    CALLING_CONVENTION(1, 2, 3, 4, 5, 6, 7)
}

fn main () -> ! {
	let res = CALL_CALLING_CONVENTION();
	assert!(res==28);
	...
}

Generated asm in release mode (debug mode has same problem, but generates a lot of check code):

As you can see the 7th argument is not retrieved from the stack, but a direct "add.n a2,a8,a9" is done (a9 is the address in memory).

(Also I wonder what the mov.n a8,a1 does at the start, it seem superfluous.)

CALLING_CONVENTION:
	entry	a1, 32
	mov.n	a8, a1
	add.n	a8, a3, a2
	add.n	a8, a8, a4
	add.n	a8, a8, a5
	add.n	a8, a8, a6
	add.n	a8, a8, a7
	addi	a9, a1, 32
	add.n	a2, a8, a9
	retw.n

With the previous commit (a5a002f) the resulting code was:

Notice the l32i.n instead of addi

CALLING_CONVENTION:
	entry	a1, 32
	mov.n	a8, a1
	add.n	a8, a3, a2
	add.n	a8, a8, a4
	add.n	a8, a8, a5
	add.n	a8, a8, a6
	add.n	a8, a8, a7
	l32i.n	a9, a1, 32
	add.n	a2, a8, a9
	retw.n

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions