Skip to content

Commit 919c0f8

Browse files
weissidas
authored andcommitted
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. Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
1 parent 4ac2139 commit 919c0f8

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
@@ -157,12 +157,22 @@ SWIFT_SRC_FILES=\
157157

158158
SWIFT_ABS_SRC_FILES = $(SWIFT_SRC_FILES:%=$(abs_srcdir)/%)
159159
SWIFT_OBJ_FILES = $(abs_builddir)/swift/swift_overlay.o
160+
SWIFT_LIBTOOL_OBJ_FILES = $(abs_builddir)/swift/swift_overlay.lo
160161

161162
SWIFTC_FLAGS+= -Xcc -fmodule-map-file=$(abs_top_srcdir)/dispatch/module.modulemap -I$(abs_top_srcdir) -Xcc -fblocks
162163
if DISPATCH_ENABLE_OPTIMIZATION
163164
SWIFTC_FLAGS+=-O
164165
endif
165166

167+
# this saves the object file, then tricks libtool into generating a .lo file and
168+
# then moves the object file back in the places libtool expects them to be for
169+
# the PIC and non-PIC case.
170+
$(abs_builddir)/swift/swift_overlay.lo: $(abs_builddir)/swift/swift_overlay.o
171+
mv $(abs_builddir)/swift/swift_overlay.o $(abs_builddir)/swift/.libs/swift_overlay.o.save
172+
$(LIBTOOL) --mode=compile --tag=CC true -o $< -c /dev/null
173+
cp $(abs_builddir)/swift/.libs/swift_overlay.o.save $(abs_builddir)/swift/.libs/swift_overlay.o
174+
mv $(abs_builddir)/swift/.libs/swift_overlay.o.save $(abs_builddir)/swift/swift_overlay.o
175+
166176
$(abs_builddir)/swift/swift_overlay.o: $(SWIFT_ABS_SRC_FILES) $(SWIFTC)
167177
@rm -f $@
168178
$(SWIFTC) -whole-module-optimization -emit-library -c $(SWIFT_ABS_SRC_FILES) \
@@ -172,8 +182,8 @@ $(abs_builddir)/swift/swift_overlay.o: $(SWIFT_ABS_SRC_FILES) $(SWIFTC)
172182
libdispatch_la_SOURCES+=swift/DispatchStubs.cc
173183
EXTRA_libdispatch_la_SOURCES+=$(SWIFT_SRC_FILES)
174184

175-
EXTRA_libdispatch_la_DEPENDENCIES+=$(SWIFT_OBJ_FILES) $(abs_builddir)/swift/Dispatch.swiftmodule
176-
libdispatch_la_LIBADD+=$(SWIFT_OBJ_FILES)
185+
EXTRA_libdispatch_la_DEPENDENCIES+=$(SWIFT_OBJ_FILES) $(SWIFT_LIBTOOL_OBJ_FILES) $(abs_builddir)/swift/Dispatch.swiftmodule
186+
libdispatch_la_LIBADD+=$(SWIFT_LIBTOOL_OBJ_FILES)
177187

178188
SWIFT_GEN_FILES= \
179189
$(abs_builddir)/swift/Dispatch.swiftmodule \

0 commit comments

Comments
 (0)