Skip to content

Commit eaa77e9

Browse files
committed
fix libdispatch.a
The static version (`libdispatch.a`) that can be compiled using `./configure --enable static=yes` was missing all the Swift overlay symbols (everything in `swift_overlay.o`). The reason for that is that the linker is invoked through libtool which wants `.lo` files but the Swift overlay got passed as a `.o` file. This first of all leads to this warning: *** Warning: Linking the shared library libdispatch.la against the non-libtool *** objects [...]/swift_overlay.o is not portable! And the result is that libtool doesn't include `swift_overlay.o` when putting together the static library `libdispatch.a`. This patch fixes this problem is a pretty crude way. The real problem is that libtool doesn't understand Swift. So it can't be used when compiling `swift_overlay.o`. In order to still get a `.lo` file this patch tricks libtool into generating one from the `swift_overlay.o` generated by `swiftc`. It's very hacky but I'm not sure what else to do.
1 parent 10eb0e4 commit eaa77e9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Makefile.am

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,22 @@ SWIFT_SRC_FILES=\
148148

149149
SWIFT_ABS_SRC_FILES = $(SWIFT_SRC_FILES:%=$(abs_srcdir)/%)
150150
SWIFT_OBJ_FILES = $(abs_builddir)/swift/swift_overlay.o
151+
SWIFT_LIBTOOL_OBJ_FILES = $(abs_builddir)/swift/swift_overlay.lo
151152

152153
SWIFTC_FLAGS+= -Xcc -fmodule-map-file=$(abs_top_srcdir)/dispatch/module.modulemap -I$(abs_top_srcdir) -Xcc -fblocks
153154
if DISPATCH_ENABLE_OPTIMIZATION
154155
SWIFTC_FLAGS+=-O
155156
endif
156157

158+
# this saves the object file, then tricks libtool into generating a .lo file and
159+
# then moves the object file back in the places libtool expects them to be for
160+
# the PIC and non-PIC case.
161+
$(abs_builddir)/swift/swift_overlay.lo: $(abs_builddir)/swift/swift_overlay.o
162+
mv $(abs_builddir)/swift/swift_overlay.o $(abs_builddir)/swift/.libs/swift_overlay.o.save
163+
$(LIBTOOL) --mode=compile --tag=CC true -o $< -c /dev/null
164+
cp $(abs_builddir)/swift/.libs/swift_overlay.o.save $(abs_builddir)/swift/.libs/swift_overlay.o
165+
mv $(abs_builddir)/swift/.libs/swift_overlay.o.save $(abs_builddir)/swift/swift_overlay.o
166+
157167
$(abs_builddir)/swift/swift_overlay.o: $(SWIFT_ABS_SRC_FILES) $(SWIFTC)
158168
@rm -f $@
159169
$(SWIFTC) -whole-module-optimization -emit-library -c $(SWIFT_ABS_SRC_FILES) \
@@ -163,8 +173,8 @@ $(abs_builddir)/swift/swift_overlay.o: $(SWIFT_ABS_SRC_FILES) $(SWIFTC)
163173
libdispatch_la_SOURCES+=swift/DispatchStubs.cc
164174
EXTRA_libdispatch_la_SOURCES+=$(SWIFT_SRC_FILES)
165175

166-
EXTRA_libdispatch_la_DEPENDENCIES+=$(SWIFT_OBJ_FILES) $(abs_builddir)/swift/Dispatch.swiftmodule
167-
libdispatch_la_LIBADD+=$(SWIFT_OBJ_FILES)
176+
EXTRA_libdispatch_la_DEPENDENCIES+=$(SWIFT_OBJ_FILES) $(SWIFT_LIBTOOL_OBJ_FILES) $(abs_builddir)/swift/Dispatch.swiftmodule
177+
libdispatch_la_LIBADD+=$(SWIFT_LIBTOOL_OBJ_FILES)
168178

169179
SWIFT_GEN_FILES= \
170180
$(abs_builddir)/swift/Dispatch.swiftmodule \

0 commit comments

Comments
 (0)