Skip to content

Fuzzing support is broken since Xcode 15 #8731

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

Open
RazrFalcon opened this issue Aug 9, 2024 · 2 comments · May be fixed by #8729
Open

Fuzzing support is broken since Xcode 15 #8731

RazrFalcon opened this issue Aug 9, 2024 · 2 comments · May be fixed by #8729
Labels

Comments

@RazrFalcon
Copy link

RazrFalcon commented Aug 9, 2024

Description

I was using the following command to build a Swift package for fuzzing before:

swift build -c debug -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library

After updating to Xcode 15 this no longer works with the following error:

Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
Undefined symbols for architecture arm64:
  "_Fuzz_main", referenced from:
      _main in command-line-aliases-file
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[6/8] Linking Fuzz

I've tried 5.10-DEVELOPMENT-SNAPSHOT-2023-12-21-a and 6.0-DEVELOPMENT-SNAPSHOT-2024-08-08-a Swift builds.

If I switch to Xcode 14, which is a bit of a pain, since it's no longer supported on macOS 14, then everything works just fine again:

> swift build -c debug -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library
Building for debugging...
ld: warning: undefined base symbol '_Fuzz_main' for alias '_main'
/Users/name/Documents/Fuzzing/.build/arm64-apple-macosx/debug/Fuzz: replacing existing signature
[6/6] Applying Fuzz
Build complete! (12.94s)

Reproduction

Download the latest Swift snapshot from https://www.swift.org/download/#snapshots Version 5 or 6, doesn't matter.

Create an empty SPM project with the following Package.swift:

// swift-tools-version: 5.7

import PackageDescription

let package = Package(
    name: "Fuzzer",
    targets: [
        .executableTarget(name: "Fuzz"),
    ]
)

and main.swift:

import Foundation

@_cdecl("LLVMFuzzerTestOneInput") public func fuzz(ptr: UnsafePointer<CChar>, size: CInt) -> CInt {
    return 0
}

Whole package: FuzzingSample.zip

Select the required Swift version using swiftenv, like:

swiftenv local 5.10-DEVELOPMENT-SNAPSHOT-2023-12-21-a

Run:

swift build -c debug -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library

Expected behavior

An ability to fuzz Swift code using libFuzzer.

Environment

Apple Swift version 5.10-dev (LLVM e8e5be8d5b39f46, Swift 935dc3eae905669)
Target: arm64-apple-macosx14.0

Xcode 15.4 (15F31d)
macOS 14.5 (23F79)

Additional information

No response

@thomasvl
Copy link
Contributor

Any chance of this getting some more attention? https://www.swift.org/support/security.html sites the oss-fuzz testing for multiple fixes, so it seems like fuzz support is somewhat importing to Swift.

@DanBlackwell
Copy link

So looking at the verbose output from the swift build command, it looks like this linker error is down to the build process attempting to alias main. See the following (final) compile command:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang /path/to/package/.build/arm64-apple-macosx/debug/swift_fuzzing_repro.build/main.swift.o ... -Xlinker -no_warn_duplicate_libraries -Xlinker -alias -Xlinker _ swift_fuzzing_repro_main -Xlinker _main ... -o /path/to/package/.build/arm64-apple-macosx/debug/swift_fuzzing_repro

Copying this command and removing -Xlinker -alias -Xlinker _swift_fuzzing_repro_main -Xlinker _main results in the fuzzer binary building correctly.

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

Successfully merging a pull request may close this issue.

3 participants