Skip to content

Commit

Permalink
Improve the building of loadable modules. Tested on Darwin and
Browse files Browse the repository at this point in the history
Linux/gcc only. Separates out shared library building from loadable
module building.  Also, some changes to the dynclasses building to
suppress abstract base class initialization.

mswin32 is guaranteed not to work with this (it includes a symbol
definition table for parrot in every dynamic link.) Hopefully I didn't
make it too much worse than it already was.

Note that this patch does NOT address dynamic oplibs. They are still
egregiously unportable for now.


git-svn-id: https://svn.parrot.org/parrot/trunk@6790 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
hotsphink committed Oct 8, 2004
1 parent 0a6a333 commit d32ce25
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 121 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ docs/tests.pod [main]doc
docs/vtables.pod [main]doc
dynclasses/README [devel]
dynclasses/dynfoo.pasm [devel]
dynclasses/dynmatch.pasm [devel]
dynclasses/dyntcl.pasm [devel]
dynclasses/ext.imc [devel]
dynclasses/foo.pmc [devel]
dynclasses/main.pasm [devel]
Expand Down
3 changes: 2 additions & 1 deletion config/gen/config_h/config_h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#define PARROT_ARCHNAME "${jitarchname}"
#define PARROT_JIT_CAPABLE ${jitcapable}
#define PARROT_EXEC_CAPABLE ${execcapable}
#define PARROT_DLL_EXTENSION "${so}"
#define PARROT_SHARE_EXT "${share_ext}"
#define PARROT_LOAD_EXT "${load_ext}"

typedef ${iv} Parrot_Int;
typedef unsigned ${iv} Parrot_UInt;
Expand Down
4 changes: 2 additions & 2 deletions config/gen/config_pm/myconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Summary of my parrot ${VERSION} configuration:
cc_ldflags='${cc_ldflags}',
libs='${libs}'
Dynamic Linking:
so='${so}', ld_shared='${ld_shared}',
ld_shared_flags='${ld_shared_flags}'
share_ext='${share_ext}', ld_share_flags='${ld_share_flags}',
load_ext='${load_ext}', ld_load_flags='${ld_load_flags}'
Types:
iv=${iv}, intvalsize=${intvalsize}, intsize=${intsize}, opcode_t=${opcode_t}, opcode_t_size=${opcode_t_size},
ptrsize=${ptrsize}, ptr_alignment=${ptr_alignment} byteorder=${byteorder},
Expand Down
7 changes: 4 additions & 3 deletions config/gen/makefiles/dynclasses.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PERL = ${perl}
RM_F = ${rm_f}
SO = ${so}
LOAD_EXT = ${load_ext}
DESTDIR = ${build_dir}${slash}runtime${slash}parrot${slash}dynext

# add your dynamic pmcs here

Expand All @@ -15,10 +16,10 @@ all :
$(BUILD) generate $(PMCS)
$(BUILD) compile $(PMCS)
$(BUILD) linklibs $(PMCS)
$(BUILD) copy --destination=../runtime/parrot/dynext $(PMCS)
$(BUILD) copy --destination=$(DESTDIR) $(PMCS)

clean :
$(RM_F) *.c *.h *$(SO) *.dump lib-*
$(RM_F) *.c *.h *$(LOAD_EXT) *.dump lib-*

realclean: clean
$(RM_F) Makefile build.pl
Expand Down
33 changes: 16 additions & 17 deletions config/gen/makefiles/dynclasses_pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ use File::Copy qw(copy move);
# Config stuff
our $CC = "${cc} -c";
our $LD = "${ld}";
our $LD_SHARED = "${ld_shared}";
our $LD_SHARED_FLAGS = "${ld_shared_flags}";
our $LDFLAGS = "${ldflags}";
our $LD_LOAD_FLAGS = "${ld_load_flags}";
our $PERL = "${perl}";
our $SO = "${so}";
our $LOAD_EXT = "${load_ext}";
our $O = "${o}";
our $CFLAGS = "${ccflags} ${cc_debug} ${ccwarn} ${cc_hasjit} ${cg_flag} ${gc_flag}";
our $PMC2C = "$PERL ${build_dir}${slash}classes${slash}pmc2c2.pl";

# Actual commands
sub compile_shared_cmd {
sub compile_loadable_cmd {
my ($target, $source) = @_;
"$LD $CFLAGS $LD_SHARED $LD_SHARED_FLAGS $LDFLAGS " .
"$LD $CFLAGS $LDFLAGS $LD_LOAD_FLAGS " .
"${cc_o_out}" . $target . " " .
"-I${build_dir}${slash}include -I${build_dir}${slash}classes " .
"-L${build_dir}${slash}blib${slash}lib -lparrot " .
$source;
};

Expand All @@ -33,7 +31,7 @@ sub compile_cmd {

sub partial_link_cmd {
my ($target, @sources) = @_;
"$LD $CFLAGS $LD_SHARED $LD_SHARED_FLAGS $LDFLAGS ".
"$LD $CFLAGS $LDFLAGS $LD_LOAD_FLAGS ".
"${cc_o_out}" . $target . " " .
join(" ", @sources);
}
Expand Down Expand Up @@ -64,7 +62,7 @@ if ($mode eq 'generate') {
my @ungrouped_pmcs = grep { ! exists $pmc_group->{$_} } @pmcs;

# Convert X.c -> X.so for all non-grouped X.c
compile_shared($_) foreach (@ungrouped_pmcs);
compile_loadable($_) foreach (@ungrouped_pmcs);

# Convert X.c -> X.o for all grouped X.c
compile($_) foreach (@grouped_pmcs);
Expand All @@ -90,9 +88,10 @@ if ($mode eq 'generate') {
my $dest = $1;

my ($group_files, $pmc_group) = gather_groups(@pmcs);
my @ungrouped_pmcs = grep { ! exists $pmc_group->{$_} } @pmcs;

foreach (@pmcs, keys %$group_files) {
copy("$_$SO", $dest) or die "Copy $_$SO failed ($?)\n";
foreach (@ungrouped_pmcs, keys %$group_files) {
copy("$_$LOAD_EXT", $dest) or die "Copy $_$LOAD_EXT failed ($?)\n";
}
} else {
die "invalid command '$mode'\nmust be one of generate, compile, linklibs, or copy\n";
Expand Down Expand Up @@ -167,22 +166,22 @@ sub compile {
}
}

sub compile_shared {
sub compile_loadable {
my ($src_stem, $dest_stem) = @_;
$dest_stem ||= $src_stem;
if (needs_build("$dest_stem$SO", "$src_stem.c")) {
run(compile_shared_cmd("$dest_stem$SO", "$src_stem.c"))
if (needs_build("$dest_stem$LOAD_EXT", "$src_stem.c")) {
run(compile_loadable_cmd("$dest_stem$LOAD_EXT", "$src_stem.c"))
or die "compile $src_stem.c failed ($?)\n";
} else {
print "$dest_stem$SO is up to date\n";
print "$dest_stem$LOAD_EXT is up to date\n";
}
}

sub partial_link {
my ($group, @stems) = @_;
my @sources = map { "$_$O" } @stems;
if (needs_build("$group$SO", @sources)) {
run(partial_link_cmd("$group$SO", @sources))
or die "partial link $group$SO failed ($?)\n";
if (needs_build("$group$LOAD_EXT", @sources)) {
run(partial_link_cmd("$group$LOAD_EXT", @sources))
or die "partial link $group$LOAD_EXT failed ($?)\n";
}
}
20 changes: 10 additions & 10 deletions config/gen/makefiles/dynoplibs.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
# sample Makefile
#
LD = ${ld}
LD_SHARED = ${ld_shared}
LD_LOAD_FLAGS = ${ld_load_flags}
PERL = ${perl}
RM_F = ${rm_f}
SO = ${so}
LOAD_EXT = ${load_ext}
OPS2C = -I..${slash}lib ..${slash}build_tools${slash}ops2c.pl
CFLAGS = ${ccflags} ${cc_debug} ${ccwarn} ${cc_hasjit} ${cg_flag} ${gc_flag}


# add your dynamic oplibs here

all: myops_ops$(SO) myops_ops_cg$(SO) myops_ops_cgp$(SO) \
myops_ops_prederef$(SO) myops_ops_switch$(SO) \
all: myops_ops$(LOAD_EXT) myops_ops_cg$(LOAD_EXT) myops_ops_cgp$(LOAD_EXT) \
myops_ops_prederef$(LOAD_EXT) myops_ops_switch$(LOAD_EXT) \
\
dan_ops$(SO) dan_ops_cg$(SO) dan_ops_cgp$(SO) \
dan_ops_prederef$(SO) dan_ops_switch$(SO)
dan_ops$(LOAD_EXT) dan_ops_cg$(LOAD_EXT) dan_ops_cgp$(LOAD_EXT) \
dan_ops_prederef$(LOAD_EXT) dan_ops_switch$(LOAD_EXT)

.SUFFIXES: .ops .c $(SO)
.SUFFIXES: .ops .c $(LOAD_EXT)

# preserve .c if needed
.PRECIOUS: %_ops.c %_ops_cgp.c %_ops_cg.c %_ops_prederef.c %_ops_switch.c
Expand All @@ -38,15 +38,15 @@ all: myops_ops$(SO) myops_ops_cg$(SO) myops_ops_cgp$(SO) \
%_ops_switch.c : %.ops
$(PERL) $(OPS2C) CSwitch --dynamic $<

%$(SO) : %.c
$(LD) $(CFLAGS) $(LD_SHARED) $(LD_SHARED_FLAGS) $(LDFLAGS) \
.c$(LOAD_EXT) :
$(LD) $(CFLAGS) $(LD_LOAD_FLAGS) $(LDFLAGS) \
${cc_o_out}$@ \
-I..${slash}include \
-L..${slash}blib${slash}lib -lparrot $<
$(PERL) -MFile::Copy=cp -e ${PQ}cp q|$@|, q|../runtime/parrot/dynext/$@|${PQ}

clean :
$(RM_F) *.c *.h *$(SO)
$(RM_F) *.c *.h *$(LOAD_EXT)

realclean: clean
$(RM_F) Makefile
Expand Down
5 changes: 3 additions & 2 deletions config/gen/makefiles/m4.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ LINKFLAGS = ${linkflags}
# Shared-library building
LD = ${ld}
LDFLAGS = ${ldflags}
LD_SHARED = ${ld_shared} # e.g. -shared
LD_SHARE_FLAGS = ${ld_share_flags} # e.g. -shared
LD_LOAD_FLAGS = ${ld_load_flags}

# some constants
M4_EVAL_COMPILER_SO = ../../runtime/parrot/dynext/m4_eval_compiler.so
Expand Down Expand Up @@ -61,7 +62,7 @@ m4.pbc: src/m4.pbc

$(M4_EVAL_COMPILER_SO): src/eval.c
$(CC) $(CFLAGS) $(CC_SHARED) $(DEBUG) $(WARN) -c src/eval.c
$(LD) $(LD_SHARED) $(LDFLAGS) -o $@ eval.o
$(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) -o $@ eval.o


src/m4.imc: src/builtin.imc src/freeze.imc src/input.imc src/macro.imc
Expand Down
57 changes: 11 additions & 46 deletions config/gen/makefiles/root.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ AR_CR = ${ar} ${ar_flags}
RANLIB = ${ranlib}
LINK = ${link}
LD = ${ld}
LD_SHARED = ${ld_shared}
TOUCH = $(PERL) -e ${PQ}open(A,qq{>>$$_}) or die foreach @ARGV${PQ}
YACC = ${yacc}
LEX = ${lex}

# file extensions and util flags
O = ${o}
SO = ${so}
SHARE_EXT = ${share_ext}
LOAD_EXT = ${load_ext}
A = ${a}
LD_OUT = ${ld_out}
LD_SHARED_FLAGS = ${ld_shared_flags}
LD_SHARE_FLAGS = ${ld_share_flags}
LD_LOAD_FLAGS = ${ld_load_flags}

INC=./${inc}

Expand Down Expand Up @@ -431,7 +432,7 @@ ALL_PARROT_LIBS = $(LIBPARROT) $(LIBICUCORE) $(LIBICUDATA) $(C_LIBS)

# dynamic extensions
DYNEXT_DIR = runtime/parrot/dynext
LIBNCI_SO = $(DYNEXT_DIR)/libnci$(SO)
LIBNCI_SO = $(DYNEXT_DIR)/libnci$(SHARE_EXT)

###############################################################################
#
Expand Down Expand Up @@ -612,7 +613,7 @@ check_source : $(GENERAL_H_FILES)
#
###############################################################################

shared : $(GEN_HEADERS) blib/lib/libparrot$(SO) $(LIBPARROT)
shared : $(GEN_HEADERS) blib/lib/libparrot$(SHARE_EXT) $(LIBPARROT)
static : $(GEN_HEADERS) $(LIBPARROT)

# XXX changes don't always propagate into libparrot
Expand All @@ -626,49 +627,13 @@ $(LIBPARROT) : $(O_FILES)
$(AR_CR) ${ar_out}$@ ${ar_extra} $(O_FILES)
$(RANLIB) $@

blib/lib/libparrot$(SO) : $(O_FILES)
blib/lib/libparrot$(SHARE_EXT) : $(O_FILES)
$(MKDIR) blib blib/lib
$(LD) $(LD_SHARED) $(LD_SHARED_FLAGS) $(LDFLAGS) $(LD_OUT)blib/lib/libparrot$(SO) $(O_FILES) $(C_LIBS) $(LIBICUCORE) $(LIBICUDATA)
$(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) $(LD_OUT)blib/lib/libparrot$(SHARE_EXT) $(O_FILES) $(C_LIBS) $(LIBICUCORE) $(LIBICUDATA)

$(TEST_PROG_SO) : $(PARROT_MAIN)$(O) blib/lib/libparrot$(SO) lib/Parrot/OpLib/core.pm
$(TEST_PROG_SO) : $(PARROT_MAIN)$(O) blib/lib/libparrot$(SHARE_EXT) lib/Parrot/OpLib/core.pm
$(LINK) $(LINKFLAGS) $(LD_OUT)$(TEST_PROG) $(PARROT_MAIN)$(O) $(LIBPARROT) $(C_LIBS)

# XXX The dependancies on SO.MAJOR.MINOR and SO.VERSION are removed
# because those should be done at "make install" and not "make shared"
# It also makes the task of getting this working on win32 much easier. :)
#
#blib/lib/libparrot$(SO).${VERSION} : $(O_FILES)
# $(MKDIR) blib blib/lib
# $(LD) $(LD_SHARED) -Wl,-soname,libparrot$(SO).${MAJOR} $(LDFLAGS) $(LD_OUT)blib/lib/libparrot$(SO).${VERSION} $(O_FILES)
#
#blib/lib/libparrot$(SO).${MAJOR}.${MINOR} : blib/lib/libparrot$(SO).${VERSION}
# $(RM_F) $@
# cd blib/lib; ln -s libparrot$(SO).${VERSION} libparrot$(SO).${MAJOR}.${MINOR}
#
#blib/lib/libparrot$(SO).${MAJOR} : blib/lib/libparrot$(SO).${MAJOR}.${MINOR}
# $(RM_F) $@
# cd blib/lib; ln -s libparrot$(SO).${MAJOR}.${MINOR} libparrot$(SO).${MAJOR}
#
#blib/lib/libparrot$(SO) : blib/lib/libparrot$(SO).${MAJOR}
# $(RM_F) $@
# cd blib/lib; ln -s libparrot$(SO).${MAJOR} libparrot$(SO)
#
#blib/lib/libcore_prederef$(SO).${VERSION} : core_ops_prederef$(O)
# $(LD) $(LD_SHARED) -Wl,-soname,libparrot$(SO).${MAJOR} $(LDFLAGS) $(LD_OUT)blib/lib/libcore_prederef$(SO).${VERSION} core_ops_prederef$(O)
#
#blib/lib/libcore_prederef$(SO).${MAJOR}.${MINOR} : blib/lib/libcore_prederef$(SO).${VERSION}
# $(RM_F) $@
# cd blib/lib; ln -s libcore_prederef$(SO).${VERSION} libcore_prederef$(SO).${MAJOR}.${MINOR}
#
#blib/lib/libcore_prederef$(SO).${MAJOR} : blib/lib/libcore_prederef$(SO).${MAJOR}.${MINOR}
# $(RM_F) $@
# cd blib/lib; ln -s libcore_prederef$(SO).${MAJOR}.${MINOR} libcore_prederef$(SO).${MAJOR}
#
#blib/lib/libcore_prederef$(SO) : blib/lib/libcore_prederef$(SO).${MAJOR}
# $(RM_F) $@
# cd blib/lib; ln -s libcore_prederef$(SO).${MAJOR} libcore_prederef$(SO)


#
# Parrot Debugger
#
Expand Down Expand Up @@ -1279,14 +1244,14 @@ miniparrot-update :
exec : $(SRC)/exec_start$(O) $(LIBPARROT)
$(LINK) ${ld_out}$(EXEC) $(LINKFLAGS) $(EXEC)$(O) $(SRC)/exec_start$(O) $(ALL_PARROT_LIBS)

exec_so : $(SRC)/exec_start$(O) blib/lib/libparrot$(SO)
exec_so : $(SRC)/exec_start$(O) blib/lib/libparrot$(SHARE_EXT)
$(LINK) ${ld_out}$(EXEC) $(LINKFLAGS) $(EXEC)$(O) $(SRC)/exec_start$(O) -lparrot $(C_LIBS)

###### OS depend targets ##########
# libnci.so used by t/pmc/nci.t

$(LIBNCI_SO): $(SRC)/nci_test$(O)
$(LD) $(LD_SHARED) ${ncilib_link_extra} $(LDFLAGS) \
$(LD) $(LD_SHARE_FLAGS) ${ncilib_link_extra} $(LDFLAGS) \
$(LD_OUT)$@ $(SRC)/nci_test$(O)

# vim ctags
Expand Down
17 changes: 11 additions & 6 deletions config/init/data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,27 @@ sub runstep {
link => $Config{cc},
linkflags => $Config{ldflags},

# ld: Tool used to build dynamically loadable libraries. Often
# $cc on Unix-ish systems, but apparently sometimes it's ld.
# ld: Tool used to build shared libraries and dynamically loadable
# modules. Often $cc on Unix-ish systems, but apparently sometimes
# it's ld.
ld => $Config{ld},
ldflags => $Config{ldflags},

# Shared libraries
ld_share_flags => $Config{lddlflags},

# Dynamically loadable modules
ld_load_flags => $Config{lddlflags},

libs => $Config{libs},

cc_inc => "-I./include",
cc_debug => '-g',
link_debug => '',

o => '.o', # object files extension
so => '.so', # dynamic link library or shared object extension
share_ext => '.so', # shared library extension
load_ext => '.so', # dynamically loadable module extension
a => '.a', # library or archive extension
exe => $Config{_exe}, # executable files extension
cc_o_out => '-o ', # cc object output file
Expand All @@ -91,9 +99,6 @@ sub runstep {

ld_out => '-o ', # ld output file
ld_debug => '-g ', # include debug info in executable
ld_shared => $Config{lddlflags},
ld_shared_flags=> '', # What is this, exactly? For GNU ld, it was
# '-Wl,-soname,libparrot$(SO)'

# should we have a dependancy upon arc to generate .a's?
blib_lib_libparrot_a => 'blib/lib/libparrot$(A)',
Expand Down
5 changes: 3 additions & 2 deletions config/init/hints/cygwin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# A. Dougherty 9/9/2002
Configure::Data->set(
ld => 'gcc',
ld_shared => '-shared',
ld_share_flags => '-shared',
ld_load_flags => '-shared',
libs => $libs,
);

Expand All @@ -25,4 +26,4 @@
}
elsif($_[2] !~ /inet_[ap]ton/) {
$_[2]=join(',', 'inet_aton', $_[2]);
}
}
3 changes: 3 additions & 0 deletions config/init/hints/darwin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
ccwarn => "-Wno-shadow",
libs => $libs,
so => '.dylib',
dynmod => '.so',
link => 'c++',
ld_share_flags => '-dynamiclib',
ld_load_flags => '-bundle -undefined suppress',
);
Loading

0 comments on commit d32ce25

Please sign in to comment.