Support -fatal-warnings (without underscore) to be compatible with ld.gold

Originator:keithbsmiley
Number:rdar://46151736 Date Originated:17-Nov-2018 01:36 PM
Status:Open Resolved:
Product:Developer Tools Product Version:ld64-409.12
Classification:UI/Usability Reproducible:Always
 
Summary:
Currently if you have a cross-platform Swift PM project, you may want to pass `-Xlinker -fatal_warnings` for release builds (along with `-Xswiftc -warnings-as-errors`). To support this on both macOS and Linux, you have to do this conditionally in some script, so that you can pass -fatal_warnings to ld64, and -fatal-warnings to ld.gold. It would be great if ld64 supported a compatible flag to not have to add a platform conditional.

Steps to Reproduce:
1. On Linux and macOS in a SwiftPM project run `swift build -Xlinker -fatal-warnings`

Expected Results:
It works on both platforms

Actual Results:
It passes on Linux, and fails on macOS

Version:
ld64-409.12

Notes:
Attached is a possible patch (with tests!) to support this based on the Xcode 10.0.0 source dump from opensource.apple.com.

Comments

Here's the patch I attached:


diff --git i/src/ld/Options.cpp w/src/ld/Options.cpp
index 09290a9..ab037f9 100644
--- i/src/ld/Options.cpp
+++ w/src/ld/Options.cpp
@@ -3103,7 +3103,7 @@ void Options::parse(int argc, const char* argv[])
 			else if ( strcmp(arg, "-w") == 0 ) {
 				// previously handled by buildSearchPaths()
 			}
-			else if ( strcmp(arg, "-fatal_warnings") == 0 ) {
+			else if ( strcmp(arg, "-fatal_warnings") == 0 ||  strcmp(arg, "-fatal-warnings") == 0 ) {
 				// previously handled by buildSearchPaths()
 			}
 			else if ( strcmp(arg, "-arch_errors_fatal") == 0 ) {
@@ -3997,7 +3997,7 @@ void Options::buildSearchPaths(int argc, const char* argv[])
 		else if ( strcmp(argv[i], "-w") == 0 ) {
 			sEmitWarnings = false;
 		}
-		else if ( strcmp(argv[i], "-fatal_warnings") == 0 ) {
+		else if ( strcmp(argv[i], "-fatal_warnings") == 0 ||  strcmp(argv[i], "-fatal-warnings") == 0 ) {
 			sFatalWarnings = true;
 		}
 		else if ( strcmp(argv[i], "-dependency_info") == 0 ) {
diff --git i/unit-tests/test-cases/fatal_warning/Makefile w/unit-tests/test-cases/fatal_warning/Makefile
index 6758bc0..9d5c621 100644
--- i/unit-tests/test-cases/fatal_warning/Makefile
+++ w/unit-tests/test-cases/fatal_warning/Makefile
@@ -34,6 +34,7 @@ run: all
 
 all:
 	${PASS_IFF_ERROR} ${CC} ${CCFLAGS} main.c -o main -pagezero_size 123 -Wl,-fatal_warnings  2>msgs.txt
+	${PASS_IFF_ERROR} ${CC} ${CCFLAGS} main.c -o main -pagezero_size 123 -Wl,-fatal-warnings  2>msgs.txt
 
 
 clean:

By keithbsmiley at Nov. 17, 2018, 9:38 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!