Skip to content

Commit dff2126

Browse files
committed
Add ocaml-common-4_14-a09-debuggasx86 patch
Fixes #8
1 parent e818e18 commit dff2126

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# GNU as x86/x86_64 debugging
2+
3+
The `asmcomp/x86_gas.ml` module (used by both IA-64 and IA-32) places `.file ""` at the top
4+
of each GNU `as` assembly source file.
5+
That is done to create reproducible builds: <https://github.com/ocaml/ocaml/issues/7037>.
6+
7+
However, we get:
8+
9+
```text
10+
./BOOT_OCAMLC -stdlib.s: Assembler messages:
11+
stdlib.s:1009: Error: file number 1 already allocated
12+
File "/work/build/DkSDKFiles/cfg-Debug/o/src/ocaml/stdlib/stdlib.ml", line 1:
13+
Error: Assembler error, input left in file /work/build/DkSDKFiles/cfg-Debug/o/src/ocaml/stdlib/stdlib.s
14+
make[2]: *** [stdlib.cmx] Error 2
15+
make[1]: *** [libraryopt] Error 2
16+
make: *** [opt-core] Error 2
17+
FATAL: make opt-core -j6 -l6 failed
18+
```
19+
20+
That is because the `.file ""` seems to be treated as an implicit file number 1,
21+
which is re-used in:
22+
23+
```asm
24+
; ...
25+
.globl camlStdlib__failwith_7
26+
camlStdlib__failwith_7:
27+
.file 1 "stdlib.ml"
28+
.loc 1 29 13
29+
; ...
30+
.L352:
31+
movl %eax, %edx
32+
movl %edx, (%esp)
33+
.file 2 "camlinternalAtomic.ml"
34+
.loc 2 27 13
35+
```
36+
37+
The patch does the following:
38+
39+
1. Starts the file numbering from 2, not 1.
40+
2. Changes `.file ""` to `.file 1 ""` to avoid `Error: unassigned file number 1`.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
diff --git a/asmcomp/amd64/emit.mlp b/asmcomp/amd64/emit.mlp
2+
index 3c58633..f69d42e 100644
3+
--- a/asmcomp/amd64/emit.mlp
4+
+++ b/asmcomp/amd64/emit.mlp
5+
@@ -922,7 +922,7 @@ let data l =
6+
7+
let begin_assembly() =
8+
X86_proc.reset_asm_code ();
9+
- reset_debug_info(); (* PR#5603 *)
10+
+ reset_debug_info_at_file_num 2; (* A09. PR#5603 *)
11+
reset_imp_table();
12+
float_constants := [];
13+
all_functions := [];
14+
diff --git a/asmcomp/emitaux.ml b/asmcomp/emitaux.ml
15+
index d3587c1..0dca6a9 100644
16+
--- a/asmcomp/emitaux.ml
17+
+++ b/asmcomp/emitaux.ml
18+
@@ -341,6 +341,10 @@ let reset_debug_info () =
19+
file_pos_nums := [];
20+
file_pos_num_cnt := 1
21+
22+
+let reset_debug_info_at_file_num file_num =
23+
+ file_pos_nums := [];
24+
+ file_pos_num_cnt := file_num
25+
+
26+
(* We only display .file if the file has not been seen before. We
27+
display .loc for every instruction. *)
28+
let emit_debug_info_gen dbg file_emitter loc_emitter =
29+
diff --git a/asmcomp/emitaux.mli b/asmcomp/emitaux.mli
30+
index df0b019..34d1ac1 100644
31+
--- a/asmcomp/emitaux.mli
32+
+++ b/asmcomp/emitaux.mli
33+
@@ -32,6 +32,7 @@ val emit_float32_directive: string -> int32 -> unit
34+
35+
val reset : unit -> unit
36+
val reset_debug_info: unit -> unit
37+
+val reset_debug_info_at_file_num: int -> unit
38+
val emit_debug_info: Debuginfo.t -> unit
39+
val emit_debug_info_gen :
40+
Debuginfo.t ->
41+
diff --git a/asmcomp/i386/emit.mlp b/asmcomp/i386/emit.mlp
42+
index b76af36..69489a2 100644
43+
--- a/asmcomp/i386/emit.mlp
44+
+++ b/asmcomp/i386/emit.mlp
45+
@@ -948,7 +948,7 @@ let data l =
46+
47+
let begin_assembly() =
48+
X86_proc.reset_asm_code ();
49+
- reset_debug_info(); (* PR#5603 *)
50+
+ reset_debug_info_at_file_num 2; (* A09. PR#5603 *)
51+
float_constants := [];
52+
if system = S_win32 then begin
53+
D.mode386 ();
54+
diff --git a/asmcomp/x86_gas.ml b/asmcomp/x86_gas.ml
55+
index 6d2363a..9548e91 100644
56+
--- a/asmcomp/x86_gas.ml
57+
+++ b/asmcomp/x86_gas.ml
58+
@@ -300,7 +300,7 @@ let print_line b = function
59+
60+
let generate_asm oc lines =
61+
let b = Buffer.create 10000 in
62+
- output_string oc "\t.file \"\"\n"; (* PR#7037 *)
63+
+ output_string oc "\t.file 1 \"\"\n"; (* A09. PR#7037 *)
64+
List.iter
65+
(fun i ->
66+
Buffer.clear b;

0 commit comments

Comments
 (0)