I'm trying to build my project with as little C as possible, but one the requirements of allocating Embedded Swift is "free" and "posix_memalign" functions. Here's the allocator code I'm trying to use:
Embedded Vision Document says: "Interestingly, it’s possible to write that implementation in “non-allocating” Baremetal Swift."
But when compiling SingleCoreAllocator.swift
with -no-allocations
"$SWIFTC" -target armv7em-none-none-eabi -wmo -enable-experimental-feature Embedded -no-allocations -c SingleCoreAllocator.swift -o $OUTPUT_DIR/SingleCoreAllocator.o
I get the followin errors
<unknown>:0: error: cannot use allocating type '_ContiguousArrayStorage<UInt>' in -no-allocations mode
in function specialized _copyCollectionToContiguousArray<A>(_:)
<unknown>:0: error: cannot use allocating type '__SwiftNativeNSArrayWithContiguousStorage' in -no-allocations mode
in function __SwiftNativeNSArrayWithContiguousStorage.__allocating_init()
To debug the issue I compile SingleCoreAllocator.swift
without -no-allocations
and I can see the symbols mentioned in error in output of nm
:
...
000027a8 T $ss28__ContiguousArrayStorageBaseC012_doNotCallMeD0AByt_tcfC
000027a8 T $ss28__ContiguousArrayStorageBaseC16canStoreElements13ofDynamicTypeSbypXp_tF
000027a4 T $ss28__ContiguousArrayStorageBaseCABycfC
000027a8 T $ss28__ContiguousArrayStorageBaseCfD
...
000027b8 T $ss41__SwiftNativeNSArrayWithContiguousStorageCABycfC
000027d0 T $ss41__SwiftNativeNSArrayWithContiguousStorageCfD
00000000 D $ss41__SwiftNativeNSArrayWithContiguousStorageCN
But these symbols don't exist in output of objdump -D
. And for addresses there's something like this
...
400: 000027a4 andeq r2, r0, r4, lsr #15
404: 00000001 andeq r0, r0, r1
408: 000027a8 andeq r2, r0, r8, lsr #15
40c: 00000001 andeq r0, r0, r1
410: 000027a8 andeq r2, r0, r8, lsr #15
414: 00000001 andeq r0, r0, r1
418: 000027a8 andeq r2, r0, r8, lsr #15
...
420: 000027b8 @ <UNDEFINED> instruction: 0x000027b8
424: 00000001 andeq r0, r0, r1
428: 000027d0 ldrdeq r2, [r0], -r0
42c: 00000001 andeq r0, r0, r1
...
To me it looks like this two functions should have been stripped from the .o file, but weren't.
I saw in this answer that -no-allocations
is aspirational. Is it not implemented yet ? Or am I doing something wrong ? Thanks!