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

[SR-2170] Linux Linker error when deriving a class from NSURL #4454

Closed
swift-ci opened this issue Jul 26, 2016 · 5 comments
Closed

[SR-2170] Linux Linker error when deriving a class from NSURL #4454

swift-ci opened this issue Jul 26, 2016 · 5 comments

Comments

@swift-ci
Copy link
Contributor

@swift-ci swift-ci commented Jul 26, 2016

Previous ID SR-2170
Radar None
Original Reporter dsperling (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Linux Toolchain 0620 or Preview 2

Additional Detail from JIRA
Votes 2
Component/s Foundation
Labels Bug, Linux
Assignee None
Priority Medium

md5: a5a07129f728b6f25484e450eb46d70d

relates to:

  • SR-1901 Linker error "hidden symbol" on subclassing Thread

Issue Description:

The following code compiles but fails to link on Linux. Mac works OK.

import Foundation

public class URLParser : NSURL {

    public init(url: NSData) {
#if os(Linux)
        super.init(string: String(data: url, encoding: NSUTF8StringEncoding) ?? "", relativeToURL: nil)!
#else
        super.init(string: String(data: url as Data, encoding: String.Encoding.utf8) ?? "", relativeTo: nil)!
#endif
    }

    // NSURL required initializers
    required convenience public init(fileReferenceLiteralResourceName path: String) {
        fatalError("init(fileReferenceLiteralResourceName:) has not been implemented")
    }
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

let _ = URLParser(url: "https://swift.org".data(using: NSUTF8StringEncoding)!)

The linker errors with:

/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLg5_baseVS_7_CFInfo' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLs5_baseVS_7_CFInfo' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLm5_baseVS_7_CFInfo' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLg6_flagsVs6UInt32' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLs6_flagsVs6UInt32' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLm6_flagsVs6UInt32' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLg9_encodingVs6UInt32' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLs9_encodingVs6UInt32' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLm9_encodingVs6UInt32' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLg7_stringGSqGSpCSo8CFString__' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLs7_stringGSqGSpCSo8CFString__' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLm7_stringGSqGSpCSo8CFString__' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLg8_baseURLGSqGSpCSo5CFURL__' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLs8_baseURLGSqGSpCSo5CFURL__' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLm8_baseURLGSqGSpCSo5CFURL__' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLg6_extraGSqVs13OpaquePointer_' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLs6_extraGSqVs13OpaquePointer_' is not defined locally
/usr/bin/ld: error: hidden symbol '_TFC10Foundation5NSURLm6_extraGSqVs13OpaquePointer_' is not defined locally

...
@swift-ci
Copy link
Contributor Author

@swift-ci swift-ci commented Jul 26, 2016

Comment by Dave Sperling (JIRA)

The problem persists with the Linux 0725 toolchain.

import Foundation

public class URLParser : NSURL {

    public init(url: Data) {
        super.init(string: String(data: url, encoding: String.Encoding.utf8) ?? "", relativeTo: nil)!
    }

    // NSURL required initializers
    required convenience public init(fileReferenceLiteralResourceName path: String) {
        fatalError("init(fileReferenceLiteralResourceName:) has not been implemented")
    }
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

let _ = URLParser(url: "https://swift.org".data(using: String.Encoding.utf8)!)

@swift-ci
Copy link
Contributor Author

@swift-ci swift-ci commented Sep 1, 2016

Comment by David Grove (JIRA)

Problem still present with Linux 0830 toolchain. Updated test case below:

import Foundation

public class URLParser : NSURL {

    public init(url: Data) {
        super.init(string: String(data: url, encoding: String.Encoding.utf8) ?? "", relativeTo: nil)!
    }

    // NSURL required initializers
    required convenience public init(fileReferenceLiteralResourceName path: String) {
        fatalError("init(fileReferenceLiteralResourceName:) has not been implemented")
    }
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

let _ = URLParser(url: "https://swift.org".data(using: String.Encoding.utf8)!)

@swift-ci
Copy link
Contributor Author

@swift-ci swift-ci commented Sep 1, 2016

Comment by David Grove (JIRA)

This is a general problem with subclassing an open class with internal members external to the defining library. For example, the code below also fails with linker errors:

import Foundation

public class MyOperation : Operation {
}

let o = MyOperation()

@modocache
Copy link
Mannequin

@modocache modocache mannequin commented Sep 21, 2016

Another example of this affecting corelibs API: #651

@spevans
Copy link
Collaborator

@spevans spevans commented Mar 5, 2020

These now compile and link under recent versions of swift - the NSURL subclassing fails for other reasons internal to the implenetation of NSURL - but the link issue is now resolved.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants