Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1068 from MartinNowak/sharedFBSD
Browse files Browse the repository at this point in the history
shared library support for FreeBSD
  • Loading branch information
MartinNowak committed Jan 23, 2015
2 parents 1a0f8aa + 7c8fa30 commit 2bccc29
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 244 deletions.
3 changes: 1 addition & 2 deletions mak/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ MANIFEST=\
src\rt\qsort.d \
src\rt\sections.d \
src\rt\sections_android.d \
src\rt\sections_freebsd.d \
src\rt\sections_linux.d \
src\rt\sections_elf_shared.d \
src\rt\sections_osx.d \
src\rt\sections_solaris.d \
src\rt\sections_win32.d \
Expand Down
3 changes: 1 addition & 2 deletions mak/SRCS
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ SRCS=\
src\rt\qsort.d \
src\rt\sections.d \
src\rt\sections_android.d \
src\rt\sections_freebsd.d \
src\rt\sections_linux.d \
src\rt\sections_elf_shared.d \
src\rt\sections_osx.d \
src\rt\sections_solaris.d \
src\rt\sections_win32.d \
Expand Down
17 changes: 11 additions & 6 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,14 @@ SRCS:=$(subst \,/,$(SRCS))

OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/bss_section.o $(OBJDIR)/threadasm.o

# build with shared library support
SHARED=$(if $(findstring $(OS),linux freebsd),1,)

LINKDL=$(if $(findstring $(OS),linux),-L-ldl,)

######################## All of'em ##############################

ifeq (linux,$(OS))
ifneq (,$(SHARED))
target : import copy dll $(DRUNTIME)
else
target : import copy $(DRUNTIME)
Expand Down Expand Up @@ -166,7 +171,7 @@ $(DRUNTIMESO) $(DRUNTIMESOLIB) dll: DFLAGS+=-version=Shared
dll: $(DRUNTIMESOLIB)

$(DRUNTIMESO): $(OBJS) $(SRCS)
$(DMD) -shared -debuglib= -defaultlib= -of$(DRUNTIMESO) $(DFLAGS) $(SRCS) $(OBJS) -L-ldl
$(DMD) -shared -debuglib= -defaultlib= -of$(DRUNTIMESO) $(DFLAGS) $(SRCS) $(OBJS) $(LINKDL)

$(DRUNTIMESOLIB): $(OBJS) $(SRCS)
$(DMD) -c -fPIC -of$(DRUNTIMESOOBJ) $(DFLAGS) $(SRCS)
Expand All @@ -181,7 +186,7 @@ UT_MODULES:=$(patsubst src/%.d,$(OBJDIR)/%,$(SRCS))
HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
ifeq ($(HAS_ADDITIONAL_TESTS),1)
ADDITIONAL_TESTS:=test/init_fini test/exceptions
ADDITIONAL_TESTS+=$(if $(findstring $(OS),linux),test/shared,)
ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,)
endif

unittest : $(UT_MODULES) $(addsuffix /.run,$(ADDITIONAL_TESTS))
Expand All @@ -196,7 +201,7 @@ endif
$(addprefix $(OBJDIR)/,$(DISABLED_TESTS)) :
@echo $@ - disabled

ifneq (linux,$(OS))
ifeq (,$(SHARED))

$(OBJDIR)/test_runner: $(OBJS) $(SRCS) src/test_runner.d
$(DMD) $(UDFLAGS) -unittest -of$@ src/test_runner.d $(SRCS) $(OBJS) -debuglib= -defaultlib=
Expand All @@ -208,7 +213,7 @@ UT_DRUNTIME:=$(OBJDIR)/lib$(DRUNTIME_BASE)-ut$(DOTDLL)
$(UT_DRUNTIME): override PIC:=-fPIC
$(UT_DRUNTIME): UDFLAGS+=-version=Shared
$(UT_DRUNTIME): $(OBJS) $(SRCS)
$(DMD) $(UDFLAGS) -shared -unittest -of$@ $(SRCS) $(OBJS) -L-ldl -debuglib= -defaultlib=
$(DMD) $(UDFLAGS) -shared -unittest -of$@ $(SRCS) $(OBJS) $(LINKDL) -debuglib= -defaultlib=

$(OBJDIR)/test_runner: $(UT_DRUNTIME) src/test_runner.d
$(DMD) $(UDFLAGS) -of$@ src/test_runner.d -L$(UT_DRUNTIME) -debuglib= -defaultlib=
Expand All @@ -232,7 +237,7 @@ test/shared/.run: $(DRUNTIMESO)

