Skip to content

Commit 6b6ccd8

Browse files
committed
* 'main' of https://github.com/llvm/llvm-project: [RISCV] Improve hasAllNBitUsers for users of SLLI. [RISCV] Invert if conditions in the switch in RISCVDAGToDAGISel::hasAllNBitUsers. NFC [Transforms] Construct SmallVector with ArrayRef (NFC) (llvm#101851) [RISCV] Capitalize some variable names. NFC [sanitizer_common] Fix UnwindFast on SPARC (llvm#101634) [builtins] Fix divtc3.c etc. compilation on Solaris/SPARC with gcc (llvm#101662) [NFC][asan] Track current dynamic init module (llvm#101597) [libc] enable most of the entrypoints on aarch64 (llvm#101797) [SandboxIR][Tracker] Track InsertIntoBB (llvm#101595) [SCEV] Use const SCEV * explicitly in more places. [ELF] Move outputSections into Ctx. NFC [ELF] Move ElfSym into Ctx. NFC [ELF] Move Out into Ctx. NFC [test][asan] Fix the test checks [NFC][asan] Switch from list to DynInitGlobalsByModule (llvm#101596) Signed-off-by: Edwiin Kusuma Jaya <[email protected]>
2 parents c7cd574 + c03bf2c commit 6b6ccd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+737
-515
lines changed

compiler-rt/lib/asan/asan_globals.cpp

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ struct DynInitGlobal {
4747
bool initialized = false;
4848
DynInitGlobal *next = nullptr;
4949
};
50-
typedef IntrusiveList<DynInitGlobal> DynInitGlobals;
51-
static DynInitGlobals dynamic_init_globals SANITIZER_GUARDED_BY(mu_for_globals);
5250

5351
// We want to remember where a certain range of globals was registered.
5452
struct GlobalRegistrationSite {
@@ -72,6 +70,25 @@ static ListOfGlobals &GlobalsByIndicator(uptr odr_indicator)
7270
return (*globals_by_indicator)[odr_indicator];
7371
}
7472

73+
static const char *current_dynamic_init_module_name
74+
SANITIZER_GUARDED_BY(mu_for_globals) = nullptr;
75+
76+
using DynInitGlobalsByModule =
77+
DenseMap<const char *, IntrusiveList<DynInitGlobal>>;
78+
79+
// TODO: Add a NoDestroy helper, this patter is very common in sanitizers.
80+
static DynInitGlobalsByModule &DynInitGlobals()
81+
SANITIZER_REQUIRES(mu_for_globals) {
82+
static DynInitGlobalsByModule *globals_by_module = nullptr;
83+
if (!globals_by_module) {
84+
alignas(alignof(DynInitGlobalsByModule)) static char
85+
placeholder[sizeof(DynInitGlobalsByModule)];
86+
globals_by_module = new (placeholder) DynInitGlobalsByModule();
87+
}
88+
89+
return *globals_by_module;
90+
}
91+
7592
ALWAYS_INLINE void PoisonShadowForGlobal(const Global *g, u8 value) {
7693
FastPoisonShadow(g->beg, g->size_with_redzone, value);
7794
}
@@ -94,6 +111,31 @@ static void AddGlobalToList(ListOfGlobals &list, const Global *g) {
94111
list.push_front(new (GetGlobalLowLevelAllocator()) GlobalListNode{g});
95112
}
96113

114+
static void UnpoisonDynamicGlobals(IntrusiveList<DynInitGlobal> &dyn_globals,
115+
bool mark_initialized) {
116+
for (auto &dyn_g : dyn_globals) {
117+
const Global *g = &dyn_g.g;
118+
if (dyn_g.initialized)
119+
continue;
120+
// Unpoison the whole global.
121+
PoisonShadowForGlobal(g, 0);
122+
// Poison redzones back.
123+
PoisonRedZones(*g);
124+
if (mark_initialized)
125+
dyn_g.initialized = true;
126+
}
127+
}
128+
129+
static void PoisonDynamicGlobals(
130+
const IntrusiveList<DynInitGlobal> &dyn_globals) {
131+
for (auto &dyn_g : dyn_globals) {
132+
const Global *g = &dyn_g.g;
133+
if (dyn_g.initialized)
134+
continue;
135+
PoisonShadowForGlobal(g, kAsanInitializationOrderMagic);
136+
}
137+
}
138+
97139
static bool IsAddressNearGlobal(uptr addr, const __asan_global &g) {
98140
if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal) return false;
99141
if (addr >= g.beg + g.size_with_redzone) return false;
@@ -257,8 +299,8 @@ static void RegisterGlobal(const Global *g) SANITIZER_REQUIRES(mu_for_globals) {
257299
AddGlobalToList(list_of_all_globals, g);
258300

259301
if (g->has_dynamic_init) {
260-
dynamic_init_globals.push_back(new (GetGlobalLowLevelAllocator())
261-
DynInitGlobal{*g, false});
302+
DynInitGlobals()[g->module_name].push_back(
303+
new (GetGlobalLowLevelAllocator()) DynInitGlobal{*g, false});
262304
}
263305
}
264306

@@ -289,13 +331,10 @@ void StopInitOrderChecking() {
289331
return;
290332
Lock lock(&mu_for_globals);
291333
flags()->check_initialization_order = false;
292-
for (const DynInitGlobal &dyn_g : dynamic_init_globals) {
293-
const Global *g = &dyn_g.g;
294-
// Unpoison the whole global.
295-
PoisonShadowForGlobal(g, 0);
296-
// Poison redzones back.
297-
PoisonRedZones(*g);
298-
}
334+
DynInitGlobals().forEach([&](auto &kv) {
335+
UnpoisonDynamicGlobals(kv.second, /*mark_initialized=*/false);
336+
return true;
337+
});
299338
}
300339

