Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWASan] Add __hwasan_init to .preinit_array.
Fixes segfaults on x86_64 caused by instrumented code running before shadow is set up. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D118171
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- hwasan_preinit.cpp ------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of HWAddressSanitizer, an address sanity checker. | ||
// | ||
// Call __hwasan_init at the very early stage of process startup. | ||
//===----------------------------------------------------------------------===// | ||
#include "hwasan_interface_internal.h" | ||
#include "sanitizer_common/sanitizer_internal_defs.h" | ||
|
||
#if SANITIZER_CAN_USE_PREINIT_ARRAY | ||
// The symbol is called __local_hwasan_preinit, because it's not intended to | ||
// be exported. | ||
// This code linked into the main executable when -fsanitize=hwaddress is in | ||
// the link flags. It can only use exported interface functions. | ||
__attribute__((section(".preinit_array"), used)) static void ( | ||
*__local_hwasan_preinit)(void) = __hwasan_init; | ||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Test that HWASan shadow is initialized before .preinit_array functions run. | ||
|
||
// RUN: %clang_hwasan %s -o %t | ||
// RUN: %run %t | ||
|
||
volatile int Global; | ||
void StoreToGlobal() { Global = 42; } | ||
|
||
__attribute__((section(".preinit_array"), used)) | ||
void (*__StoreToGlobal_preinit)() = StoreToGlobal; | ||
|
||
int main() { return Global != 42; } |