Skip to content

Commit ad2a96f

Browse files
gretay-jspoechsel
authored andcommitted
Revert "Semaphore without probes: dummy notes (#142)" (#242)
This reverts commit 8c9bf5e.
1 parent 1a432f6 commit ad2a96f

File tree

3 files changed

+55
-99
lines changed

3 files changed

+55
-99
lines changed

backend/amd64/emit.mlp

Lines changed: 44 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -528,29 +528,18 @@ let function_name = ref ""
528528
let tailrec_entry_point = ref None
529529

530530
(* Emit tracing probes *)
531-
type probe_handler =
532-
{
533-
probe_stack_offset: int;
534-
probe_num_stack_slots: int array;
535-
(* Record frame info held in the corresponding mutable variables. *)
536-
probe_handler_code_sym: string;
537-
(* Probe handler function symbol. *)
538-
probe_arg: Reg.t array;
539-
probe_live: Reg.Set.t;
540-
(* Information about Iprobe instruction,
541-
recorded at probe site and used for emitting the notes and
542-
the wrapper code at the end of the compilation unit. *)
543-
}
544531

545532
type probe =
546533
{
534+
stack_offset: int;
535+
num_stack_slots: int array;
536+
(* Record frame info held in the corresponding mutable variables. *)
547537
probe_label: label;
548538
(* Probe site, recorded in .note.stapsdt section
549539
for enabling and disabling the probes *)
550-
probe_name: string;
551-
(* User-defined name of the probe. *)
552-
probe_handler: probe_handler option;
553-
(* User-defined handler or None for dummy probes. *)
540+
probe_insn: Linear.instruction;
541+
(* Iprobe instruction, recorded at probe site and used for emitting
542+
the notes and the wrapper code at the end of the compilation unit. *)
554543
}
555544

556545
let probe_handler_wrapper_name probe_label =
@@ -946,20 +935,13 @@ let emit_instr fallthrough i =
946935
in
947936
I.prefetch is_write locality (addressing addr QWORD i 0)
948937
| Lop (Iname_for_debugger _) -> ()
949-
| Lop (Iprobe { name; handler_code_sym }) ->
938+
| Lop (Iprobe _) ->
950939
let probe_label = new_label () in
951-
let h =
952-
{ probe_handler_code_sym = handler_code_sym;
953-
probe_arg = Array.copy i.arg;
954-
probe_live = i.live;
955-
probe_stack_offset = !stack_offset;
956-
probe_num_stack_slots = Array.copy num_stack_slots;
957-
}
958-
in
959940
let probe =
960941
{ probe_label;
961-
probe_name = name;
962-
probe_handler = Some h;
942+
probe_insn = i;
943+
stack_offset = !stack_offset;
944+
num_stack_slots = Array.copy num_stack_slots;
963945
}
964946
in
965947
probes := probe :: !probes;
@@ -1301,20 +1283,23 @@ let make_stack_loc ~offset i (r : Reg.t) =
13011283

13021284
let emit_probe_handler_wrapper p =
13031285
let wrap_label = probe_handler_wrapper_name p.probe_label in
1304-
let h = Option.get p.probe_handler in
1286+
let probe_name, handler_code_sym =
1287+
match p.probe_insn.desc with
1288+
| Lop (Iprobe { name; handler_code_sym; }) -> name, handler_code_sym
1289+
| _ -> assert false
1290+
in
13051291
(* Restore stack frame info as it was at the probe site, so we can easily
13061292
refer to slots in the corresponding frame. (As per the comment above,
13071293
recall that the wrapper does however have its own frame.) *)
13081294
frame_required := true;
1309-
stack_offset := h.probe_stack_offset;
1295+
stack_offset := p.stack_offset;
13101296
for i = 0 to Proc.num_register_classes - 1 do
1311-
num_stack_slots.(i) <- h.probe_num_stack_slots.(i);
1297+
num_stack_slots.(i) <- p.num_stack_slots.(i);
13121298
done;
13131299
(* Account for the return address that is now pushed on the stack. *)
13141300
stack_offset := !stack_offset + 8;
13151301
(* Emit function entry code *)
1316-
D.comment (Printf.sprintf "probe %s %s" p.probe_name
1317-
h.probe_handler_code_sym);
1302+
D.comment (Printf.sprintf "probe %s %s" probe_name handler_code_sym);
13181303
emit_named_text_section wrap_label;
13191304
D.align 16;
13201305
_label wrap_label;
@@ -1328,15 +1313,15 @@ let emit_probe_handler_wrapper p =
13281313
assert (size_addr = 8 && size_int = 8 && size_float = 8);
13291314
(* Compute the size of stack slots for all live hard registers. *)
13301315
let live =
1331-
Reg.Set.elements h.probe_live
1316+
Reg.Set.elements p.probe_insn.live
13321317
|> List.filter Reg.is_reg
13331318
|> Array.of_list
13341319
in
13351320
let live_offset = 8 * (Array.length live) in
13361321
(* Compute the size of stack slots for spilling all arguments of the probe. *)
13371322
let aux_offset = 8 (* for saving r15 *) in
1338-
let tmp_offset = 8 * (Array.length h.probe_arg) in
1339-
let loc_args, loc_offset = Proc.loc_arguments (Reg.typv h.probe_arg) in
1323+
let tmp_offset = 8 * (Array.length p.probe_insn.arg) in
1324+
let loc_args, loc_offset = Proc.loc_arguments (Reg.typv p.probe_insn.arg) in
13401325
(* Ensure the stack is aligned.
13411326
Assuming that the stack at the probe site is 16-byte aligned,
13421327
[loc_arguments] ensures that [loc_offset] is 16-byte aligned.
@@ -1360,16 +1345,16 @@ let emit_probe_handler_wrapper p =
13601345
I.mov r15 (reg saved_r15);
13611346
(* Spill all arguments of the probe. Some of these may already be on the
13621347
stack, in which case a temporary is used for the move. *)
1363-
let tmp = Array.mapi (make_stack_loc ~offset:loc_offset) h.probe_arg in
1348+
let tmp = Array.mapi (make_stack_loc ~offset:loc_offset) p.probe_insn.arg in
13641349
Array.iteri (fun i reg -> move_allowing_stack_to_stack reg (tmp.(i)))
1365-
h.probe_arg;
1350+
p.probe_insn.arg;
13661351
(* Load probe arguments to correct locations for the handler *)
13671352
Array.iteri (fun i reg -> move_allowing_stack_to_stack tmp.(i) reg) loc_args;
13681353
(* Reload spilled registers used as temporaries *)
13691354
I.mov (reg saved_r15) r15;
13701355
(* Emit call to handler *)
1371-
add_used_symbol h.probe_handler_code_sym;
1372-
emit_call h.probe_handler_code_sym;
1356+
add_used_symbol handler_code_sym;
1357+
emit_call handler_code_sym;
13731358
(* Record a frame description for the wrapper *)
13741359
let label = new_label () in
13751360
let live_offset =
@@ -1398,7 +1383,7 @@ let emit_probe_handler_wrapper p =
13981383
cfi_endproc ();
13991384
emit_function_type_and_size wrap_label
14001385

1401-
let emit_probe_notes0 probes =
1386+
let emit_probe_notes0 () =
14021387
begin match system with
14031388
| S_gnu | S_cygwin | S_solaris | S_win32 | S_linux_elf | S_bsd_elf
14041389
| S_beos | S_mingw | S_win64 | S_linux | S_mingw64 | S_unknown ->
@@ -1418,16 +1403,18 @@ let emit_probe_notes0 probes =
14181403
Printf.sprintf "%d@%s" (Reg.size_of_contents_in_bytes arg) arg_name
14191404
in
14201405
let describe_one_probe p =
1406+
let probe_name =
1407+
match p.probe_insn.desc with
1408+
| Lop (Iprobe { name; _; }) -> name
1409+
| _ -> assert false
1410+
in
14211411
let args =
1422-
match p.probe_handler with
1423-
| None -> ""
1424-
| Some h ->
1425-
Array.fold_right (fun arg acc -> (stap_arg arg)::acc)
1426-
h.probe_arg
1427-
[]
1428-
|> String.concat " "
1412+
Array.fold_right (fun arg acc -> (stap_arg arg)::acc)
1413+
p.probe_insn.arg
1414+
[]
1415+
|> String.concat " "
14291416
in
1430-
let semaphore_label = emit_symbol (find_or_add_semaphore p.probe_name) in
1417+
let semaphore_label = emit_symbol (find_or_add_semaphore probe_name) in
14311418
D.align 4;
14321419
let a = new_label() in
14331420
let b = new_label() in
@@ -1453,13 +1440,13 @@ let emit_probe_notes0 probes =
14531440
D.qword (const 0)
14541441
end;
14551442
D.qword (ConstLabel semaphore_label);
1456-
D.bytes "ocaml.2\000";
1457-
D.bytes (p.probe_name ^ "\000");
1443+
D.bytes "ocaml.1\000";
1444+
D.bytes (probe_name ^ "\000");
14581445
D.bytes (args ^ "\000");
14591446
def_label d;
14601447
D.align 4;
14611448
in
1462-
List.iter describe_one_probe probes;
1449+
List.iter describe_one_probe !probes;
14631450
begin match system with
14641451
| S_gnu | S_cygwin | S_solaris | S_win32 | S_linux_elf | S_bsd_elf
14651452
| S_beos | S_mingw | S_win64 | S_linux | S_mingw64 | S_unknown ->
@@ -1488,49 +1475,10 @@ let emit_probe_notes0 probes =
14881475
add_def_symbol label)
14891476
!probe_semaphores
14901477

1491-
let emit_probe_notes probes =
1492-
match probes, String.Map.is_empty !probe_semaphores with
1493-
| [], true -> ()
1494-
| _ -> emit_probe_notes0 probes
1495-
1496-
let emit_dummy_probe_sites () =
1497-
let semaphores_without_probes =
1498-
List.fold_left (fun acc probe ->
1499-
String.Map.remove probe.probe_name acc)
1500-
!probe_semaphores !probes in
1501-
if (String.Map.is_empty semaphores_without_probes) then []
1502-
else begin
1503-
let fun_name = Compilenv.make_symbol (Some "___dummy_probes") in
1504-
1505-
(* start the function (as in fundecl) *)
1506-
emit_named_text_section fun_name;
1507-
D.align 16;
1508-
add_def_symbol fun_name;
1509-
D.global (emit_symbol fun_name);
1510-
D.label (emit_symbol fun_name);
1511-
cfi_startproc ();
1512-
1513-
(* emit dummy probe sites: labeled NOP only for stapsdt probes to work,
1514-
but no calls to probe wrapper because there is no ocaml probe handler. *)
1515-
let dummy_probes =
1516-
String.Map.fold (fun probe_name _label acc ->
1517-
let probe_label = new_label () in
1518-
def_label probe_label;
1519-
I.nop (); (* for uprobes and usdt probes as well *)
1520-
let probe = { probe_name;
1521-
probe_label;
1522-
probe_handler = None;
1523-
}
1524-
in
1525-
probe :: acc)
1526-
semaphores_without_probes []
1527-
in
1528-
I.ret ();
1529-
(* end the function (as in fundecl) *)
1530-
cfi_endproc ();
1531-
emit_function_type_and_size fun_name;
1532-
dummy_probes
1533-
end
1478+
let emit_probe_notes () =
1479+
match !probes with
1480+
| [] -> ()
1481+
| _ -> emit_probe_notes0 ()
15341482

15351483
let end_assembly() =
15361484
if !float_constants <> [] then begin
@@ -1547,9 +1495,6 @@ let end_assembly() =
15471495
(* Emit probe handler wrappers *)
15481496
List.iter emit_probe_handler_wrapper !probes;
15491497

1550-
(* Emit dummy probes for semaphores without probes in this compilation unit. *)
1551-
let dummy_probes = emit_dummy_probe_sites () in
1552-
15531498
emit_named_text_section (Compilenv.make_symbol (Some "code_end"));
15541499
if system = S_macosx then I.nop ();
15551500
(* suppress "ld warning: atom sorting error" *)
@@ -1599,7 +1544,7 @@ let end_assembly() =
15991544
D.size frametable (ConstSub (ConstThis, ConstLabel frametable))
16001545
end;
16011546

1602-
emit_probe_notes (dummy_probes @ !probes);
1547+
emit_probe_notes ();
16031548

16041549
if system = S_linux then
16051550
(* Mark stack as non-executable, PR#4564 *)

ocaml/typing/typecore.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ type error =
124124
| Probe_format
125125
| Probe_name_too_long of string
126126
| Probe_name_format of string
127+
| Probe_name_undefined of string
127128
| Probe_is_enabled_format
128129
| Literal_overflow of string
129130
| Unknown_literal of string * char
@@ -3752,6 +3753,10 @@ and type_expect_
37523753
_ } ,
37533754
_)}]) ->
37543755
check_probe_name name name_loc env;
3756+
add_delayed_check
3757+
(fun () ->
3758+
if not (Env.has_probe name) then
3759+
raise(Error(name_loc, env, (Probe_name_undefined name))));
37553760
rue {
37563761
exp_desc = Texp_probe_is_enabled {name};
37573762
exp_loc = loc; exp_extra = [];
@@ -5601,6 +5606,11 @@ let report_error ~loc env = function
56015606
Probe names may only contain alphanumeric characters or \
56025607
underscores."
56035608
name
5609+
| Probe_name_undefined name ->
5610+
Location.errorf ~loc
5611+
"Undefined probe name `%s' used in %%probe_is_enabled. \
5612+
Not found [%%probe \"%s\" ...] in the same compilation unit."
5613+
name name
56045614
| Probe_format ->
56055615
Location.errorf ~loc
56065616
"Probe points must consist of a name, as a string \

ocaml/typing/typecore.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ type error =
181181
| Probe_format
182182
| Probe_name_too_long of string
183183
| Probe_name_format of string
184+
| Probe_name_undefined of string
184185
(* CR-soon mshinwell: Use an inlined record *)
185186
| Probe_is_enabled_format
186187
| Literal_overflow of string

0 commit comments

Comments
 (0)