Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 14828 - duplicate symbol __ModuleInfoZ #4858

Merged
merged 1 commit into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/backend.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extern extern (C++) void obj_write_deferred(Library library);
extern extern (C++) Type getTypeInfoType(Type t, Scope* sc);
extern extern (C++) Expression getInternalTypeInfo(Type t, Scope* sc);
extern extern (C++) void genObjFile(Module m, bool multiobj);
extern extern (C++) void genhelpers(Module m, bool multiobj);

extern extern (C++) Symbol* toInitializer(AggregateDeclaration sd);
extern extern (C++) Symbol* toModuleArray(Module m);
Expand Down
35 changes: 11 additions & 24 deletions src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Symbol *toModuleAssert(Module *m);
Symbol *toModuleUnittest(Module *m);
Symbol *toModuleArray(Module *m);
Symbol *toSymbolX(Dsymbol *ds, const char *prefix, int sclass, type *t, const char *suffix);
void genhelpers(Module *m, bool iscomdat);
static void genhelpers(Module *m);

elem *eictor;
symbol *ictorlocalgot;
Expand Down Expand Up @@ -475,34 +475,23 @@ void genObjFile(Module *m, bool multiobj)
return;
}

if (global.params.multiobj)
{
/* This is necessary because the main .obj for this module is written
* first, but determining whether marray or massert or munittest are needed is done
* possibly later in the doppelganger modules.
* Another way to fix it is do the main one last.
*/
toModuleAssert(m);
toModuleUnittest(m);
toModuleArray(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()*/)
genModuleInfo(m);

genhelpers(m, false);
/* 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();
}

void genhelpers(Module *m, bool iscomdat)
static void genhelpers(Module *m)
{
if (global.params.betterC)
return;

// If module assert
for (int i = 0; i < 3; i++)
{
Expand All @@ -511,9 +500,9 @@ void genhelpers(Module *m, bool iscomdat)
unsigned bc;
switch (i)
{
case 0: ma = m->marray; rt = RTLSYM_DARRAY; bc = BCexit; break;
case 1: ma = m->massert; rt = RTLSYM_DASSERT; bc = BCexit; break;
case 2: ma = m->munittest; rt = RTLSYM_DUNITTEST; bc = BCret; break;
case 0: ma = toModuleArray(m); rt = RTLSYM_DARRAY; bc = BCexit; break;
case 1: ma = toModuleAssert(m); rt = RTLSYM_DASSERT; bc = BCexit; break;
case 2: ma = toModuleUnittest(m); rt = RTLSYM_DUNITTEST; bc = BCret; break;
default: assert(0);
}

Expand Down Expand Up @@ -553,7 +542,7 @@ void genhelpers(Module *m, bool iscomdat)
b->Belem = e;
ma->Sfunc->Fstartline.Sfilename = m->arg;
ma->Sfunc->Fstartblock = b;
ma->Sclass = iscomdat ? SCcomdat : SCglobal;
ma->Sclass = SCglobal;
ma->Sfl = 0;
ma->Sflags |= rtlsym[rt]->Sflags & SFLexit;
writefunc(ma);
Expand Down Expand Up @@ -1551,5 +1540,3 @@ elem *toEfilename(Module *m)
// Turn static array into dynamic array
return el_pair(TYdarray, el_long(TYsize_t, len), el_ptr(m->sfilename));
}


5 changes: 0 additions & 5 deletions src/gluestub.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ void genObjFile(Module *m, bool multiobj)
{
}

void genhelpers(Module *m, bool iscomdat)
{
assert(0);
}

// msc

void backend_init()
Expand Down
13 changes: 0 additions & 13 deletions src/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ void updateRealEnvironment(StringTable *environment);
void parseConfFile(StringTable *environment, const char *path, size_t len, unsigned char *buffer, Strings *sections);

void genObjFile(Module *m, bool multiobj);
void genhelpers(Module *m, bool iscomdat);

/** Normalize path by turning forward slashes into backslashes */
const char * toWinPath(const char *src)
Expand Down Expand Up @@ -1674,12 +1673,6 @@ Language changes listed by -transition=id:\n\
if (entrypoint && m == rootHasMain)
genObjFile(entrypoint, false);
}
for (size_t i = 0; i < Module::amodules.dim; i++)
{
Module *m = Module::amodules[i];
if (!m->isRoot() && (m->marray || m->massert || m->munittest))
genhelpers(m, true);
}
if (!global.errors && modules.dim)
{
obj_end(library, modules[0]->objfile);
Expand All @@ -1697,12 +1690,6 @@ Language changes listed by -transition=id:\n\
genObjFile(m, global.params.multiobj);
if (entrypoint && m == rootHasMain)
genObjFile(entrypoint, global.params.multiobj);
for (size_t j = 0; j < Module::amodules.dim; j++)
{
Module *mx = Module::amodules[j];
if (mx != m && mx->importedFrom == m && (mx->marray || mx->massert || mx->munittest))
genhelpers(mx, true);
}
obj_end(library, m->objfile);
obj_write_deferred(library);

Expand Down
15 changes: 0 additions & 15 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ unsigned char deduceWildHelper(Type *t, Type **at, Type *tparam);
MATCH deduceTypeHelper(Type *t, Type **at, Type *tparam);
void mangleToBuffer(Expression *e, OutBuffer *buf);

// Glue layer
Symbol *toModuleAssert(Module *m);
Symbol *toModuleUnittest(Module *m);
Symbol *toModuleArray(Module *m);

/********************************************
* These functions substitute for dynamic_cast. dynamic_cast does not work
* on earlier versions of gcc.
Expand Down Expand Up @@ -5912,16 +5907,6 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs)
if (errors)
goto Lerror;

if (Module *m = tempdecl->scope->module) // should use getModule() instead?
{
// Generate these functions as they may be used
// when template is instantiated in other modules
// even if assertions or bounds checking are disabled in this module
toModuleArray(m);
toModuleAssert(m);
toModuleUnittest(m);
}

/* See if there is an existing TemplateInstantiation that already
* implements the typeargs. If so, just refer to that one instead.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module imports.link846a;
module link846a;

template ElemTypeOf(T)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import imports.link846a;
import lib846;

void main()
{
Expand Down
2 changes: 1 addition & 1 deletion test/runnable/ice10857.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// EXTRA_SOURCES: imports/ice10857b.d
// EXTRA_SOURCES: imports/ice10857a.d imports/ice10857b.d

import imports.ice10857a;
25 changes: 25 additions & 0 deletions test/runnable/link846.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -e

src=runnable${SEP}extra-files
dir=${RESULTS_DIR}${SEP}runnable
output_file=${dir}/link846.sh.out

if [ $OS == "win32" -o $OS == "win64" ]; then
LIBEXT=.lib
else
LIBEXT=.a
fi
libname=${dir}${SEP}link846${LIBEXT}

# build library with -release
$DMD -m${MODEL} -I${src} -of${libname} -release -boundscheck=off -lib ${src}${SEP}lib846.d

# use lib with -debug
$DMD -m${MODEL} -I${src} -of${dir}${SEP}link846${EXE} -debug ${src}${SEP}main846.d ${libname}

rm ${libname}
rm ${dir}/{link846${OBJ},link846${EXE}}

echo Success > ${output_file}