@@ -43,107 +43,6 @@ module ND = Asm_targets.Asm_directives_new
43
43
module S = Asm_targets. Asm_symbol
44
44
module L = Asm_targets. Asm_label
45
45
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
-
147
46
(* * Turn a Linear label into an assembly label. The section is checked against the
148
47
section tracked by [D] when emitting label definitions. *)
149
48
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 =
351
250
| _ ->
352
251
ND. switch_to_section_raw
353
252
~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 ;
355
254
(* Warning: We set the internal section ref to Text here, because it
356
255
currently does not supported named text sections. In the rest of this
357
256
file, we pretend the section is called Text rather than the function
@@ -2428,8 +2327,7 @@ let begin_assembly unix =
2428
2327
ND. initialize ~big_endian: Arch. big_endian
2429
2328
~emit_assembly_comments: ! Flambda_backend_flags. dasm_comments
2430
2329
(* 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));
2433
2331
let code_begin = Cmm_helpers. make_symbol " code_begin" in
2434
2332
let code_end = Cmm_helpers. make_symbol " code_end" in
2435
2333
Emitaux.Dwarf_helpers. begin_dwarf ~code_begin ~code_end ~file_emitter ;
@@ -2901,7 +2799,7 @@ let end_assembly () =
2901
2799
then
2902
2800
(* Mark stack as non-executable, PR#4564 *)
2903
2801
ND. switch_to_section_raw ~names: [" .note.GNU-stack" ] ~flags: (Some " " )
2904
- ~args: [" %progbits" ];
2802
+ ~args: [" %progbits" ] ~is_delayed: false ;
2905
2803
if is_win64 system
2906
2804
then (
2907
2805
ND. comment " External functions" ;
0 commit comments