Changeset 295

Show
Ignore:
Timestamp:
04/21/08 06:52:37 (9 months ago)
Author:
h3r3tic
Message:

more flexible linking, forgotten files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ddl/ExportClass.d

    r292 r295  
    4545 
    4646   this(ClassInfo classInfo, char[] name, DynamicLibrary lib) { 
     47      if (name.length > 2 && name[0..2] == "_D") { 
     48        name = name[2..$]; 
     49      } 
     50       
    4751      this.classInfo = classInfo; 
    4852      this.name = name; 
     
    6165      auto ctor = cast(Object function (Object)) dynamicLib.getSymbol( 
    6266         "_D" ~ name ~ mangleSymbolName!("_ctor") 
    63          ~ "F" 
     67         ~ "MF" 
    6468         ~ "ZC" ~ name).address; 
    6569 
     
    6973         auto Regex ctorMatch = new Regex( 
    7074               `^_D` ~ name ~ mangleSymbolName!("_ctor") 
    71                ~ `F` ~ `.*` 
     75               ~ `MF` ~ `.*` 
    7276               ~ `ZC` ~ name ~ `$`); 
    7377 
     
    8589      return cast(baseType)obj; 
    8690   } 
     91    
     92    baseType newObject(P...)(P p) { 
     93        assert (!isAbstract); 
    8794 
    88    baseType newObject(P1)(P1 p1) { 
     95        char[] symName = "_D" ~ name ~ mangleSymbolName!("_ctor") ~ "MF"; 
     96        foreach (par; P) { 
     97            symName ~= par.mangleof; 
     98        } 
     99        symName ~= "ZC" ~ name; 
     100        auto ctor = cast(Object function (P, Object)) dynamicLib.getSymbol(symName).address; 
     101        assert (ctor !is null, symName); 
     102 
     103        auto obj = _d_newclass(classInfo); 
     104        ctor(p, obj); 
     105        return cast(baseType)obj; 
     106    } 
     107 
     108   /+baseType newObject(P1)(P1 p1) { 
    89109      assert (!isAbstract); 
    90110 
    91111      auto ctor = cast(Object function (P1, Object)) dynamicLib.getSymbol( 
    92112         "_D" ~ name ~ mangleSymbolName!("_ctor") 
    93          ~ "F" ~ P1.mangleof 
     113         ~ "MF" ~ P1.mangleof 
    94114         ~ "ZC" ~ name).address; 
    95115      assert (ctor !is null); 
     
    104124      assert (!isAbstract); 
    105125 
    106       auto ctor = cast(Object function (P1, P2, Object)) dynamicLib.getSymbol( 
     126        char[] symName = 
    107127         "_D" ~ name ~ mangleSymbolName!("_ctor") 
    108          ~ "F" ~ P1.mangleof ~ P2.mangleof 
    109          ~ "ZC" ~ name).address; 
    110       assert (ctor !is null); 
     128         ~ "MF" ~ P1.mangleof ~ P2.mangleof 
     129         ~ "ZC" ~ name; 
     130          
     131      auto ctor = cast(Object function (P1, P2, Object)) dynamicLib.getSymbol(symName).address; 
     132      assert (ctor !is null, symName); 
    111133 
    112134      auto obj = _d_newclass(classInfo); 
    113135      ctor(p1, p2, obj); 
    114136      return cast(baseType)obj; 
    115    }    
     137   }   +/ 
    116138} 
  • trunk/ddl/Linker.d

    r294 r295  
    9696} 
    9797 
     98 
     99 
     100struct LinkerBehavior { 
     101    bool runModuleCtors = true; 
     102    bool replaceStrongSymbols = false; 
     103    bool delegate(DynamicModule mod, ExportSymbol sym, DynamicModule otherMod, ExportSymbol otherSym) shouldReplaceSymbol; 
     104} 
     105 
     106 
     107 
    98108/** 
    99109    General-Purpose runtime linker for DDL. 
    100110*/ 
    101111class Linker{ 
    102     public bool autoRunModuleCtors = true; 
     112    public LinkerBehavior behavior;// bool autoRunModuleCtors = true; 
    103113     
    104114     
     
    247257    alias ModuleInfo[char[]] ModuleSet;  
    248258     
    249     public void link(DynamicModule mod, inout ModuleSet moduleSet, bool canSelfResolve)
     259    public void link(DynamicModule mod, inout ModuleSet moduleSet, bool canSelfResolve, int callDepth = 0)
    250260        if (mod.isLinking) { 
    251261            return; 
     
    257267        auto modSymbols = mod.getSymbols(); 
    258268        symbolIter: foreach (ref sym; modSymbols) { 
    259             if (SymbolType.Strong == sym.type) { 
     269            // outsource all symbols when commented out 
     270            // this is equivalent to ignoring multiple symbol definitions and choosing the 'first' one 
     271            // should probably be driven by some flexible linking mechanism 
     272             
     273            if (SymbolType.Strong == sym.type && (!behavior.replaceStrongSymbols || callDepth > 0)) { 
    260274                continue; 
    261275            } 
     
    270284                 
    271285                if (!otherMod.isResolved) { 
    272                     this.link(otherMod, moduleSet, true); 
     286                    this.link(otherMod, moduleSet, true, callDepth+1); 
    273287                } 
    274288                 
    275289                auto otherSym = otherMod.getSymbol(sym.name); 
    276290                 
    277                 if (SymbolType.Unresolved != otherSym.type) { 
    278                 /+if ( 
     291                //if (SymbolType.Unresolved != otherSym.type) { 
     292                if ( 
    279293                    SymbolType.Strong == otherSym.type 
    280294                    || (SymbolType.Weak == otherSym.type && SymbolType.Unresolved == sym.type) 
    281                 ) {+/ 
    282                     sym.address = otherSym.address; 
    283                     sym.type = SymbolType.Strong; 
    284                     sym.isExternal = true; 
    285                     continue symbolIter; 
     295                ) { 
     296                    if (behavior.shouldReplaceSymbol is null || behavior.shouldReplaceSymbol(mod, sym, otherMod, *otherSym)) { 
     297                        /+printf("Binding %.*s symbol %.*s :: %.*s to %.*s symbol %.*s :: %.*s"\n, 
     298                            sym.getTypeName, mod.getName, sym.name, 
     299                            otherSym.getTypeName, otherMod.getName, otherSym.name);+/ 
     300                        sym.address = otherSym.address; 
     301                        sym.type = otherSym.type;//SymbolType.Strong; 
     302                        sym.isExternal = true; 
     303                        continue symbolIter; 
     304                    } 
    286305                } 
    287306            } 
     
    313332            if (sym.name.length > suffix.length && sym.name[$ - suffix.length .. $] == suffix) { 
    314333                debug debugLog("Found moduleinfo for {0} at [{1:8X}] {2}", mod.getName, sym.address, sym.name); 
     334                //printf("Found moduleinfo for %.*s at %d %.*s"\n, mod.getName, sym.address, sym.name); 
    315335                moduleSet[sym.name] = cast(ModuleInfo)(sym.address); 
    316336            } 
     
    493513    +/ 
    494514     
    495         if (autoRunModuleCtors) { 
     515        if (behavior.runModuleCtors) { 
    496516            runModuleCtors(moduleSet); 
    497517        } 
  • trunk/utils/bless_bn.d

    r292 r295  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 769
     4long auto_build_number = 770
  • trunk/utils/ddlinfo_bn.d

    r292 r295  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 849
     4long auto_build_number = 850
  • trunk/utils/insitu_bn.d

    r292 r295  
    22// This file is automatically maintained by the BUILD utility, 
    33// Please refrain from manually editing it. 
    4 long auto_build_number = 766
     4long auto_build_number = 767