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-397] Linux - module using <dispatch/dispatch.h> does not compile cleanly with "swift build" #5437

Closed
swift-ci opened this issue Dec 28, 2015 · 29 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-397
Radar None
Original Reporter tomsheffler (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Ubuntu 14.04

Additional Detail from JIRA
Votes 3
Component/s Compiler, Package Manager
Labels Bug, Dispatch, Linux
Assignee @aciidb0mb3r
Priority Medium

md5: 3ce10e8ea99c16ef2da7e8631d663144

is duplicated by:

  • SR-415 blocks support in external c libraries disabled
  • SR-577 Compiler should pass -Xcc -fblocks when processing .h files

Issue Description:

While libdispatch is well-supported on Linux, using "Swift Build" for a module wrapping <dispatch/dispatch.h> does not compile cleanly. The problem is that to get all of the features of dispatch, "-fblocks" needs to be specified to Clang, and currently, "swift build" does not enable "-fblocks" for modules that wrap C libraries.

  • using "swift build" does not include the -fblocks directive

  • compiling directly with swiftc and including the -fblocks directive works fine

  • creating a module map that specifies "requires blocks" causes a complaint that Objective-C is not supported

Here is my original report, and a Github repo that illustrates the problem.

I made a module called "CDispatch" with a module.modulemap like this

=======
module CDispatch [system] {
header "/usr/include/dispatch/dispatch.h"
export *
link "dispatch"
}

Then I created a little demo project called gcd4 whose Source/main.swift prints some things and then uses a dispatch queue and a block to print a message after 2 seconds delay.

=========
CDispatch.dispatch_after(time, queue, {
print("Delayed!")
})

The entire project is checked in at https://github.com/sheffler/gcd4 <https://github.com/sheffler/gcd4\>
and the CDispatch module is checked in at https://github.com/sheffler/CDispatch <https://github.com/sheffler/CDispatch\>

If I try to "swift build" the project, it almost works but reports that dispatch_after is not found. It seems that this function is not defined if the "blocks" feature is not provided at compilation time.

========
Compiling Swift Module 'gcd4' (1 sources)
/home/sheffler/swift/gcd4/Sources/main.swift:42:1: error: module 'CDispatch' has no member named 'dispatch_after'
CDispatch.dispatch_after(time, queue, {
^~~~~~~~~ ~~~~~~~~~~~~~~
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/home/sheffler/src/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/swift-build-tool", "-f", "/home/sheffler/swift/gcd4/.build/debug/gcd4.o/llbuild.yaml"]

I got the demo program to work by first using "swift build" to retrieve the CDispatch module, and then manually running the compiler like this (and including the "-Xcc -fblocks" arguments)

swiftc -v -o gcd4 Sources/main.swift -I .build/debug -j8 -Onone -g -Xcc -fblocks -Xcc -F-module-map=Packages/CDispatch-1.0.0/module.modulemap -I Packages/CDispatch-1.0.0 -I /usr/local/include

@drewcrawford
Copy link
Contributor

cc: @mxcl

Would it be an acceptable resolution here to allow Package.swift to have an extraSwiftCArgs: ["-Xcc","-fblocks"] specifier? That is a simple solution that I can PR quickly.

[SR-415] is possibly a dupe of this bug.

@drewcrawford
Copy link
Contributor

I'm going to PR the solution above.

@drewcrawford
Copy link
Contributor

It looks like this has been PRed and closed before under #75.

I'm going to resurrect this discussion on the list; clearing assignment for now.

@drewcrawford
Copy link
Contributor

I have resurrected this idea under PR #107. If that PR is merged, we can say

otherCompilerOptions: ["-Xcc", "-fblocks"] 

to work around this issue.

@belkadan
Copy link

belkadan commented Jan 4, 2016

We should just add this to the compiler. However, I think we were hoping to establish a different blocks ABI on Linux, so that we can at least use Swift's retain-counting on them instead of Objective-C's.

@belkadan
Copy link

belkadan commented Jan 4, 2016

cc @jckarter, @parkera

@mxcl
Copy link
Contributor

mxcl commented Jan 4, 2016

So, to be clear, `-fblocks` is required for anything that links to `CDispatch`?

@parkera
Copy link
Member

parkera commented Jan 5, 2016

It may be possible to use dispatch without blocks (the _f functions), but it's not something I really care about supporting in Swift.

@swift-ci
Copy link
Contributor Author

swift-ci commented Jan 6, 2016

Comment by Tom Sheffler (JIRA)

This issue is actually pretty subtle. At the present time, there is probably only one C module anywhere that provides a header file with blocks – and that is libdispatch. Expanding the module mechanism to handle this one case may be overkill.

On the other hand, it blocked me. So already it's a small issue.

Perhaps there could be support for a "good" way to make modules, and a "messy" way ... that is more akin to using clang to create a library, but requires the programmer to create a Makefile or recipe. Even a well-documented workaround would be ok.

In the future there will be a more Swift-y libDispatch, and from the comments here I'm surmising that it will use runtime support different from that of ObjC.

@swift-ci
Copy link
Contributor Author

Comment by Daniel Eggert (JIRA)

In my opinion the _f variants are perfectly fine. I added workaround code to SR-577 that shows how to use them with blocks — the block variants of libdispatch’s functions also call into these after wrapping the blocks. That approach would allow for a a different blocks ABI on Linux.

@mxcl
Copy link
Contributor

mxcl commented Jan 28, 2016

In case you missed it you can now specify `-Xcc` and `-Xlinker` flags to `swift build`.

So here you could do `swift build -Xcc -fblocks`

@swift-ci
Copy link
Contributor Author

Comment by Tom Sheffler (JIRA)

I verified this against swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a/swift-DEVELOPMENT-SNAPSHOT-2016-01-25-a-ubuntu14.04.tar.gz

Using

swift build -Xcc -fblocks

this example compiles and runs just fine now.

@swift-ci
Copy link
Contributor Author

swift-ci commented Mar 9, 2016

Comment by Joel Saltzman (JIRA)

It mostly works for me. I can't seem to get dispatch_get_specific to compile. I updated the working example project to show my compile errors:

root@dec0c641b9ec:/gcd# swift build -Xcc -fblocks
Compiling Swift Module 'gcd' (1 sources)
/gcd/Sources/main.swift:45:20: error: use of unresolved identifier 'dispatch_get_specific'
print("name: (dispatch_get_specific(&name))")

gcd4-master.zip

@swift-ci
Copy link
Contributor Author

Comment by Joel Saltzman (JIRA)

Old version of libdispatch on Linux 😛

@abertelrud
Copy link
Contributor

In general, most use of libdispatch on Linux should use https://github.com/apple/swift-corelibs-libdispatch. But if I read this correctly, this issue here is about instead using the C API directly. And from s00p3rj03l (JIRA User)'s comment above, it sounds as if this may now work, if the version of `libdispatch` was old?

@swift-ci
Copy link
Contributor Author

Comment by David Grove (JIRA)

This issue will be resolved by apple/swift#3835

@ddunbar
Copy link
Member

ddunbar commented Aug 31, 2016

I think in SwiftPM we still need to get -fblocks for C language targets which we build not via swiftc.

@ankitspd
Copy link
Member

ankitspd commented Sep 1, 2016

Looks like libdispatch.so in toolchains is not able to link with C code because of the swift symbols, I couldn't find any other libdispatch binary in the toolchain.
@ddunbar any idea what can be done here?


$ swift build -Xcc -I/home/ankit/toolchain/usr/lib/swift/ -Xcc -fblocks -Xlinker -L/home/ankit/toolchain/usr/lib/swift/linux -Xlinker -ldispatch
Linking ispatch
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_isUniquelyReferencedOrPinned_nonNull_native'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs10ArraySlice'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaCs18_DropWhileSequence'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaCs12_SequenceBox'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs23BidirectionalCollectionWx8Iterator7Element_S_rGVs30FlattenBidirectionalCollectionx_s23_BidirectionalIndexables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs5UInt8'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWPSis14_SignedIntegers'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaCs15_PrefixSequence'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs26DefaultRandomAccessIndicesx_s23_BidirectionalIndexables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_release'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWPSis10Strideables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps14_IndexableBase'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_bufferAllocate'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs26DefaultRandomAccessIndices'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWPOs14_StopIterations5Errors'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWVBo'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_release_n'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_deallocClassInstance'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaCs23_ContiguousArrayStorage'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_allocError'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_deallocObject'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TZFSa28_allocateBufferUninitializedfT15minimumCapacitySi_GVs22_ContiguousArrayBufferx'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs15ContiguousArray'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMSi'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs18BidirectionalSlice'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_storeEnumTagSinglePayload'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps9OptionSet'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps10Comparable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs6UInt64'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWPSis8Hashables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs14CountableRange'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGVs15EmptyCollectionx_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs17RandomAccessSlicex_s10Collections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_dynamicCast'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs5UInt8'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMSu'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_stdlib_strlen'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swiftEmptyArrayStorage'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps25ExpressibleByArrayLiteral'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs17RandomAccessSlicex_S_s'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs17RandomAccessSlicex_s14_IndexableBases'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps22RandomAccessCollection'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs6UInt16'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps10SetAlgebra'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_slowDealloc'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs10_ArrayBody'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs26DefaultRandomAccessIndicesx_s10Collections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGVs11AnySequencex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs26DefaultRandomAccessIndicesx_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs26DefaultRandomAccessIndicesx_S_s'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMOs14_StopIteration'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs15EmptyCollection'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaSa'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs30FlattenBidirectionalCollection'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs17RandomAccessSlice'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_allocateGenericClassMetadata'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_allocObject'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs17RandomAccessSlicex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaSi'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs4Int8'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs16IteratorProtocolrGCs15_PrefixSequencex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TMT'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_stdlib_malloc_size'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs16IteratorProtocolrGCs18_DropWhileSequencex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps23BidirectionalCollection'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaSQ'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGVs10ArraySlicex_s23BidirectionalCollections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGSax_s23BidirectionalCollections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs23BidirectionalCollectionWx8Iterator7Element_S_rGVs30FlattenBidirectionalCollectionx_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGVs10ArraySlicex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs18_StringBufferIVars'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWPuRxs8HashablerGVs20_ConcreteHashableBoxx_s15_AnyHashableBoxs'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps5Error'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs26DefaultRandomAccessIndicesx_s10_Indexables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps9Equatable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs17RandomAccessSlicex_s23BidirectionalCollections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs16IteratorProtocolrGCs18_DropFirstSequencex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_retain'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_getGenericMetadata'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_once'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps16RawRepresentable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMSV'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaSis13SignedIntegers'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_getEnumCaseSinglePayload'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs11AnySequence'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs23_BidirectionalIndexablerGVs18BidirectionalSlicex_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGVs15ContiguousArrayx_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps10Collection'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_retain_n'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGVs22_ContiguousArrayBufferx_s22RandomAccessCollections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMVs13OpaquePointer'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TFVs15ContiguousArray37_appendElementAssumeUniqueAndCapacityfTSi10newElementx_T'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaSq'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs26DefaultRandomAccessIndicesx_s23BidirectionalCollections'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaSu'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps8Hashable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_release'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps22_RandomAccessIndexable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs6UInt32'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TFVs22_ContiguousArrayBuffer13_copyContentsfT8subRangeGVs5RangeSi_12initializingGSpxGSpx'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TFVs15ContiguousArray16_copyToNewBufferfT8oldCountSi_T'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaCs18_HeapBufferStorage'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWauRxs22_RandomAccessIndexablerGVs17RandomAccessSlicex_s23_BidirectionalIndexables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_stdlib_makeAnyHashableUpcastingToHashableBaseType'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_Tvs19_emptyStringStorageVs6UInt32'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps10_Indexable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_slowAlloc'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_stdlib_reportUnimplementedInitializer'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TFs16_assertionFailedFTVs12StaticStringSSS_Su5flagsVs6UInt32_Os5Never'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_getFunctionTypeMetadata1'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_setDeallocating'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs6UInt64'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_getExistentialTypeMetadata'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs20_ConcreteHashableBox'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaSis10Comparables'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TWaurGSax_s8Sequences'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_swift_isUniquelyReferenced_nonNull_native'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaCs18_DropFirstSequence'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_initClassMetadata_UniversalStrategy'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps9_Hashable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMaVs22_ContiguousArrayBuffer'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_getTupleTypeMetadata2'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `swift_initStackObject'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps23_BidirectionalIndexable'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps16IteratorProtocol'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TFVs22_ContiguousArrayBufferCfT19_uninitializedCountSi15minimumCapacitySi_GS_x'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `TTSfq4n_s_TFVs11_StringCore15_encodeSomeUTF8fT4fromSi_TSiVs6UInt64'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps8Sequence'
/home/ankit/toolchain/usr/lib/swift/linux/libdispatch.so: undefined reference to `_TMps35_HasCustomAnyHashableRepresentation'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /home/ankit/toolchain/usr/bin/swift-build-tool -f /tmp/ankit/ispatch/.build/debug.yaml

@ddunbar
Copy link
Member

ddunbar commented Sep 2, 2016

I guess we aren't building libdispatch.so separately from the overlay library.

dgrove-oss (JIRA User) any opinion on whether it would be nice to be able to build against C libdispatch without the Swift portions?

I still think we should probably pass {-fblocks} to C code, so that you can have C code which uses blocks and is linked into something else which uses libdispatch.

@swift-ci
Copy link
Contributor Author

swift-ci commented Sep 2, 2016

Comment by David Grove (JIRA)

That's correct, on Linux we bundle both the core C library and the overlay library into libdispatch.so. My recollection is that we did this intentionally because we don't really want to support the full C API of libdispatch on Linux; just the Swift3 API. das (JIRA User) should verify this. It would not be that hard to restructure the build to produce two shared objects (libcdispatch and libdispatch), but I think it is intentional that we did not do that.

@swift-ci
Copy link
Contributor Author

swift-ci commented Sep 6, 2016

Comment by Daniel A. Steffen (JIRA)

The intentional part is that we don't want to support deprecated C API symbols and private SPI symbols (i.e. *_private.h headers) for either Swift or C clients.

Continued support for C clients (and all existing ports & platforms, including macOS) in general is definitely a goal of the project and I'd like us to keep the shared autotools buildsystem working for all such clients.

I don't think we have decided either way if that extends to the binaries produced by the swift buildsystem and included in the swift runtime (what support should C code in a swift package be able to expect in general from the fact that Swift is installed ?)

Supporting interoperability between C and Swift clients of libdispatch in the same process will almost certainly require a single shared object (both sides need to refer to the same global data structures)

@swift-ci
Copy link
Contributor Author

swift-ci commented Sep 8, 2016

Comment by David Grove (JIRA)

After thinking about it some more, I think the best fix is that if someone is using swift build to link against the C APIs of the libdispatch.so that is provided by the Swift toolchain, we should require them to have the linker arguments:

@swift-ci
Copy link
Contributor Author

Comment by Tom Sheffler (JIRA)

Hi dgrove-oss (JIRA User) - earlier you suggested not supporting the full API of dispatch on Linux. I hope you are not suggesting discontinuing the blocks API in libdispatch on Linux. I have a couple of (personal) media projects using blocks in ObjC2/C with libdispatch and it is working really nicely!

@ddunbar
Copy link
Member

ddunbar commented Sep 11, 2016

dgrove-oss (JIRA User) I wonder if we could get those to be in the libdispatch module map, so that things would work automatically?

@swift-ci
Copy link
Contributor Author

Comment by David Grove (JIRA)

Stepping back, I've lost track of what scenario isn't working now. I think I'm missing the full command line @aciidb0mb3r was trying that was failing to link.

If the goal is to support building Swift programs with "swift build" that bypass the Swift3 Dispatch API and instead import CDispatch with block support enabled, that already works for me on Linux with the current Swift toolchain. The module.modulemap for libdispatch in the Swift toolchain defines both Dispatch and CDispatch modules. A Swift program can import the predefined CDispatch module, and the linkage works automatically against the libdispatch.so in the Swift toolchain (and block support is enabled without -Xcc -fblocks on the command line because the header files for dispatch come through the Swift importer). I tested this using an updated gcd4-main.zip example, removing the external definition of CDispatch from Package.swift. Compiles and runs.

When this bug was originally opened, we didn't have libdispatch.so or module.modulemap for CDispatch in the Swift toolchain. Now that we do, I don't think we want to support a user using swift build to link against a libdispatch.so that they have built themselves. That will get them into trouble because Foundation and XCTest are linked against the libdispatch that is included in the toolchain and linking against two versions of libdispatch.so will cause problems at runtime.

tomsheffler (JIRA User) what I was questioning above was whether or not the libdispatch team at Apple intended to support the usage of libdispatch on Linux beyond its usage as part of Swift. That's not my decision to make – up to them to decide.

@drewcrawford
Copy link
Contributor

I have a project that depends on libdispatch and not on foundation or xctest. We don't currently build libdispatch separately, but we have an issue open to do it.

@swift-ci
Copy link
Contributor Author

Comment by David Grove (JIRA)

@drewcrawford, I'm still missing the big picture. If it is a Swift project (assuming it is, since using swift build), why doesn't importing CDispatch from the Swift toolchain work? Why build libdispatch yourself to use CDispatch from Swift?

@drewcrawford
Copy link
Contributor

Sorry, I misread your comment. We don't use swift build, so restrictions that are specific to that build system won't impact us.

@ankitspd
Copy link
Member

#1370
d01f13b

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 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

8 participants