test/%/.run: test/%/Makefile
$(QUIET)$(MAKE) -C test/$* MODEL=$(MODEL) OS=$(OS) DMD=$(abspath $(DMD)) \
DRUNTIME=$(abspath $(DRUNTIME)) DRUNTIMESO=$(abspath $(DRUNTIMESO)) QUIET=$(QUIET)
DRUNTIME=$(abspath $(DRUNTIME)) DRUNTIMESO=$(abspath $(DRUNTIMESO)) QUIET=$(QUIET) LINKDL=$(LINKDL)

detab:
detab $(MANIFEST)
Expand Down
10 changes: 6 additions & 4 deletions src/core/sys/freebsd/sys/link_elf.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ struct dl_phdr_info
};


private alias extern(C) int function(dl_phdr_info*, size_t, void*) __dl_iterate_hdr_callback;
extern int dl_iterate_phdr(__dl_iterate_hdr_callback, void*);
extern int _rtld_addr_phdr(const void*, dl_phdr_info*);
extern int _rtld_get_stack_prot();
private alias extern(C) int function(dl_phdr_info*, size_t, void *) dl_iterate_phdr_cb;
private alias extern(C) int function(dl_phdr_info*, size_t, void *) @nogc dl_iterate_phdr_cb_ngc;
extern int dl_iterate_phdr(dl_iterate_phdr_cb __callback, void*__data);
extern int dl_iterate_phdr(dl_iterate_phdr_cb_ngc __callback, void*__data) @nogc;
extern int _rtld_addr_phdr(const void*, dl_phdr_info*) @nogc;
extern int _rtld_get_stack_prot() @nogc;
7 changes: 4 additions & 3 deletions src/core/sys/linux/link.d
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ struct dl_phdr_info
void *dlpi_tls_data;
}

private alias extern(C) int function(dl_phdr_info*, size_t, void *) __Callback;
extern int dl_iterate_phdr(__Callback __callback, void*__data);

private alias extern(C) int function(dl_phdr_info*, size_t, void *) dl_iterate_phdr_cb;
private alias extern(C) int function(dl_phdr_info*, size_t, void *) @nogc dl_iterate_phdr_cb_ngc;
extern int dl_iterate_phdr(dl_iterate_phdr_cb __callback, void*__data);
extern int dl_iterate_phdr(dl_iterate_phdr_cb_ngc __callback, void*__data) @nogc;

// ld.so auditing interfaces prototypes have to be defined by the auditing DSO.
extern uint la_version(uint __version);
Expand Down
6 changes: 4 additions & 2 deletions src/core/sys/solaris/link.d
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,7 @@ struct dl_phdr_info {
uint64_t dlpi_subs;
};

private alias extern(C) int function(dl_phdr_info*, size_t, void*) __dl_iterate_hdr_callback;
extern int dl_iterate_phdr(__dl_iterate_hdr_callback, void*);
private alias extern(C) int function(dl_phdr_info*, size_t, void *) dl_iterate_phdr_cb;
private alias extern(C) int function(dl_phdr_info*, size_t, void *) @nogc dl_iterate_phdr_cb_ngc;
extern int dl_iterate_phdr(dl_iterate_phdr_cb __callback, void*__data);
extern int dl_iterate_phdr(dl_iterate_phdr_cb_ngc __callback, void*__data) @nogc;
4 changes: 3 additions & 1 deletion src/rt/bss_section.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
/* These symbols are defined in the linker script and bracket the
* .bss, .lbss, .lrodata and .ldata sections.
*/
#if __linux__
#if defined(__linux__) || defined(__FreeBSD__)
// Need to use weak linkage to workaround a bug in ld.bfd (Bugzilla 13025).
extern int __attribute__((weak)) __bss_start, _end;

__attribute__ ((visibility ("hidden"))) void* rt_get_bss_start();
__attribute__ ((visibility ("hidden"))) void* rt_get_end();
void* rt_get_bss_start() { return (void*)&__bss_start; }
void* rt_get_end() { return (void*)&_end; }
#endif
4 changes: 2 additions & 2 deletions src/rt/sections.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
module rt.sections;

version (linux)
public import rt.sections_linux;
public import rt.sections_elf_shared;
else version (FreeBSD)
public import rt.sections_freebsd;
public import rt.sections_elf_shared;
else version (Solaris)
public import rt.sections_solaris;
else version (OSX)
Expand Down
Loading

0 comments on commit 2bccc29

Please sign in to comment.