-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: "unable to evaluate constant expression" when depending on symbol address #6789
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
Comments
I wasn't aware that Zig allows pointer math? Don't you have to use |
Pointer math is allowed on unknown-length pointers ( |
Cool didn't know that. I guess that and intToPtr/ptrToInt are not currently allowed in a global expression. The only workaround I got to work was making the stack 257 values long: var stack: [257]u32 = undefined;
export const interrupt_table = [_][*]u32{
@ptrCast([*]u32, &stack[256]),
}; |
Here's how I worked around it. |
@vegecode yeah, using linker script magic is a option here. for now, i just keep that part in C, doesn't really hurt. Can i somehow contact you on irc/discord/mail? I'd like to create some good embedded ARM base and it looks like you also did some work already :) |
@MasterQ32, Sure you can contact me. I'm on reddit with the same username, I think discord too. I got burned out juggling family stuff, work, and side projects so I haven't done much in a while. I'd love to be re-inspired though! I can PM you my email on there which is probably the easiest way to get a response from me. |
Does "address of symbol" even make sense with weak linkage? For example, the address is not defined at compile time (of the object file), but will be defined when linked with other objects later. Examplemain.c: #include <stdio.h>
extern __attribute__((weak)) int foo;
int main() {
printf("%p\n", &foo);
if (&foo != 0) {
printf("foo = %d\n", foo);
}
fflush(stdout);
} lib.c: int foo = 42;
|
Why are you bringing up weak linkage? None of the symbols in the examples have weak linkage. |
It is not in the example. I fear that some compiler/linker with attempt to move the PLT table after the zig code is already compiled (e.g. with compiler flags). It is a concern for relocatable linkable objects too, where exported symbols can change address. |
Regardless, it does still make sense. Comptime known addresses are symbolic values that will be resolved after comptime. They can be passed around and you can use It's implemented by tracking offsets and emitting relocations anywhere this value is stored. |
If #9646 is implemented then it is fine. |
this is marked stage1 and seems to compile now, can it be closed since stage2 is default? |
Works in master. |
Consider the following Zig code:
which will yield this error:
Such code is required when bootstrapping microcontrolls like the Cortex M3, as it requires the initial stack pointer to be stored in the interrupt vector table.
The C equivalent works:
Example in godbolt: https://c.godbolt.org/z/zhxcMM
One workaround i tried was declaring the end of stack as a separate symbol:
but this yields this error:
This code is required to work, otherwise it is not possible to bootstrap such microcontrollers in Zig.
The text was updated successfully, but these errors were encountered: