Skip to content

Panic related strings are still in binary with custom panic_fmt #47526

Open
@pepyakin

Description

@pepyakin

It seems that custom panic_fmt that doesn't touches Arguments doesnt not help to strip all panic-related strings from final binary while compiling to wasm (either emscripten or wasm32-unknown-unknown)

#![feature(lang_items)]
#![no_std]
#![no_main]

extern "C" {
    fn halt();
}

#[no_mangle]
#[lang = "panic_fmt"]
pub extern "C" fn panic_fmt(
    _args: ::core::fmt::Arguments,
    _file: &'static str,
    _line: u32,
    _col: u32,
) -> ! {
    loop { 
        unsafe { halt() }
    }
}

#[lang = "eh_personality"] extern fn eh_personality() {}

#[no_mangle]
pub fn call(descriptor: u8) -> u8 {
    assert!(descriptor > 0);
    descriptor
}

Invocation:
rustc --target=wasm32-unknown-emscripten --emit llvm-ir -C lto -C opt-level=3 src/main.rs

$ rustc --version
rustc 1.24.0-nightly (1956d5535 2017-12-03)

this produces the following LLVM IR.

The problem is that panic_fmt is not using it's _args, so it is a dead arg. However, despite this, strings for panic messages are still end up in the LLVM IR}.

It seems that running opt -deadargelim -globaldce helps to strip this strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-heavyIssue: Problems and improvements with respect to binary size of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-embeddedWorking group: Embedded systems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions