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-9384] Figure out why Foundation integration test for compiling on Linux with -static-stdlib fails #628

Open
gottesmm opened this issue Nov 30, 2018 · 13 comments

Comments

@gottesmm
Copy link
Member

Previous ID SR-9384
Radar None
Original Reporter @gottesmm
Type Task
Additional Detail from JIRA
Votes 0
Component/s Foundation, libdispatch
Labels Task
Assignee None
Priority Medium

md5: a5cc649f55665ecc6571bab8d1d28caa

relates to:

Issue Description:

I committed this test thinking that this was working. I am going to disable this and send it over to compnerd/spevans who were the ones messing with this I believe.

From the bot:

"/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-master/buildbot_linux/none-swift_package_sandbox_linux-x86_64/usr/bin/swiftc" "-static-stdlib" "/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-master/swift-integration-tests/test-static-stdlib/main.swift" "-o" "/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-master/buildbot_linux/none-swift_package_sandbox_linux-x86_64/tests/test-static-stdlib/Output/test-static-stdlib.test.tmp/main"

And a selection of errors:

/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-master/buildbot_linux/none-swift_package_sandbox_linux-x86_64/usr/lib/swift_static/linux/libdispatch.a(apply.c.o): requires unsupported dynamic reloc 11; recompile with -fPIC

*01:36:40* /home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-master/buildbot_linux/none-swift_package_sandbox_linux-x86_64/usr/lib/swift_static/linux/libFoundation.a(Bundle.swift.o):Bundle.swift.o:function $s10Foundation6BundleC16bundleIdentifierSSSgvg: error: undefined reference to 'CFBundleGetIdentifier'
@gottesmm
Copy link
Member Author

@spevans @compnerd thoughts?

@gottesmm
Copy link
Member Author

Here is the build:

https://ci.swift.org/job/swift-PR-Linux/9316/

@gottesmm
Copy link
Member Author

Disabled in thie PR: apple/swift-integration-tests#45

@spevans
Copy link
Contributor

spevans commented Nov 30, 2018

When I was trying this out before I think I just used the -fPIC for libdispatch and it worked.

The 2nd error looks to be that CoreFoundation.a is not linked into libFoundation.a

@spevans
Copy link
Contributor

spevans commented Nov 30, 2018

I ran this test myself and there is also an error, undefined reference to strlcpy and getprogname. This is due to a lack of -lbsd.

We could try and fix up the auto link or alternatively make libdispatch use program_invocation_short_name and snprintf on Linux and remove the use of -lbsd completely.

@compnerd
Copy link
Collaborator

Cool, I think that fixing the PIC thing is easy. The linking ... well, that requires a bit more effort. The problem is that ELF doesn't have autolinking. I've added an extension to LLVM to add support for this to lld. We could hack this via the linker response file that we build.

@gottesmm
Copy link
Member Author

I would love if swift on Linux used lld provided lld is ready (that is my only concern). It will enable us to use more advanced features and a higher likelihood of being able to push in features to the linker that we need on Linux without having to leave LLVM land.

@compnerd
Copy link
Collaborator

compnerd commented Dec 1, 2018

Created #434 for building libdispatch as PIC. Tweaking the CoreFoundation link is a second issue.

@gottesmm, I think that the biggest blocker to that is the fact that it requires updating the `update-checkout` and `build-script` monsters. I can tell you that it has been extensively tested and should be considered production ready for Linux (and resultantly, android) x86, x86_64, arm, aarch64. I am unsure if the Linux PPC, PPC64 targets have received as much testing. Windows x86, x86_64 should be considered production ready, the support for Windows arm be considered experimental, and Windows arch64 is missing.

@spevans, when you say that CoreFoundation is not linked into Foundation what do you mean? static libraries aren't really linked per se. Should we be including the target objects of CoreFoundation into Foundation?

@spevans
Copy link
Contributor

spevans commented Dec 1, 2018

Yes, before the CMake changes, libFoundation.a had the libCoreFoundation.a objects included:

$ nm swift-4.2-RELEASE-ubuntu18.04/usr/lib/swift_static/linux/libFoundation.a |grep ' CFHashBytes'
00000000000000f0 T CFHashBytes
                 U CFHashBytes
[...etc...]

$ nm swift-DEVELOPMENT-SNAPSHOT-2018-11-30-a-ubuntu18.04/usr/lib/swift_static/linux/libFoundation.a |grep ' CFHashBytes'
                 U CFHashBytes
[...etc...]                 

@gottesmm
Copy link
Member Author

gottesmm commented Dec 2, 2018

@compnerd I am fine in that case, but I think it is important that a discussion happens on swift-dev. Additionally, instead of conditionally cloning lld only on linux (like we are doing now with ICU), can we just always check it out.

It makes it so that I can clone on a Darwin host and then compile on a docker Linux much faster.

@spevans
Copy link
Contributor

spevans commented Dec 2, 2018

I tested the PIC change and added -lbsd into utils/gen-static-stdlib-link-args which generated the usr/lib/swift_static/linux/static-stdlib-args.lnk file and these two changes worked so I think merging the CoreFoundation objects into libFoundation.a is the last bit to do.

@spevans
Copy link
Contributor

spevans commented Oct 5, 2020

This looks to have been fixed by https://github.com/apple/swift-corelibs-foundation/pull/2850

I locally re-enabled the test disabled in apple/swift-integration-tests#45 and it passed so I think this is now fixed.

@spevans
Copy link
Contributor

spevans commented Nov 29, 2020

PR to re-enable this test: apple/swift-integration-tests#78

This should work now that -static-stdlib works on Linux

@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
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

3 participants