Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pico-blink Build Error #5

Open
star-light-1 opened this issue Apr 18, 2024 · 7 comments
Open

pico-blink Build Error #5

star-light-1 opened this issue Apr 18, 2024 · 7 comments
Assignees

Comments

@star-light-1
Copy link

When trying to build the pico-blink example on macOS with:

cd swift-embedded-examples/pico-blink
rm -rf .build ; TOOLCHAINS=org.swift.59202404131a ./build.sh

I get the following error:

# Link
$CLANG .build/release/Support.build/{Support.c,crt0.S}.o .build/release/Blinky.build/*.o -target armv6m-apple-none-macho -o $BUILDROOT/blinky $LD_FLAGS
+ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/bin/clang .build/release/Support.build/Support.c.o .build/release/Support.build/crt0.S.o .build/release/Blinky.build/Blinky.swift.o -target armv6m-apple-none-macho -o /path/to/swift-embedded-examples/pico-blink/.build/armv6m-apple-none-macho/release/blinky -static -Wl,-e,_reset -dead_strip -Wl,-no_zero_fill_sections -Wl,-segalign,4 -Wl,-segaddr,__RESET,0x20000000 -Wl,-segaddr,__VECTORS,0x20000100 -Wl,-seg1addr,0x20000200 -Wl,-pagezero_size,0 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/macho_embedded/libclang_rt.soft_static.a
ld: warning: ignoring file /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain/usr/lib/clang/17/lib/darwin/macho_embedded/libclang_rt.soft_static.a, building for free standing-armv6m but attempting to link with file built for macOS-armv7
ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/macho_embedded/libclang_rt.soft_static.a, building for free standing-armv6m but attempting to link with file built for macOS-armv7
Undefined symbols for architecture armv6m:
  "___muldi3", referenced from:
      _$s6Blinky4MainV5delayyySiFZTf4nd_n in Blinky.swift.o
ld: symbol(s) not found for architecture armv6m
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is the ___muldi3 symbol not available on armv6m? If not, why is it being used?

System information:

swift-DEVELOPMENT-SNAPSHOT-2024-04-13-a.xctoolchain
Apple Swift version 6.0-dev (LLVM 01231f56c62f4c4, Swift abaa63821080b92)
Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1

Toolchain ID:

$ plutil -extract CFBundleIdentifier raw -o - /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-*.xctoolchain/Info.plist                                    
org.swift.59202404131a

Git commit of swift-embedded-examples:

69dc23e718c5b20797daec17d4754cd42bb21c24

Full build log: pico-blink-build-log.txt

@Joannis
Copy link

Joannis commented Apr 26, 2024

@star-light-1 ___muldi3 multiplies two integers. The 100 * N is where multiplication is used in func delay(_ N: Int)

@Joannis
Copy link

Joannis commented Apr 26, 2024

Try using the toolchain from April 3rd, that worked for me.

@star-light-1
Copy link
Author

The oldest toolchain I could find in section "Trunk Development (main)" on swift.org/download is April 4, 2024, which for me produces the same error shown above.
Latest toolchain of the 5.10 branch produces:

error: unable to load standard library for target 'armv6m-apple-none-macho'

@kubamracek
Copy link
Collaborator

I can sort-of reproduce the problem. One issue is that this part of the build script for pico-blink should not be necessary anymore, as the expectation is that the downloadable swift.org toolchain includes a valid libclang_rt.soft_static.a for the CPU arch we're building here (armv6m):

XCODE_RESOURCE_DIR=`env TOOLCHAINS="" xcrun clang -print-resource-dir`
LD_FLAGS+=" $XCODE_RESOURCE_DIR/lib/darwin/macho_embedded/libclang_rt.soft_static.a"

Once I drop this, I get:

# Link
$CLANG .build/release/Support.build/{Support.c,crt0.S}.o .build/release/Blinky.build/*.o -target armv6m-apple-none-macho -o $BUILDROOT/blinky $LD_FLAGS
+ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-25-a.xctoolchain/usr/bin/clang .build/release/Support.build/Support.c.o .build/release/Support.build/crt0.S.o .build/release/Blinky.build/Blinky.swift.o -target armv6m-apple-none-macho -o /Users/kuba/Documents/swift-embedded-examples/pico-blink/.build/armv6m-apple-none-macho/release/blinky -static -Wl,-e,_reset -dead_strip -Wl,-no_zero_fill_sections -Wl,-segalign,4 -Wl,-segaddr,__RESET,0x20000000 -Wl,-segaddr,__VECTORS,0x20000100 -Wl,-seg1addr,0x20000200 -Wl,-pagezero_size,0
ld: warning: ignoring file /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-25-a.xctoolchain/usr/lib/clang/17/lib/darwin/macho_embedded/libclang_rt.soft_static.a, building for free standing-armv6m but attempting to link with file built for macOS-armv7
Undefined symbols for architecture armv6m:
  "___muldi3", referenced from:
      _$s6Blinky4MainV5delayyySiFZTf4nd_n in Blinky.swift.o
ld: symbol(s) not found for architecture armv6m

The problem is that libclang_rt.soft_static.a is somehow only armv7 and contains no other slices. That will need to be fixed, but I'm not sure how that happens in the first place.

The only workaround I can think of (short of actually removing the multiplication from source code, but sometimes those are really useful 😄) would be to rebuild libclang_rt from LLVM's compiler-rt from source and explicitly build the armv6m slice, and link that instead.

@kubamracek
Copy link
Collaborator

@star-light-1 can I also ask which Xcode version are you using?

@kubamracek kubamracek self-assigned this Apr 27, 2024
@star-light-1
Copy link
Author

This happend using Xcode 15.3 (15E204a)

@Bauer312
Copy link

Bauer312 commented May 5, 2024

The most recent 5.10 (May 1, 2024) and 6.0 (April 30, 2024) snapshot both still produce the linker warning
ld: warning: ignoring file /<SNIP>/macho_embedded/libclang_rt.soft_static.a, building for free standing-armv6m but attempting to link with file built for macOS-armv7

5.10 fails with the undefined symbol, while 6.0 continues and produces the expected blinky.uf2 output, although not in the location that the README says it will appear. I have a pico w and it appears to reject loading it, but I need to do more testing to see if this is unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants