mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-06 09:28:50 +00:00
Revert D138095 Use InernalAlloc in DemangleCXXABI
Broke 2/3 tests on macOS which seem to be related to `free(demangled_name)` in DemangleCXXABI.
This commit is contained in:
parent
655d857325
commit
06c74b5e73
@ -149,8 +149,8 @@ static void CheckODRViolationViaIndicator(const Global *g) {
|
||||
if (g->odr_indicator == l->g->odr_indicator &&
|
||||
(flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
|
||||
!IsODRViolationSuppressed(g->name))
|
||||
ReportODRViolation(g, FindRegistrationSite(g), l->g,
|
||||
FindRegistrationSite(l->g));
|
||||
ReportODRViolation(g, FindRegistrationSite(g),
|
||||
l->g, FindRegistrationSite(l->g));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,17 +49,12 @@ const char *DemangleCXXABI(const char *name) {
|
||||
// FIXME: __cxa_demangle aggressively insists on allocating memory.
|
||||
// There's not much we can do about that, short of providing our
|
||||
// own demangler (libc++abi's implementation could be adapted so that
|
||||
// it does not allocate). For now, we just call it anyway, and use
|
||||
// InternalAlloc to prevent lsan error.
|
||||
if (&__cxxabiv1::__cxa_demangle) {
|
||||
if (char *demangled_name = __cxxabiv1::__cxa_demangle(name, 0, 0, 0)) {
|
||||
size_t size = internal_strlen(demangled_name) + 1;
|
||||
char *buf = (char *)InternalAlloc(size);
|
||||
internal_memcpy(buf, demangled_name, size);
|
||||
free(demangled_name);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
// it does not allocate). For now, we just call it anyway, and we leak
|
||||
// the returned value.
|
||||
if (&__cxxabiv1::__cxa_demangle)
|
||||
if (const char *demangled_name =
|
||||
__cxxabiv1::__cxa_demangle(name, 0, 0, 0))
|
||||
return demangled_name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
@ -2264,12 +2264,11 @@ bool ModuleAddressSanitizer::InstrumentGlobals(IRBuilder<> &IRB, Module &M,
|
||||
if (G->hasSanitizerMetadata())
|
||||
MD = G->getSanitizerMetadata();
|
||||
|
||||
// The runtime library tries demangling symbol names in the descriptor but
|
||||
// functionality like __cxa_demangle may be unavailable (e.g.
|
||||
// -static-libstdc++). So we demangle the symbol names here.
|
||||
std::string NameForGlobal = G->getName().str();
|
||||
// TODO: Symbol names in the descriptor can be demangled by the runtime
|
||||
// library. This could save ~0.4% of VM size for a private large binary.
|
||||
std::string NameForGlobal = llvm::demangle(G->getName().str());
|
||||
GlobalVariable *Name =
|
||||
createPrivateGlobalForString(M, llvm::demangle(NameForGlobal),
|
||||
createPrivateGlobalForString(M, NameForGlobal,
|
||||
/*AllowMerging*/ true, kAsanGenPrefix);
|
||||
|
||||
Type *Ty = G->getValueType();
|
||||
|
@ -13,20 +13,17 @@ target triple = "x86_64-unknown-linux-gnu"
|
||||
@a = dso_local global [2 x i32] zeroinitializer, align 4
|
||||
@b = private global [2 x i32] zeroinitializer, align 4
|
||||
@c = internal global [2 x i32] zeroinitializer, align 4
|
||||
@_ZL1d = unnamed_addr global [2 x i32] zeroinitializer, align 4
|
||||
@d = unnamed_addr global [2 x i32] zeroinitializer, align 4
|
||||
|
||||
; Check that we generate internal alias and odr indicator symbols for global to be protected.
|
||||
; CHECK-NOINDICATOR-NOT: __odr_asan_gen_a
|
||||
; CHECK-NOALIAS-NOT: private alias
|
||||
; CHECK-INDICATOR: @___asan_gen_.1 = private unnamed_addr constant [2 x i8] c"a\00", align 1
|
||||
; CHECK-INDICATOR: @__odr_asan_gen_a = global i8 0, align 1
|
||||
; CHECK-INDICATOR: @___asan_gen_.4 = private unnamed_addr constant [2 x i8] c"d\00", align 1
|
||||
; CHECK-INDICATOR: @__odr_asan_gen__ZL1d = global i8 0, align 1
|
||||
; CHECK-ALIAS: @0 = private alias { [2 x i32], [24 x i8] }, ptr @a
|
||||
|
||||
; CHECK-ALIAS: @1 = private alias { [2 x i32], [24 x i8] }, ptr @b
|
||||
; CHECK-ALIAS: @2 = private alias { [2 x i32], [24 x i8] }, ptr @c
|
||||
; CHECK-ALIAS: @3 = private alias { [2 x i32], [24 x i8] }, ptr @_ZL1d
|
||||
; CHECK-ALIAS: @3 = private alias { [2 x i32], [24 x i8] }, ptr @d
|
||||
|
||||
; Function Attrs: nounwind sanitize_address uwtable
|
||||
define i32 @foo(i32 %M) #0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user