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

Undefined hidden symbols when linking with -c opt on Linux #882

Closed
jpsim opened this issue Aug 23, 2022 · 3 comments
Closed

Undefined hidden symbols when linking with -c opt on Linux #882

jpsim opened this issue Aug 23, 2022 · 3 comments

Comments

@jpsim
Copy link
Contributor

jpsim commented Aug 23, 2022

Linker errors
ERROR: /workdir/BUILD:33:13: Linking swiftlint failed: (Exit 1): clang-13 failed: error executing command /usr/bin/clang-13 @bazel-out/k8-opt/bin/external/sourcekitten_com_github_drmohundro_SWXMLHash/SWXMLHash.autolink ... (remaining 12 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
ld.lld: error: undefined hidden symbol: __start_swift5_protocols
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_protocols
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_protocol_conformances
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_protocol_conformances
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_type_metadata
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_type_metadata
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_assocty
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_assocty
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_replace
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_replace
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_replac2
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_replac2
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __start_swift5_builtin
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())

ld.lld: error: undefined hidden symbol: __stop_swift5_builtin
>>> referenced by SwiftRT-ELF.cpp
>>>               /usr/lib/swift/linux/x86_64/swiftrt.o:(swift_image_constructor())
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce (Requires Docker):

$ git clone https://github.com/realm/SwiftLint.git
$ cd SwiftLint
$ git checkout 145175f16c6b53c2b9e7a7a9497d92d1bdcbd26a
$ docker build .

Also full logs are available on SwiftLint's CI: https://github.com/realm/SwiftLint/runs/7976793407?check_suite_focus=true

If you change -c opt for -c dbg on this line there are no linker errors: https://github.com/realm/SwiftLint/blob/145175f16c6b53c2b9e7a7a9497d92d1bdcbd26a/Dockerfile#L26

I see the same error if I build for amd64 or arm64. I don't have the same error if I build on macOS.

I'm using rules_swift 469db13

@keith
Copy link
Member

keith commented Aug 23, 2022

This is because of this swift issue swiftlang/swift#60406, it only appears in opt because bazel passes --gc-sections only for opt builds. You should be able to work around it by passing --linkopt=-z --linkopt nostart-stop-gc on Linux.

@keith
Copy link
Member

keith commented Aug 23, 2022

In Swift 5.7 (or maybe 5.7.1 who knows), it will be fixed by automatically adding this for you when using lld. You can also switch to a different linker to avoid this if that's easier.

@jpsim
Copy link
Contributor Author

jpsim commented Aug 23, 2022

Thanks for linking the root issue, I'll close this since it's not rules_swift-specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants