-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
VTables which end up in the data segment are miscompiled on AVR. #79889
Comments
For the sake of confirming expected behavior of vtables, I tested the following snippet in avr-gcc, which generates a manual vtable in the data segment: void foo() {}
struct Pointers {
void (*fun)();
};
static struct Pointers pointers = {
foo
};
void call(struct Pointers* pointers) {
pointers->fun();
}
void main() {
call(&pointers);
} This emits pretty much what I would have expected, with the vtable containing 0x004B for a function which is at byte-address 0x0096:
I have no idea if the version of clang on my |
I was able to narrow this down a bit further. Building my example rust code as a static lib, I was able to inspect the relocations in the vtable.
For my C code built by avr-gcc:
It looks like the wrong relocation type is being selected for the vtable entries. |
Followup 3: This is supposedly fixed by https://reviews.llvm.org/D87631, which appears to have stalled. I can't find an actual issue on bugs.llvm.org that's tracking this, though. |
Committed D87631 upstream in llvm/llvm-project@2ccb941 |
llvm/llvm-project@2ccb941 seems to fix it, although it's not worth cherry-picking it until https://reviews.llvm.org/D95664 lands, as currently we hit rust-lang/compiler-builtins#400 on the master build for the reproduction example on this issue. |
has the llvm fix trickled into our LLVM fork yet? |
Yeah, it's part of LLVM 13. The commit: rust-lang/llvm-project@2ccb941 |
The following code snippet should light the pin 13 LED when compiled for the atmega328 and run on an arduino. It does not. This is possibly related to #74743, and potentially also avr-rust#47. I initially found this while trying to implement a
RawWakerVTable
, so it is not restricted to compiler-generated vtables - any function pointers which are stored in the data segment are affected.Attempting to simplify further (such as using a single function pointer) tends to end up with pointers which are passed entirely in code and never loaded from the data segment. These appear to be compiled correctly.
Built + Flashed with:
Stepping through the execution in simavr/gdb makes the failure obvious - the vtable contains the byte-address of the implementation function, but the
icall
instruction (and indeed the instruction pointer of the AVR in general) uses word-addresses.As can be seen from the GDB output, after loading the VTable entry the Z register (the combination of r30 and r31) contains "0x00A8", and execution jumps to "0x0150". The vtable should instead include "0x0054", which when treated as a word-address will jump to the expected "0x00A8".
The text was updated successfully, but these errors were encountered: