Skip to content

Commit 0237451

Browse files
authored
Semaphores for ocaml probes (#60)
* Separate semaphore for ocaml probes to correctly support probe_is_enabled * Emit semaphore symbol as weak and hidden and without compilation unit in its name * Update version of ocaml probe notes
1 parent 41722da commit 0237451

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

backend/amd64/emit.mlp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ let find_or_add_semaphore name =
559559
match String.Map.find_opt name !probe_semaphores with
560560
| Some label -> label
561561
| None ->
562-
let sym = Compilenv.make_symbol (Some ("semaphore_"^name)) in
562+
let sym = "caml_probes_semaphore_"^name in
563563
probe_semaphores := String.Map.add name sym !probe_semaphores;
564564
sym
565565

@@ -944,7 +944,11 @@ let emit_instr fallthrough i =
944944
semaphores are of type unsigned short.
945945
[1] https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
946946
*)
947-
I.mov (addressing (Ibased(semaphore_sym, 0)) WORD i 0) (res16 i 0);
947+
(* OCaml has it's own semaphore, in addition to system tap,
948+
to control ocaml probe handlers independently from stap probe handlers.
949+
It is placed immediately after stap semaphore, and is the same
950+
size - hence offset 2. *)
951+
I.mov (addressing (Ibased(semaphore_sym, 2)) WORD i 0) (res16 i 0);
948952
(* If the semaphore is 0, then the result is 0, otherwise 1. *)
949953
I.cmp (int 0) (res16 i 0);
950954
I.set (cond (Iunsigned Cne)) (res8 i 0);
@@ -1421,7 +1425,7 @@ let emit_probe_notes0 () =
14211425
D.qword (const 0)
14221426
end;
14231427
D.qword (ConstLabel semaphore_label);
1424-
D.bytes "ocaml\000";
1428+
D.bytes "ocaml.1\000";
14251429
D.bytes (probe_name ^ "\000");
14261430
D.bytes (args ^ "\000");
14271431
def_label d;
@@ -1448,9 +1452,11 @@ let emit_probe_notes0 () =
14481452
end;
14491453
D.align 2;
14501454
String.Map.iter (fun _ label ->
1451-
D.global label;
1455+
D.weak label;
1456+
D.hidden label;
14521457
_label label;
1453-
D.word (const 0);
1458+
D.word (const 0); (* for systemtap probes *)
1459+
D.word (const 0); (* for ocaml probes *)
14541460
add_def_symbol label)
14551461
!probe_semaphores
14561462

0 commit comments

Comments
 (0)