-
Notifications
You must be signed in to change notification settings - Fork 128
Change how libraries are specified to the linker when using searched libs #890
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
daveinglis
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
daveinglis:building_tests_fixes_windows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1289,41 +1289,12 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec | |
| private static func computeLibraryArgs(_ libraries: [LibrarySpecifier], scope: MacroEvaluationScope) -> (args: [String], inputs: [Path]) { | ||
| // Construct the library arguments. | ||
| return libraries.compactMap { specifier -> (args: [String], inputs: [Path]) in | ||
| let basename = specifier.path.basename | ||
|
|
||
| // FIXME: This isn't a good system, we need to redesign how we talk to the linker w.r.t. search paths and our notion of paths. | ||
| switch specifier.kind { | ||
| case .static: | ||
| if specifier.useSearchPaths, basename.hasPrefix("lib"), basename.hasSuffix(".a") { | ||
| return (specifier.searchPathFlagsForLd(basename.withoutPrefix("lib").withoutSuffix(".a")), []) | ||
| } | ||
| return (specifier.absolutePathFlagsForLd(), [specifier.path]) | ||
| case .dynamic: | ||
| let suffix = ".\(scope.evaluate(BuiltinMacros.DYNAMIC_LIBRARY_EXTENSION))" | ||
| if specifier.useSearchPaths, basename.hasPrefix("lib"), basename.hasSuffix(suffix) { | ||
| return (specifier.searchPathFlagsForLd(basename.withoutPrefix("lib").withoutSuffix(suffix)), []) | ||
| } | ||
| return (specifier.absolutePathFlagsForLd(), [specifier.path]) | ||
| case .textBased: | ||
| if specifier.useSearchPaths, basename.hasPrefix("lib"), basename.hasSuffix(".tbd") { | ||
| // .merge and .reexport are not supported for text-based libraries. | ||
| return (specifier.searchPathFlagsForLd(basename.withoutPrefix("lib").withoutSuffix(".tbd")), []) | ||
| } | ||
| return (specifier.absolutePathFlagsForLd(), [specifier.path]) | ||
| case .framework: | ||
| let frameworkName = Path(basename).withoutSuffix | ||
| case .static, .dynamic, .textBased, .framework: | ||
| if specifier.useSearchPaths { | ||
| return (specifier.searchPathFlagsForLd(frameworkName), []) | ||
| return (specifier.searchPathFlagsForLd(), []) | ||
| } | ||
| let absPathArgs = specifier.absolutePathFlagsForLd() | ||
| let returnPath: Path | ||
| if let pathArg = absPathArgs.last, Path(pathArg).basename == frameworkName { | ||
| returnPath = Path(pathArg) | ||
| } | ||
| else { | ||
| returnPath = specifier.path | ||
| } | ||
| return (absPathArgs, [returnPath]) | ||
| return (specifier.absolutePathFlagsForLd(), [specifier.path]) | ||
| case .object: | ||
| // Object files are added to linker inputs in the sources task producer. | ||
| return ([], []) | ||
|
|
@@ -1559,35 +1530,47 @@ public final class LdLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @unchec | |
|
|
||
| /// Extensions to `LinkerSpec.LibrarySpecifier` specific to the dynamic linker. | ||
| fileprivate extension LinkerSpec.LibrarySpecifier { | ||
| func searchPathFlagsForLd(_ name: String) -> [String] { | ||
|
|
||
| func searchPathFlagsForLd() -> [String] { | ||
| precondition(useSearchPaths) | ||
| // Extract basename once to avoid redundant operations | ||
| let basename = path.basename | ||
| let basenameWithoutSuffix = Path(basename).withoutSuffix | ||
| // Strip the prefix if one exists and is present in the basename | ||
| let strippedName: String | ||
| if let prefix = libPrefix, basename.hasPrefix(prefix) { | ||
| strippedName = basenameWithoutSuffix.withoutPrefix(prefix) | ||
| } else { | ||
| strippedName = basenameWithoutSuffix | ||
| } | ||
| switch (kind, mode) { | ||
| case (.dynamic, .normal): | ||
| return ["-l" + name] | ||
| return ["-l" + strippedName] | ||
| case (.dynamic, .reexport): | ||
| return ["-Xlinker", "-reexport-l" + name] | ||
| return ["-Xlinker", "-reexport-l" + strippedName] | ||
| case (.dynamic, .merge): | ||
| return ["-Xlinker", "-merge-l" + name] | ||
| return ["-Xlinker", "-merge-l" + strippedName] | ||
| case (.dynamic, .reexport_merge): | ||
| return ["-Xlinker", "-no_merge-l" + name] | ||
| return ["-Xlinker", "-no_merge-l" + strippedName] | ||
| case (.dynamic, .weak): | ||
| return ["-weak-l" + name] | ||
| return ["-weak-l" + strippedName] | ||
| case (.static, .weak), | ||
| (.textBased, .weak): | ||
| return ["-weak-l" + name] | ||
| return ["-weak-l" + strippedName] | ||
| case (.static, _), | ||
| (.textBased, _): | ||
| // Other modes are not supported for these kinds. | ||
| return ["-l" + name] | ||
| return ["-l" + strippedName] | ||
| case (.framework, .normal): | ||
| return ["-framework", name] | ||
| return ["-framework", strippedName] | ||
| case (.framework, .reexport): | ||
| return ["-Xlinker", "-reexport_framework", "-Xlinker", name] | ||
| return ["-Xlinker", "-reexport_framework", "-Xlinker", strippedName] | ||
| case (.framework, .merge): | ||
| return ["-Xlinker", "-merge_framework", "-Xlinker", name] | ||
| return ["-Xlinker", "-merge_framework", "-Xlinker", strippedName] | ||
| case (.framework, .reexport_merge): | ||
| return ["-Xlinker", "-no_merge_framework", "-Xlinker", name] | ||
| return ["-Xlinker", "-no_merge_framework", "-Xlinker", strippedName] | ||
| case (.framework, .weak): | ||
| return ["-weak_framework", name] | ||
| return ["-weak_framework", strippedName] | ||
| case (.object, _): | ||
| // Object files are added to linker inputs in the sources task producer. | ||
| return [] | ||
|
|
@@ -1724,15 +1707,17 @@ public final class LibtoolLinkerSpec : GenericLinkerSpec, SpecIdentifierType, @u | |
| delegate.warning("Product \(cbc.output.basename) cannot weak-link \(specifier.kind) \(basename)") | ||
| } | ||
|
|
||
| if specifier.useSearchPaths, basename.hasPrefix("lib"), basename.hasSuffix(".a") { | ||
| if specifier.useSearchPaths { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we emit some kind of warning here if the library name doesn't have one of the prefixes we think will allow it to be found via search paths? |
||
| // Locate using search paths: Add a -l option and *don't* add the path to the library as an input to the task. | ||
| return ["-l" + basename.withoutPrefix("lib").withoutSuffix(".a")] | ||
| } | ||
| else { | ||
| // Locate using an absolute path: Add the path as an option and as an input to the task. | ||
| inputPaths.append(specifier.path) | ||
| return [specifier.path.str] | ||
| let basename = specifier.path.basename | ||
| let expectedPrefix = specifier.libPrefix ?? "lib" | ||
| if basename.hasPrefix(expectedPrefix) { | ||
| return ["-l" + Path(basename).withoutSuffix.withoutPrefix(expectedPrefix)] | ||
| } | ||
| } | ||
| // Locate using an absolute path: Add the path as an option and as an input to the task. | ||
| inputPaths.append(specifier.path) | ||
| return [specifier.path.str] | ||
|
|
||
| case .object: | ||
| // Object files are added to linker inputs in the sources task producer and so end up in the link-file-list. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here, should we warn if we get a filename format we don't recognize here / don't think will be found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, rethinking this.... I think we need to fallback to using absolute path linking when that happens, this would be the same as how it was before....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are also tests that would have this warning (and fail due to it), but since we will fallback to an absolute path, not sure the warning it necessary now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
falling back w/ no warning makes sense to me