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

Suppress redundant linkage warnings due to dependency linkage propagation #7404

Merged
merged 16 commits into from Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,9 +8,7 @@ let package = Package(
.executableTarget(
name: "DoNotFilterLinkerDiagnostics",
linkerSettings: [
.linkedLibrary("z"),
.unsafeFlags(["-lz"]),
// should produce: ld: warning: ignoring duplicate libraries: '-lz'
.unsafeFlags(["-Lfoobar"]),
]
),
]
Expand Down
Expand Up @@ -189,6 +189,12 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription

var isLinkingStaticStdlib = false
let triple = self.buildParameters.triple

// radar://112671586 supress unnecessary warnings
if triple.isMacOSX {
args += ["-Xlinker", "-no_warn_duplicate_libraries"]
}

switch derivedProductType {
case .macro:
throw InternalError("macro not supported") // should never be reached
Expand Down
3 changes: 3 additions & 0 deletions Sources/XCBuildSupport/PIFBuilder.swift
Expand Up @@ -672,6 +672,9 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
impartedSettings[.OTHER_LDFLAGS, default: ["$(inherited)"]].append("-lc++")
}

// radar://112671586 supress unnecessary warnings
impartedSettings[.OTHER_LDFLAGS, default: ["$(inherited)"]].append("-Wl,-no_warn_duplicate_libraries")

addSources(target.sources, to: pifTarget)

// Handle the target's dependencies (but don't link against them).
Expand Down
15 changes: 15 additions & 0 deletions Tests/BuildTests/BuildPlanTests.swift
Expand Up @@ -773,6 +773,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -1186,6 +1187,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-dead_strip",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
Expand Down Expand Up @@ -1276,6 +1278,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -1435,6 +1438,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -1625,6 +1629,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -1779,6 +1784,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -2027,6 +2033,7 @@ final class BuildPlanTests: XCTestCase {
buildPath.appending(components: "PkgPackageTests.xctest", "Contents", "MacOS", "PkgPackageTests")
.pathString,
"-module-name", "PkgPackageTests",
"-Xlinker", "-no_warn_duplicate_libraries",
"-Xlinker", "-bundle",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path/../../../",
"@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -2125,6 +2132,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-dead_strip",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
Expand Down Expand Up @@ -2489,6 +2497,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -2636,6 +2645,7 @@ final class BuildPlanTests: XCTestCase {
"-o", buildPath.appending(components: "Foo").pathString,
"-module-name", "Foo",
"-lBar-Baz",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "Foo.product", "Objects.LinkFileList"))",
Expand All @@ -2651,6 +2661,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "libBar-Baz.dylib").pathString,
"-module-name", "Bar_Baz",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-library",
"-Xlinker", "-install_name", "-Xlinker", "@rpath/libBar-Baz.dylib",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
Expand Down Expand Up @@ -2803,6 +2814,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "liblib.dylib").pathString,
"-module-name", "lib",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-library",
"-Xlinker", "-install_name", "-Xlinker", "@rpath/liblib.dylib",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
Expand Down Expand Up @@ -2942,6 +2954,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "liblib.dylib").pathString,
"-module-name", "lib",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-library",
"-Xlinker", "-install_name", "-Xlinker", "@rpath/liblib.dylib",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
Expand All @@ -2956,6 +2969,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"-Xlinker", "-rpath", "-Xlinker", "@loader_path",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
Expand Down Expand Up @@ -6158,6 +6172,7 @@ final class BuildPlanTests: XCTestCase {
"-L", buildPath.pathString,
"-o", buildPath.appending(components: "exe").pathString,
"-module-name", "exe",
"-Xlinker", "-no_warn_duplicate_libraries",
"-emit-executable",
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/BuildSystemDelegateTests.swift
Expand Up @@ -25,7 +25,7 @@ final class BuildSystemDelegateTests: XCTestCase {
try XCTSkipIf(true, "test is only supported on macOS")
#endif
let (fullLog, _) = try executeSwiftBuild(fixturePath)
XCTAssertTrue(fullLog.contains("ld: warning: ignoring duplicate libraries: '-lz'"), "log didn't contain expected linker diagnostics")
XCTAssertTrue(fullLog.contains("ld: warning: search path 'foobar' not found"), "log didn't contain expected linker diagnostics")
}
}

Expand Down
6 changes: 4 additions & 2 deletions Tests/XCBuildSupportTests/PIFBuilderTests.swift
Expand Up @@ -1312,6 +1312,7 @@ class PIFBuilderTests: XCTestCase {
"-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/FooLib1.modulemap"
])
XCTAssertEqual(settings[.OTHER_LDRFLAGS], [])
XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-Wl,-no_warn_duplicate_libraries"])
}
}

Expand Down Expand Up @@ -1384,7 +1385,7 @@ class PIFBuilderTests: XCTestCase {
"-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/FooLib2.modulemap"
])
XCTAssertEqual(settings[.OTHER_LDRFLAGS], [])
XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-lc++"])
XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-lc++", "-Wl,-no_warn_duplicate_libraries"])
XCTAssertEqual(settings[.OTHER_SWIFT_FLAGS], [
"$(inherited)",
"-Xcc", "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/FooLib2.modulemap"
Expand Down Expand Up @@ -1463,6 +1464,7 @@ class PIFBuilderTests: XCTestCase {
"-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/BarLib.modulemap"
])
XCTAssertEqual(settings[.OTHER_LDRFLAGS], [])
XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-Wl,-no_warn_duplicate_libraries"])
XCTAssertEqual(settings[.OTHER_SWIFT_FLAGS], [
"$(inherited)",
"-Xcc", "-fmodule-map-file=$(OBJROOT)/GeneratedModuleMaps/$(PLATFORM_NAME)/BarLib.modulemap"
Expand Down Expand Up @@ -2393,7 +2395,7 @@ class PIFBuilderTests: XCTestCase {
target.checkImpartedBuildSettings { settings in
XCTAssertEqual(settings[.GCC_PREPROCESSOR_DEFINITIONS], nil)
XCTAssertEqual(settings[.HEADER_SEARCH_PATHS], nil)
XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-lz"])
XCTAssertEqual(settings[.OTHER_LDFLAGS], ["$(inherited)", "-Wl,-no_warn_duplicate_libraries", "-lz"])
XCTAssertEqual(settings[.OTHER_SWIFT_FLAGS], nil)
}
}
Expand Down