forked from OSchip/llvm-project
[Darwin] Remove workaround for symbolication in iOS simulator runtimes
A while ago we added some code to the sanitizer runtimes for iOS simulators to allow `atos` (external process) to inspect the sanitized process during report generation to enable symbolication. This was done by setting the `__check_mach_ports_lookup` env var early during process startup which came with a couple of complications. This workaround is not required anymore and removing it fixes TSan in the iOS simulator after the new TSan runtime landed. (https://reviews.llvm.org/D112603) Relevant/reverted revisions: https://reviews.llvm.org/D78178 https://reviews.llvm.org/D78179 https://reviews.llvm.org/D78525 rdar://86472733 Differential Revision: https://reviews.llvm.org/D115767
This commit is contained in:
parent
5c0ea7488b
commit
a7cbe198ce
|
@ -138,10 +138,4 @@ Symbolizer::SymbolizerScope::~SymbolizerScope() {
|
|||
sym_->end_hook_();
|
||||
}
|
||||
|
||||
void Symbolizer::LateInitializeTools() {
|
||||
for (auto &tool : tools_) {
|
||||
tool.LateInitialize();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
|
|
@ -213,9 +213,6 @@ class Symbolizer final {
|
|||
private:
|
||||
const Symbolizer *sym_;
|
||||
};
|
||||
|
||||
// Calls `LateInitialize()` on all items in `tools_`.
|
||||
void LateInitializeTools();
|
||||
};
|
||||
|
||||
#ifdef SANITIZER_WINDOWS
|
||||
|
|
|
@ -70,11 +70,6 @@ class SymbolizerTool {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// Called during the LateInitialize phase of Sanitizer initialization.
|
||||
// Usually this is a safe place to call code that might need to use user
|
||||
// memory allocators.
|
||||
virtual void LateInitialize() {}
|
||||
|
||||
protected:
|
||||
~SymbolizerTool() {}
|
||||
};
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <mach/mach.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
@ -58,13 +57,6 @@ bool DlAddrSymbolizer::SymbolizeData(uptr addr, DataInfo *datainfo) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#define K_ATOS_ENV_VAR "__check_mach_ports_lookup"
|
||||
|
||||
// This cannot live in `AtosSymbolizerProcess` because instances of that object
|
||||
// are allocated by the internal allocator which under ASan is poisoned with
|
||||
// kAsanInternalHeapMagic.
|
||||
static char kAtosMachPortEnvEntry[] = K_ATOS_ENV_VAR "=000000000000000";
|
||||
|
||||
class AtosSymbolizerProcess final : public SymbolizerProcess {
|
||||
public:
|
||||
explicit AtosSymbolizerProcess(const char *path)
|
||||
|
@ -72,51 +64,13 @@ class AtosSymbolizerProcess final : public SymbolizerProcess {
|
|||
pid_str_[0] = '\0';
|
||||
}
|
||||
|
||||
void LateInitialize() {
|
||||
if (SANITIZER_IOSSIM) {
|
||||
// `putenv()` may call malloc/realloc so it is only safe to do this
|
||||
// during LateInitialize() or later (i.e. we can't do this in the
|
||||
// constructor). We also can't do this in `StartSymbolizerSubprocess()`
|
||||
// because in TSan we switch allocators when we're symbolizing.
|
||||
// We use `putenv()` rather than `setenv()` so that we can later directly
|
||||
// write into the storage without LibC getting involved to change what the
|
||||
// variable is set to
|
||||
int result = putenv(kAtosMachPortEnvEntry);
|
||||
CHECK_EQ(result, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool StartSymbolizerSubprocess() override {
|
||||
// Configure sandbox before starting atos process.
|
||||
|
||||
// Put the string command line argument in the object so that it outlives
|
||||
// the call to GetArgV.
|
||||
internal_snprintf(pid_str_, sizeof(pid_str_), "%d", internal_getpid());
|
||||
|
||||
if (SANITIZER_IOSSIM) {
|
||||
// `atos` in the simulator is restricted in its ability to retrieve the
|
||||
// task port for the target process (us) so we need to do extra work
|
||||
// to pass our task port to it.
|
||||
mach_port_t ports[]{mach_task_self()};
|
||||
kern_return_t ret =
|
||||
mach_ports_register(mach_task_self(), ports, /*count=*/1);
|
||||
CHECK_EQ(ret, KERN_SUCCESS);
|
||||
|
||||
// Set environment variable that signals to `atos` that it should look
|
||||
// for our task port. We can't call `setenv()` here because it might call
|
||||
// malloc/realloc. To avoid that we instead update the
|
||||
// `mach_port_env_var_entry_` variable with our current PID.
|
||||
uptr count = internal_snprintf(kAtosMachPortEnvEntry,
|
||||
sizeof(kAtosMachPortEnvEntry),
|
||||
K_ATOS_ENV_VAR "=%s", pid_str_);
|
||||
CHECK_GE(count, sizeof(K_ATOS_ENV_VAR) + internal_strlen(pid_str_));
|
||||
// Document our assumption but without calling `getenv()` in normal
|
||||
// builds.
|
||||
DCHECK(getenv(K_ATOS_ENV_VAR));
|
||||
DCHECK_EQ(internal_strcmp(getenv(K_ATOS_ENV_VAR), pid_str_), 0);
|
||||
}
|
||||
|
||||
// Configure sandbox before starting atos process.
|
||||
return SymbolizerProcess::StartSymbolizerSubprocess();
|
||||
}
|
||||
|
||||
|
@ -140,10 +94,6 @@ class AtosSymbolizerProcess final : public SymbolizerProcess {
|
|||
}
|
||||
|
||||
char pid_str_[16];
|
||||
// Space for `\0` in `K_ATOS_ENV_VAR` is reused for `=`.
|
||||
static_assert(sizeof(kAtosMachPortEnvEntry) ==
|
||||
(sizeof(K_ATOS_ENV_VAR) + sizeof(pid_str_)),
|
||||
"sizes should match");
|
||||
};
|
||||
|
||||
#undef K_ATOS_ENV_VAR
|
||||
|
@ -249,8 +199,6 @@ bool AtosSymbolizer::SymbolizeData(uptr addr, DataInfo *info) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void AtosSymbolizer::LateInitialize() { process_->LateInitialize(); }
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // SANITIZER_MAC
|
||||
|
|
|
@ -35,7 +35,6 @@ class AtosSymbolizer final : public SymbolizerTool {
|
|||
|
||||
bool SymbolizePC(uptr addr, SymbolizedStack *stack) override;
|
||||
bool SymbolizeData(uptr addr, DataInfo *info) override;
|
||||
void LateInitialize() override;
|
||||
|
||||
private:
|
||||
AtosSymbolizerProcess *process_;
|
||||
|
|
|
@ -100,9 +100,7 @@ Symbolizer *Symbolizer::PlatformInit() {
|
|||
return new (symbolizer_allocator_) Symbolizer({});
|
||||
}
|
||||
|
||||
void Symbolizer::LateInitialize() {
|
||||
Symbolizer::GetOrInit()->LateInitializeTools();
|
||||
}
|
||||
void Symbolizer::LateInitialize() { Symbolizer::GetOrInit(); }
|
||||
|
||||
void StartReportDeadlySignal() {}
|
||||
void ReportDeadlySignal(const SignalContext &sig, u32 tid,
|
||||
|
|
|
@ -492,7 +492,7 @@ Symbolizer *Symbolizer::PlatformInit() {
|
|||
}
|
||||
|
||||
void Symbolizer::LateInitialize() {
|
||||
Symbolizer::GetOrInit()->LateInitializeTools();
|
||||
Symbolizer::GetOrInit();
|
||||
InitializeSwiftDemangler();
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ Symbolizer *Symbolizer::PlatformInit() {
|
|||
}
|
||||
|
||||
void Symbolizer::LateInitialize() {
|
||||
Symbolizer::GetOrInit()->LateInitializeTools();
|
||||
Symbolizer::GetOrInit();
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
|
Loading…
Reference in New Issue