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

#![no_builtins] attribute isn't honored #570

Open
kellda opened this issue Oct 27, 2024 · 5 comments
Open

#![no_builtins] attribute isn't honored #570

kellda opened this issue Oct 27, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@kellda
Copy link

kellda commented Oct 27, 2024

#![no_std]
#![no_builtins]

#[no_mangle]
#[inline(never)]
pub unsafe fn set_bytes_bytes(mut s: *mut u8, c: u8, n: usize) {
    let end = s.add(n);
    while s < end {
        *s = c;
        s = s.add(1);
    }
}

Even with the #![no_builtins] attribute, the above loop is replaced by a call to memset. This is problematic when compiling compiler_builtins, because memset end up recursively calling itself.

000003bc <set_bytes_bytes.constprop.0>:
     3bc:       9c 21 ff f8     l.addi r1,r1,-8
     3c0:       18 a0 00 08     l.movhi r5,0x8
     3c4:       18 80 00 00     l.movhi r4,0x0
     3c8:       d4 01 80 00     l.sw 0(r1),r16
     3cc:       d4 01 48 04     l.sw 4(r1),r9
     3d0:       04 00 00 02     l.jal 3d8 <set_bytes_bytes.constprop.0+0x1c>
     3d4:       1a 00 00 00     l.movhi r16,0x0
     3d8:       aa 10 52 08     l.ori r16,r16,0x5208
     3dc:       e2 10 48 00     l.add r16,r16,r9
     3e0:       04 00 0c 4a     l.jal 3508 <memset>
     3e4:       84 70 00 0c     l.lwz r3,12(r16)
     3e8:       85 21 00 04     l.lwz r9,4(r1)
     3ec:       86 01 00 00     l.lwz r16,0(r1)
     3f0:       44 00 48 00     l.jr r9
     3f4:       9c 21 00 08     l.addi r1,r1,8
@antoyo
Copy link
Contributor

antoyo commented Oct 29, 2024

I guess this would be a matter of adding the flag -fno-builtin.

Assuming this doesn't break something else.

@antoyo antoyo added enhancement New feature or request good first issue Good for newcomers labels Jan 11, 2025
@Anon258
Copy link
Contributor

Anon258 commented Jan 16, 2025

@kellda What is the tool you have used here to inspect the asm? Is it cargo-asm?

@kellda
Copy link
Author

kellda commented Jan 16, 2025

No, it was plain old objdump -d or objdump -S

@Anon258
Copy link
Contributor

Anon258 commented Jan 16, 2025

I would like to work on this issue to learn more about the Rust compiler process. However I am not that well acquainted with rust compiler process. I have just read through the basic rust dev guide, can I still work on this issue?

@antoyo
Copy link
Contributor

antoyo commented Jan 16, 2025

Yes, I assigned this issue to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants