Skip to content

Commit f9bd95d

Browse files
committed
remove old directives
1 parent dd5e4e9 commit f9bd95d

17 files changed

+224
-593
lines changed

backend/amd64/emit.ml

+3-105
Original file line numberDiff line numberDiff line change
@@ -43,107 +43,6 @@ module ND = Asm_targets.Asm_directives_new
4343
module S = Asm_targets.Asm_symbol
4444
module L = Asm_targets.Asm_label
4545

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

backend/arm64/emit.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,8 @@ let emit_literals p align emit_literal =
767767
D.switch_to_section_raw
768768
~names:["__TEXT,__literal" ^ Int.to_string align]
769769
~flags:None
770-
~args:[Int.to_string align ^ "byte_literals"];
770+
~args:[Int.to_string align ^ "byte_literals"]
771+
~is_delayed:false;
771772
(* CR sspies: The following section is incorrect. We are in a data section
772773
here. Fix this when cleaning up the section mechanism. *)
773774
D.unsafe_set_interal_section_ref Text);
@@ -1226,7 +1227,7 @@ let emit_named_text_section func_name =
12261227
the new asm directives. *)
12271228
D.switch_to_section_raw
12281229
~names:[".text.caml." ^ S.encode (S.create func_name)]
1229-
~flags:(Some "ax") ~args:["%progbits"];
1230+
~flags:(Some "ax") ~args:["%progbits"] ~is_delayed:false;
12301231
(* Warning: We set the internal section ref to Text here, because it
12311232
currently does not supported named text sections. In the rest of this
12321233
file, we pretend the section is called Text rather than the function
@@ -2237,5 +2238,5 @@ let end_assembly () =
22372238
| "linux" ->
22382239
(* Mark stack as non-executable *)
22392240
D.switch_to_section_raw ~names:[".note.GNU-stack"] ~flags:(Some "")
2240-
~args:["%progbits"]
2241+
~args:["%progbits"] ~is_delayed:false
22412242
| _ -> ()

backend/asm_targets/asm_directives.ml

+2-2
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)