Skip to content

Commit 39f53ad

Browse files
committed
comments and smart constructor for label offsets
1 parent ae0ac31 commit 39f53ad

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

backend/amd64/emit.ml

+13-4
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ let emit_imp_table () =
256256
D.qword (ConstLabel (emit_symbol s))
257257
in
258258
D.data ();
259-
D.comment "relocation table start";
259+
if !Clflags.keep_asm_file && !Flambda_backend_flags.dasm_comments
260+
then D.comment "relocation table start";
260261
D.align ~data:true 8;
261262
Hashtbl.iter f imp_table;
262-
D.comment "relocation table end"
263+
if !Clflags.keep_asm_file && !Flambda_backend_flags.dasm_comments
264+
then D.comment "relocation table end"
263265

264266
let mem__imp s =
265267
let imp_s = get_imp_symbol s in
@@ -2115,6 +2117,12 @@ let fundecl fundecl =
21152117
emit_function_type_and_size fundecl.fun_name
21162118

21172119
(* Emission of data *)
2120+
let const_label_offset s o : X86_ast.constant =
2121+
if Int64.equal o 0L
2122+
then ConstLabel s
2123+
else if Int64.compare o 0L > 0
2124+
then ConstAdd (ConstLabel s, Const o)
2125+
else ConstSub (ConstLabel s, Const (Int64.neg o))
21182126

21192127
let emit_item : Cmm.data_item -> unit = function
21202128
| Cdefine_symbol s -> (
@@ -2140,7 +2148,7 @@ let emit_item : Cmm.data_item -> unit = function
21402148
D.qword (ConstLabel (emit_cmm_symbol s))
21412149
| Csymbol_offset (s, o) ->
21422150
add_used_symbol s.sym_name;
2143-
D.qword (ConstLabelOffset (emit_cmm_symbol s, o))
2151+
D.qword (const_label_offset (emit_cmm_symbol s) (Int64.of_int o))
21442152
| Cstring s -> D.bytes s
21452153
| Cskip n -> if n > 0 then D.space n
21462154
| Calign n -> D.align ~data:true n
@@ -2340,7 +2348,8 @@ let emit_probe_handler_wrapper p =
23402348
(* Account for the return address that is now pushed on the stack. *)
23412349
stack_offset := !stack_offset + 8;
23422350
(* Emit function entry code *)
2343-
D.comment (Printf.sprintf "probe %s %s" probe_name handler_code_sym);
2351+
if !Clflags.keep_asm_file && !Flambda_backend_flags.dasm_comments
2352+
then D.comment (Printf.sprintf "probe %s %s" probe_name handler_code_sym);
23442353
emit_named_text_section wrap_label;
23452354
D.align ~data:false 16;
23462355
_label wrap_label;

backend/asm_targets/asm_directives_new.ml

+12-2
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,19 @@ let size ?size_of symbol =
623623

624624
let label ?comment label = const_machine_width ?comment (Label label)
625625

626+
(* CR sspies: Without this smart constructor, there is a difference in the dwarf
627+
assembly output. *)
628+
let const_add_offset s o =
629+
if Int64.equal o 0L
630+
then s
631+
else if Int64.compare o 0L > 0
632+
then const_add s (const_int64 o)
633+
else const_sub s (const_int64 (Int64.neg o))
634+
626635
let label_plus_offset ?comment lab ~offset_in_bytes =
627636
let offset_in_bytes = Targetint.to_int64 offset_in_bytes in
628637
let lab = const_label lab in
629-
const_machine_width ?comment (const_add lab (const_int64 offset_in_bytes))
638+
const_machine_width ?comment (const_add_offset lab offset_in_bytes)
630639

631640
let define_label label =
632641
let lbl_section = Asm_label.section label in
@@ -797,7 +806,8 @@ let symbol ?comment sym = const_machine_width ?comment (Symbol sym)
797806

798807
let symbol_plus_offset symbol ~offset_in_bytes =
799808
let offset_in_bytes = Targetint.to_int64 offset_in_bytes in
800-
const_machine_width (Add (Symbol symbol, Signed_int offset_in_bytes))
809+
let sym = Symbol symbol in
810+
const_machine_width (const_add_offset sym offset_in_bytes)
801811

802812
let int8 ?comment i =
803813
const ?comment (Signed_int (Int64.of_int (Int8.to_int i))) Eight

0 commit comments

Comments
 (0)