Skip to content

Commit 77ac450

Browse files
authored
Revert "Use new directives on x86" (#3985)
Revert "Use new directives on x86 (#3931)" This reverts commit 66a06b9.
1 parent 586cc9e commit 77ac450

11 files changed

+457
-659
lines changed

backend/amd64/emit.ml

+401-454
Large diffs are not rendered by default.

backend/arm64/emit.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ let emit_literals p align emit_literal =
776776
(* CR sspies: The following section is incorrect. We are in a data section
777777
here. Fix this when cleaning up the section mechanism. *)
778778
D.unsafe_set_internal_section_ref Text);
779-
D.align ~fill_x86_bin_emitter:Nop ~bytes:align;
779+
D.align ~bytes:align;
780780
List.iter emit_literal !p;
781781
p := [])
782782

@@ -2080,7 +2080,7 @@ let fundecl fundecl =
20802080
contains_calls := fundecl.fun_contains_calls;
20812081
emit_named_text_section !function_name;
20822082
let fun_sym = S.create fundecl.fun_name in
2083-
D.align ~fill_x86_bin_emitter:Nop ~bytes:8;
2083+
D.align ~bytes:8;
20842084
D.global fun_sym;
20852085
D.type_symbol ~ty:Function fun_sym;
20862086
D.define_symbol_label ~section:Text fun_sym;
@@ -2141,11 +2141,11 @@ let emit_item (d : Cmm.data_item) =
21412141
D.symbol_plus_offset ~offset_in_bytes:(Targetint.of_int o) sym
21422142
| Cstring s -> D.string s
21432143
| Cskip n -> D.space ~bytes:n
2144-
| Calign n -> D.align ~fill_x86_bin_emitter:Zero ~bytes:n
2144+
| Calign n -> D.align ~bytes:n
21452145

21462146
let data l =
21472147
D.data ();
2148-
D.align ~fill_x86_bin_emitter:Zero ~bytes:8;
2148+
D.align ~bytes:8;
21492149
List.iter emit_item l
21502150

21512151
let file_emitter ~file_num ~file_name =
@@ -2183,7 +2183,7 @@ let begin_assembly _unix =
21832183
if macosx
21842184
then (
21852185
DSL.ins I.NOP [||];
2186-
D.align ~fill_x86_bin_emitter:Nop ~bytes:8);
2186+
D.align ~bytes:8);
21872187
let code_end = Cmm_helpers.make_symbol "code_end" in
21882188
Emitaux.Dwarf_helpers.begin_dwarf ~code_begin ~code_end ~file_emitter
21892189

