Merge "Fix elftls_dl#dtv_resize with HWASan"

This commit is contained in:
Treehugger Robot 2023-05-30 20:44:01 +00:00 committed by Gerrit Code Review
commit 41ea538b40

View file

@ -154,7 +154,6 @@ TEST(elftls_dl, tlsdesc_missing_weak) {
} }
TEST(elftls_dl, dtv_resize) { TEST(elftls_dl, dtv_resize) {
SKIP_WITH_HWASAN; // TODO(b/271243811): Fix for new toolchain
#if defined(__BIONIC__) #if defined(__BIONIC__)
#define LOAD_LIB(soname) ({ \ #define LOAD_LIB(soname) ({ \
auto lib = dlopen(soname, RTLD_LOCAL | RTLD_NOW); \ auto lib = dlopen(soname, RTLD_LOCAL | RTLD_NOW); \
@ -167,11 +166,12 @@ TEST(elftls_dl, dtv_resize) {
static_assert(sizeof(TlsDtv) == 3 * sizeof(void*), static_assert(sizeof(TlsDtv) == 3 * sizeof(void*),
"This test assumes that the Dtv has a 3-word header"); "This test assumes that the Dtv has a 3-word header");
// Initially there are 4 modules: // Initially there are 4 modules (5 w/ hwasan):
// - the main test executable // - the main test executable
// - libc // - libc
// - libtest_elftls_shared_var // - libtest_elftls_shared_var
// - libtest_elftls_tprel // - libtest_elftls_tprel
// - w/ hwasan: libclang_rt.hwasan
// The initial DTV is an empty DTV with no generation and a size of 0. // The initial DTV is an empty DTV with no generation and a size of 0.
TlsDtv* zero_dtv = dtv(); TlsDtv* zero_dtv = dtv();
@ -179,25 +179,25 @@ TEST(elftls_dl, dtv_resize) {
ASSERT_EQ(nullptr, zero_dtv->next); ASSERT_EQ(nullptr, zero_dtv->next);
ASSERT_EQ(kTlsGenerationNone, zero_dtv->generation); ASSERT_EQ(kTlsGenerationNone, zero_dtv->generation);
// Load the fifth module. // Load module 5 (6 w/ hwasan).
auto func1 = LOAD_LIB("libtest_elftls_dynamic_filler_1.so"); auto func1 = LOAD_LIB("libtest_elftls_dynamic_filler_1.so");
ASSERT_EQ(101, func1()); ASSERT_EQ(101, func1());
// After loading one module, the DTV should be initialized to the next // After loading one module, the DTV should be initialized to the next
// power-of-2 size (including the header). // power-of-2 size (including the header).
TlsDtv* initial_dtv = dtv(); TlsDtv* initial_dtv = dtv();
ASSERT_EQ(5u, initial_dtv->count); ASSERT_EQ(running_with_hwasan() ? 13u : 5u, dtv()->count);
ASSERT_EQ(zero_dtv, initial_dtv->next); ASSERT_EQ(zero_dtv, initial_dtv->next);
ASSERT_LT(0u, initial_dtv->generation); ASSERT_LT(0u, initial_dtv->generation);
// Load module 6. // Load module 6 (7 w/ hwasan).
auto func2 = LOAD_LIB("libtest_elftls_dynamic_filler_2.so"); auto func2 = LOAD_LIB("libtest_elftls_dynamic_filler_2.so");
ASSERT_EQ(102, func1()); ASSERT_EQ(102, func1());
#if defined(__aarch64__) #if defined(__aarch64__)
// The arm64 TLSDESC resolver doesn't update the DTV if it is new enough for // The arm64 TLSDESC resolver doesn't update the DTV if it is new enough for
// the given access. // the given access.
ASSERT_EQ(5u, dtv()->count); ASSERT_EQ(running_with_hwasan() ? 13u : 5u, dtv()->count);
#else #else
// __tls_get_addr updates the DTV anytime the generation counter changes. // __tls_get_addr updates the DTV anytime the generation counter changes.
ASSERT_EQ(13u, dtv()->count); ASSERT_EQ(13u, dtv()->count);
@ -205,11 +205,13 @@ TEST(elftls_dl, dtv_resize) {
ASSERT_EQ(201, func2()); ASSERT_EQ(201, func2());
TlsDtv* new_dtv = dtv(); TlsDtv* new_dtv = dtv();
if (!running_with_hwasan()) {
ASSERT_NE(initial_dtv, new_dtv); ASSERT_NE(initial_dtv, new_dtv);
ASSERT_EQ(initial_dtv, new_dtv->next); ASSERT_EQ(initial_dtv, new_dtv->next);
}
ASSERT_EQ(13u, new_dtv->count); ASSERT_EQ(13u, new_dtv->count);
// Load module 7. // Load module 7 (8 w/ hwasan).
auto func3 = LOAD_LIB("libtest_elftls_dynamic_filler_3.so"); auto func3 = LOAD_LIB("libtest_elftls_dynamic_filler_3.so");
ASSERT_EQ(103, func1()); ASSERT_EQ(103, func1());
ASSERT_EQ(202, func2()); ASSERT_EQ(202, func2());