Skip to content

Commit c219e28

Browse files
authored
Binary emitter understands relocations emitted for probes (#1486)
1 parent 957b53c commit c219e28

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

backend/x86_binary_emitter.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,8 @@ let emit_SHR b dst src = emit_shift 5 b dst src
10231023

10241024
let emit_SAR b dst src = emit_shift 7 b dst src
10251025

1026-
let record_local_reloc b local_reloc =
1027-
local_relocs := (Buffer.length b.buf, local_reloc) :: !local_relocs
1026+
let record_local_reloc b ?(offset=0) local_reloc =
1027+
local_relocs := (Buffer.length b.buf + offset, local_reloc) :: !local_relocs
10281028

10291029
let emit_reloc_jump near_opcodes far_opcodes b loc symbol =
10301030
if String.Tbl.mem local_labels symbol then
@@ -1682,7 +1682,15 @@ let assemble_line b loc ins =
16821682
for _ = 1 to n do
16831683
buf_int8 b 0
16841684
done
1685-
| Hidden _ | Weak _ | Reloc _ | NewLine | Sleb128 _ | Uleb128 _ | Direct_assignment _ -> ()
1685+
| Hidden _ | Weak _ | NewLine -> ()
1686+
| Reloc { name = R_X86_64_PLT32;
1687+
expr = ConstSub (ConstLabel wrap_label, Const 4L);
1688+
offset = ConstSub (ConstThis, Const 4L);
1689+
} when String.Tbl.mem local_labels wrap_label ->
1690+
record_local_reloc b ~offset:(-4) (RelocCall wrap_label)
1691+
| Reloc _ | Sleb128 _ | Uleb128 _ | Direct_assignment _ ->
1692+
X86_gas.generate_asm Out_channel.stderr [ins];
1693+
Misc.fatal_errorf "x86_binary_emitter: unsupported instruction"
16861694
with e ->
16871695
Printf.eprintf "Exception %s:\n%!" (Printexc.to_string e);
16881696
(*

0 commit comments

Comments
 (0)