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

Very weird error when compiling a very basic program: __addsf3 multiple defenitions #541

Open
itamarsch opened this issue Apr 30, 2024 · 8 comments
Labels
compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM

Comments

@itamarsch
Copy link

itamarsch commented Apr 30, 2024

image

#![no_std]
#![no_main]
use arduino_hal::clock::MHz16;
use arduino_hal::hal::delay::Delay;
use arduino_hal::{delay_ms, i2c};
use arduino_hal::{I2c, Peripherals};
use lcd_lcm1602_i2c::Lcd;
use numtoa::NumToA;
use panic_serial;
const PHI: f64 = 1.61803398;

type LCD<'a> = Lcd<'a, I2c, Delay<MHz16>>;
const LCD_ADDRESS: u8 = 0x3f;
//
panic_serial::impl_panic_handler!(
  arduino_hal::usart::Usart<
    arduino_hal::pac::USART0,
    arduino_hal::port::Pin<arduino_hal::port::mode::Input, arduino_hal::hal::port::PD0>,
    arduino_hal::port::Pin<arduino_hal::port::mode::Output, arduino_hal::hal::port::PD1>
  >
);

fn lcd_init<'a>(i2c: &'a mut I2c, delay: &'a mut Delay<MHz16>) -> Result<LCD<'a>, i2c::Error> {
    let mut lcd = lcd_lcm1602_i2c::Lcd::new(i2c, delay)
        .address(LCD_ADDRESS)
        .rows(2) // two rows
        .init()?;

    lcd.backlight(lcd_lcm1602_i2c::Backlight::On)?;
    lcd.clear()?;
    lcd.set_cursor(0, 0)?;
    Ok(lcd)
}

#[arduino_hal::entry]
fn main() -> ! {
    let dp = Peripherals::take().unwrap();
    let pins = arduino_hal::pins!(dp);
    let serial = arduino_hal::default_serial!(dp, pins, 57600);
    let serial = share_serial_port_with_panic(serial);

    let mut i2c = arduino_hal::I2c::new(
        dp.TWI,
        pins.a4.into_pull_up_input(),
        pins.a5.into_pull_up_input(),
        50000,
    );

    let mut delay = arduino_hal::Delay::new();

    let mut lcd = lcd_init(&mut i2c, &mut delay).unwrap();

    let mut i: f64 = 1.0;
    let mut buf = [0u8; 100];

    loop {
        i = libm::round(i * PHI);
        let u32v = i as u32;
        delay_ms(10);
        lcd.clear().unwrap();
        lcd.set_cursor(0, 0).unwrap();
        lcd.write_str(u32v.numtoa_str(10, &mut buf)).unwrap();
    }
}
@itamarsch itamarsch changed the title Very weird error when compiling a very basic program: Very weird error when compiling a very basic program: __addsf3 multiple occorances Apr 30, 2024
@itamarsch itamarsch changed the title Very weird error when compiling a very basic program: __addsf3 multiple occorances Very weird error when compiling a very basic program: __addsf3 multiple defenitions Apr 30, 2024
@stappersg
Copy link
Contributor

I think:

  • There should a git repository with the above main.rs PLUS Cargo.toml and such files for reproducablity
  • This should be in a discussion

@Rahix
Copy link
Owner

Rahix commented May 4, 2024

First of all, you really should be avoiding the use of f64 on AVR microcontrollers. This will eat up tons and tons of memory because all floating point operations need to be implemented in software. If you really need floats, f32 is at least not quite as bloaty...

That said, the error still shouldn't happen. It is most likely a compiler issue of some sorts, though. Ping @Patryk27 maybe you know something?

@Rahix Rahix added the compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM label May 4, 2024
@Patryk27
Copy link
Contributor

Patryk27 commented May 4, 2024

It looks like I've accidentally forgotten to #[avr_skip] this intrinsic way back in 2023 👀

(tl;dr this function gets provided both by GCC's standard library and Rust's compiler-builtins, which creates a linking conflict)

I've created rust-lang/compiler-builtins#601 to fix this; after it gets merged, I'll bump compiler-builtins within rustc and ping back, as always 🙂

@itamarsch
Copy link
Author

It looks like I've accidentally forgotten to #[avr_skip] this intrinsic way back in 2023 👀

(tl;dr this function gets provided both by GCC's standard library and Rust's compiler-builtins, which creates a linking conflict)

I've created rust-lang/compiler-builtins#601 to fix this; after it gets merged, I'll bump compiler-builtins within rustc and ping back, as always 🙂

In rustc where is the version of compiler-builtins defined? I'm not really familiar with the rustc codebase

@Patryk27
Copy link
Contributor

Patryk27 commented May 7, 2024

Right here :-)

@itamarsch
Copy link
Author

itamarsch commented May 11, 2024

It looks like I've accidentally forgotten to #[avr_skip] this intrinsic way back in 2023 👀

(tl;dr this function gets provided both by GCC's standard library and Rust's compiler-builtins, which creates a linking conflict)

I've created rust-lang/compiler-builtins#601 to fix this; after it gets merged, I'll bump compiler-builtins within rustc and ping back, as always 🙂

@Patryk27
Have you bumped up compiler-builtins?

@Patryk27
Copy link
Contributor

I'm on it, but there are some (AVR-unrelated) crashes that I need to investigate.

@Patryk27
Copy link
Contributor

Status: together with my AVR fix, bumping compiler-builtins brought some extra (non-AVR-related) f16 & f128 changes which need special handling in the compiler, so it's not as easy of a merge as usual - the current pull request is:

rust-lang/rust#125016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-bug Not a bug in avr-hal, but a bug in the rust compiler/LLVM
Projects
None yet
Development

No branches or pull requests

4 participants