Skip to content

Commit

Permalink
fix Issue 10710 - phobos depends on versioned libcurl
Browse files Browse the repository at this point in the history
- create a libcurl_stub.so for linking

- set it's soname to libcurl.so.4 so that phobos
  gets a DT_NEEDED libcurl.so.4 entry

- the runtime linker will load libcurl.so and resolve
  all undefined references

- disable pragma(lib, "curl") because it doesn't work
  for archives anyways and additionally links against
  the real libcurl (dmd appends -L-lcurl when building phobos).
  • Loading branch information
MartinNowak committed Dec 20, 2013
1 parent 5dc4dfa commit d0e51e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion etc/c/curl.d
Expand Up @@ -31,7 +31,7 @@

module etc.c.curl;

pragma(lib, "curl");
version (Windows) pragma(lib, "curl");

import core.stdc.time;
import core.stdc.config;
Expand Down
18 changes: 13 additions & 5 deletions posix.mak
Expand Up @@ -168,6 +168,9 @@ else
LIB:=$(ROOT)/phobos.lib
endif

LIBCURL_STUB:=$(if $(findstring $(OS),linux),$(ROOT)/libcurl_stub.so,)
LINKCURL:=$(if $(LIBCURL_STUB),-L$(LIBCURL_STUB),-L-lcurl)

################################################################################
MAIN = $(ROOT)/emptymain.d

Expand Down Expand Up @@ -282,8 +285,13 @@ $(ROOT)/libphobos2.so: $(ROOT)/$(SONAME)
$(ROOT)/$(SONAME): $(LIBSO)
ln -sf $(notdir $(LIBSO)) $@

$(LIBSO): $(OBJS) $(ALL_D_FILES) druntime_libs
$(DMD) $(DFLAGS) -shared -debuglib= -defaultlib= -of$@ -L-soname=$(SONAME) $(DRUNTIMESO) $(LINKDL) $(D_FILES) $(OBJS)
$(LIBSO): $(OBJS) $(ALL_D_FILES) druntime_libs $(LIBCURL_STUB)
$(DMD) $(DFLAGS) -shared -debuglib= -defaultlib= -of$@ -L-soname=$(SONAME) $(DRUNTIMESO) $(LINKDL) $(LINKCURL) $(D_FILES) $(OBJS)

# stub library with soname of the real libcurl.so (Bugzilla 10710)
$(LIBCURL_STUB):
@echo "void curl_global_init() {}" > $(ROOT)/libcurl_stub.c
$(CC) -shared $(CFLAGS) $(ROOT)/libcurl_stub.c -o $@ -Wl,-soname=libcurl.so.4

ifeq (osx,$(OS))
# Build fat library that combines the 32 bit and the 64 bit libraries
Expand Down Expand Up @@ -311,15 +319,15 @@ $(UT_D_OBJS): $(ROOT)/unittest/%.o: %.d
ifneq (linux,$(OS))

$(ROOT)/unittest/test_runner: $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) druntime_libs
$(DMD) $(DFLAGS) -unittest -of$@ $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME) -defaultlib= -debuglib= -L-lcurl
$(DMD) $(DFLAGS) -unittest -of$@ $(DRUNTIME_PATH)/src/test_runner.d $(UT_D_OBJS) $(OBJS) $(DRUNTIME) $(LINKCURL) -defaultlib= -debuglib=

else

UT_LIBSO:=$(ROOT)/unittest/libphobos2-ut.so

$(UT_LIBSO): override PIC:=-fPIC
$(UT_LIBSO): $(UT_D_OBJS) $(OBJS) druntime_libs
$(DMD) $(DFLAGS) -shared -unittest -of$@ $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO) $(LINKDL) -defaultlib= -debuglib= -L-lcurl
$(UT_LIBSO): $(UT_D_OBJS) $(OBJS) druntime_libs $(LIBCURL_STUB)
$(DMD) $(DFLAGS) -shared -unittest -of$@ $(UT_D_OBJS) $(OBJS) $(DRUNTIMESO) $(LINKDL) $(LINKCURL) -defaultlib= -debuglib=

$(ROOT)/unittest/test_runner: $(DRUNTIME_PATH)/src/test_runner.d $(UT_LIBSO)
$(DMD) $(DFLAGS) -of$@ $< -L$(UT_LIBSO) -defaultlib= -debuglib=
Expand Down
2 changes: 1 addition & 1 deletion std/net/curl.d
Expand Up @@ -188,7 +188,7 @@ version(unittest)
}
version(StdDdoc) import std.stdio;

pragma(lib, "curl");
version (Windows) pragma(lib, "curl");
extern (C) void exit(int);

// Default data timeout for Protcools
Expand Down

0 comments on commit d0e51e1

Please sign in to comment.