-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Debug symbols not recognized by Valgrind if .data
section is omitted
#15254
Comments
Here's a zip with a working exe (compiled with |
Found a reproduction without the libc linking. If you modify export var bar: usize = 1;
pub fn main() void {
foo().* += 1;
}
fn foo() *i32 {
bar += 1;
return @intToPtr(*i32, 10000000);
} then the (Zig EDIT: It might be more complicated than just the EDIT#2: Got a reproduction with // test.c
static int *foo(void) {
return (int *)10000000;
}
int main(void) {
int *x = foo();
*x += 1;
}
__attribute__((force_align_arg_pointer))
void _start() {
main();
asm("movl $1,%eax;"
"xorl %ebx,%ebx;"
"int $0x80"
);
__builtin_unreachable();
} $ clang test.c -g -c -o test.o
$ ld.lld -o test test.o
$ readelf --hex-dump=.data test
readelf: Warning: Section '.data' was not dumped because it does not exist!
$ valgrind ./test
==3509349== Invalid read of size 4
==3509349== at 0x2011B5: ??? (in /home/ryan/Programming/zig/tmp/valgrind-test/test)
==3509349== by 0x2011EC: ??? (in /home/ryan/Programming/zig/tmp/valgrind-test/test)
==3509349== Address 0x989680 is not stack'd, malloc'd or (recently) free'd But if $ clang test.c -g -c -o test.o
$ ld.lld -o test test.o -pie
$ readelf --hex-dump=.data test
readelf: Warning: Section '.data' was not dumped because it does not exist!
$ valgrind ./test
==3709531== Invalid read of size 4
==3709531== at 0x1092A5: main (test.c:8)
==3709531== Address 0x989680 is not stack'd, malloc'd or (recently) free'd So something to do with EDIT#3: It seems to be some combination (or some other confounding factor), as |
.data
section is omitted
I suppose we could solve this by automatically emitting a data section, even if it is empty, in the case of valgrind being enabled. |
EDIT: Here's a potential workaround:
There might be a better way to go about it, but this has worked for me.
Zig Version
0.11.0-dev.2546+cb54e9a3c
Steps to Reproduce and Observed Behavior
Similar to #896 but doesn't seem to be the same cause (the
--no-rosegment
workaround does not change anything).Same test file as #896:
Debug symbols do not work with Zig
0.11.0-dev.2546+cb54e9a3c
and Valgrind3.20.0
(tested with older Valgrinds [3.17.0
,3.13.0
] and they all work the same so this does not seem to be a Valgrind regression):But debug symbols do work with Zig
0.8.0
(this seems to be the latest version that it still worked with,0.9.0
contains the regression):However, if linking libc (statically with musl or dynamically with glibc), the debug symbols will work fine again:
Expected Behavior
Debug symbols to work with Valgrind when not linking libc.
The text was updated successfully, but these errors were encountered: