Skip to content

Commit 9d81dea

Browse files
authored
Update compiler-rt from LLVM 20.1.8 to 21.1.8 (#26045)
This updates compiler-rt from 20.1.8 to LLVM 21.1.8: https://github.com/llvm/llvm-project/releases/tag/llvmorg-21.1.8 Additional change: - `StackSizeIsUnlimited` in `lib/sanitizer_common/sanitizer_posix_libcdep.cpp` was excluded from Emscripten build along with several other methods in #20740. A new call to `StackSizeIsUnlimited` was added in `lib/asan/asan_rtl.cpp` in this version, so this excludes the call too.
1 parent 4c3a201 commit 9d81dea

File tree

106 files changed

+2799
-1248
lines changed

Some content is hidden

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

106 files changed

+2799
-1248
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.24 (in development)
2222
-----------------------
23+
- compiler-rt was updated to LLVM 21.1.8. (#26405)
2324

2425
4.0.23 - 01/10/26
2526
-----------------

system/lib/compiler-rt/lib/asan/asan_activation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static struct AsanDeactivatedFlags {
5858
cf.verbosity = Verbosity();
5959
cf.help = false; // this is activation-specific help
6060

61-
// Check if activation flags need to be overriden.
61+
// Check if activation flags need to be overridden.
6262
if (const char *env = GetEnv("ASAN_ACTIVATION_OPTIONS")) {
6363
parser.ParseString(env);
6464
}

system/lib/compiler-rt/lib/asan/asan_allocator.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,15 @@ struct Allocator {
424424
PoisonShadow(chunk, allocated_size, kAsanHeapLeftRedzoneMagic);
425425
}
426426

427-
void ReInitialize(const AllocatorOptions &options) {
427+
// Apply provided AllocatorOptions to an Allocator
428+
void ApplyOptions(const AllocatorOptions &options) {
428429
SetAllocatorMayReturnNull(options.may_return_null);
429430
allocator.SetReleaseToOSIntervalMs(options.release_to_os_interval_ms);
430431
SharedInitCode(options);
432+
}
433+
434+
void ReInitialize(const AllocatorOptions &options) {
435+
ApplyOptions(options);
431436

432437
// Poison all existing allocation's redzones.
433438
if (CanPoisonMemory()) {
@@ -977,6 +982,11 @@ void ReInitializeAllocator(const AllocatorOptions &options) {
977982
instance.ReInitialize(options);
978983
}
979984

985+
// Apply provided AllocatorOptions to an Allocator
986+
void ApplyAllocatorOptions(const AllocatorOptions &options) {
987+
instance.ApplyOptions(options);
988+
}
989+
980990
void GetAllocatorOptions(AllocatorOptions *options) {
981991
instance.GetOptions(options);
982992
}

system/lib/compiler-rt/lib/asan/asan_allocator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct AllocatorOptions {
4747
void InitializeAllocator(const AllocatorOptions &options);
4848
void ReInitializeAllocator(const AllocatorOptions &options);
4949
void GetAllocatorOptions(AllocatorOptions *options);
50+
void ApplyAllocatorOptions(const AllocatorOptions &options);
5051

5152
class AsanChunkView {
5253
public:
@@ -238,7 +239,7 @@ using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
238239
typedef CompactSizeClassMap SizeClassMap;
239240
template <typename AddressSpaceViewTy>
240241
struct AP32 {
241-
static const uptr kSpaceBeg = 0;
242+
static const uptr kSpaceBeg = SANITIZER_MMAP_BEGIN;
242243
static const u64 kSpaceSize = SANITIZER_MMAP_RANGE_SIZE;
243244
static const uptr kMetadataSize = 0;
244245
typedef __asan::SizeClassMap SizeClassMap;

system/lib/compiler-rt/lib/asan/asan_descriptions.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ bool GetStackAddressInformation(uptr addr, uptr access_size,
211211
descr->frame_pc = access.frame_pc;
212212
descr->frame_descr = access.frame_descr;
213213

214-
#if SANITIZER_PPC64V1
215-
// On PowerPC64 ELFv1, the address of a function actually points to a
216-
// three-doubleword data structure with the first field containing
217-
// the address of the function's code.
214+
#if SANITIZER_PPC64V1 || SANITIZER_AIX
215+
// On PowerPC64 ELFv1 or AIX, the address of a function actually points to a
216+
// three-doubleword (or three-word for 32-bit AIX) data structure with
217+
// the first field containing the address of the function's code.
218218
descr->frame_pc = *reinterpret_cast<uptr *>(descr->frame_pc);
219219
#endif
220220
descr->frame_pc += 16;
@@ -444,6 +444,16 @@ AddressDescription::AddressDescription(uptr addr, uptr access_size,
444444
data.kind = kAddressKindShadow;
445445
return;
446446
}
447+
448+
// Check global first. On AIX, some global data defined in shared libraries
449+
// are put to the STACK region for unknown reasons. Check global first can
450+
// workaround this issue.
451+
// TODO: Look into whether there's a different solution to this problem.
452+
if (GetGlobalAddressInformation(addr, access_size, &data.global)) {
453+
data.kind = kAddressKindGlobal;
454+
return;
455+
}
456+
447457
if (GetHeapAddressInformation(addr, access_size, &data.heap)) {
448458
data.kind = kAddressKindHeap;
449459
return;
@@ -461,10 +471,6 @@ AddressDescription::AddressDescription(uptr addr, uptr access_size,
461471
return;
462472
}
463473

464-
if (GetGlobalAddressInformation(addr, access_size, &data.global)) {
465-
data.kind = kAddressKindGlobal;
466-
return;
467-
}
468474
data.kind = kAddressKindWild;
469475
data.wild.addr = addr;
470476
data.wild.access_size = access_size;

system/lib/compiler-rt/lib/asan/asan_errors.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "asan_errors.h"
15+
1516
#include "asan_descriptions.h"
1617
#include "asan_mapping.h"
18+
#include "asan_poisoning.h"
1719
#include "asan_report.h"
1820
#include "asan_stack.h"
1921
#include "sanitizer_common/sanitizer_stackdepot.h"
@@ -611,6 +613,44 @@ static void PrintShadowMemoryForAddress(uptr addr) {
611613
Printf("%s", str.data());
612614
}
613615

616+
static void CheckPoisonRecords(uptr addr) {
617+
if (!AddrIsInMem(addr))
618+
return;
619+
620+
u8 *shadow_addr = (u8 *)MemToShadow(addr);
621+
// If we are in the partial right redzone, look at the next shadow byte.
622+
if (*shadow_addr > 0 && *shadow_addr < 128)
623+
shadow_addr++;
624+
u8 shadow_val = *shadow_addr;
625+
626+
if (shadow_val != kAsanUserPoisonedMemoryMagic)
627+
return;
628+
629+
Printf("\n");
630+
631+
if (flags()->poison_history_size <= 0) {
632+
Printf(
633+
"NOTE: the stack trace above identifies the code that *accessed* "
634+
"the poisoned memory.\n");
635+
Printf(
636+
"To identify the code that *poisoned* the memory, try the "
637+
"experimental setting ASAN_OPTIONS=poison_history_size=<size>.\n");
638+
return;
639+
}
640+
641+
PoisonRecord record;
642+
if (FindPoisonRecord(addr, record)) {
643+
StackTrace poison_stack = StackDepotGet(record.stack_id);
644+
if (poison_stack.size > 0) {
645+
Printf("Memory was manually poisoned by thread T%u:\n", record.thread_id);
646+
poison_stack.Print();
647+
}
648+
} else {
649+
Printf("ERROR: no matching poison tracking record found.\n");
650+
Printf("Try a larger value for ASAN_OPTIONS=poison_history_size=<size>.\n");
651+
}
652+
}
653+
614654
void ErrorGeneric::Print() {
615655
Decorator d;
616656
Printf("%s", d.Error());
@@ -634,6 +674,9 @@ void ErrorGeneric::Print() {
634674
PrintContainerOverflowHint();
635675
ReportErrorSummary(bug_descr, &stack);
636676
PrintShadowMemoryForAddress(addr);
677+
678+
// This is an experimental flag, hence we don't make a special handler.
679+
CheckPoisonRecords(addr);
637680
}
638681

639682
} // namespace __asan

system/lib/compiler-rt/lib/asan/asan_fake_stack.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static const u64 kAllocaRedzoneMask = 31UL;
2727

2828
// For small size classes inline PoisonShadow for better performance.
2929
ALWAYS_INLINE void SetShadow(uptr ptr, uptr size, uptr class_id, u64 magic) {
30+
CHECK(AddrIsAlignedByGranularity(ptr + size));
3031
u64 *shadow = reinterpret_cast<u64*>(MemToShadow(ptr));
3132
if (ASAN_SHADOW_SCALE == 3 && class_id <= 6) {
3233
// This code expects ASAN_SHADOW_SCALE=3.
@@ -39,6 +40,11 @@ ALWAYS_INLINE void SetShadow(uptr ptr, uptr size, uptr class_id, u64 magic) {
3940
// The size class is too big, it's cheaper to poison only size bytes.
4041
PoisonShadow(ptr, size, static_cast<u8>(magic));
4142
}
43+
44+
if (magic == 0) {
45+
uptr redzone_size = FakeStack::BytesInSizeClass(class_id) - size;
46+
PoisonShadow(ptr + size, redzone_size, kAsanStackRightRedzoneMagic);
47+
}
4248
}
4349

4450
FakeStack *FakeStack::Create(uptr stack_size_log) {

system/lib/compiler-rt/lib/asan/asan_flags.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ static void InitializeDefaultFlags() {
177177
DisplayHelpMessages(&asan_parser);
178178
}
179179

180+
// Validate flags and report incompatible configurations
180181
static void ProcessFlags() {
181182
Flags *f = flags();
182183

@@ -250,11 +251,12 @@ void InitializeFlags() {
250251
ProcessFlags();
251252

252253
#if SANITIZER_WINDOWS
253-
// On Windows, weak symbols are emulated by having the user program
254-
// register which weak functions are defined.
255-
// The ASAN DLL will initialize flags prior to user module initialization,
256-
// so __asan_default_options will not point to the user definition yet.
257-
// We still want to ensure we capture when options are passed via
254+
// On Windows, weak symbols (such as the `__asan_default_options` function)
255+
// are emulated by having the user program register which weak functions are
256+
// defined. The ASAN DLL will initialize flags prior to user module
257+
// initialization, so __asan_default_options will not point to the user
258+
// definition yet. We still want to ensure we capture when options are passed
259+
// via
258260
// __asan_default_options, so we add a callback to be run
259261
// when it is registered with the runtime.
260262

@@ -265,21 +267,13 @@ void InitializeFlags() {
265267
// __sanitizer_register_weak_function.
266268
AddRegisterWeakFunctionCallback(
267269
reinterpret_cast<uptr>(__asan_default_options), []() {
268-
FlagParser asan_parser;
269-
270-
RegisterAsanFlags(&asan_parser, flags());
271-
RegisterCommonFlags(&asan_parser);
272-
asan_parser.ParseString(__asan_default_options());
273-
274-
DisplayHelpMessages(&asan_parser);
270+
// We call `InitializeDefaultFlags` again, instead of just parsing
271+
// `__asan_default_options` directly, to ensure that flags set through
272+
// `ASAN_OPTS` take precedence over those set through
273+
// `__asan_default_options`.
274+
InitializeDefaultFlags();
275275
ProcessFlags();
276-
277-
// TODO: Update other globals and data structures that may need to change
278-
// after initialization due to new flags potentially being set changing after
279-
// `__asan_default_options` is registered.
280-
// See GH issue 'https://github.com/llvm/llvm-project/issues/117925' for
281-
// details.
282-
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
276+
ApplyFlags();
283277
});
284278

285279
# if CAN_SANITIZE_UB

system/lib/compiler-rt/lib/asan/asan_flags.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
// ASan flag values can be defined in four ways:
2121
// 1) initialized with default values at startup.
22-
// 2) overriden during compilation of ASan runtime by providing
22+
// 2) overridden during compilation of ASan runtime by providing
2323
// compile definition ASAN_DEFAULT_OPTIONS.
24-
// 3) overriden from string returned by user-specified function
24+
// 3) overridden from string returned by user-specified function
2525
// __asan_default_options().
26-
// 4) overriden from env variable ASAN_OPTIONS.
27-
// 5) overriden during ASan activation (for now used on Android only).
26+
// 4) overridden from env variable ASAN_OPTIONS.
27+
// 5) overridden during ASan activation (for now used on Android only).
2828

2929
namespace __asan {
3030

system/lib/compiler-rt/lib/asan/asan_flags.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ ASAN_FLAG(bool, poison_partial, true,
116116
"stack buffers.")
117117
ASAN_FLAG(bool, poison_array_cookie, true,
118118
"Poison (or not) the array cookie after operator new[].")
119+
ASAN_FLAG(int, poison_history_size, 0,
120+
"[EXPERIMENTAL] Number of most recent memory poisoning calls for "
121+
"which the stack traces will be recorded.")
119122

120123
// Turn off alloc/dealloc mismatch checker on Mac and Windows for now.
121124
// https://github.com/google/sanitizers/issues/131

0 commit comments

Comments
 (0)