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

create_object_file doesn't set correct ELF header flags for AVR targets #106576

Closed
agausmann opened this issue Jan 7, 2023 · 1 comment · Fixed by #106619
Closed

create_object_file doesn't set correct ELF header flags for AVR targets #106576

agausmann opened this issue Jan 7, 2023 · 1 comment · Fixed by #106619
Assignees
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)

Comments

@agausmann
Copy link
Contributor

agausmann commented Jan 7, 2023

(Downstream issue: Rahix/avr-hal#388)

A bug was introduced in #103240 (5642a75) when compiling for AVR targets, causing errors in linking which look like:

error: linking with `avr-gcc` failed: exit status: 1
  |
  = note: "avr-gcc" "-mmcu=attiny404" "/tmp/rustcmivxhx/symbols.o" "/home/goose/dev/hwlife/life-cell/firmware/target/avr-attiny404/debug/deps/life_cell-6668cd99ba2eaeff.avrxmega_hal-cc404b4688795bef.avrxmega_hal.d6125529-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/home/goose/dev/hwlife/life-cell/firmware/target/avr-attiny404/debug/deps" "-L" "/home/goose/dev/hwlife/life-cell/firmware/target/debug/deps" "-L" "/home/goose/build/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/avr-attiny404/lib" "-Wl,-Bstatic" "/home/goose/dev/hwlife/life-cell/firmware/target/avr-attiny404/debug/deps/libcompiler_builtins-dfbc3c77452aecc4.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-znoexecstack" "-L" "/home/goose/build/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/avr-attiny404/lib" "-o" "/home/goose/dev/hwlife/life-cell/firmware/target/avr-attiny404/debug/deps/life_cell-6668cd99ba2eaeff.elf" "-Wl,--gc-sections" "-no-pie"
  = note: /usr/lib/arduino/hardware/tools/avr/bin/../lib/gcc/avr/7.3.0/../../../../avr/bin/ld: avr architecture of input file `/tmp/rustcmivxhx/symbols.o' is incompatible with avr:103 output
          collect2: error: ld returned 1 exit status

The PR in question added support for AVR architecture in create_object_file, but it doesn't actually make the necessary changes to set the e_flags field, which is used to specify the AVR ISA revision. As a knock-on-effect, this causes add_linked_symbol_object to avoid an early return and succeed in creating a symbols.o file, but this object file doesn't have e_flags set correctly.

I believe that is the cause of this error; the AVR linker checks the e_flags field to make sure the ISA revision matches what is expected, and rustc is not setting that field correctly.

@agausmann agausmann added the C-bug Category: This is a bug. label Jan 7, 2023
@agausmann
Copy link
Contributor Author

@rustbot claim

@workingjubilee workingjubilee added the O-AVR Target: AVR processors (ATtiny, ATmega, etc.) label Jan 27, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 30, 2023
Fix unset e_flags in ELF files generated for AVR targets

Closes rust-lang#106576

~~Sort-of blocked by gimli-rs/object#500~~ (merged)

I'm not sure whether the list of AVR CPU names is okay here. Maybe it could be moved out-of-line to improve the readability of the function.
@bors bors closed this as completed in af9df2f Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants