From ba1c7eeefdf4d23eab0fd9dda8be72c980b81399 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Wed, 25 Jun 2025 14:40:15 +0200 Subject: [PATCH 1/2] Add a note about unintended _main symbol generation. --- .../Documentation.docc/UsingEmbeddedSwift/Basics.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md b/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md index ad18f8c..553dd10 100644 --- a/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md +++ b/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md @@ -52,6 +52,8 @@ $ swiftc -target armv7-none-none-eabi -enable-experimental-feature Embedded -wmo input1.swift input2.swift ... -c -o output.o ``` +> Note: Passing only a single `.swift` file to swiftc results in the generation of a `_main` symbol. During linking, this symbol could potentially clash with other objects that also define one. To avoid this, compile multiple Swift files together or use the `-parse-as-library` flag. + Additionally, you probably want to specify additional Clang and/or LLVM flags to get the compiler to produce code for the exact ISA and ABI you need for your target. For example, a Raspberry Pi Pico / Pico W should target the ARMv6-M architecture via the `armv6m-*` target triple, but the `-mfloat-abi=soft` Clang option should also be used, and if you want to match ABI with libraries built with the GNU toolchain, you might also need `-fshort-enums`. To pass those to Swift, use the `-Xcc` prefix: From c86e8c837761271dda7e96d5c0fbcbdd09293b89 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Wed, 2 Jul 2025 20:31:13 +0200 Subject: [PATCH 2/2] Differentiate between main symbols by target --- .../Documentation.docc/UsingEmbeddedSwift/Basics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md b/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md index 553dd10..edf6ae5 100644 --- a/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md +++ b/Sources/EmbeddedSwift/Documentation.docc/UsingEmbeddedSwift/Basics.md @@ -52,7 +52,7 @@ $ swiftc -target armv7-none-none-eabi -enable-experimental-feature Embedded -wmo input1.swift input2.swift ... -c -o output.o ``` -> Note: Passing only a single `.swift` file to swiftc results in the generation of a `_main` symbol. During linking, this symbol could potentially clash with other objects that also define one. To avoid this, compile multiple Swift files together or use the `-parse-as-library` flag. +> Note: Passing only a single `.swift` file to swiftc results in the generation of a `_main` (Mach-O targets) or `main` (ELF) symbol. During linking, this symbol could potentially clash with other objects that also define one. To avoid this, compile multiple Swift files together or use the `-parse-as-library` flag. Additionally, you probably want to specify additional Clang and/or LLVM flags to get the compiler to produce code for the exact ISA and ABI you need for your target.