1- // swift-tools-version: 5.10
1+ // swift-tools-version: 5.8
22
33import PackageDescription
44
55let package = Package (
66 name: " FuzzTesting " ,
77 products: [
8+ // Discussion: Why we build libraries instead of executables linking libFuzzer?
9+ //
10+ // First, libclang_rt.fuzzer.a defines the main function for the fuzzing process
11+ // and object files given by the user are expected not to have a "main" function
12+ // to avoid conflicts.
13+ // Fortunately, SwiftPM asks the compiler frontend to define the main entrypoint as
14+ // `<module_name>_main` for testing executable targets (`-entry-point-function-name`)
15+ // so object files of `executableTarget` targets are capable of being linked with
16+ // libclang_rt.fuzzer.a.
17+ // However, at link-time, SwiftPM asks the linker to rename the `<module_name>_main`
18+ // symbol back to `main` for the final executable (`--defsym main=<module_name>_main`)
19+ // and gold linker respects the renamed "main" symbol rather than the one defined in
20+ // libclang_rt.fuzzer.a, so the final executable does not start the fuzzing process.
21+ //
22+ // Instead of relying on the SwiftPM's linking process, we build libraries defining
23+ // fuzzing target functions and manually link them with fuzzing runtime libraries.
824 . library( name: " FuzzTranslator " , type: . static, targets: [ " FuzzTranslator " ] ) ,
925 . library( name: " FuzzExecute " , type: . static, targets: [ " FuzzExecute " ] ) ,
26+ // FuzzDifferential is not a libFuzzer-based target, so we build it as an executable.
1027 . executable( name: " FuzzDifferential " , targets: [ " FuzzDifferential " ] ) ,
1128 ] ,
1229 dependencies: [
@@ -27,10 +44,3 @@ let package = Package(
2744 . target( name: " WasmCAPI " ) ,
2845 ]
2946)
30-
31- let libFuzzerTargets = [ " FuzzTranslator " , " FuzzExecute " ]
32-
33- for target in package . targets {
34- guard libFuzzerTargets. contains ( target. name) else { continue }
35- target. swiftSettings = [ . unsafeFlags( [ " -Xfrontend " , " -sanitize=fuzzer,address " ] ) ]
36- }
0 commit comments