diff --git a/test b/test index bbfd6c8f3..154895fe4 160000 --- a/test +++ b/test @@ -1 +1 @@ -Subproject commit bbfd6c8f3de5d8e38988bd7f27af3a151e239bb4 +Subproject commit 154895fe439c0ca50b60a711c30464509cd72f7f diff --git a/x86/TargetPrinter.ml b/x86/TargetPrinter.ml index 86fa4d6d2..2755cb25f 100644 --- a/x86/TargetPrinter.ml +++ b/x86/TargetPrinter.ml @@ -106,6 +106,7 @@ module type SYSTEM = val comment: string val raw_symbol: out_channel -> string -> unit val symbol: out_channel -> P.t -> unit + val symbol_paren: out_channel -> P.t -> unit val label: out_channel -> int -> unit val name_of_section: section_name -> string val stack_alignment: int @@ -130,6 +131,12 @@ module ELF_System : SYSTEM = let symbol = elf_symbol + let symbol_paren oc symb = + let s = extern_atom symb in + if String.length s > 0 && s.[0] = '$' + then fprintf oc "(%s)" s + else fprintf oc "%s" s + let label = elf_label let name_of_section = function @@ -164,8 +171,8 @@ module ELF_System : SYSTEM = let print_mov_rs oc rd id = if Archi.ptr64 - then fprintf oc " movq %a@GOTPCREL(%%rip), %a\n" symbol id ireg64 rd - else fprintf oc " movl $%a, %a\n" symbol id ireg32 rd + then fprintf oc " movq %a@GOTPCREL(%%rip), %a\n" symbol_paren id ireg64 rd + else fprintf oc " movl $%a, %a\n" symbol_paren id ireg32 rd let print_fun_info = elf_print_fun_info @@ -196,6 +203,9 @@ module MacOS_System : SYSTEM = let symbol oc symb = raw_symbol oc (extern_atom symb) + let symbol_paren = symbol + (* the leading '_' protects the leading '$' *) + let label oc lbl = fprintf oc "L%d" lbl @@ -262,6 +272,12 @@ module Cygwin_System : SYSTEM = let symbol oc symb = raw_symbol oc (extern_atom symb) + let symbol_paren oc symb = + let s = extern_atom symb in + if String.length s > 0 && s.[0] = '$' + then fprintf oc "(%a)" raw_symbol s + else raw_symbol oc s + let label oc lbl = fprintf oc "L%d" lbl @@ -341,13 +357,13 @@ module Target(System: SYSTEM):TARGET = (* RIP-relative addressing *) let ofs' = Z.to_int64 ofs in if ofs' = 0L - then fprintf oc "%a(%%rip)" symbol id + then fprintf oc "%a(%%rip)" symbol_paren id else fprintf oc "(%a + %Ld)(%%rip)" symbol id ofs' end else begin (* Absolute addressing *) let ofs' = Z.to_int32 ofs in if ofs' = 0l - then fprintf oc "%a" symbol id + then fprintf oc "%a" symbol_paren id else fprintf oc "(%a + %ld)" symbol id ofs' end end; @@ -707,7 +723,7 @@ module Target(System: SYSTEM):TARGET = | Pjmp_l(l) -> fprintf oc " jmp %a\n" label (transl_label l) | Pjmp_s(f, sg) -> - fprintf oc " jmp %a\n" symbol f + fprintf oc " jmp %a\n" symbol_paren f | Pjmp_r(r, sg) -> fprintf oc " jmp *%a\n" ireg r | Pjcc(c, l) -> @@ -733,7 +749,7 @@ module Target(System: SYSTEM):TARGET = fprintf oc " jmp *%a(, %a, 4)\n" label l ireg r end | Pcall_s(f, sg) -> - fprintf oc " call %a\n" symbol f; + fprintf oc " call %a\n" symbol_paren f; if (not Archi.ptr64) && sg.sig_cc.cc_structret then fprintf oc " pushl %%eax\n" | Pcall_r(r, sg) ->