Skip to content

[sanitizer][Fuchsia] Add callback at end of __sanitizer_startup_hook #131886

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

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler-rt/lib/asan/asan_fuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
# include "asan_thread.h"
# include "lsan/lsan_common.h"

namespace __sanitizer {
// ASan doesn't need to do anything else special in the startup hook.
void EarlySanitizerInit() {}
} // namespace __sanitizer

namespace __asan {

// The system already set up the shadow memory for us.
Expand Down
9 changes: 9 additions & 0 deletions compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
SANITIZER_INTERFACE_ATTRIBUTE
THREADLOCAL uptr __hwasan_tls;

namespace __sanitizer {
void EarlySanitizerInit() {
// Setup the hwasan runtime before any `__libc_extensions_init`s are called.
// This is needed because libraries which define this function (like fdio)
// may be instrumented and either access `__hwasan_tls` or make runtime calls.
__hwasan_init();
}
} // namespace __sanitizer

namespace __hwasan {

bool InitShadow() {
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ void __sanitizer_startup_hook(int argc, char **argv, char **envp,
__sanitizer::StoredEnviron = envp;
__sanitizer::MainThreadStackBase = reinterpret_cast<uintptr_t>(stack_base);
__sanitizer::MainThreadStackSize = stack_size;

EarlySanitizerInit();
}

void __sanitizer_set_report_path(const char *path) {
Expand Down
7 changes: 7 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ struct MemoryMappingLayoutData {

void InitShadowBounds();

// Individual sanitizers can define this to explicitly run something at the end
// of `__sanitizer_startup_hook`. This can be useful if a sanitizer needs to do
// extra work after the common startup hook code is called and before module
// ctors are invoked. For example, hwasan can explicitly call its initializing
// function here so it can be set up before libc extensions are initialized.
void EarlySanitizerInit();

} // namespace __sanitizer

#endif // SANITIZER_FUCHSIA
Expand Down
7 changes: 7 additions & 0 deletions compiler-rt/lib/ubsan/ubsan_init_standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
#include "ubsan_init.h"
#include "ubsan_signals_standalone.h"

#if SANITIZER_FUCHSIA
namespace __sanitizer {
// UBSan doesn't need to do anything else special in the startup hook.
void EarlySanitizerInit() {}
} // namespace __sanitizer
#endif // SANITIZER_FUCHSIA

namespace __ubsan {

class UbsanStandaloneInitializer {
Expand Down