swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.72k stars 1.34k forks source link

[SR-13257] SwiftPM no longer works with libFuzzer #4522

Open Lukasa opened 4 years ago

Lukasa commented 4 years ago
Previous ID SR-13257
Radar rdar://problem/65819513
Original Reporter @Lukasa
Type Bug
Environment Swift 5.2.4, Ubuntu 20.04.
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 1 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 1628e01c9e53e190c7b97a3890151108

Issue Description:

Somewhere in the last few releases of Swift, SwiftPM can no longer build the kind of executable that Swift's libfuzzer integration needs.

Previously to build a fuzzer with SwiftPM one would create a Package.swift that defined an executable product and target for the fuzzer. This executable target would not contain a main.swift file, as libFuzzer wants to provide its own main symbol. Instead, it would contain a different file that contained the symbol LLVMFuzzOneInput.

To build this with SwiftPM, you'd pass -Xswiftc -sanitize=fuzzer -Xswiftc -parse-as-library. SwiftPM would trust you, try to build the executable, and find that the linker was happy due to libfuzzer providing the main symbol.

This no longer works: SwiftPM aborts early, by spotting that there is no main.swift file in the executable target. We should address this to re-enable libfuzzer support in SwiftPM.

Lukasa commented 4 years ago

@swift-ci create

aciidgh commented 4 years ago

Interesting that this ever worked. You’re effectively on your own when you use -X* escape hatch so this can’t be considered a bug. I’d instead turn this bug into adding real support for libFuzzer in SwiftPM (or maybe we already have one).

toffaletti commented 3 months ago

I was able to work around this by using -v and then stripping out all the -Xlinker flags passed at the last build step to clang. Very inconvenient though. How are folks fuzzing swift these days?