301340
static bool IsASCII(unsigned char c) { return /*0x00 <= c &&*/ c <= 0x7F; }
@@ -456,17 +495,29 @@ void __asan_before_dynamic_init(const char *module_name) {
456495
CHECK(module_name);
457496
CHECK(AsanInited());
458497
Lock lock(&mu_for_globals);
498+
if (current_dynamic_init_module_name == module_name)
499+
return;
459500
if (flags()->report_globals >= 3)
460501
Printf("DynInitPoison module: %s\n", module_name);
461-
for (DynInitGlobal &dyn_g : dynamic_init_globals) {
462-
const Global *g = &dyn_g.g;
463-
if (dyn_g.initialized)
464-
continue;
465-
if (g->module_name != module_name)
466-
PoisonShadowForGlobal(g, kAsanInitializationOrderMagic);
467-
else if (!strict_init_order)
468-
dyn_g.initialized = true;
502+
503+
if (current_dynamic_init_module_name == nullptr) {
504+
// First call, poison all globals from other modules.
505+
DynInitGlobals().forEach([&](auto &kv) {
506+
if (kv.first != module_name) {
507+
PoisonDynamicGlobals(kv.second);
508+
} else {
509+
UnpoisonDynamicGlobals(kv.second,
510+
/*mark_initialized=*/!strict_init_order);
511+
}
512+
return true;
513+
});
514+
} else {
515+
// Module changed.
516+
PoisonDynamicGlobals(DynInitGlobals()[current_dynamic_init_module_name]);
517+
UnpoisonDynamicGlobals(DynInitGlobals()[module_name],
518+
/*mark_initialized=*/!strict_init_order);
469519
}
520+
current_dynamic_init_module_name = module_name;
470521
}
471522

472523
// This method runs immediately after dynamic initialization in each TU, when
@@ -477,15 +528,16 @@ void __asan_after_dynamic_init() {
477528
return;
478529
CHECK(AsanInited());
479530
Lock lock(&mu_for_globals);
531+
if (!current_dynamic_init_module_name)
532+
return;
533+
480534
if (flags()->report_globals >= 3)
481535
Printf("DynInitUnpoison\n");
482-
for (const DynInitGlobal &dyn_g : dynamic_init_globals) {
483-
const Global *g = &dyn_g.g;
484-
if (!dyn_g.initialized) {
485-
// Unpoison the whole global.
486-
PoisonShadowForGlobal(g, 0);
487-
// Poison redzones back.
488-
PoisonRedZones(*g);
489-
}
490-
}
536+
537+
DynInitGlobals().forEach([&](auto &kv) {
538+
UnpoisonDynamicGlobals(kv.second, /*mark_initialized=*/false);
539+
return true;
540+
});
541+
542+
current_dynamic_init_module_name = nullptr;
491543
}

compiler-rt/lib/builtins/divtc3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#define QUAD_PRECISION
1414
#include "fp_lib.h"
1515

16-
#if defined(CRT_HAS_F128)
16+
#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128)
1717

1818
// Returns: the quotient of (a + ib) / (c + id)
1919

compiler-rt/lib/builtins/multc3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "int_lib.h"
1616
#include "int_math.h"
1717

18-
#if defined(CRT_HAS_F128)
18+
#if defined(CRT_HAS_128BIT) && defined(CRT_HAS_F128)
1919

2020
// Returns: the product of a + ib and c + id
2121

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_sparc.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,16 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
5858
// Avoid infinite loop when frame == frame[0] by using frame > prev_frame.
5959
while (IsValidFrame(bp, stack_top, bottom) && IsAligned(bp, sizeof(uhwptr)) &&
6060
size < max_depth) {
61-
uhwptr pc1 = ((uhwptr *)bp)[15];
61+
// %o7 contains the address of the call instruction and not the
62+
// return address, so we need to compensate.
63+
uhwptr pc1 = GetNextInstructionPc(((uhwptr *)bp)[15]);
6264
// Let's assume that any pointer in the 0th page is invalid and
6365
// stop unwinding here. If we're adding support for a platform
6466
// where this isn't true, we need to reconsider this check.
6567
if (pc1 < kPageSize)
6668
break;
67-
if (pc1 != pc) {
68-
// %o7 contains the address of the call instruction and not the
69-
// return address, so we need to compensate.
70-
trace_buffer[size++] = GetNextInstructionPc((uptr)pc1);
71-
}
69+
if (pc1 != pc)
70+
trace_buffer[size++] = pc1;
7271
bottom = bp;
7372
bp = (uptr)((uhwptr *)bp)[14] + STACK_BIAS;
7473
}

compiler-rt/test/asan/TestCases/initialization-nobug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int getStructWithDtorValue() { return struct_with_dtor.value; }
4343

4444
int main() { return 0; }
4545

46-
// CHECK: DynInitPoison module: {{.*}}initialization-nobug.cpp
46+
// CHECK: DynInitPoison
4747
// CHECK: DynInitUnpoison
48-
// CHECK: DynInitPoison module: {{.*}}initialization-nobug-extra.cpp
48+
// CHECK: DynInitPoison
4949
// CHECK: DynInitUnpoison

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ function(get_object_files_for_test result skipped_entrypoints_list)
2222
foreach(dep IN LISTS unchecked_list)
2323
if (NOT TARGET ${dep})
2424
# Skip tests with undefined dependencies.
25-
list(APPEND skipped_list ${dep})
25+
# Compiler-RT targets are added only if they are enabled. However, such targets may not be defined
26+
# at the time of the libc build. We should skip checking such targets.
27+
if (NOT ${dep} MATCHES "^RTScudo.*|^RTGwp.*")
28+
list(APPEND skipped_list ${dep})
29+
endif()
2630
continue()
2731
endif()
2832
get_target_property(aliased_target ${dep} "ALIASED_TARGET")

0 commit comments

Comments
 (0)