Skip to content

Commit cbe1d79

Browse files
committed
bugfix: De-duplicate consecutive ARM32 label
Fixes #6
1 parent 19b0377 commit cbe1d79

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
`flexdll/flexdll.c`, etc. to make robust to the lack of `flexdll/.git`.
88
Vendor supplied patches are used by DkSDK CMake's `110-ocaml-lang`.
99
* Supply `DKML_HOST_ABI` to post-transform configure scripts.
10+
* bugfix: De-duplicate consecutive ARM32 label. <https://github.com/diskuv/dkml-compiler/issues/6>
1011

1112
## 2.1.3
1213

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# arm32 deduplicate labels
2+
3+
Problem that only appears on clang (not former GNU AS used before Android NDK 24):
4+
5+
```text
6+
make: Entering directory '/workspaces/dkml-compiler/dist-android_arm32v7a-on-linux_x86/opt/mlcross/android_arm32v7a/src/ocaml/stdlib'
7+
/usr/bin/env /workspaces/dkml-compiler/dist-android_arm32v7a-on-linux_x86/opt/mlcross/android_arm32v7a/src/ocaml/support/ocamloptTarget.wrapper -strict-sequence -absname -w +a-4-9-41-42-44-45-48-70 -g -warn-error +A -bin-annot -nostdlib -principal -safe-string -strict-formats -dstartup -S -nopervasives -c camlinternalAtomic.ml
8+
camlinternalAtomic.s:94:1: error: symbol '.L100' is already defined
9+
.L100:
10+
^
11+
camlinternalAtomic.s:146:1: error: symbol '.L105' is already defined
12+
.L105:
13+
^
14+
camlinternalAtomic.s:173:1: error: symbol '.L106' is already defined
15+
.L106:
16+
^
17+
camlinternalAtomic.s:202:1: error: symbol '.L108' is already defined
18+
.L108:
19+
^
20+
camlinternalAtomic.s:262:1: error: symbol '.L110' is already defined
21+
.L110:
22+
^
23+
camlinternalAtomic.s:289:1: error: symbol '.L112' is already defined
24+
.L112:
25+
^
26+
File "/workspaces/dkml-compiler/dist-android_arm32v7a-on-linux_x86/opt/mlcross/android_arm32v7a/src/ocaml/stdlib/camlinternalAtomic.ml", line 1:
27+
Error: Assembler error, input left in file /workspaces/dkml-compiler/dist-android_arm32v7a-on-linux_x86/opt/mlcross/android_arm32v7a/src/ocaml/stdlib/camlinternalAtomic.s
28+
make: *** [Makefile:231: camlinternalAtomic.cmx] Error 2
29+
make: Leaving directory '/workspaces/dkml-compiler/dist-android_arm32v7a-on-linux_x86/opt/mlcross/android_arm32v7a/src/ocaml/stdlib'
30+
```
31+
32+
Here is the definition of a function:
33+
34+
```armasm
35+
# lines 1 - 82
36+
camlCamlinternalAtomic__make_9: # line 83
37+
.file 2 "camlinternalAtomic.ml"
38+
.loc 2 27
39+
.cfi_startproc
40+
.loc 2 27
41+
sub sp, sp, #0x8 # Beginning of [Lprologue]
42+
.cfi_adjust_cfa_offset 8
43+
.cfi_offset 14, -4
44+
str lr, [sp, #4]
45+
.L100: # line 92
46+
.loc 2 27 # End of [Lprologue]
47+
.L100: # line 94. Beginning and end of [Llabel]
48+
.loc 2 27
49+
sub alloc_ptr, alloc_ptr, #0x8
50+
ldr r1, [domain_state_ptr, 0]
51+
cmp alloc_ptr, r1
52+
bcc .L102
53+
.L103: add r1, alloc_ptr, #4
54+
ldr lr, [sp, #4]
55+
movs r2, #0x400
56+
str r2, [r1, #-4]
57+
str r0, [r1, #0]
58+
mov r0, r1
59+
add sp, sp, #0x8
60+
.cfi_adjust_cfa_offset -8
61+
bx lr
62+
.cfi_adjust_cfa_offset 8
63+
.L102: bl caml_call_gc(PLT)
64+
.L101: b .L103
65+
.cfi_endproc
66+
.type camlCamlinternalAtomic__make_9, %function
67+
.size camlCamlinternalAtomic__make_9, .-camlCamlinternalAtomic__make_9
68+
```
69+
70+
This patch gets rid of any duplicate, consecutive labels.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff --git a/asmcomp/arm/emit.mlp b/asmcomp/arm/emit.mlp
2+
index a8285d7363..16645da96e 100644
3+
--- a/asmcomp/arm/emit.mlp
4+
+++ b/asmcomp/arm/emit.mlp
5+
@@ -884,10 +884,17 @@ let max_instruction_size i =
6+
7+
(* Emission of an instruction sequence *)
8+
9+
-let rec emit_all env ninstr fallthrough i =
10+
+let rec emit_all env ninstr fallthrough prev_desc i =
11+
(* ninstr = number of 32-bit code words emitted since last constant island *)
12+
(* fallthrough is true if previous instruction can fall through *)
13+
if i.desc = Lend then () else begin
14+
+ match prev_desc, i.desc with
15+
+ | Some Lprologue, Llabel lbl when env.f.fun_tailrec_entry_point_label=lbl ->
16+
+ (* Skip duplicate, consecutive labels which cause
17+
+ > error: symbol '.L100' is already defined
18+
+ with clang (ex. Android NDK 24+) but not with GNU AS. *)
19+
+ emit_all env ninstr (has_fallthrough i.desc) (Some i.desc) i.next
20+
+ | _ ->
21+
(* Make sure literals not yet emitted remain addressable,
22+
or emit them in a new constant island. *)
23+
(* fldd can address up to +/-1KB, ldr can address up to +/-4KB *)
24+
@@ -908,7 +915,7 @@ let rec emit_all env ninstr fallthrough i =
25+
end else
26+
ninstr in
27+
let n = emit_instr env i in
28+
- emit_all env (ninstr' + n) (has_fallthrough i.desc) i.next
29+
+ emit_all env (ninstr' + n) (has_fallthrough i.desc) (Some i.desc) i.next
30+
end
31+
32+
(* Emission of a function declaration *)
33+
@@ -926,7 +933,7 @@ let fundecl fundecl =
34+
`{emit_symbol fundecl.fun_name}:\n`;
35+
emit_debug_info fundecl.fun_dbg;
36+
cfi_startproc();
37+
- emit_all env 0 true fundecl.fun_body;
38+
+ emit_all env 0 true None fundecl.fun_body;
39+
emit_literals env;
40+
List.iter emit_call_gc env.call_gc_sites;
41+
List.iter emit_call_bound_error env.bound_error_sites;

0 commit comments

Comments
 (0)