-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[build] Illegal instruction when calling 'ImageResize', related to "Disable UBSAN in zig builds" #3674
Comments
I searched from the existing issues and then I found this pull request related to it. This is the fix: But it has been reverted in this commit So, if I add // This has been tested to work with zig 0.11.0 and zig 0.12.0-dev.1390+94cee4fb2
pub fn addRaylib(b: *std.Build, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode, options: Options) *std.Build.CompileStep {
const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
"-DGL_SILENCE_DEPRECATION=199309L",
"-fno-sanitize=undefined", // Add this line
}; Then re-run |
@wisonye Thanks for reporting! Feel free to send a PR! NOTE: Not sure if related but recently |
Hi all, looking at the involved source I am not sure whether disabling a sanitizer is a good approach. Short: I believe it is better to explicitly force STBIR to use the safer code paths in a zig build. Long:
This is a macro, which is provided a few lines before, depending on another define:
The Furthermore: Though, to be sure my cursory poking in the source is actually correct - @wisonye , may I ask you to test if building it with |
@dertseha Hi, thanks for taking the time to dive deep and figure it out, but it doesn't fix the problem. Here is what I've tried in const raylib_flags = &[_][]const u8{
"-std=gnu99",
"-D_GNU_SOURCE",
"-DGL_SILENCE_DEPRECATION=199309L",
"-DSTBIR__SEPARATE_ALLOCATIONS", // What you ask for a test
}; The problem is still here, same error:) One more thing, if I remove the This is what happened when I was trying to do INFO: AUDIO: Device initialized successfully
INFO: > Backend: miniaudio / PulseAudio
INFO: > Format: 32-bit IEEE Floating Point -> 16-bit Signed Integer
INFO: > Channels: 2 -> 2
INFO: > Sample rate: 48000 -> 48000
INFO: > Periods size: 3600
INFO: FILEIO: [resources/enable_fireball.wav] File loaded successfully
INFO: WAVE: Data loaded successfully (48000 Hz, 16 bit, 2 channels)
Illegal instruction at address 0x6fc636
src/external/miniaudio.h:54131:82: 0x6fc636 in ma_data_converter_init_preallocated (/home/wison/zig/raylib-box2d-tutorials/raylib/src/raudio.c)
src/external/miniaudio.h:54242:14: 0x6fe619 in ma_data_converter_init (/home/wison/zig/raylib-box2d-tutorials/raylib/src/raudio.c)
src/external/miniaudio.h:56061:14: 0x704fd5 in ma_convert_frames_ex (/home/wison/zig/raylib-box2d-tutorials/raylib/src/raudio.c)
src/external/miniaudio.h:56049:12: 0x704f71 in ma_convert_frames (/home/wison/zig/raylib-box2d-tutorials/raylib/src/raudio.c)
src/raudio.c:911:43: 0x7b599f in LoadSoundFromWave (/home/wison/zig/raylib-box2d-tutorials/raylib/src/raudio.c)
src/raudio.c:884:19: 0x7b5796 in LoadSound (/home/wison/zig/raylib-box2d-tutorials/raylib/src/raudio.c)
/home/wison/zig/raylib-box2d-tutorials/src/temp_test.zig:41:38: 0x2a3ff6 in main (temp-test)
const sound_effect = rl.LoadSound("resources/enable_fireball.wav");
^
/home/wison/my-shell/zig-nightly/lib/std/start.zig:585:37: 0x2a480b in main (temp-test)
const result = root.main() catch |err| {
^
???:?:?: 0x7fe8c9a77ccf in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7fe8c9a77ccf` was not available, trace may be incomplete Just in case you might doubt about the zig cache, I made sure that I removed all zig cache before making a clean build like this: # Remove 'raylib' submodule zig related folder
rm -rf raylib/{zig-cache, zig-out}
# Remove my project zig related folder
rm -rf ./{zig-cache, zig-out}
# Then rebuild everything .... |
I found that the better way is only to apply if (options.raudio) {
addCSourceFilesVersioned(raylib, &.{
srcdir ++ "/raudio.c",
}, &[_][]const u8{
"-fno-sanitize=undefined",
} ++ raylib_flags); // https://github.com/raysan5/raylib/issues/3674
}
if (options.rtextures) {
addCSourceFilesVersioned(raylib, &.{
srcdir ++ "/rtextures.c",
}, &[_][]const u8{
"-fno-sanitize=undefined",
} ++ raylib_flags); // https://github.com/raysan5/raylib/issues/3674
}
`` |
Well, that's unfortunate. I'm sorry that the approach with the define doesn't work. (Albeit I'm a bit puzzled that the define isn't picked up by STBIR) As for the other crash, in miniaudio, the line 54131:82 refers to another macro that does some pointer offset magic ( I'm still not satisfied that the only way out would be to disable a sanitizer, yet I'm also lacking further knowledge on these details. I wonder which particular operation is the wrong one - as in: Which undefined behaviour is the code relying on. (Plus: shouldn't the sanitizer name what it trips on?) |
@dertseha Yup, I know what you mean and usually, I will do that same when I have time (I prefer to figure out what happens under the hood and fix it in the right way). But I don't have much time on this at this moment, just want to finish my tutorial before my holiday ends:) Also, what Also, the following content comes from this blog > When compiling without -O2 or -O3, Zig infers Debug Mode. Zig passes -fsanitize=undefined -fsanitize-trap=undefined to Clang in this mode. This causes Undefined Behavior to cause an Illegal Instruction. So, I will fire the PR later for the quick fix, plz feel free to update here if you found a better solution:) |
Please, before submitting a new issue verify and check:
Issue description
I'm using the latest master version and
zig build
to produceraylib/zig-out/libraylib.a
, and then I write a simple zig program to load the image and draw texture. Everything works fine except it crashes if callingImageResize
. Here is the console log:Environment
Code Example
The text was updated successfully, but these errors were encountered: