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

Calling function with bad signature, Rust 0.13.0-nightly #17974

Closed
alexispurslane opened this issue Oct 12, 2014 · 4 comments
Closed

Calling function with bad signature, Rust 0.13.0-nightly #17974

alexispurslane opened this issue Oct 12, 2014 · 4 comments

Comments

@alexispurslane
Copy link
Contributor

So, i am compileing a version of rustboot that uses some changes that someone else had made so that it could display text on the screen, but when I compile I get this:

rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/llvm/lib/IR/Instructions.cpp:276: void llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&): Assertion `(Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"' failed.
make: *** [main.o] Aborted (core dumped)

i have checked all the other issues about this, but none of them have helped. My code looks like this:

#![no_std]
#![allow(ctypes)]
#![feature(lang_items)]

#[allow(dead_code)]
enum Color {
    Black      = 0,
    Blue       = 1,
    Green      = 2,
    Cyan       = 3,
    Red        = 4,
    Pink       = 5,
    Brown      = 6,
    LightGray  = 7,
    DarkGray   = 8,
    LightBlue  = 9,
    LightGreen = 10,
    LightCyan  = 11,
    LightRed   = 12,
    LightPink  = 13,
    Yellow     = 14,
    White      = 15,
}

enum DisplayInfo {
    VGAWIDTH = 80,
    VGAHEIGHT = 25,
    VGAADDRESS = 0xb8000,
}

#[lang="sized"]
fn clear_screen(background: Color) {
    let limit = 80u * 25u;
    let mut i = 0u;
    while i < limit {
        unsafe {
            *((VGAADDRESS as u16 + i as u16 * 2) as *mut u16) = (background as u16) << 12;
        }
        i += 1;
    }
}

fn make_vgaentry(c: u8, fg: Color, bg: Color) -> u16 {
    let color = fg as u16 | (bg as u16 << 4);
    c as u16 | (color << 8)
}
pub fn putc(x: u16, y: u16, c: u8) {
    let idx: uint = (y * VGAWIDTH as u16 * 2 + x * 2) as uint;
    unsafe {
        *((VGAADDRESS as u16 + idx as u16) as *mut u16) = make_vgaentry(c, Green, Black)
    }
}

#[lang="fail_bounds_check"]
pub fn write_x_y(s: &[u8], x: u16, y: u16, len: uint) {
    let mut i = 0u;
    while i < len {
        putc(x + i as u16, y, s[i]);
        i += 1;
    }
}


#[no_mangle]
#[no_split_stack]
pub fn main() {
    clear_screen(Black);
    let prompt = b"==> ";
    write_x_y(prompt, 2, 3, 4);
}

I am fairly new to rust, and pretty much copy-and-pasteing stuff in. You will notice I cannot program very rust-idiomaticly becouse I have to do without the standard library, and cannot compile libcore for i386-intel-linux, which is what the loader assembly code is written for.

@bkoropoff
Copy link
Contributor

I'm guessing it's due to #[lang="fail_bounds_check"] being attached to write_x_y. It needs to be attached to a separate function with the correct prototype:

#[lang="fail_bounds_check"]
fn fail_bounds_check(file_line: &(&'static str, uint), index: uint, len: uint) -> ! {
    // This should probably do something more intelligent
    loop {}
}

The sized lang item also needs to be attached to a trait:

#[lang="sized"]
trait Sized {}

This bug should be left open, though, as the compiler should give an error message instead of asserting in llvm.

@ghost
Copy link

ghost commented Oct 12, 2014

The issue tracking type checking of lang items is #9307.

@alexispurslane
Copy link
Contributor Author

Cool, thanks. I hope I'm not making myself a nuisance, but when I compile my code with your changes, I get:

main.o: In function `write_x_y::h7be34e5c69623465Tda':
main.0.rs:(.text._ZN9write_x_y20h7be34e5c69623465TdaE+0x14): undefined reference to `__morestack'
make: *** [main.bin] Error 1

I looked through my code, and I don't actually see a reference anywhere to __morestack. At least it is a different error! ]-:

@thestinger
Copy link
Contributor

Closing as a duplicate of #9307.

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
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

No branches or pull requests

3 participants