@@ -2201,7 +2201,7 @@ let end_assembly () =
22012201
D.global data_end_sym;
22022202
D.define_symbol_label ~section:Data data_end_sym;
22032203
D.int64 0L;
2204-
D.align ~fill_x86_bin_emitter:Zero ~bytes:8;
2204+
D.align ~bytes:8;
22052205
(* #7887 *)
22062206
let frametable = Cmm_helpers.make_symbol "frametable" in
22072207
let frametable_sym = S.create frametable in
@@ -2224,7 +2224,7 @@ let end_assembly () =
22242224
(* CR sspies: for some reason, we can get negative numbers here *)
22252225
efa_32 = (fun n -> D.int32 n);
22262226
efa_word = (fun n -> D.targetint (Targetint.of_int_exn n));
2227-
efa_align = (fun n -> D.align ~fill_x86_bin_emitter:Zero ~bytes:n);
2227+
efa_align = (fun n -> D.align ~bytes:n);
22282228
efa_label_rel =
22292229
(fun lbl ofs ->
22302230
let lbl = label_to_asm_label ~section:Data lbl in

backend/asm_targets/asm_directives_new.ml

+9-79
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ type symbol_type =
6060
| Function
6161
| Object
6262

63-
type align_padding =
64-
| Nop
65-
| Zero
66-
6763
(* CR sspies: We should use the "STT" forms when they are supported as they are
6864
unambiguous across platforms (cf.
6965
https://sourceware.org/binutils/docs/as/Type.html). *)
@@ -149,15 +145,10 @@ module Directive = struct
149145
| Code
150146
| Machine_width_data
151147

152-
type reloc_type = R_X86_64_PLT32
153-
154148
type comment = string
155149

156150
type t =
157-
| Align of
158-
{ bytes : int;
159-
fill_x86_bin_emitter : align_padding
160-
}
151+
| Align of { bytes : int }
161152
| Bytes of
162153
{ str : string;
163154
comment : string option
@@ -211,14 +202,6 @@ module Directive = struct
211202
comment : string option
212203
}
213204
| Protected of string
214-
| Hidden of string
215-
| Weak of string
216-
| External of string
217-
| Reloc of
218-
{ offset : Constant.t;
219-
name : reloc_type;
220-
expr : Constant.t
221-
}
222205

223206
let bprintf = Printf.bprintf
224207

@@ -283,8 +266,6 @@ module Directive = struct
283266
bprintf buf "\t.ascii\t\"%s\""
284267
(string_of_string_literal (String.sub s !i (l - !i)))
285268

286-
let reloc_type_to_string = function R_X86_64_PLT32 -> "R_X86_64_PLT32"
287-
288269
let print_gas buf t =
289270
let gas_comment_opt comment_opt =
290271
if not (emit_comments ())
@@ -295,10 +276,7 @@ module Directive = struct
295276
| Some comment -> Printf.sprintf "\t/* %s */" comment
296277
in
297278
match t with
298-
| Align { bytes = n; fill_x86_bin_emitter = _ } ->
299-
(* The flag [fill_x86_bin_emitter] is only relevant for the binary
300-
emitter. On GAS, we can ignore it and just use [.align] in both
301-
cases. *)
279+
| Align { bytes = n } ->
302280
(* Some assemblers interpret the integer n as a 2^n alignment and others
303281
as a number of bytes. *)
304282
let n =
@@ -398,14 +376,6 @@ module Directive = struct
398376
Misc.fatal_error
399377
"Cannot emit [Direct_assignment] except on macOS-like assemblers")
400378
| Protected s -> bprintf buf "\t.protected\t%s" s
401-
| Hidden s -> bprintf buf "\t.hidden\t%s" s
402-
| Weak s -> bprintf buf "\t.weak\t%s" s
403-
(* masm only *)
404-
| External _ -> assert false
405-
| Reloc { offset; name; expr } ->
406-
bprintf buf "\t.reloc\t%a, %s, %a" Constant.print offset
407-
(reloc_type_to_string name)
408-
Constant.print expr
409379

410380
let print_masm buf t =
411381
let unsupported name =
@@ -420,10 +390,7 @@ module Directive = struct
420390
| Some comment -> Printf.sprintf "\t; %s" comment
421391
in
422392
match t with
423-
| Align { bytes; fill_x86_bin_emitter = _ } ->
424-
(* The flag [fill_x86_bin_emitter] is only relevant for the x86 binary
425-
emitter. On MASM, we can ignore it. *)
426-
bprintf buf "\tALIGN\t%d" bytes
393+
| Align { bytes } -> bprintf buf "\tALIGN\t%d" bytes
427394
| Bytes { str; comment } ->
428395
buf_bytes_directive buf ~directive:"BYTE" str;
429396
bprintf buf "%s" (masm_comment_opt comment)
@@ -469,11 +436,6 @@ module Directive = struct
469436
| Uleb128 _ -> unsupported "Uleb128"
470437
| Direct_assignment _ -> unsupported "Direct_assignment"
471438
| Protected _ -> unsupported "Protected"
472-
| Hidden _ -> unsupported "Hidden"
473-
| Weak _ -> unsupported "Weak"
474-
| External s -> bprintf buf "\tEXTRN\t%s: NEAR" s
475-
(* The only supported "type" on EXTRN declarations is NEAR. *)
476-
| Reloc _ -> unsupported "Reloc"
477439

478440
let print b t =
479441
match TS.assembler () with
@@ -518,13 +480,6 @@ let const_variable var = Variable var
518480

519481
let const_int64 i : expr = Signed_int i
520482

521-
let const_with_offset const (offset : int64) =
522-
if Int64.equal offset 0L
523-
then const
524-
else if Int64.compare offset 0L < 0
525-
then Sub (const, Signed_int (Int64.neg offset))
526-
else Add (const, Signed_int offset)
527-
528483
let emit_ref = ref None
529484

530485
let emit (d : Directive.t) =
@@ -537,8 +492,7 @@ let emit_non_masm (d : Directive.t) =
537492

538493
let section ~names ~flags ~args = emit (Section { names; flags; args })
539494

540-
let align ~fill_x86_bin_emitter ~bytes =
541-
emit (Align { bytes; fill_x86_bin_emitter })
495+
let align ~bytes = emit (Align { bytes })
542496

543497
let should_generate_cfi () =
544498
(* We generate CFI info even if we're not generating any other debugging
@@ -589,16 +543,8 @@ let indirect_symbol symbol = emit (Indirect_symbol (Asm_symbol.encode symbol))
589543

590544
let private_extern symbol = emit (Private_extern (Asm_symbol.encode symbol))
591545

592-
let extrn symbol = emit (External (Asm_symbol.encode symbol))
593-
594-
let hidden symbol = emit (Hidden (Asm_symbol.encode symbol))
595-
596-
let weak symbol = emit (Weak (Asm_symbol.encode symbol))
597-
598546
let size symbol cst = emit (Size (Asm_symbol.encode symbol, lower_expr cst))
599547

600-
let size_const sym n = emit (Size (Asm_symbol.encode sym, Signed_int n))
601-
602548
let type_ symbol ~type_ = emit (Type (symbol, type_))
603549

604550
let sleb128 ?comment i =
@@ -675,7 +621,7 @@ let label ?comment label = const_machine_width ?comment (Label label)
675621
let label_plus_offset ?comment lab ~offset_in_bytes =
676622
let offset_in_bytes = Targetint.to_int64 offset_in_bytes in
677623
let lab = const_label lab in
678-
const_machine_width ?comment (const_with_offset lab offset_in_bytes)
624+
const_machine_width ?comment (const_add lab (const_int64 offset_in_bytes))
679625

680626
let define_label label =
681627
let lbl_section = Asm_label.section label in
@@ -847,7 +793,7 @@ let symbol ?comment sym = const_machine_width ?comment (Symbol sym)
847793

848794
let symbol_plus_offset symbol ~offset_in_bytes =
849795
let offset_in_bytes = Targetint.to_int64 offset_in_bytes in
850-
const_machine_width (const_with_offset (Symbol symbol) offset_in_bytes)
796+
const_machine_width (Add (Symbol symbol, Signed_int offset_in_bytes))
851797

852798
let int8 ?comment i =
853799
const ?comment (Signed_int (Int64.of_int (Int8.to_int i))) Eight
@@ -938,14 +884,9 @@ let between_labels_16_bit ?comment:_ ~upper:_ ~lower:_ () =
938884
(* CR poechsel: use the arguments *)
939885
Misc.fatal_error "between_labels_16_bit not implemented yet"
940886

941-
let between_labels_32_bit ?comment:_comment ~upper ~lower () =
942-
let expr = const_sub (const_label upper) (const_label lower) in
943-
(* CR sspies: Unlike in most of the other distance computation functions in
944-
this file, we do not force an assembly time constant in this function. This
945-
is to follow the existing/previous implementation of the x86 backend. In
946-
the future, we should investigate whether it would be more appropriate to
947-
force an assembly time constant. *)
948-
const expr Thirty_two
887+
let between_labels_32_bit ?comment:_ ~upper:_ ~lower:_ () =
888+
(* CR poechsel: use the arguments *)
889+
Misc.fatal_error "between_labels_32_bit not implemented yet"
949890

950891
let between_labels_64_bit ?comment:_ ~upper:_ ~lower:_ () =
951892
(* CR poechsel: use the arguments *)
@@ -1118,14 +1059,3 @@ let offset_into_dwarf_section_symbol ?comment:_comment
11181059
match width with
11191060
| Thirty_two -> const expr Thirty_two
11201061
| Sixty_four -> const expr Sixty_four
1121-
1122-
let reloc_x86_64_plt32 ~offset_from_this ~target_symbol ~rel_offset_from_next =
1123-
emit
1124-
(Reloc
1125-
{ offset = Sub (This, Signed_int offset_from_this);
1126-
name = R_X86_64_PLT32;
1127-
expr =
1128-
Sub
1129-
( Named_thing (Asm_symbol.encode target_symbol),
1130-
Signed_int rel_offset_from_next )
1131-
})

backend/asm_targets/asm_directives_new.mli

+3-47
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,8 @@ val cfi_def_cfa_register : reg:string -> unit
158158
supported on all platforms. *)
159159
val mark_stack_non_executable : unit -> unit
160160

161-
type align_padding =
162-
| Nop
163-
| Zero
164-
165-
(** Leave as much space as is required to achieve the given alignment. On x86 in the
166-
binary emitter, it is important what the space is filled with: in the text section,
167-
one would typically fill it with [nop] instructions and in the data section, one
168-
would typically fill it with zeros. This is controlled by the parameter
169-
[fill_x86_bin_emitter]. *)
170-
val align : fill_x86_bin_emitter:align_padding -> bytes:int -> unit
161+
(** Leave as much space as is required to achieve the given alignment. *)
162+
val align : bytes:int -> unit
171163

172164
(** Emit a directive giving the displacement between the given symbol and
173165
the current position. This should only be used to state sizes of
@@ -176,8 +168,6 @@ val align : fill_x86_bin_emitter:align_padding -> bytes:int -> unit
176168
from that whose size is being stated (e.g. on POWER with ELF ABI v1). *)
177169
val size : ?size_of:Asm_symbol.t -> Asm_symbol.t -> unit
178170

179-
val size_const : Asm_symbol.t -> int64 -> unit
180-
181171
(** Leave a gap in the object file. *)
182172
val space : bytes:int -> unit
183173

@@ -207,15 +197,6 @@ val protected : Asm_symbol.t -> unit
207197
details). *)
208198
val private_extern : Asm_symbol.t -> unit
209199

210-
(** Mark an already encoded symbol as external. *)
211-
val extrn : Asm_symbol.t -> unit
212-
213-
(** Mark an already encoded symbol or label as hidden. *)
214-
val hidden : Asm_symbol.t -> unit
215-
216-
(** Mark an already encoded symbol or label as weak. *)
217-
val weak : Asm_symbol.t -> unit
218-
219200
(** Marker inside the definition of a lazy symbol stub (see platform or
220201
assembler documentation for details). *)
221202
val indirect_symbol : Asm_symbol.t -> unit
@@ -325,12 +306,6 @@ val offset_into_dwarf_section_symbol :
325306
Asm_symbol.t ->
326307
unit
327308

328-
val reloc_x86_64_plt32 :
329-
offset_from_this:int64 ->
330-
target_symbol:Asm_symbol.t ->
331-
rel_offset_from_next:int64 ->
332-
unit
333-
334309
module Directive : sig
335310
module Constant : sig
336311
(* CR sspies: make this private again once the first-class module has been
@@ -379,10 +354,6 @@ module Directive : sig
379354
removed *)
380355
type comment = string
381356

382-
(* ELF specific *)
383-
type reloc_type = R_X86_64_PLT32
384-
(* X86 only *)
385-
386357
(* CR sspies: make this private again once the first-class module has been
387358
removed *)
388359

@@ -392,14 +363,7 @@ module Directive : sig
392363
have had all necessary prefixing, mangling, escaping and suffixing
393364
applied. *)
394365
type t =
395-
| Align of
396-
{ bytes : int;
397-
(** The number of bytes to align to. This will be taken log2 by the emitter on
398-
Arm and macOS platforms.*)
399-
fill_x86_bin_emitter : align_padding
400-
(** The [fill_x86_bin_emitter] flag controls whether the x86 binary emitter
401-
emits NOP instructions or null bytes. *)
402-
}
366+
| Align of { bytes : int }
403367
| Bytes of
404368
{ str : string;
405369
comment : string option
@@ -453,14 +417,6 @@ module Directive : sig
453417
comment : string option
454418
}
455419
| Protected of string
456-
| Hidden of string
457-
| Weak of string
458-
| External of string
459-
| Reloc of
460-
{ offset : Constant.t;
461-
name : reloc_type;
462-
expr : Constant.t
463-
}
464420

