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

global_asm! macro causes non-fatal errors to be printed during compilation for some RISC-V extension instructions when targeting the GC extensions #80608

Open
repnop opened this issue Jan 2, 2021 · 9 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-external-bug Category: issue that is caused by bugs in software beyond our control F-asm `#![feature(asm)]` (not `llvm_asm`) O-riscv Target: RISC-V architecture

Comments

@repnop
Copy link
Contributor

repnop commented Jan 2, 2021

I'm currently using the asm! macro on the riscv64gc-unknown-none-elf target, and have been getting some "errors" for a while about instructions requiring extensions -- except that GC includes the extensions of the instructions I'm using (IMAFDC). So far I've seen errors for F, D, and A instructions, everything else seems to be fine that I've used so far. Despite them being reported as errors, the build still succeeds however. @nbdd0121 suggested this may be an LLVM bug.

Example:

error: instruction requires the following: 'D' (Double-Precision Floating-Point)
        fsd f0, 248(sp)
        ^
error: instruction requires the following: 'A' (Atomic Instructions)
        sc.d zero, zero, 0(sp)
        ^
@repnop repnop added the C-bug Category: This is a bug. label Jan 2, 2021
@jonas-schievink jonas-schievink added A-inline-assembly Area: Inline assembly (`asm!(…)`) F-asm `#![feature(asm)]` (not `llvm_asm`) O-riscv Target: RISC-V architecture labels Jan 2, 2021
@Amanieu
Copy link
Member

Amanieu commented Jan 2, 2021

I can't seem to reproduce this: https://rust.godbolt.org/z/5hW8jn

@repnop
Copy link
Contributor Author

repnop commented Jan 2, 2021

