I fiddled a bit more and learned that I can either stud those functions that are outputted from the linker (ld.lld: error: undefined symbol: <symbol>
) or use a command line flag swiftc [...] -function-sections
.
While fiddling I came across some very good resources:
This fork of apples swift-embedded-examples got actually adjusted to that I should run fine on linux.
For those who are interested. I came up with this simple Makefile that builds object files and link them together into a binary.
TARGET := armv7-none-none-eabi
SWIFTC_FLAGS := -enable-experimental-feature Embedded -target $(TARGET) -wmo -Osize -Xcc -ffreestanding -Xfrontend -function-sections
CLANG_FLAGS := -target $(TARGET) -Oz
LD_FLAGS := -target $(TARGET) -static -nostdlib -Wl,-gc-sections -Wl,-T,stm32.ld -Wl,-Map,.build/firmware.map
all: startup.o firmware.o link bin
startup.o: startup.c
clang $(CLANG_FLAGS) -c $^ -o .build/$@
firmware.o: Sources/Firmware/firmware.swift
swiftc $(SWIFTC_FLAGS) -c $^ -o .build/$@
link:
clang $(LD_FLAGS) .build/*.o -o .build/firmware.elf
# requires `brew install binutils`
bin:
objcopy -O binary .build/firmware.elf .build/firmware.bin
clean:
rm -rf .build/*
Thank you kubamracek and navan for your input. I think I can preceed from here on.