From a941bf2ac2bc5bb8102c5768eb404d9e6ba309d8 Mon Sep 17 00:00:00 2001 From: Jacob Carlborg Date: Wed, 24 Aug 2016 11:01:24 +0200 Subject: [PATCH 1/3] Fix issue 16423 - ModuleInfo missing when linking to static lib with classes --- src/glue.c | 23 +++++++------------- test/runnable/extra-files/test16423lib.d | 26 +++++++++++++++++++++++ test/runnable/extra-files/test16423main.d | 19 +++++++++++++++++ test/runnable/test13117.d | 2 +- test/runnable/test13117b.d | 2 +- test/runnable/test16096.sh | 2 +- test/runnable/test16423.sh | 23 ++++++++++++++++++++ 7 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 test/runnable/extra-files/test16423lib.d create mode 100644 test/runnable/extra-files/test16423main.d create mode 100755 test/runnable/test16423.sh diff --git a/src/glue.c b/src/glue.c index 7941a303c318..5a539208b96c 100644 --- a/src/glue.c +++ b/src/glue.c @@ -475,16 +475,6 @@ void genObjFile(Module *m, bool multiobj) m->ssharedctor = callFuncsAndGates(m, &ssharedctors, (StaticDtorDeclarations *)&esharedctorgates, "__modsharedctor"); m->sshareddtor = callFuncsAndGates(m, &sshareddtors, NULL, "__modshareddtor"); m->stest = callFuncsAndGates(m, &stests, NULL, "__modtest"); - - if (m->doppelganger) - genModuleInfo(m); - } - - if (m->doppelganger) - { - objc_Module_genmoduleinfo_classes(); - objmod->termfile(); - return; } /* Always generate module info, because of templates and -cov. @@ -493,11 +483,14 @@ void genObjFile(Module *m, bool multiobj) if (!global.params.betterC /*|| needModuleInfo()*/) genModuleInfo(m); - /* Always generate helper functions b/c of later templates instantiations - * with different -release/-debug/-boundscheck/-unittest flags. - */ - if (!global.params.betterC) - genhelpers(m); + if (!m->doppelganger) + { + /* Always generate helper functions b/c of later templates instantiations + * with different -release/-debug/-boundscheck/-unittest flags. + */ + if (!global.params.betterC) + genhelpers(m); + } objmod->termfile(); } diff --git a/test/runnable/extra-files/test16423lib.d b/test/runnable/extra-files/test16423lib.d new file mode 100644 index 000000000000..084c13038cc8 --- /dev/null +++ b/test/runnable/extra-files/test16423lib.d @@ -0,0 +1,26 @@ +module test16423lib; + +enum classFqn = __MODULE__ ~ '.' ~ Class.stringof; + +void testFromLibrary() +{ + testTypeid(); + testFindingClassInfoFromLibrary(); +} + +private: + +class Class {} + +void testTypeid() +{ + auto c = new Class; + assert(typeid(c) !is null, "typeid not working properly"); +} + +void testFindingClassInfoFromLibrary() +{ + auto classInfo = ClassInfo.find(classFqn); + assert(classInfo !is null, "could not find class info for '" ~ classFqn ~ + "' from library"); +} diff --git a/test/runnable/extra-files/test16423main.d b/test/runnable/extra-files/test16423main.d new file mode 100644 index 000000000000..1642336de920 --- /dev/null +++ b/test/runnable/extra-files/test16423main.d @@ -0,0 +1,19 @@ +import test16423lib; + +void testFindingClassInfoFromExecutable() +{ + auto classInfo = ClassInfo.find(classFqn); + assert(classInfo !is null, "could not find class info for '" ~ classFqn ~ + "' from executable"); +} + +void testFromExecutable() +{ + testFindingClassInfoFromExecutable(); +} + +void main() +{ + testFromLibrary(); + testFromExecutable(); +} diff --git a/test/runnable/test13117.d b/test/runnable/test13117.d index 42ce95eabe0d..2b1a62bb3f1d 100644 --- a/test/runnable/test13117.d +++ b/test/runnable/test13117.d @@ -6,7 +6,7 @@ int main() auto size = thisExePath.getSize(); writeln(size); version (D_LP64) - enum limit = 1_906_432; + enum limit = 2_151_480; else enum limit = 1_900_000; return size > limit * 11 / 10; diff --git a/test/runnable/test13117b.d b/test/runnable/test13117b.d index 53d0504af208..5a1aef68d585 100644 --- a/test/runnable/test13117b.d +++ b/test/runnable/test13117b.d @@ -9,6 +9,6 @@ int main() version (D_LP64) enum limit = 2023652; else - enum limit = 1763328; + enum limit = 1977556; return size > limit * 11 / 10; } diff --git a/test/runnable/test16096.sh b/test/runnable/test16096.sh index 28fefcb5fa29..a9ba881f856d 100755 --- a/test/runnable/test16096.sh +++ b/test/runnable/test16096.sh @@ -17,4 +17,4 @@ ${RESULTS_DIR}/runnable/test16096 rm ${dir}/{test16096a.a,test16096} -echo Success >${output_file} +echo Success > "$output_file" diff --git a/test/runnable/test16423.sh b/test/runnable/test16423.sh new file mode 100755 index 000000000000..3e131faa6a7e --- /dev/null +++ b/test/runnable/test16423.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +if [ $OS == "win32" -o $OS == "win64" ]; then + libext=.lib +else + libext=.a +fi + +filename_ext=`basename $0` +filename="${filename_ext%.*}" +src=runnable/extra-files +dir=${RESULTS_DIR}/runnable +output_file=${dir}/${filename_ext}.out + +$DMD -m${MODEL} -I${src} -of${dir}${SEP}${filename}lib${libext} -lib ${src}/${filename}lib.d +$DMD -m${MODEL} -I${src} -of${dir}${SEP}${filename} ${src}/${filename}main.d ${dir}/${filename}lib${libext} +${RESULTS_DIR}/runnable/${filename} + +rm ${dir}/{${filename}lib${libext},${filename}} + +echo Success > "$output_file" From fc44e7554eea9bfd1689f30944ed276176286d51 Mon Sep 17 00:00:00 2001 From: Jacob Carlborg Date: Tue, 6 Sep 2016 18:32:19 +0200 Subject: [PATCH 2/3] Try to fix issue for Windows --- src/glue.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/glue.c b/src/glue.c index 5a539208b96c..099c29c8b532 100644 --- a/src/glue.c +++ b/src/glue.c @@ -475,12 +475,15 @@ void genObjFile(Module *m, bool multiobj) m->ssharedctor = callFuncsAndGates(m, &ssharedctors, (StaticDtorDeclarations *)&esharedctorgates, "__modsharedctor"); m->sshareddtor = callFuncsAndGates(m, &sshareddtors, NULL, "__modshareddtor"); m->stest = callFuncsAndGates(m, &stests, NULL, "__modtest"); + + if (m->doppelganger && global.params.isWindows) + genModuleInfo(m); } /* Always generate module info, because of templates and -cov. * But module info needs the runtime library, so disable it for betterC. */ - if (!global.params.betterC /*|| needModuleInfo()*/) + if (!global.params.betterC && !global.params.isWindows /*|| needModuleInfo()*/) genModuleInfo(m); if (!m->doppelganger) From 204b4b3b5a2ccbc697fb4e9ae422294ee21867d2 Mon Sep 17 00:00:00 2001 From: Jacob Carlborg Date: Wed, 7 Sep 2016 16:43:08 +0200 Subject: [PATCH 3/3] Second try --- src/glue.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/glue.c b/src/glue.c index 099c29c8b532..9387f792d621 100644 --- a/src/glue.c +++ b/src/glue.c @@ -480,20 +480,21 @@ void genObjFile(Module *m, bool multiobj) genModuleInfo(m); } - /* Always generate module info, because of templates and -cov. - * But module info needs the runtime library, so disable it for betterC. - */ - if (!global.params.betterC && !global.params.isWindows /*|| needModuleInfo()*/) - genModuleInfo(m); - - if (!m->doppelganger) + if (!global.params.betterC) { - /* Always generate helper functions b/c of later templates instantiations - * with different -release/-debug/-boundscheck/-unittest flags. - */ - if (!global.params.betterC) - genhelpers(m); + if (m->doppelganger) + { + if (!global.params.isWindows) + genModuleInfo(m); + } + else + { + genModuleInfo(m); + genhelpers(m); + } } + else + objc_Module_genmoduleinfo_classes(); objmod->termfile(); }