-
Notifications
You must be signed in to change notification settings - Fork 269
Fix crash on startup #719
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
Open
jengelh
wants to merge
6
commits into
DescentDevelopers:main
Choose a base branch
from
jengelh:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix crash on startup #719
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Separate trivial and more complex class construction.
Lgt2x
reviewed
Jun 15, 2025
When descent3 is built with g++ -flto=auto, there is a crash at startup: ``` Program received signal SIGSEGV, Segmentation fault. 0x00005555557b3b20 in pilot::initialize ( this=this@entry=0x555555fbd480 <Current_pilot>) at Descent3/pilot_class.cpp:208 208 game_window_w = Video_res_list[Current_video_resolution_id].width; Missing separate debuginfos, use: zypper install libcpp-httplib0_20-debuginfo-0.20.1-2.1.x86_64 libSDL3-0-debuginfo-3.2.16-1.1.x86_64 libzstd1-x86-64-v3-debuginfo-1.5.7-3.1.x86_64 (gdb) p Current_video_resolution_id $1 = 0 (gdb) p Video_res_list $2 = std::vector of length 0, capacity 0 (gdb) bt f0 pilot::initialize (this=this@entry=0x555555fbd480 <Current_pilot>) at Descent3/pilot_class.cpp:208 f1 pilot::pilot (this=<optimized out>, this=<optimized out>) at Descent3/pilot_class.cpp:177 f2 _sub_I_65535_0.0 () f3 call_init (argc=1, argv=0x7fffffffdb68, env=<optimized out>) at ../csu/libc-start.c:145 f4 __libc_start_main_impl f5 _start () at ../sysdeps/x86_64/start.S:115 ``` When ASAN/UBSAN is enabled in conjunction with LTO: ``` /usr/include/c++/14/bits/stl_vector.h:1144:34: runtime error: reference binding to null pointer of type 'struct value_type' Descent3/pilot_class.cpp:208:63: runtime error: member access within null pointer of type 'struct value_type' AddressSanitizer:DEADLYSIGNAL ================================================================= ==58724==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 ==58724==The signal is caused by a READ memory access. ==58724==Hint: address points to the zero page. f0 pilot::initialize() Descent3/pilot_class.cpp:208 f1 pilot::pilot() Descent3/pilot_class.cpp:177 f2 _sub_I_65535_0.0 (b/build/Descent3+0x52ece3) f3 call_init ../csu/libc-start.c:145 f4 __libc_start_main_impl ../csu/libc-start.c:347 f5 _start ../sysdeps/x86_64/start.S:115 ``` ``_sub_I_65535_0.0`` is indicative of a global constructor, so we are looking at a case of Static Initialization Order Fiasco whereby ``pilot::initialize`` runs before ``Video_res_list`` and ``Current_resolution_id`` get initialized. Perform pilot construction explicitly in main(). Fixes: 40c7f0d
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Type
Description
When descent3 is built with g++ -flto=auto, there is a crash at startup:
When ASAN/UBSAN is enabled in conjunction with LTO:
_sub_I_65535_0.0
is indicative of a global constructor, so weare looking at a case of Static Initialization Order Fiasco whereby
pilot::initialize
runs beforeVideo_res_list
gets initialized.Static variables declared in functions are initialized on first use,
which can help steer global initialization short of placing the
global state in a class instance of its own.
Fixes: 40c7f0d
Related Issues
#667
Checklist