Commit 0791d5d
committed
init libsupc++ emergency_pool early
When an exception is thrown and caught, destruction of the exception checks whether the exception was allocated in the `emergency_pool`, which is a global variable.
This global variable has a runtime constructor, which means access to it is valid only once the constructor has run during the module init phase.
But throwing and catching an exception is permitted at any time, not just during the lifetime of `main`. And this must be true whether libsupc++ is linked dynamically or statically.
LLVM Address Sanitizer aborts with `initialization-order-fiasco` when, in a binary which links libsupc++ statically, an exception is thrown and caught in some global constructor which happens to run prior to the global constructor of `emergency_pool`.
```
ERROR: AddressSanitizer: initialization-order-fiasco ...
READ of size 8 at ... thread T0
SCARINESS: 14 (8-byte-read-initialization-order-fiasco)
#0 ... in (anonymous namespace)::pool::in_pool(void*) gcc-11.x/libstdc++-v3/libsupc++/eh_alloc.cc:258
gcc-mirror#1 ... in __cxa_free_exception gcc-11.x/libstdc++-v3/libsupc++/eh_alloc.cc:302
gcc-mirror#2 ... in __gxx_exception_cleanup(_Unwind_Reason_Code, _Unwind_Exception*) gcc-11.x/libstdc++-v3/libsupc++/eh_throw.cc:51
gcc-mirror#3 ... in __cxa_end_catch gcc-11.x/libstdc++-v3/libsupc++/eh_catch.cc:125
...
... in __cxx_global_var_init ...
...
... in call_init.part.0 glibc-2.40/elf/dl-init.c:74:3
... in call_init glibc-2.40/elf/dl-init.c:120:14
... in _dl_init glibc-2.40/elf/dl-init.c:121:5
... in _dl_start_user glibc-2.40/elf/../sysdeps/aarch64/dl-start.S:46
... is located 56 bytes inside of global variable '(anonymous namespace)::emergency_pool' defined in 'gcc-11.x/libstdc++-v3/libsupc++/eh_alloc.cc' (...) of size 72
registered at:
#0 ... in __asan_register_globals.part.0 llvm-project/compiler-rt/lib/asan/asan_globals.cpp:393:3
gcc-mirror#1 ... in __asan_register_globals llvm-project/compiler-rt/lib/asan/asan_globals.cpp:392:3
gcc-mirror#2 ... in __asan_register_elf_globals llvm-project/compiler-rt/lib/asan/asan_globals.cpp:376:26
gcc-mirror#3 ... in call_init.part.0 glibc-2.40/elf/dl-init.c:74:3
gcc-mirror#4 ... in call_init glibc-2.40/elf/dl-init.c:120:14
gcc-mirror#5 ... in _dl_init glibc-2.40/elf/dl-init.c:121:5
gcc-mirror#6 ... in _dl_start_user glibc-2.40/elf/../sysdeps/aarch64/dl-start.S:46
```1 parent 2954038 commit 0791d5d
1 file changed
+30
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
374 | 394 | | |
375 | 395 | | |
376 | 396 | | |
| |||
380 | 400 | | |
381 | 401 | | |
382 | 402 | | |
383 | | - | |
| 403 | + | |
384 | 404 | | |
385 | | - | |
386 | | - | |
| 405 | + | |
| 406 | + | |
387 | 407 | | |
388 | 408 | | |
389 | 409 | | |
| |||
399 | 419 | | |
400 | 420 | | |
401 | 421 | | |
402 | | - | |
| 422 | + | |
403 | 423 | | |
404 | 424 | | |
405 | 425 | | |
| |||
416 | 436 | | |
417 | 437 | | |
418 | 438 | | |
419 | | - | |
420 | | - | |
| 439 | + | |
| 440 | + | |
421 | 441 | | |
422 | 442 | | |
423 | 443 | | |
| |||
431 | 451 | | |
432 | 452 | | |
433 | 453 | | |
434 | | - | |
| 454 | + | |
435 | 455 | | |
436 | 456 | | |
437 | 457 | | |
| |||
448 | 468 | | |
449 | 469 | | |
450 | 470 | | |
451 | | - | |
452 | | - | |
| 471 | + | |
| 472 | + | |
453 | 473 | | |
454 | 474 | | |
455 | 475 | | |
| |||
0 commit comments