Skip to content

Commit 61c8313

Browse files
hanno-beckermkannwischer
authored andcommitted
Backends: Namespace assembly local labels with mlk_ prefix
Previously, local labels in the assembly backends were prefixed only by the name of the enclosing function, e.g. Lntt_layer123_start in ntt_aarch64_asm.S. Global entry symbols are namespaced per project via MLK_ASM_NAMESPACE(), but local labels are emitted as literal text and survive verbatim into the autogenerated mlkem/*.S files. mldsa-native derives its assembly from mlkem-native and kept the same function and label names, so its local labels are byte-for-byte identical (Lntt_layer123_start, Lrej_uniform_loop48, ...). This is harmless as long as each backend is assembled into its own object file, but breaks when both backends are merged into a single link unit: AWS-LC's FIPS build concatenates all sources and runs them through the delocate tool, which flattens them into one symbol namespace and panics on the duplicate labels. This commit adds a fixed mlk_ project prefix to every local label across all backends (AArch64 arithmetic and FIPS202, x86_64 AVX2, Armv8.1-M MVE, ppc64le), not just the ones that clash today, so mlkem-native emits Lmlk_ntt_layer123_start and a future mld_-prefixed mldsa-native drop can no longer collide, independent of the integrator or platform. The change is made in the dev/ assembly sources and propagated to mlkem/*.S and the proofs/hol_light/* drops via scripts/simpasm. Local labels emit no object-code bytes, and branch targets encode PC-relative offsets rather than names, so the assembled .text is byte-identical; the byte-locked HOL Light and CBMC proofs are unaffected. check_asm_loop_labels in scripts/autogen is updated to require the mlk_-prefixed function-derived prefix, so a newly added un-namespaced label fails CI. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 2cf613b commit 61c8313

75 files changed

Lines changed: 350 additions & 332 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dev/aarch64_clean/src/intt_aarch64_asm.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ MLK_ASM_FN_SYMBOL(intt_aarch64_asm)
239239
mov count, #8
240240

241241
.p2align 2
242-
intt_layer4567_start:
242+
mlk_intt_layer4567_start:
243243

244244
ldr q_data0, [inp, #(16*0)]
245245
ldr q_data1, [inp, #(16*1)]
@@ -301,7 +301,7 @@ intt_layer4567_start:
301301
str q_data3, [inp, #(-64 + 16*3)]
302302

303303
sub count, count, #1
304-
cbnz count, intt_layer4567_start
304+
cbnz count, mlk_intt_layer4567_start
305305

306306
// ---------------------------------------------------------------------
307307

@@ -310,7 +310,7 @@ intt_layer4567_start:
310310

311311
.p2align 2
312312

313-
intt_layer123_start:
313+
mlk_intt_layer123_start:
314314

315315
ldr q_data0, [in, #0]
316316
ldr q_data1, [in, #(1*(512/8))]
@@ -349,7 +349,7 @@ intt_layer123_start:
349349
str q_data3, [in, #(-16 + 3*(512/8))]
350350

351351
sub count, count, #1
352-
cbnz count, intt_layer123_start
352+
cbnz count, mlk_intt_layer123_start
353353

354354
pop_stack
355355
ret

dev/aarch64_clean/src/ntt_aarch64_asm.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ MLK_ASM_FN_SYMBOL(ntt_aarch64_asm)
221221
//
222222
// See test/test_bounds.py for more details.
223223

224-
ntt_layer123_start:
224+
mlk_ntt_layer123_start:
225225

226226
ldr q_data0, [in, #0]
227227
ldr q_data1, [in, #(1*(512/8))]
@@ -257,13 +257,13 @@ ntt_layer123_start:
257257
str q_data7, [in, #(-16 + 7*(512/8))]
258258

259259
sub count, count, #1
260-
cbnz count, ntt_layer123_start
260+
cbnz count, mlk_ntt_layer123_start
261261

262262
mov in, inp
263263
mov count, #8
264264

265265
.p2align 2
266-
ntt_layer4567_start:
266+
mlk_ntt_layer4567_start:
267267

268268
ldr q_data0, [in, #(16*0)]
269269
ldr q_data1, [in, #(16*1)]
@@ -293,7 +293,7 @@ ntt_layer4567_start:
293293
str q_data3, [in, #(-16*1)]
294294

295295
sub count, count, #1
296-
cbnz count, ntt_layer4567_start
296+
cbnz count, mlk_ntt_layer4567_start
297297

298298
pop_stack
299299
ret

dev/aarch64_clean/src/poly_mulcache_compute_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ MLK_ASM_FN_SYMBOL(poly_mulcache_compute_aarch64_asm)
8686
dup modulus_twisted.8h, wtmp
8787

8888
mov count, #16
89-
poly_mulcache_compute_loop_start:
89+
mlk_poly_mulcache_compute_loop_start:
9090
ldr q_tmp0, [data_ptr], #32
9191
ldr q_tmp1, [data_ptr, #-16]
9292
ldr q_zeta, [zeta_ptr], #16
@@ -101,7 +101,7 @@ poly_mulcache_compute_loop_start:
101101
str q_dst, [cache_ptr], #16
102102

103103
subs count, count, #1
104-
cbnz count, poly_mulcache_compute_loop_start
104+
cbnz count, mlk_poly_mulcache_compute_loop_start
105105

106106
ret
107107

dev/aarch64_clean/src/poly_reduce_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ MLK_ASM_FN_SYMBOL(poly_reduce_aarch64_asm)
6767
dup modulus_twisted.8h, wtmp
6868

6969
mov count, #8
70-
poly_reduce_loop_start:
70+
mlk_poly_reduce_loop_start:
7171
ldr q_data, [ptr], #64
7272
barrett_reduce data
7373
scalar_signed_to_unsigned data
@@ -89,7 +89,7 @@ poly_reduce_loop_start:
8989
str q_data, [ptr, #-16]
9090

9191
subs count, count, #1
92-
cbnz count, poly_reduce_loop_start
92+
cbnz count, mlk_poly_reduce_loop_start
9393

9494
ret
9595

dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
MLK_ASM_FN_SYMBOL(poly_tobytes_aarch64_asm)
6060

6161
mov count, #16
62-
poly_tobytes_loop_start:
62+
mlk_poly_tobytes_loop_start:
6363
ld2_wrap data, src
6464

6565
// r[3 * i + 0] = (t0 >> 0);
@@ -77,7 +77,7 @@ poly_tobytes_loop_start:
7777
st3 {out0.8b, out1.8b, out2.8b}, [dst], #24
7878

7979
subs count, count, #1
80-
cbnz count, poly_tobytes_loop_start
80+
cbnz count, mlk_poly_tobytes_loop_start
8181
ret
8282

8383
.unreq data0

dev/aarch64_clean/src/poly_tomont_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ MLK_ASM_FN_SYMBOL(poly_tomont_aarch64_asm)
6464
dup factor_t.8h, wtmp
6565

6666
mov count, #8
67-
poly_tomont_loop:
67+
mlk_poly_tomont_loop:
6868

6969
ldr q_data, [src], #64
7070
mulmod res, data, factor, factor_t
@@ -83,7 +83,7 @@ poly_tomont_loop:
8383
str q_res, [src, #-16]
8484

8585
sub count, count, #1
86-
cbnz count, poly_tomont_loop
86+
cbnz count, mlk_poly_tomont_loop
8787

8888
ret
8989

dev/aarch64_clean/src/polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ MLK_ASM_FN_SYMBOL(polyvec_basemul_acc_montgomery_cached_k2_aarch64_asm)
201201
add b1_cache_ptr, b0_cache_ptr, #(1 * 512/2)
202202

203203
mov count, #(MLKEM_N / 16)
204-
polyvec_basemul_acc_montgomery_cached_k2_loop_start:
204+
mlk_polyvec_basemul_acc_montgomery_cached_k2_loop_start:
205205

206206
load_polys aa, bb, a0_ptr, b0_ptr, b0_cache_ptr
207207
pmull res, aa, bb
@@ -214,7 +214,7 @@ polyvec_basemul_acc_montgomery_cached_k2_loop_start:
214214
st2_wrap out, out
215215

216216
subs count, count, #1
217-
cbnz count, polyvec_basemul_acc_montgomery_cached_k2_loop_start
217+
cbnz count, mlk_polyvec_basemul_acc_montgomery_cached_k2_loop_start
218218

219219
pop_stack
220220
ret

dev/aarch64_clean/src/polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ MLK_ASM_FN_SYMBOL(polyvec_basemul_acc_montgomery_cached_k3_aarch64_asm)
203203
add b2_cache_ptr, b0_cache_ptr, #(2 * 512/2)
204204

205205
mov count, #(MLKEM_N / 16)
206-
polyvec_basemul_acc_montgomery_cached_k3_loop_start:
206+
mlk_polyvec_basemul_acc_montgomery_cached_k3_loop_start:
207207

208208
load_polys aa, bb, a0_ptr, b0_ptr, b0_cache_ptr
209209
pmull res, aa, bb
@@ -218,7 +218,7 @@ polyvec_basemul_acc_montgomery_cached_k3_loop_start:
218218
st2_wrap out, out
219219

220220
subs count, count, #1
221-
cbnz count, polyvec_basemul_acc_montgomery_cached_k3_loop_start
221+
cbnz count, mlk_polyvec_basemul_acc_montgomery_cached_k3_loop_start
222222

223223
pop_stack
224224
ret

dev/aarch64_clean/src/polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ MLK_ASM_FN_SYMBOL(polyvec_basemul_acc_montgomery_cached_k4_aarch64_asm)
211211
// before Montgomery reduction is bound by 2^30.
212212

213213
mov count, #(MLKEM_N / 16)
214-
polyvec_basemul_acc_montgomery_cached_k4_loop_start:
214+
mlk_polyvec_basemul_acc_montgomery_cached_k4_loop_start:
215215

216216
load_polys aa, bb, a0_ptr, b0_ptr, b0_cache_ptr
217217
pmull res, aa, bb
@@ -228,7 +228,7 @@ polyvec_basemul_acc_montgomery_cached_k4_loop_start:
228228
st2_wrap out, out
229229

230230
subs count, count, #1
231-
cbnz count, polyvec_basemul_acc_montgomery_cached_k4_loop_start
231+
cbnz count, mlk_polyvec_basemul_acc_montgomery_cached_k4_loop_start
232232

233233
pop_stack
234234
ret

dev/aarch64_clean/src/rej_uniform_aarch64_asm.S

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,27 +174,27 @@ MLK_ASM_FN_SYMBOL(rej_uniform_aarch64_asm)
174174
// in case not enough bytes have been sampled, zero the temporary buffer.
175175
mov initial_zero_count, #0
176176
eor val0.16b, val0.16b, val0.16b
177-
rej_uniform_initial_zero:
177+
mlk_rej_uniform_initial_zero:
178178
str val0q, [output_tmp], #64
179179
str val0q, [output_tmp, #-48]
180180
str val0q, [output_tmp, #-32]
181181
str val0q, [output_tmp, #-16]
182182
add initial_zero_count, initial_zero_count, #32
183183
cmp initial_zero_count, #MLKEM_N
184-
b.lt rej_uniform_initial_zero
184+
b.lt mlk_rej_uniform_initial_zero
185185

186186
mov output_tmp, output_tmp_base
187187

188188
mov count, #0
189189
mov len, #MLKEM_N
190190

191191
cmp buflen, #48
192-
b.lo rej_uniform_loop48_end
192+
b.lo mlk_rej_uniform_loop48_end
193193

194-
rej_uniform_loop48:
194+
mlk_rej_uniform_loop48:
195195
// Finish once we've generated sufficiently many coefficients
196196
cmp count, len
197-
b.hs rej_uniform_memory_copy
197+
b.hs mlk_rej_uniform_memory_copy
198198

199199
// First, we unpack the byte stream into a stream of signed
200200
// coefficients, interpreting each consecutive 3 bytes as two
@@ -304,15 +304,15 @@ rej_uniform_loop48:
304304
add count, count, ctr23
305305

306306
cmp buflen, #48
307-
b.hs rej_uniform_loop48
308-
rej_uniform_loop48_end:
307+
b.hs mlk_rej_uniform_loop48
308+
mlk_rej_uniform_loop48_end:
309309

310310
// Finish once we've generated sufficiently many coefficients
311311
cmp count, len
312-
b.hs rej_uniform_memory_copy
312+
b.hs mlk_rej_uniform_memory_copy
313313

314314
cmp buflen, #24
315-
b.lo rej_uniform_memory_copy
315+
b.lo mlk_rej_uniform_memory_copy
316316

317317
ld3 {buf0.8b, buf1.8b, buf2.8b}, [buf], #24
318318

@@ -360,7 +360,7 @@ rej_uniform_loop48_end:
360360
add count, count, ctr0
361361
add count, count, ctr1
362362

363-
rej_uniform_memory_copy:
363+
mlk_rej_uniform_memory_copy:
364364
// min = min(count,len)
365365
cmp count, len
366366
csel count, count, len, lo
@@ -370,7 +370,7 @@ rej_uniform_memory_copy:
370370
// allows us to stick to vectorized code.
371371
mov final_copy_count, #0
372372
mov output_tmp, output_tmp_base
373-
rej_uniform_final_copy:
373+
mlk_rej_uniform_final_copy:
374374
ldr val0q, [output_tmp], #64
375375
ldr val1q, [output_tmp, #-48]
376376
ldr val2q, [output_tmp, #-32]
@@ -381,11 +381,11 @@ rej_uniform_final_copy:
381381
str val3q, [output, #-16]
382382
add final_copy_count, final_copy_count, #32
383383
cmp final_copy_count, #MLKEM_N
384-
b.lt rej_uniform_final_copy
384+
b.lt mlk_rej_uniform_final_copy
385385

386386
mov x0, count
387387

388-
rej_uniform_return:
388+
mlk_rej_uniform_return:
389389
pop_stack
390390
ret
391391

0 commit comments

Comments
 (0)