Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Plecra
    @Plecra
    Jake Goulding
    @shepmaster
    @lights0123 how are you avoiding the LLVM error that @aykevl and I are talking about? It makes the function pointers in the vtable incorrect.
    Jake Goulding
    @shepmaster
    @Plecra what problem (s) are you experiencing?
    Plecra
    @Plecra
    I haven't tried it yet ^^ I was following the Rust-AVR book, and it doesn't have any instructions for using the toolchain on windows
    I thought someone might've already given it a shot, and it'd be nice to hear how that went
    Ayke
    @aykevl
    @Plecra WSL is basically just Linux, so any instructions for Linux should work
    (there might be some exceptions around external devices)
    Ben Schattinger
    @lights0123
    @shepmaster I just... don't? This works just fine for me:
    #[export_name = "__vector_18"]
    pub unsafe extern "avr-interrupt" fn __vector_18() {
        let mut led: atmega328p_hal::port::portb::PB5<Output> = unsafe { core::mem::zeroed() };
        led.set_high();
    }
    Ayke
    @aykevl
    @lights0123 it's possible the compiler managed to optimize away the indirection, this can happen especially when the program is very small
    Compilers try to eliminate function pointer calls as function pointers are really hard to optimize.
    Ben Schattinger
    @lights0123
    This works too
    #[export_name = "__vector_18"]
    pub unsafe extern "avr-interrupt" fn __vector_18() {
        test();
    }
    
    #[inline(never)]
    fn test() {
        let mut led: atmega328p_hal::port::portb::PB5<Output> = unsafe { core::mem::zeroed() };
        led.set_high();
    }
    but I don't know how much it actually respects #[inline(never)]
    Ayke
    @aykevl
    The set_high can still be inlined, for example
    (I don't really know Rust but I'm assuming it works similar to C here)
    Ben Schattinger
    @lights0123
    yeah but wouldn't that function boundary of test produce the same error?
    Ayke
    @aykevl
    no, that's a direct call
    Ben Schattinger
    @lights0123
    it's a call within a call?
    Ayke
    @aykevl
    an indirect call is a function pointer, whenever you're storing a reference to a function and calling it elsewhere
    closures are also a kind of function pointer (not sure whether Rust has them tbh)
    Ben Schattinger
    @lights0123

    yeah it does have closures

    Ok, I get it now—is there a problem with the VTable for Futures? I've totally skipped over Wakers for now and am just busy-loop polling.

    Ayke
    @aykevl
    That's a bit out of my Rust knowledge, but normally a vtable is basically an array of function pointers that is usually stored as a global (for virtual functions in C++ for example). Calling a method from a vtable means doing an indirect call (as you're not directly calling the function, but loading the function address from the vtable and calling the function through that).
    Again, the compiler will try to optimize the vtable away if possible, which may definitely happen in small programs
    You could try looking at the disassembly, if you have any experience with that.
    Ben Schattinger
    @lights0123
    Yep, I just ran into the same problem. When trying to clone a Waker, which calls a function defined in a manual VTable, my Arduino just crashes and doesn't respond.
    Jake Goulding
    @shepmaster
    Yup. That’s because the relocation is invalid and you are jumping to the wrong place.
    @aykevl maybe you could ping @dylanmckay for tips on where to look to emit the right assembly?
    Jonah Dahlquist
    @jonahbron
    Hey I just saw that AVR-Rust has been upstreamed, super exciting!
    I'm having trouble building though, issues with avr-gcc.
    It seems like there avr-gcc flags being set that aren't supported by the one I have installed. Any ideas how to configure how avr-gcc gets called?
    error: linking with `avr-gcc` failed: exit code: 1
      |
      = note: "avr-gcc" "-Os" "-mmcu=atmega328p" "-Wl,--eh-frame-hdr" "-L" "/home/jonah/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/avr-atmega328p/lib" "/run/media/jonah/data/Projects/smart-plug/target/avr-atmega328p/release/deps/smart_plug-12f5bd55c8f99728.smart_plug.davrc7f1-cgu.0.rcgu.o" "-o" "/run/media/jonah/data/Projects/smart-plug/target/avr-atmega328p/release/deps/smart_plug-12f5bd55c8f99728.elf" "-Wl,--gc-sections" "-L" "/run/media/jonah/data/Projects/smart-plug/target/avr-atmega328p/release/deps" "-L" "/run/media/jonah/data/Projects/smart-plug/target/release/deps" "-L" "/home/jonah/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/avr-atmega328p/lib" "-Wl,--start-group" "-Wl,--end-group" "-Wl,-Bstatic" "/run/media/jonah/data/Projects/smart-plug/target/avr-atmega328p/release/deps/libcompiler_builtins-3056cbb15200d16d.rlib" "-Wl,-Bdynamic" "-Wl,--gc-sections"
      = note: /home/jonah/Downloads/avr8-gnu-toolchain-3.6.2.1759-linux.any.x86_64/avr8-gnu-toolchain-linux_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: unrecognized option '--eh-frame-hdr'
              /home/jonah/Downloads/avr8-gnu-toolchain-3.6.2.1759-linux.any.x86_64/avr8-gnu-toolchain-linux_x86_64/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: use the --help option for usage information
              collect2: error: ld returned 1 exit status
    David Lenfesty
    @davidlenfesty
    Same problem here, I was trying to build blinky and got the same issue. FWIW I'm on avr-gcc 10.1.0
    I guess ld binutils version 2.34
    David Lenfesty
    @davidlenfesty
    I found this fix for an issue on illumos rust-lang/rust@8f8ff15
    Jonah Dahlquist
    @jonahbron
    That's a great find David. Maybe we use that lead to figure out a way to disable it.
    @davidlenfesty What platform are you on, how did you install avr-gcc?
    David Lenfesty
    @davidlenfesty
    Manjaro
    pacman -S avr-gcc
    So I looked at the rust source tree, and traced back to the option that enables disables that flag
    Jonah Dahlquist
    @jonahbron
    aw dang okay. Good thing I didn't act on my inclination to switch to Arch to fix the problem.
    David Lenfesty
    @davidlenfesty
    and it seems to be false
    Jonah Dahlquist
    @jonahbron
    Really? You're saying it shouldn't even be on?
    David Lenfesty
    @davidlenfesty
    Not from what's master. Hold on a bit and I'll show the code path
    last link is the line that says it's false
    Jonah Dahlquist
    @jonahbron
    Yeah that sure seems like it should be false.
    Maybe it's time to file a ticket on the Rust repo.
    David Lenfesty
    @davidlenfesty
    Probably, I want to verify what commit I'm running