[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.

Changed the way moduleinfo is registered to use the same approach as DMD, this eliminates the need for correct linking order and should make the way for using a natively compiled runtime library. This should speed up linking tremendously and should now be possible.
Fixed the llvm.used array to only be emitted if really necessary.
This commit is contained in:
Tomas Lindquist Olsen
2008-07-09 23:43:51 +02:00
parent 64ab226a4b
commit 2dfb2fcf19
10 changed files with 129 additions and 60 deletions

View File

@@ -1013,19 +1013,22 @@ class ModuleInfo
}
// Win32: this gets initialized by minit.asm
// linux: this gets initialized in _moduleCtor()
// this gets initialized in _moduleCtor()
extern (C) ModuleInfo[] _moduleinfo_array;
// llvmdc method
extern (C) void** _d_get_moduleinfo_array();
// This linked list is created by a compiler generated function inserted
// into the .ctor list by the compiler.
struct ModuleReference
{
ModuleReference* next;
ModuleInfo mod;
}
extern (C) ModuleReference* _Dmodule_ref; // start of linked list
// this list is built from the linked list above
ModuleInfo[] _moduleinfo_dtors;
uint _moduleinfo_dtors_i;
// Register termination function pointers
extern (C) int _fatexit(void *);
/**
* Initialize the modules.
*/
@@ -1034,32 +1037,22 @@ extern (C) void _moduleCtor()
{
debug(PRINTF) printf("_moduleCtor()\n");
ModuleInfo* mrbegin = cast(ModuleInfo*)_d_get_moduleinfo_array();
assert(mrbegin !is null);
int len = 0;
ModuleInfo* mr;
for (mr = mrbegin; *mr !is null; ++mr)
ModuleReference *mr;
for (mr = _Dmodule_ref; mr; mr = mr.next)
len++;
_moduleinfo_array = new ModuleInfo[len];
len = 0;
for (mr = mrbegin; *mr !is null; ++mr)
{ _moduleinfo_array[len] = *mr;
for (mr = _Dmodule_ref; mr; mr = mr.next)
{ _moduleinfo_array[len] = mr.mod;
len++;
}
version (Win32)
{
// Ensure module destructors also get called on program termination
//_fatexit(&_STD_moduleDtor);
}
_moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length];
debug(PRINTF) printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors);
_moduleIndependentCtors();
_moduleCtor2(_moduleinfo_array, 0);
debug(PRINTF) printf("_moduleCtor() DONE\n");
}
extern (C) void _moduleIndependentCtors()

View File

@@ -56,9 +56,6 @@ LIB_DEST=..
.d.bc:
$(DC) -c $(DFLAGS) $< -of$@
.ll.bc:
$(LLC) -f -o=$@ $<
.d.html:
$(DC) -c -o- $(DOCFLAGS) -Df$*.html llvmdc.ddoc $<
@@ -87,12 +84,6 @@ OBJ_BASE= \
qsort2.bc \
switch.bc \
# NOTE: trace.obj and cover.obj are not necessary for a successful build
# as both are used for debugging features (profiling and coverage)
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for linux
# NOTE: deh.o is only needed for Win32, linux uses deh2.o
OBJ_UTIL= \
util/console.bc \
util/ctype.bc \
@@ -139,8 +130,7 @@ OBJ_TI= \
ALL_OBJS= \
$(OBJ_BASE) \
$(OBJ_UTIL) \
$(OBJ_TI) \
moduleinfo.bc
$(OBJ_TI)
######################################################

View File

@@ -1,9 +0,0 @@
; ModuleID = 'internal.moduleinit_backend'
@_d_moduleinfo_array = appending constant [1 x i8*] [ i8* null ]
define i8** @_d_get_moduleinfo_array() {
entry:
%tmp = getelementptr [1 x i8*]* @_d_moduleinfo_array, i32 0, i32 0
ret i8** %tmp
}

View File

@@ -1,4 +0,0 @@
[Environment]
DFLAGS=-I%@P%/../tango -E%@P%/../lib -L-L=%@P%/../lib