Skip to content

Commit 58a16d8

Browse files
committed
Reland "[BOLT][Instrumentation] Don't share counters when using append-pid"
This reverts commit c15e9b6. The issue appears unrelated as the crash happened in the BOLTed binary, not instrumented binary.
1 parent afd2058 commit 58a16d8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

bolt/runtime/instr.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,25 +1586,29 @@ extern "C" void __bolt_instr_indirect_tailcall();
15861586

15871587
/// Initialization code
15881588
extern "C" void __attribute((force_align_arg_pointer)) __bolt_instr_setup() {
1589+
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
1590+
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
1591+
15891592
const uint64_t CountersStart =
15901593
reinterpret_cast<uint64_t>(&__bolt_instr_locations[0]);
15911594
const uint64_t CountersEnd = alignTo(
15921595
reinterpret_cast<uint64_t>(&__bolt_instr_locations[__bolt_num_counters]),
15931596
0x1000);
15941597
DEBUG(reportNumber("replace mmap start: ", CountersStart, 16));
15951598
DEBUG(reportNumber("replace mmap stop: ", CountersEnd, 16));
1596-
assert (CountersEnd > CountersStart, "no counters");
1597-
// Maps our counters to be shared instead of private, so we keep counting for
1598-
// forked processes
1599+
assert(CountersEnd > CountersStart, "no counters");
1600+
1601+
const bool Shared = !__bolt_instr_use_pid;
1602+
const uint64_t MapPrivateOrShared = Shared ? MAP_SHARED : MAP_PRIVATE;
1603+
15991604
void *Ret =
16001605
__mmap(CountersStart, CountersEnd - CountersStart, PROT_READ | PROT_WRITE,
1601-
MAP_ANONYMOUS | MAP_SHARED | MAP_FIXED, -1, 0);
1606+
MAP_ANONYMOUS | MapPrivateOrShared | MAP_FIXED, -1, 0);
16021607
assert(Ret != MAP_FAILED, "__bolt_instr_setup: Failed to mmap counters!");
1603-
__bolt_ind_call_counter_func_pointer = __bolt_instr_indirect_call;
1604-
__bolt_ind_tailcall_counter_func_pointer = __bolt_instr_indirect_tailcall;
1608+
16051609
// Conservatively reserve 100MiB shared pages
16061610
GlobalAlloc.setMaxSize(0x6400000);
1607-
GlobalAlloc.setShared(true);
1611+
GlobalAlloc.setShared(Shared);
16081612
GlobalWriteProfileMutex = new (GlobalAlloc, 0) Mutex();
16091613
if (__bolt_instr_num_ind_calls > 0)
16101614
GlobalIndCallCounters =

0 commit comments

Comments
 (0)