Skip to content

Commit a9457e8

Browse files
authored
Remove old x86 Directives (#3948)
1 parent 8263ffe commit a9457e8

17 files changed

+229
-578
lines changed

backend/amd64/emit.ml

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -44,108 +44,6 @@ module ND = Asm_targets.Asm_directives_new
4444
module S = Asm_targets.Asm_symbol
4545
module L = Asm_targets.Asm_label
4646

47-
let rec to_x86_constant (c : ND.Directive.Constant.t) : X86_ast.constant =
48-
match c with
49-
| Signed_int i -> Const i
50-
| Unsigned_int i -> Const (Numbers.Uint64.to_int64 i)
51-
| This -> ConstThis
52-
| Named_thing s ->
53-
ConstLabel s
54-
(* both seem to be printed directly to the buffer without any conversion*)
55-
| Add (c1, c2) -> ConstAdd (to_x86_constant c1, to_x86_constant c2)
56-
| Sub (c1, c2) -> ConstSub (to_x86_constant c1, to_x86_constant c2)
57-
58-
let to_x86_constant_with_width (c : ND.Directive.Constant_with_width.t) :
59-
X86_ast.asm_line =
60-
let width = ND.Directive.Constant_with_width.width_in_bytes c in
61-
let const = ND.Directive.Constant_with_width.constant c in
62-
let const = to_x86_constant const in
63-
match width with
64-
| Eight -> Byte const
65-
(* on x86 Word is 2 bytes; warning this is not the same on Arm *)
66-
| Sixteen -> Word const
67-
| Thirty_two -> Long const
68-
| Sixty_four -> Quad const
69-
70-
let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
71-
let comment_lines comment =
72-
(* CR sspies: This check is usually done in the printing function of the new
73-
directives. Since we are skipping those at the moment (by emitting via
74-
the X86 DSL), we do the same check here in the conversion. *)
75-
if !Clflags.keep_asm_file && !Flambda_backend_flags.dasm_comments
76-
then Option.to_list (Option.map (fun s -> X86_ast.Comment s) comment)
77-
else []
78-
in
79-
match dir with
80-
| Align { bytes; fill_x86_bin_emitter } ->
81-
let data = match fill_x86_bin_emitter with Zero -> true | Nop -> false in
82-
[X86_ast.Align (data, bytes)]
83-
(* The [fill_x86_bin_emitter] field is currently ignored by GAS and MASM,
84-
but used in the binary emitter. The bytes field is only converted to the
85-
final value when printing. *)
86-
| Bytes { str; comment } -> comment_lines comment @ [X86_ast.Bytes str]
87-
| Comment s -> comment_lines (Some s)
88-
| Const { constant; comment } ->
89-
comment_lines comment @ [to_x86_constant_with_width constant]
90-
| Direct_assignment (s, c) ->
91-
(* We use [.set s c] for direct assignments, since it evaluates [c]
92-
directly. The alternative, [s = c], is sensitive to relocations. *)
93-
[X86_ast.Set (s, to_x86_constant c)]
94-
| File { file_num = None; _ } ->
95-
Misc.fatal_error "file directive must always carry a number on x86"
96-
| File { file_num = Some file_num; filename } ->
97-
[X86_ast.File (file_num, filename)]
98-
| Global s -> [X86_ast.Global s]
99-
| Indirect_symbol s -> [X86_ast.Indirect_symbol s]
100-
| Loc { file_num; line; col; discriminator } ->
101-
(* Behavior differs for negative column values. x86 will not output
102-
anything, but new directives will output 0. *)
103-
[X86_ast.Loc { file_num; line; col; discriminator }]
104-
(* CR sspies: The [typ] matters only for MASM. The convention (implemented in
105-
asm directives) is that in the text section, we use Code (NONE) and in the
106-
data section, we use Machine_width_data (QWORD for amd64). The two will be
107-
emitted differently by MASM. Because some code such as the frame tables
108-
have moved from the data section to the text section (but were previously
109-
still emitted with QUAD), using the new directives below changes this
110-
behavior. *)
111-
| New_label (s, Code) -> [X86_ast.NewLabel (s, NONE)]
112-
| New_label (s, Machine_width_data) -> [X86_ast.NewLabel (s, QWORD)]
113-
| New_line -> [X86_ast.NewLine]
114-
| Private_extern s -> [X86_ast.Private_extern s]
115-
| Section { names; flags; args } ->
116-
[X86_ast.Section (names, flags, args, false)]
117-
(* delayed for this directive is always ignored in GAS printing, and section
118-
is not supported in binary emitter. In MASM, it only supports .text and
119-
.data. *)
120-
| Size (s, c) -> [X86_ast.Size (s, to_x86_constant c)]
121-
| Sleb128 { constant; comment } ->
122-
comment_lines comment @ [X86_ast.Sleb128 (to_x86_constant constant)]
123-
| Space { bytes } -> [Space bytes]
124-
| Type (n, st) ->
125-
let typ = ND.symbol_type_to_string st in
126-
[Type (n, typ)]
127-
| Uleb128 { constant; comment } ->
128-
comment_lines comment @ [X86_ast.Uleb128 (to_x86_constant constant)]
129-
| Cfi_adjust_cfa_offset n -> [X86_ast.Cfi_adjust_cfa_offset n]
130-
| Cfi_def_cfa_offset n -> [X86_ast.Cfi_def_cfa_offset n]
131-
| Cfi_endproc -> [X86_ast.Cfi_endproc]
132-
| Cfi_offset { reg; offset } -> [X86_ast.Cfi_offset (reg, offset)]
133-
| Cfi_startproc -> [X86_ast.Cfi_startproc]
134-
| Cfi_remember_state -> [X86_ast.Cfi_remember_state]
135-
| Cfi_restore_state -> [X86_ast.Cfi_restore_state]
136-
| Cfi_def_cfa_register r -> [X86_ast.Cfi_def_cfa_register r]
137-
| Protected s -> [X86_ast.Protected s]
138-
| Hidden s -> [X86_ast.Hidden s]
139-
| Weak s -> [X86_ast.Weak s]
140-
| External s -> [X86_ast.External (s, NEAR)]
141-
(* All uses of [.extrn] use NEAR as the type. *)
142-
| Reloc { offset; name = R_X86_64_PLT32; expr } ->
143-
[ X86_ast.Reloc
144-
{ offset = to_x86_constant offset;
145-
name = R_X86_64_PLT32;
146-
expr = to_x86_constant expr
147-
} ]
148-
14947
(** Turn a Linear label into an assembly label. The section is checked against the
15048
section tracked by [D] when emitting label definitions. *)
15149
let label_to_asm_label (l : label) ~(section : Asm_targets.Asm_section.t) : L.t
@@ -348,7 +246,7 @@ let emit_named_text_section ?(suffix = "") func_name =
348246
| _ ->
349247
ND.switch_to_section_raw
350248
~names:[Printf.sprintf ".text.caml.%s%s" (emit_symbol func_name) suffix]
351-
~flags:(Some "ax") ~args:["@progbits"];
249+
~flags:(Some "ax") ~args:["@progbits"] ~is_delayed:false;
352250
(* Warning: We set the internal section ref to Text here, because it
353251
currently does not supported named text sections. In the rest of this
354252
file, we pretend the section is called Text rather than the function
@@ -2237,8 +2135,7 @@ let begin_assembly unix =
22372135
ND.initialize ~big_endian:Arch.big_endian
22382136
~emit_assembly_comments:!Flambda_backend_flags.dasm_comments
22392137
(* As a first step, we emit by calling the corresponding x86 emit
2240-
directives. *) ~emit:(fun d ->
2241-
List.iter directive (to_x86_directive d));
2138+
directives. *) ~emit:(fun d -> directive (Directive d));
22422139
let code_begin = Cmm_helpers.make_symbol "code_begin" in
22432140
let code_end = Cmm_helpers.make_symbol "code_end" in
22442141
Emitaux.Dwarf_helpers.begin_dwarf ~code_begin ~code_end ~file_emitter;

backend/arm64/emit.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ let emit_literals p align emit_literal =
776776
D.switch_to_section_raw
777777
~names:["__TEXT,__literal" ^ Int.to_string align]
778778
~flags:None
779-
~args:[Int.to_string align ^ "byte_literals"];
779+
~args:[Int.to_string align ^ "byte_literals"]
780+
~is_delayed:false;
780781
(* CR sspies: The following section is incorrect. We are in a data section
781782
here. Fix this when cleaning up the section mechanism. *)
782783
D.unsafe_set_internal_section_ref Text);
@@ -1236,7 +1237,7 @@ let emit_named_text_section func_name =
12361237
the new asm directives. *)
12371238
D.switch_to_section_raw
12381239
~names:[".text.caml." ^ S.encode (S.create func_name)]
1239-
~flags:(Some "ax") ~args:["%progbits"];
1240+
~flags:(Some "ax") ~args:["%progbits"] ~is_delayed:false;
12401241
(* Warning: We set the internal section ref to Text here, because it
12411242
currently does not supported named text sections. In the rest of this
12421243
file, we pretend the section is called Text rather than the function

backend/asm_targets/asm_directives.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ module Make (A : Asm_directives_intf.Arg) : Asm_directives_intf.S = struct
135135
()
136136
| _ ->
137137
current_dwarf_section_ref := Some section;
138-
let ({ names; flags; args } : Asm_section.section_details) =
138+
let ({ names; flags; args; is_delayed } : Asm_section.section_details) =
139139
Asm_section.details section ~first_occurrence
140140
in
141141
if not first_occurrence then new_line ();
142-
D.section ~delayed:(Asm_section.is_delayed section) names flags args;
142+
D.section ~delayed:is_delayed names flags args;
143143
if first_occurrence then define_label (Asm_label.for_section section)
144144

145145
let initialize () =

0 commit comments

Comments
 (0)