Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1882: dylib.patch

File dylib.patch, 22.0 kB (added by doob, 2 years ago)

I've moved all new files to rt/compiler/dmd/darwin/

  • build/script/bob.rb

    old new  
    104104end 
    105105 
    106106class FileFilter 
    107     VERSION = 1.1 
     107    VERSION = 1.2 
    108108    @@builders = {} 
    109109     
    110110    def initialize (args) 
     
    201201    end 
    202202     
    203203    def makeLib 
    204         exec("ar -r " + @args.lib + " " + @libs.string) if (@libs.length > 0) 
    205     end  
     204        if @libs.length > 0 
     205            if @args.dynamic 
     206                options = "-dynamiclib -install_name @rpath/#{File.basename(@args.lib)} -Xlinker -headerpad_max_install_names" if DARWIN 
     207 
     208                exec("gcc #{options} -o #{@args.lib} #{@libs.string} -lz -lbz2") 
     209            else 
     210                exec("ar -r #{@args.lib} #{@libs.string}") 
     211            end 
     212        end 
     213    end 
    206214     
    207215    def exec (cmd) 
    208216        exec2(cmd, nil, nil) 
     
    248256        libs("-c -n -p256\n" + @args.lib) 
    249257         
    250258        exclude("tango/core/rt/compiler/dmd/posix") 
     259        exclude("tango/core/rt/compiler/dmd/darwin") 
    251260         
    252261        scan(".d") do |file| 
    253262            compile(dmd, file) 
     
    275284    def initialize (args, os, dmd, ldc, gdc) 
    276285        super(args) 
    277286        include("tango/sys/" + os) 
     287                 
    278288        FileFilter.register(os, "dmd", :dmd, self) 
    279289        FileFilter.register(os, "ldc", :ldc, self) 
    280290        FileFilter.register(os, "gdc", :gdc, self) 
     
    284294        @dmd = dmd 
    285295        @ldc = ldc 
    286296        @gdc = gdc 
     297        @os = os 
    287298    end 
    288299     
    289300    def compile (file, cmd) 
     
    296307        return temp 
    297308    end 
    298309     
    299     def dmd () 
     310    def dmd ()       
     311        exclude("tango/core/rt/compiler/dmd/darwin") unless @os == "darwin"      
    300312        exclude("tango/core/rt/compiler/dmd/windows") 
    301313         
    302314        scan(".d") do |file| 
     
    370382end 
    371383 
    372384Args = Struct.new(:verbose, :inhibit, :include, :target, :compiler,  
    373                   :flags, :lib, :os, :core, :root, :filter, :quick, :objs) do 
     385                  :flags, :lib, :os, :core, :root, :filter, :quick, 
     386                  :objs, :dynamic) do 
    374387                     
    375388    def initialize 
    376389        self.verbose = false 
     
    388401        self.filter = false 
    389402        self.quick = false 
    390403        self.objs = File.expand_path("objs") 
     404        self.dynamic = false 
    391405         
    392406        self.os = "" 
    393407        self.os = "darwin" if DARWIN 
     
    434448            options.compiler = opt 
    435449        end 
    436450         
     451        opts.on("-d", "--dynamic", "Build Tango as a dynamic/shared library") do |opt| 
     452            if DARWIN 
     453                options.dynamic = true 
     454            else 
     455                die "Building Tango as a dynamic/shared library is currently not supported on this platform." 
     456            end 
     457        end 
     458         
    437459        opts.on("-o", "--options OPTIONS", "Specify D compiler options") do |opt| 
    438460            options.flags = opt 
    439461        end 
    440462         
    441463        opts.on("-l", "--library NAME", "Specify library name (sans .ext)") do |opt| 
    442             options.lib = opt + libext 
     464            options.lib = opt 
    443465        end 
    444466         
    445467        opts.on(nil, "--objs PATH", "Specify the path where to place temporary object files (defaults to ./objs)") do |opt| 
     
    476498                die "No package filter given" unless options.filter 
    477499            end 
    478500             
    479             options.lib += ".lib" if WINDOWS 
    480             options.lib += ".a" unless WINDOWS 
     501            if options.dynamic 
     502                if DARWIN 
     503                    options.lib += ".dylib" 
     504                elsif WINDOWS 
     505                    options.lib += ".dll" 
     506                else 
     507                    options.lib += ".so" 
     508                end 
     509            else 
     510                options.lib += ".lib" if WINDOWS 
     511                options.lib += ".a" unless WINDOWS 
     512            end 
    481513             
    482514            options.root = File.expand_path(args[0]) 
    483515        end 
  • build/src/bob.d

    old new  
    7171                libs ("-c -n -p256\n"~args.lib~"\n"); 
    7272 
    7373                exclude ("tango/core/rt/compiler/dmd/posix"); 
     74                exclude ("tango/core/rt/compiler/dmd/darwin"); 
    7475                foreach (file; scan(".d")) 
    7576                         compile (dmd, file); 
    7677 
     
    161162        { 
    162163                auto dmd = "dmd -c -I"~args.root~"/tango/core -I"~args.root~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
    163164                exclude ("tango/core/rt/compiler/dmd/windows"); 
     165                exclude ("tango/core/rt/compiler/dmd/darwin"); 
    164166                foreach (file; scan(".d")) { 
    165167                         auto obj = compile (file, dmd); 
    166168                         addToLib(obj); 
     
    246248                register ("osx", "dmd", &dmd); 
    247249                register ("osx", "ldc", &ldc); 
    248250                register ("osx", "gdc", &gdc); 
     251                include ("tango/core/rt/util/darwin"); 
    249252        } 
    250253 
    251254        private char[] compile (FilePath file, char[] cmd) 
     
    362365        int dmd () 
    363366        { 
    364367                auto dmd = "dmd -version=freebsd -c -I"~args.root~"/tango/core -I"~args.root~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
    365                 exclude ("tango/core/rt/compiler/dmd/windows");  
     368                exclude ("tango/core/rt/compiler/dmd/windows"); 
     369                exclude ("tango/core/rt/compiler/dmd/darwin");  
    366370                foreach (file; scan(".d")) { 
    367371                         auto obj = compile (file, dmd); 
    368372                         addToLib(obj); 
     
    462466                auto dmd = "dmd -version=solaris -c -I"~args.root~"/tango/core -I"~args.root~"  
    463467-I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 
    464468                exclude ("tango/core/rt/compiler/dmd/windows");  
     469                exclude ("tango/core/rt/compiler/dmd/darwin"); 
    465470                foreach (file; scan(".d")) { 
    466471                         auto obj = compile (file, dmd); 
    467472                         addToLib(obj); 
     
    712717                if (libs.readable > 2) 
    713718                   { 
    714719                   auto files = cast(char[]) libs.slice [0..$-1]; 
    715                    exec ("ar -r "~args.lib~" "~ files); 
     720                    
     721                   if (args.dynamic) 
     722                   { 
     723                       version (osx) 
     724                       { 
     725                           auto path = Path.parse(args.lib); 
     726                           auto name = path.file; 
     727                           auto options = "-dynamiclib -install_name @rpath/" ~ name ~ " -Xlinker -headerpad_max_install_names"; 
     728                       } 
     729                        
     730                       exec ("gcc " ~ options ~ " -o " ~ args.lib ~ " " ~ files ~ " -lz -lbz2");                         
     731                   } 
     732                    
     733                   else 
     734                       exec ("ar -r "~args.lib~" "~ files);         
    716735         
    717736                   if (args.quick is false) 
    718737                       // TODO: remove the list of filenames in 'files'  
     
    772791                user, 
    773792                quick, 
    774793                inhibit, 
    775                 verbose; 
     794                verbose, 
     795                dynamic; 
    776796 
    777797        char[]  os, 
    778798                lib, 
     
    787807                        "\t[-q]\t\t\tquick execution\n" 
    788808                        "\t[-i]\t\t\tinhibit execution\n" 
    789809                        "\t[-u]\t\t\tinclude user modules\n" 
     810                        "\t[-d]\t\t\tbuild Tango as a dynamic/shared library\n" 
    790811                        "\t[-r=dmd|gdc|ldc]\tinclude a runtime target\n" 
    791                         "\t[-c=dmd|gdc|ldc]\tspecify a compiler to use\n" 
     812                        "\t[-c=dmd|gdc|ldc]\tspecify a compiler to use\n"                         
    792813                        "\t[-o=\"options\"]\t\tspecify D compiler options\n" 
    793814                        "\t[-l=libname]\t\tspecify lib name (sans .ext)\n" 
    794815                        "\t[-p=sysname]\t\tdetermines package filtering (windows|linux|osx|freebsd|solaris)\n"; 
     
    807828                auto r = args('r').smush.params(1).defaults("dmd").restrict("dmd", "gdc", "ldc"); 
    808829                auto n = args(null).params(1).required.title("tango-path"); 
    809830                auto h = args("help").aliased('h').aliased('?').halt; 
     831                auto d = args('d'); 
    810832 
    811833                version (Windows) 
    812834                         p.defaults("windows"); 
     
    843865                   quick = q.set; 
    844866                   inhibit = i.set; 
    845867                   verbose = v.set; 
     868                   dynamic = d.set; 
    846869                   os = p.assigned[0]; 
    847870                   root = n.assigned[0]; 
    848871                   flags = o.assigned[0]; 
    849872                   target = r.assigned[0]; 
    850873                   compiler = c.assigned[0]; 
    851                    lib = l.assigned[0]~libext; 
     874                   lib = l.assigned[0]; 
     875                    
     876                   if (dynamic) 
     877                   { 
     878                       version (osx) 
     879                           lib ~= ".dylib"; 
     880                       else 
     881                           throw new Exception("Building Tango as a dynamic library is currently only supported on Mac OS X", __FILE__, __LINE__); 
     882                   } 
     883                    
     884                   else 
     885                   { 
     886                       version (Windows) 
     887                           lib ~= ".lib"; 
     888                            
     889                       else 
     890                           lib ~= ".a"; 
     891                   } 
     892                    
    852893                   return true; 
    853894                   } 
    854895 
  • tango/core/rt/compiler/dmd/darwin/getsect.d

    old new  
     1/** 
     2 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved. 
     3 * Authors: Jacob Carlborg 
     4 * Version: Initial created: Mar 16, 2010 
     5 * License: BSD style: $(LICENSE) 
     6 */ 
     7module rt.compiler.dmd.darwin.getsect; 
     8 
     9version (darwin): 
     10 
     11import rt.compiler.dmd.darwin.loader; 
     12 
     13extern (C): 
     14 
     15section* getsectbynamefromheader (in mach_header* mhp, in char* segname, in char* sectname); 
     16section_64* getsectbynamefromheader_64 (mach_header_64* mhp, in char* segname, in char* sectname); 
  • tango/core/rt/compiler/dmd/darwin/Image.d

    old new  
     1/** 
     2 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved. 
     3 * Authors: Jacob Carlborg 
     4 * Version: Initial created: Feb 23, 2010 
     5 * License: BSD style: $(LICENSE) 
     6 */ 
     7module rt.compiler.dmd.darwin.Image; 
     8 
     9version (darwin): 
     10 
     11import rt.compiler.dmd.darwin.dyld; 
     12import rt.compiler.dmd.darwin.loader; 
     13import rt.compiler.dmd.darwin.getsect; 
     14 
     15struct Image 
     16{ 
     17    private mach_header* header_; 
     18    private uint index_; 
     19     
     20    static Image opCall (uint index) 
     21    { 
     22        Image image; 
     23        image.header_ = _dyld_get_image_header(index); 
     24        image.index_ = index; 
     25         
     26        return image; 
     27    } 
     28     
     29    static uint numberOfImages () 
     30    { 
     31        return _dyld_image_count; 
     32    } 
     33     
     34    static int opApply (int delegate(ref Image) dg) 
     35    { 
     36        int result; 
     37         
     38        for (size_t i = 0; i < numberOfImages; i++) 
     39        { 
     40            result = dg(Image(i)); 
     41             
     42            if (result) 
     43                break; 
     44        } 
     45         
     46        return result; 
     47    } 
     48     
     49    static int opApplyReverse (int delegate(ref Image) dg) 
     50    { 
     51        int result; 
     52         
     53        for (int i = numberOfImages - 1; i >= 0; i--) 
     54        { 
     55            result = dg(Image(i)); 
     56             
     57            if (result) 
     58                break; 
     59        } 
     60         
     61        return result; 
     62    } 
     63     
     64    mach_header* header () 
     65    { 
     66        return header_; 
     67    } 
     68     
     69    mach_header_64* header64 () 
     70    { 
     71        return cast(mach_header_64*) header_; 
     72    } 
     73     
     74    CPU cpu () 
     75    { 
     76        return CPU(header_); 
     77    } 
     78} 
     79 
     80struct CPU 
     81{ 
     82    private mach_header* header; 
     83     
     84    static CPU opCall (mach_header* header) 
     85    { 
     86        CPU cpu; 
     87        cpu.header = header; 
     88         
     89        return cpu; 
     90    } 
     91     
     92    bool is32bit () 
     93    {        
     94        return (header.magic & MH_MAGIC) != 0; 
     95    } 
     96 
     97    bool is64bit () 
     98    { 
     99        return (header.magic & MH_MAGIC_64) != 0; 
     100    } 
     101} 
     102 
     103T[] getSectionData (T, char[] segmentName, char[] sectionName) () 
     104{ 
     105    T[] array; 
     106     
     107    const c_segmentName = segmentName.ptr; 
     108    const c_sectionName = sectionName.ptr;     
     109     
     110    void* start; 
     111    void* end; 
     112     
     113    foreach_reverse (image ; Image) 
     114    {             
     115        if (image.cpu.is32bit) 
     116        { 
     117            auto header = image.header; 
     118            section* sect = getsectbynamefromheader(header, c_segmentName, c_sectionName); 
     119             
     120            if (sect is null || sect.size == 0) 
     121                continue; 
     122 
     123            start = cast(void*) (cast(byte*) header + sect.offset); 
     124            end = cast(void*) (cast(byte*) start + sect.size); 
     125        } 
     126         
     127        else 
     128        { 
     129            auto header = image.header64; 
     130            section_64* sect = getsectbynamefromheader_64(header, c_segmentName, c_sectionName); 
     131             
     132            if (sect is null || sect.size == 0) 
     133                continue; 
     134 
     135            start = cast(void*) (cast(byte*) header + sect.offset); 
     136            end = cast(void*) (cast(byte*) start + sect.size); 
     137        } 
     138         
     139        size_t len = cast(T*)end - cast(T*)start; 
     140        array ~= (cast(T*)start)[0 .. len]; 
     141    } 
     142     
     143    return array; 
     144} 
  • tango/core/rt/compiler/dmd/darwin/loader.d

    old new  
     1/** 
     2 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved. 
     3 * Authors: Jacob Carlborg 
     4 * Version: Initial created: Feb 20, 2010 
     5 * License: BSD style: $(LICENSE) 
     6 */ 
     7module rt.compiler.dmd.darwin.loader; 
     8 
     9version (darwin): 
     10 
     11struct mach_header 
     12{ 
     13    uint magic; 
     14    int cputype; 
     15    int cpusubtype; 
     16    uint filetype; 
     17    uint ncmds; 
     18    uint sizeofcmds; 
     19    uint flags; 
     20} 
     21 
     22struct mach_header_64 
     23{ 
     24    uint magic; 
     25    int cputype; 
     26    int cpusubtype; 
     27    uint filetype; 
     28    uint ncmds; 
     29    uint sizeofcmds; 
     30    uint flags; 
     31    uint reserved; 
     32} 
     33 
     34enum : uint 
     35{ 
     36    MH_MAGIC = 0xfeedface, 
     37    MH_CIGAM = 0xcefaedfe, 
     38    MH_MAGIC_64 = 0xfeedfacf, 
     39    MH_CIGAM_64 = 0xcffaedfe, 
     40} 
     41 
     42struct section 
     43{ 
     44    char[16] sectname; 
     45    char[16] segname; 
     46    uint addr; 
     47    uint size; 
     48    uint offset; 
     49    uint align_; 
     50    uint reloff; 
     51    uint nreloc; 
     52    uint flags; 
     53    uint reserved1; 
     54    uint reserved2; 
     55} 
     56 
     57struct section_64 
     58{ 
     59    char[16] sectname; 
     60    char[16] segname; 
     61    long addr; 
     62    long size; 
     63    uint offset; 
     64    uint align_; 
     65    uint reloff; 
     66    uint nreloc; 
     67    uint flags; 
     68    uint reserved1; 
     69    uint reserved2; 
     70    uint reserved3; 
     71} 
  • tango/core/rt/compiler/dmd/darwin/dynamic_lib_fixes.c

    old new  
     1#ifdef __APPLE__ 
     2    void* _Dmain __attribute__ ((weak)); 
     3    char rt_init (); 
     4    char rt_term (); 
     5     
     6    __attribute__((constructor)) static void initializer () 
     7    { 
     8        rt_init(); 
     9    } 
     10     
     11    __attribute__((destructor)) static void finalizer () 
     12    { 
     13        rt_term(); 
     14    } 
     15#endif 
  • tango/core/rt/compiler/dmd/darwin/dyld.d

    old new  
     1/** 
     2 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved. 
     3 * Authors: Jacob Carlborg 
     4 * Version: Initial created: Feb 20, 2010 
     5 * License: BSD style: $(LICENSE) 
     6 */ 
     7module rt.compiler.dmd.darwin.dyld; 
     8 
     9version (darwin): 
     10 
     11import rt.compiler.dmd.darwin.loader; 
     12 
     13extern (C): 
     14 
     15uint _dyld_image_count (); 
     16mach_header* _dyld_get_image_header (uint image_index); 
  • tango/core/rt/compiler/dmd/rt/dmain2.d

    old new  
    8989 
    9090void _d_criticalInit() 
    9191{ 
     92    static bool hasBeenCalled; 
     93     
     94    if (hasBeenCalled) 
     95        return; 
     96         
     97    hasBeenCalled = true; 
     98     
    9299    version (Posix) 
    93100    { 
    94101        _STI_monitor_staticctor(); 
     
    100107 
    101108extern (C) bool rt_init( ExceptionHandler dg = null ) 
    102109{ 
     110    static bool result; 
     111     
     112    if (result) 
     113        return result; 
     114     
    103115    _d_criticalInit(); 
    104116 
    105117    try 
     
    108120        version (Win32) 
    109121            _minit(); 
    110122        _moduleCtor(); 
    111         return true; 
     123        return result = true; 
    112124    } 
    113125    catch( Exception e ) 
    114126    { 
     
    120132 
    121133    } 
    122134    _d_criticalTerm(); 
    123     return false; 
     135    return result = false; 
    124136} 
    125137 
    126138void _d_criticalTerm() 
    127139{ 
     140    static bool hasBeenCalled; 
     141     
     142    if (hasBeenCalled) 
     143        return; 
     144         
     145    hasBeenCalled = true; 
     146     
    128147    version (Posix) 
    129148    { 
    130149        _STD_critical_term(); 
     
    134153 
    135154extern (C) bool rt_term( ExceptionHandler dg = null ) 
    136155{ 
     156    static bool result; 
     157     
     158    if (result) 
     159        return result; 
     160     
    137161    try 
    138162    { 
    139         thread_joinAll(); 
    140163        _d_isHalting = true; 
     164        thread_joinAll();         
    141165        _moduleDtor(); 
    142166        gc_term(); 
    143         return true; 
     167        return result = true; 
    144168    } 
    145169    catch( Exception e ) 
    146170    { 
     
    155179    { 
    156180        _d_criticalTerm(); 
    157181    } 
    158     return false; 
     182    return result = false; 
    159183} 
    160184 
    161185version (OSX) 
     
    215239     */ 
    216240    __libc_stack_end = cast(void*)&argv; 
    217241    } 
     242     
    218243    version (Posix) 
    219     { 
    220         _STI_monitor_staticctor(); 
    221         _STI_critical_init(); 
    222     } 
     244        _d_criticalInit(); 
    223245 
    224246    version (Win32) 
    225247    { 
     
    305327 
    306328    void runAll() 
    307329    { 
    308         gc_init(); 
    309         version (Win32) 
    310             _minit(); 
    311         _moduleCtor(); 
     330        rt_init(); 
    312331        if (runModuleUnitTests()) 
    313332            tryExec(&runMain); 
    314         _d_isHalting = true; 
    315         thread_joinAll(); 
    316         _moduleDtor(); 
    317         gc_term(); 
     333        rt_term(); 
    318334    } 
    319335 
    320336    tryExec(&runAll); 
    321337 
    322338    version (Posix) 
    323     { 
    324         _STD_critical_term(); 
    325         _STD_monitor_staticdtor(); 
    326     } 
     339        _d_criticalTerm(); 
     340         
    327341    return result; 
    328342} 
  • tango/core/rt/compiler/dmd/object_.d

    old new  
    4848    import rt.compiler.dmd.rt.aaA; 
    4949    debug(PRINTF) import tango.stdc.stdio: printf; 
    5050    extern (C) Object _d_newclass(ClassInfo ci); 
     51     
     52    version (darwin) 
     53        import rt.compiler.dmd.darwin.Image; 
    5154} 
    5255 
    5356// NOTE: For some reason, this declaration method doesn't work 
     
    12201223    extern (C) ModuleReference *_Dmodule_ref;   // start of linked list  
    12211224} 
    12221225 
    1223 version( OSX ) 
    1224 { 
    1225     extern (C) 
    1226     { 
    1227     extern void* _minfo_beg; 
    1228     extern void* _minfo_end; 
    1229     } 
    1230 } 
    1231  
    12321226ModuleInfo[] _moduleinfo_dtors; 
    12331227uint         _moduleinfo_dtors_i; 
    12341228 
     
    12801274     * and __minfo_end. The variables _minfo_beg and _minfo_end 
    12811275     * are of zero size and are in the two bracketing segments, 
    12821276     * respectively. 
     1277     *  
     1278     * The __minfo_beg and __minfo_end sections are not put into 
     1279     * dynamic libraries therefore we cannot use them or the 
     1280     * _minfo_beg and _minfo_end variables. Instead we loop through 
     1281     * all the loaded images (executables and dynamic libraries) and 
     1282     * collect all the ModuleInfo references. 
    12831283     */ 
    1284         size_t length = cast(ModuleInfo*)&_minfo_end - cast(ModuleInfo*)&_minfo_beg; 
    1285         _moduleinfo_array = (cast(ModuleInfo*)&_minfo_beg)[0 .. length]; 
     1284        _moduleinfo_array = getSectionData!(ModuleInfo, "__DATA", "__minfodata");         
    12861285        debug(PRINTF) printf("moduleinfo: ptr = %p, length = %d\n", _moduleinfo_array.ptr, _moduleinfo_array.length); 
    12871286 
    12881287        debug(PRINTF) foreach (m; _moduleinfo_array) 
  • tango/core/rt/compiler/dmd/posix/deh.d

    old new  
    2929import tango.stdc.stdio : printf; 
    3030import tango.stdc.stdlib : exit; 
    3131 
     32version (darwin) 
     33    import rt.compiler.dmd.darwin.Image; 
     34 
    3235extern (C) 
    3336{ 
    34     extern void* _deh_beg; 
    35     extern void* _deh_end; 
     37    version (darwin) {} 
     38     
     39    else 
     40    { 
     41        extern void* _deh_beg; 
     42        extern void* _deh_end; 
     43    } 
    3644 
    3745    int _d_isbaseof(ClassInfo oc, ClassInfo c); 
    3846} 
     
    99107 
    100108DHandlerTable *__eh_finddata(void *address) 
    101109{ 
    102     FuncTable *ft; 
    103  
    104 //    debug printf("__eh_finddata(address = x%x)\n", address); 
    105 //    debug printf("_deh_beg = x%x, _deh_end = x%x\n", &_deh_beg, &_deh_end); 
    106     for (ft = cast(FuncTable *)&_deh_beg; 
    107          ft < cast(FuncTable *)&_deh_end; 
    108          ft++) 
     110    version (darwin) 
    109111    { 
    110 //      debug printf("\tfptr = x%x, fsize = x%03x, handlertable = x%x\n", 
    111 //              ft.fptr, ft.fsize, ft.handlertable); 
     112        static FuncTable[] functionTables; 
     113        static bool hasFunctionTables; 
     114         
     115        if (!hasFunctionTables) 
     116        { 
     117            functionTables = getSectionData!(FuncTable, "__DATA", "__deh_eh"); 
     118            hasFunctionTables = true; 
     119        } 
     120         
     121        foreach (ft ; functionTables) 
     122        { 
     123            if (ft.fptr <= address && address < cast(void *)(cast(char *)ft.fptr + ft.fsize)) 
     124                return ft.handlertable; 
     125        } 
     126                 
     127        return null; 
     128    } 
     129     
     130    else 
     131    { 
     132        FuncTable *ft; 
    112133 
    113         if (ft.fptr <= address && 
    114             address < cast(void *)(cast(char *)ft.fptr + ft.fsize)) 
     134    //      debug printf("__eh_finddata(address = x%x)\n", address); 
     135    //    debug printf("_deh_beg = x%x, _deh_end = x%x\n", &_deh_beg, &_deh_end); 
     136        for (ft = cast(FuncTable *)&_deh_beg; 
     137             ft < cast(FuncTable *)&_deh_end; 
     138             ft++) 
    115139        { 
    116 //          debug printf("\tfound handler table\n"); 
    117             return ft.handlertable; 
     140    //      debug printf("\tfptr = x%x, fsize = x%03x, handlertable = x%x\n", 
     141    //              ft.fptr, ft.fsize, ft.handlertable); 
     142 
     143            if (ft.fptr <= address && 
     144                address < cast(void *)(cast(char *)ft.fptr + ft.fsize)) 
     145            { 
     146    //          debug printf("\tfound handler table\n"); 
     147                return ft.handlertable; 
     148            } 
    118149        } 
     150    //    debug printf("\tnot found\n"); 
     151        return null; 
    119152    } 
    120 //    debug printf("\tnot found\n"); 
    121     return null; 
    122153} 
    123154 
    124155