Skip to content

Commit 4c703f1

Browse files
committed
architecture specific symbol types
1 parent 62e9ab4 commit 4c703f1

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

backend/amd64/emit.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ let to_x86_directive (dir : ND.Directive.t) : X86_ast.asm_line list =
110110
comment_lines comment @ [X86_ast.Sleb128 (to_x86_constant constant)]
111111
| Space { bytes } -> [Space bytes]
112112
| Type (n, st) ->
113-
let typ = match st with Function -> "STT_FUNC" | Object -> "STT_OBJECT" in
113+
let typ = ND.symbol_type_to_string st in
114114
[Type (n, typ)]
115115
| Uleb128 { constant; comment } ->
116116
comment_lines comment @ [X86_ast.Uleb128 (to_x86_constant constant)]

backend/asm_targets/asm_directives_new.ml

+11-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ type symbol_type =
6565
| Function
6666
| Object
6767

68+
(* CR sspies: We should use the "STT" forms when they are supported as they are
69+
unambiguous across platforms (cf.
70+
https://sourceware.org/binutils/docs/as/Type.html). *)
71+
let symbol_type_to_string sym =
72+
match TS.architecture () with
73+
| AArch64 -> ( match sym with Function -> "%function" | Object -> "%object")
74+
| X86_64 -> (
75+
match sym with Function -> "@function" | Object -> "STT_OBJECT")
76+
| _ -> Misc.fatal_error "Symbol types not implemented for this architecture."
77+
6878
let bprintf = Printf.bprintf
6979

7080
module Directive = struct
@@ -349,12 +359,7 @@ module Directive = struct
349359
let comment = gas_comment_opt comment in
350360
bprintf buf "\t.sleb128\t%a%s" Constant.print constant comment
351361
| Type (s, typ) ->
352-
(* We use the "STT" forms when they are supported as they are unambiguous
353-
across platforms (cf. https://sourceware.org/binutils/docs/as/Type.html
354-
). *)
355-
let typ =
356-
match typ with Function -> "STT_FUNC" | Object -> "STT_OBJECT"
357-
in
362+
let typ = symbol_type_to_string typ in
358363
bprintf buf "\t.type %s %s" s typ
359364
| Uleb128 { constant; comment } ->
360365
let comment = gas_comment_opt comment in

backend/asm_targets/asm_directives_new.mli

+3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ type symbol_type =
210210
| Function
211211
| Object
212212

213+
(** The string representation, architecture dependent at the moment. *)
214+
val symbol_type_to_string : symbol_type -> string
215+
213216
val type_symbol : Asm_symbol.t -> ty:symbol_type -> unit
214217

215218
val type_label : Asm_label.t -> ty:symbol_type -> unit

0 commit comments

Comments
 (0)