Ah, finally was able to reproduce it, looks like its not asm! but global_asm! (I never made the connection between the output and global_asm!, I assumed it affected both since I don't use those instructions in non-global_asm! code), so I'll correct the title. It also requires the --emit=dep-info,link argument to be passed to rustc, at which point you can see all of the errors, here's a godbolt link: https://rust.godbolt.org/z/KreW3M

@repnop repnop changed the title asm! macro causes non-fatal errors to be printed during compilation for some RISC-V extension instructions when targeting the GC extensions global_asm! macro causes non-fatal errors to be printed during compilation for some RISC-V extension instructions when targeting the GC extensions Jan 2, 2021
@usamoi
Copy link
Contributor

usamoi commented Apr 10, 2022

I saw error: instruction requires the following: 'D' (Double-Precision Floating-Point) in my global_asm on the riscv64gc-unknown-none-elf target, too, but only in release mode.

@Amanieu
Copy link
Member

Amanieu commented Apr 10, 2022

I still don't know what the cause of this problem is (it seems to be in LLVM?). However I have found a workaround: you need to add .attribute arch, "rv64gc" to the assembly code to enable the f and d features in the assembler.

@deepaksirone
Copy link

I see the following in a release build with global_asm!:

error: instruction requires the following: 'A' (Atomic Instructions)
        amoswap.d.aq t0, t0, (t1)
        ^
error: instruction requires the following: 'M' (Integer Multiplication and Division) or 'Zmmul' (Integer Multiplication)
        mul t1, a3, t2

@Amanieu Amanieu added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Apr 6, 2023
@Amanieu
Copy link
Member

Amanieu commented Apr 6, 2023

Upstream bug: llvm/llvm-project#61991

trdthg added a commit to trdthg/WebKit that referenced this issue Nov 10, 2024
https://bugs.webkit.org/show_bug.cgi?id=282900

Reviewed by NOBODY (OOPS!).

This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
will lost after it got llvm side. So we have to set arch here.

More related infomations are here:

- rust-lang/rust#80608
- llvm/llvm-project#61991
- llvm/llvm-project#97685

* Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
* Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
trdthg added a commit to trdthg/WebKit that referenced this issue Nov 10, 2024
https://bugs.webkit.org/show_bug.cgi?id=282900

Reviewed by NOBODY (OOPS!).

This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
will lost after it got llvm side. So we have to set arch here.

More related infomations are here:

- rust-lang/rust#80608
- llvm/llvm-project#61991
- llvm/llvm-project#97685

* Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
* Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
trdthg added a commit to trdthg/WebKit that referenced this issue Nov 10, 2024
https://bugs.webkit.org/show_bug.cgi?id=282900

Reviewed by NOBODY (OOPS!).

This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
will lost after it got llvm side. So we have to set arch here.

More related infomations are here:

- rust-lang/rust#80608
- llvm/llvm-project#61991
- llvm/llvm-project#97685

* Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
* Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
trdthg added a commit to trdthg/WebKit that referenced this issue Nov 11, 2024
https://bugs.webkit.org/show_bug.cgi?id=282900

Reviewed by NOBODY (OOPS!).

This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
will lost after it got llvm side. So we have to set arch here.

More related infomations are here:

- rust-lang/rust#80608
- llvm/llvm-project#61991
- llvm/llvm-project#97685

* Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
* Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
webkit-commit-queue pushed a commit to trdthg/WebKit that referenced this issue Nov 19, 2024
https://bugs.webkit.org/show_bug.cgi?id=282900

Reviewed by Yusuke Suzuki.

This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
will lost after it got llvm side. So we have to set arch here.

More related infomations are here:

- rust-lang/rust#80608
- llvm/llvm-project#61991
- llvm/llvm-project#97685

* Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
* Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:

Canonical link: https://commits.webkit.org/286815@main
@nbdd0121
Copy link
Contributor

This is now also affecting naked functions after the codegen switch. cc @folkertdev (example: https://github.com/nbdd0121/unwinding/actions/runs/12341696455/job/34440632980)

@folkertdev
Copy link
Contributor

Well, that's unfortunate. The LLVM changes don't have any action since August, are there any strings we can pull to give that some extra attention?

aperezdc pushed a commit to WebKit/WebKit that referenced this issue Dec 15, 2024
…gi?id=282900

    [RISCV] Fix instruction requires the following: 'D'/'F'/'M'
    https://bugs.webkit.org/show_bug.cgi?id=282900

    Reviewed by Yusuke Suzuki.

    This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
    will lost after it got llvm side. So we have to set arch here.

    More related infomations are here:

    - rust-lang/rust#80608
    - llvm/llvm-project#61991
    - llvm/llvm-project#97685

    * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
    * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:

    Canonical link: https://commits.webkit.org/286815@main

Canonical link: https://commits.webkit.org/282416.360@webkitglib/2.46
@xobs
Copy link
Contributor

xobs commented Dec 17, 2024

Here's a minimal reproduction:

#![feature(naked_functions)]

#[naked]
pub extern "C-unwind" fn example() {
    #[cfg(target_feature = "d")]
    unsafe {
        core::arch::naked_asm!("fsd fs0, 0x140(sp)");
    }
}

Compile with cargo +nightly build --target riscv64gc-unknown-linux-gnu --release (the --release is important)

@jieyouxu jieyouxu added C-external-bug Category: issue that is caused by bugs in software beyond our control and removed C-bug Category: This is a bug. labels Dec 17, 2024
mnutt pushed a commit to movableink/webkit that referenced this issue Dec 23, 2024
https://bugs.webkit.org/show_bug.cgi?id=282900

Reviewed by Yusuke Suzuki.

This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang
will lost after it got llvm side. So we have to set arch here.

More related infomations are here:

- rust-lang/rust#80608
- llvm/llvm-project#61991
- llvm/llvm-project#97685

* Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp:
* Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:

Canonical link: https://commits.webkit.org/286815@main
nbdd0121 pushed a commit to xobs/unwinding that referenced this issue Dec 26, 2024
Since 2024-12-12 the Rust compiler now requires all naked ASM functions
to include `.cfi_startproc` and `.cfi_endproc`. Without these
directives, the build will fail.

Add these directives to all supported platforms.

This also works around rust-lang/rust#80608 by forcing LLVM to consider that
code with the "d" extension has an FPU.

Signed-off-by: Sean Cross <sean@xobs.io>
xobs added a commit to betrusted-io/rust that referenced this issue Dec 26, 2024
With rust-lang#80608 the `unwinding` crate no longer builds. The upstream crate
has been updated to build by manually adding directives to the naked_asm
stream.

Bump the dependency in Rust to get this newer version. This fixes the
build for Xous, and closes rust-lang#134403.

Signed-off-by: Sean Cross <sean@xobs.io>
jhpratt added a commit to jhpratt/rust that referenced this issue Dec 27, 2024
…5.0, r=Mark-Simulacrum

unwinding: bump version to fix naked_asm on Xous

With rust-lang#80608 the `unwinding` crate no longer builds. The upstream crate has been updated to build by manually adding directives to the naked_asm stream.

Bump the dependency in Rust to get this newer version. This fixes the build for Xous, and closes rust-lang#134403.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 27, 2024
Rollup merge of rust-lang#134789 - betrusted-io:bump-unwinding-to-0.25.0, r=Mark-Simulacrum

unwinding: bump version to fix naked_asm on Xous

With rust-lang#80608 the `unwinding` crate no longer builds. The upstream crate has been updated to build by manually adding directives to the naked_asm stream.

Bump the dependency in Rust to get this newer version. This fixes the build for Xous, and closes rust-lang#134403.
poliorcetics pushed a commit to poliorcetics/rust that referenced this issue Dec 28, 2024
With rust-lang#80608 the `unwinding` crate no longer builds. The upstream crate
has been updated to build by manually adding directives to the naked_asm
stream.

Bump the dependency in Rust to get this newer version. This fixes the
build for Xous, and closes rust-lang#134403.

Signed-off-by: Sean Cross <sean@xobs.io>
poliorcetics pushed a commit to poliorcetics/rust that referenced this issue Dec 28, 2024
…5.0, r=Mark-Simulacrum

unwinding: bump version to fix naked_asm on Xous

With rust-lang#80608 the `unwinding` crate no longer builds. The upstream crate has been updated to build by manually adding directives to the naked_asm stream.

Bump the dependency in Rust to get this newer version. This fixes the build for Xous, and closes rust-lang#134403.
sunfishcode added a commit to sunfishcode/c-ward that referenced this issue Jan 2, 2025
sunfishcode added a commit to sunfishcode/c-ward that referenced this issue Jan 2, 2025
* Update to the latest nightly Rust.

Update to origin 0.24 and the latest nightly Rust.

* Fix setjmp on riscv64 with soft-float.

* Add a workaround for rust-lang/rust#80608 for riscv64.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-external-bug Category: issue that is caused by bugs in software beyond our control F-asm `#![feature(asm)]` (not `llvm_asm`) O-riscv Target: RISC-V architecture
Projects
None yet
Development

No branches or pull requests

9 participants