Skip to content

Commit 1e3b86a

Browse files
Address reviewer feedback
1 parent 106ef2f commit 1e3b86a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

compiler-rt/lib/xray/xray_init.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ __xray_register_sleds(const XRaySledEntry *SledsBegin,
102102
return -1;
103103
}
104104

105-
if (Verbosity()) {
105+
if (Verbosity())
106106
Report("Registering %d new functions!\n", SledMap.Functions);
107-
}
108107

109108
{
110109
SpinMutexLock Guard(&XRayInstrMapMutex);
@@ -145,9 +144,15 @@ void __xray_init() XRAY_NEVER_INSTRUMENT {
145144
// Pre-allocation takes up approx. 5kB for XRayMaxObjects=64.
146145
XRayInstrMaps = allocateBuffer<XRaySledMap>(XRayMaxObjects);
147146

148-
__xray_register_sleds(__start_xray_instr_map, __stop_xray_instr_map,
147+
int MainBinaryId = __xray_register_sleds(__start_xray_instr_map, __stop_xray_instr_map,
149148
__start_xray_fn_idx, __stop_xray_fn_idx, false, {});
150149

150+
// The executable should always get ID 0.
151+
if (MainBinaryId != 0) {
152+
Report("Registering XRay sleds failed.\n");
153+
return;
154+
}
155+
151156
atomic_store(&XRayInitialized, true, memory_order_release);
152157

153158
#ifndef XRAY_NO_PREINIT
@@ -187,8 +192,12 @@ SANITIZER_INTERFACE_ATTRIBUTE int32_t __xray_register_dso(
187192

188193
SANITIZER_INTERFACE_ATTRIBUTE bool
189194
__xray_deregister_dso(int32_t ObjId) XRAY_NEVER_INSTRUMENT {
190-
// Make sure XRay has been initialized in the main executable.
191-
__xray_init();
195+
196+
if (!atomic_load(&XRayInitialized, memory_order_acquire)) {
197+
if (Verbosity())
198+
Report("XRay has not been initialized. Cannot deregister DSO.\n");
199+
return false;
200+
}
192201

193202
if (ObjId <= 0 || ObjId >= __xray_num_objects()) {
194203
if (Verbosity())
@@ -210,8 +219,9 @@ __xray_deregister_dso(int32_t ObjId) XRAY_NEVER_INSTRUMENT {
210219
if (Verbosity())
211220
Report("Can't deregister object with ID %d: object is not loaded.\n",
212221
ObjId);
222+
return false;
213223
}
214-
// This is all we have to do here.
224+
// Mark DSO as unloaded. No need to unpatch.
215225
Entry.Loaded = false;
216226
}
217227

0 commit comments

Comments
 (0)