465421
(** Translate the given directive to textual form. This produces output
466422
suitable for either gas or MASM as appropriate. *)

backend/asm_targets/asm_label.ml

-7
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ let create_string section label =
6969
assert (not (contains_escapable_char label));
7070
{ section; label = String label }
7171

72-
let create_string_unchecked section label = { section; label = String label }
73-
7472
let label_prefix =
7573
match Target_system.assembler () with MacOS -> "L" | MASM | GAS_like -> ".L"
7674

@@ -140,7 +138,6 @@ let for_dwarf_section (dwarf_section : Asm_section.dwarf_section) =
140138
| Debug_str -> Lazy.force debug_str_label
141139
| Debug_line -> Lazy.force debug_line_label
142140

143-
(* CR sspies: Remove the other cases where we never emit a label upfront. *)
144141
let for_section (section : Asm_section.t) =
145142
match section with
146143
| DWARF dwarf_section -> for_dwarf_section dwarf_section
@@ -150,7 +147,3 @@ let for_section (section : Asm_section.t) =
150147
| Eight_byte_literals -> Lazy.force eight_byte_literals_label
151148
| Sixteen_byte_literals -> Lazy.force sixteen_byte_literals_label
152149
| Jump_tables -> Lazy.force jump_tables_label
153-
| Stapsdt_base -> Misc.fatal_error "Stapsdt_base has no associated label"
154-
| Stapsdt_note -> Misc.fatal_error "Stapsdt_note has no associated label"
155-
| Probes -> Misc.fatal_error "Probes has no associated label"
156-
| Note_ocaml_eh -> Misc.fatal_error "Note_ocaml_eh has no associated label"

backend/asm_targets/asm_label.mli

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ val create_int : Asm_section.t -> int -> t
5252
(** Create a textual label. The supplied name must not require escaping. *)
5353
val create_string : Asm_section.t -> string -> t
5454

55-
(** Create a textual label. Argument string is not checked, so use with caution. *)
56-
val create_string_unchecked : Asm_section.t -> string -> t
57-
5855
(** Convert a label to the corresponding textual form, suitable for direct
5956
emission into an assembly file. This may be useful e.g. when emitting an
6057
instruction referencing a label. *)

0 commit comments

Comments
 (0)