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

specify #[panic_handler] for default_panic_handler #84

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

Conversation

publicqi
Copy link
Contributor

@publicqi publicqi commented Mar 3, 2025

#![no_std]
use pinocchio::{
    account_info::AccountInfo, default_allocator, default_panic_handler, program_entrypoint,
    pubkey::Pubkey, ProgramResult,
};

program_entrypoint!(process_instruction);
default_allocator!();
default_panic_handler!();

fn process_instruction(_: &Pubkey, _: &[AccountInfo], _: &[u8]) -> ProgramResult {
    Ok(())
}
[package]
name = "pinocchio-test"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]

[dependencies]
pinocchio = { version = "0.7.1" }

[profile.release]
# strip = "symbols"
lto = true
opt-level = 3

This code doesn't compile now. Error message is

error: `#[panic_handler]` function required, but not found

@febo
Copy link
Collaborator

febo commented Mar 9, 2025

Did you try compiling without being #![no_std]? I think when you link the std, this change might conflict.

@febo
Copy link
Collaborator

febo commented Mar 10, 2025

Perhaps instead of modifying the existing macro, we need to add one specific for no_std:

#[macro_export]
macro_rules! nostd_panic_handler {
    () => {
        /// A panic handler for `no_std`.
        #[cfg(not(test))]
        #[no_mangle]
        #[panic_handler]
        fn custom_panic(info: &core::panic::PanicInfo<'_>) -> ! {
            if let Some(location) = info.location() {
                $crate::log::sol_log(location.file());
            }
            // Panic reporting.
            $crate::log::sol_log("** PANICKED **");
            // Never returns.
            loop {}
        }
    };
}

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.

2 participants