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 104 104 end 105 105 106 106 class FileFilter 107 VERSION = 1. 1107 VERSION = 1.2 108 108 @@builders = {} 109 109 110 110 def initialize (args) … … 201 201 end 202 202 203 203 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 206 214 207 215 def exec (cmd) 208 216 exec2(cmd, nil, nil) … … 248 256 libs("-c -n -p256\n" + @args.lib) 249 257 250 258 exclude("tango/core/rt/compiler/dmd/posix") 259 exclude("tango/core/rt/compiler/dmd/darwin") 251 260 252 261 scan(".d") do |file| 253 262 compile(dmd, file) … … 275 284 def initialize (args, os, dmd, ldc, gdc) 276 285 super(args) 277 286 include("tango/sys/" + os) 287 278 288 FileFilter.register(os, "dmd", :dmd, self) 279 289 FileFilter.register(os, "ldc", :ldc, self) 280 290 FileFilter.register(os, "gdc", :gdc, self) … … 284 294 @dmd = dmd 285 295 @ldc = ldc 286 296 @gdc = gdc 297 @os = os 287 298 end 288 299 289 300 def compile (file, cmd) … … 296 307 return temp 297 308 end 298 309 299 def dmd () 310 def dmd () 311 exclude("tango/core/rt/compiler/dmd/darwin") unless @os == "darwin" 300 312 exclude("tango/core/rt/compiler/dmd/windows") 301 313 302 314 scan(".d") do |file| … … 370 382 end 371 383 372 384 Args = 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 374 387 375 388 def initialize 376 389 self.verbose = false … … 388 401 self.filter = false 389 402 self.quick = false 390 403 self.objs = File.expand_path("objs") 404 self.dynamic = false 391 405 392 406 self.os = "" 393 407 self.os = "darwin" if DARWIN … … 434 448 options.compiler = opt 435 449 end 436 450 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 437 459 opts.on("-o", "--options OPTIONS", "Specify D compiler options") do |opt| 438 460 options.flags = opt 439 461 end 440 462 441 463 opts.on("-l", "--library NAME", "Specify library name (sans .ext)") do |opt| 442 options.lib = opt + libext464 options.lib = opt 443 465 end 444 466 445 467 opts.on(nil, "--objs PATH", "Specify the path where to place temporary object files (defaults to ./objs)") do |opt| … … 476 498 die "No package filter given" unless options.filter 477 499 end 478 500 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 481 513 482 514 options.root = File.expand_path(args[0]) 483 515 end -
build/src/bob.d
old new 71 71 libs ("-c -n -p256\n"~args.lib~"\n"); 72 72 73 73 exclude ("tango/core/rt/compiler/dmd/posix"); 74 exclude ("tango/core/rt/compiler/dmd/darwin"); 74 75 foreach (file; scan(".d")) 75 76 compile (dmd, file); 76 77 … … 161 162 { 162 163 auto dmd = "dmd -c -I"~args.root~"/tango/core -I"~args.root~" -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 163 164 exclude ("tango/core/rt/compiler/dmd/windows"); 165 exclude ("tango/core/rt/compiler/dmd/darwin"); 164 166 foreach (file; scan(".d")) { 165 167 auto obj = compile (file, dmd); 166 168 addToLib(obj); … … 246 248 register ("osx", "dmd", &dmd); 247 249 register ("osx", "ldc", &ldc); 248 250 register ("osx", "gdc", &gdc); 251 include ("tango/core/rt/util/darwin"); 249 252 } 250 253 251 254 private char[] compile (FilePath file, char[] cmd) … … 362 365 int dmd () 363 366 { 364 367 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"); 366 370 foreach (file; scan(".d")) { 367 371 auto obj = compile (file, dmd); 368 372 addToLib(obj); … … 462 466 auto dmd = "dmd -version=solaris -c -I"~args.root~"/tango/core -I"~args.root~" 463 467 -I"~args.root~"/tango/core/vendor "~args.flags~" -of"; 464 468 exclude ("tango/core/rt/compiler/dmd/windows"); 469 exclude ("tango/core/rt/compiler/dmd/darwin"); 465 470 foreach (file; scan(".d")) { 466 471 auto obj = compile (file, dmd); 467 472 addToLib(obj); … … 712 717 if (libs.readable > 2) 713 718 { 714 719 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); 716 735 717 736 if (args.quick is false) 718 737 // TODO: remove the list of filenames in 'files' … … 772 791 user, 773 792 quick, 774 793 inhibit, 775 verbose; 794 verbose, 795 dynamic; 776 796 777 797 char[] os, 778 798 lib, … … 787 807 "\t[-q]\t\t\tquick execution\n" 788 808 "\t[-i]\t\t\tinhibit execution\n" 789 809 "\t[-u]\t\t\tinclude user modules\n" 810 "\t[-d]\t\t\tbuild Tango as a dynamic/shared library\n" 790 811 "\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" 792 813 "\t[-o=\"options\"]\t\tspecify D compiler options\n" 793 814 "\t[-l=libname]\t\tspecify lib name (sans .ext)\n" 794 815 "\t[-p=sysname]\t\tdetermines package filtering (windows|linux|osx|freebsd|solaris)\n"; … … 807 828 auto r = args('r').smush.params(1).defaults("dmd").restrict("dmd", "gdc", "ldc"); 808 829 auto n = args(null).params(1).required.title("tango-path"); 809 830 auto h = args("help").aliased('h').aliased('?').halt; 831 auto d = args('d'); 810 832 811 833 version (Windows) 812 834 p.defaults("windows"); … … 843 865 quick = q.set; 844 866 inhibit = i.set; 845 867 verbose = v.set; 868 dynamic = d.set; 846 869 os = p.assigned[0]; 847 870 root = n.assigned[0]; 848 871 flags = o.assigned[0]; 849 872 target = r.assigned[0]; 850 873 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 852 893 return true; 853 894 } 854 895 -
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 */ 7 module rt.compiler.dmd.darwin.getsect; 8 9 version (darwin): 10 11 import rt.compiler.dmd.darwin.loader; 12 13 extern (C): 14 15 section* getsectbynamefromheader (in mach_header* mhp, in char* segname, in char* sectname); 16 section_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 */ 7 module rt.compiler.dmd.darwin.Image; 8 9 version (darwin): 10 11 import rt.compiler.dmd.darwin.dyld; 12 import rt.compiler.dmd.darwin.loader; 13 import rt.compiler.dmd.darwin.getsect; 14 15 struct 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 80 struct 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 103 T[] 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 */ 7 module rt.compiler.dmd.darwin.loader; 8 9 version (darwin): 10 11 struct 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 22 struct 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 34 enum : uint 35 { 36 MH_MAGIC = 0xfeedface, 37 MH_CIGAM = 0xcefaedfe, 38 MH_MAGIC_64 = 0xfeedfacf, 39 MH_CIGAM_64 = 0xcffaedfe, 40 } 41 42 struct 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 57 struct 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 */ 7 module rt.compiler.dmd.darwin.dyld; 8 9 version (darwin): 10 11 import rt.compiler.dmd.darwin.loader; 12 13 extern (C): 14 15 uint _dyld_image_count (); 16 mach_header* _dyld_get_image_header (uint image_index); -
tango/core/rt/compiler/dmd/rt/dmain2.d
old new 89 89 90 90 void _d_criticalInit() 91 91 { 92 static bool hasBeenCalled; 93 94 if (hasBeenCalled) 95 return; 96 97 hasBeenCalled = true; 98 92 99 version (Posix) 93 100 { 94 101 _STI_monitor_staticctor(); … … 100 107 101 108 extern (C) bool rt_init( ExceptionHandler dg = null ) 102 109 { 110 static bool result; 111 112 if (result) 113 return result; 114 103 115 _d_criticalInit(); 104 116 105 117 try … … 108 120 version (Win32) 109 121 _minit(); 110 122 _moduleCtor(); 111 return true;123 return result = true; 112 124 } 113 125 catch( Exception e ) 114 126 { … … 120 132 121 133 } 122 134 _d_criticalTerm(); 123 return false;135 return result = false; 124 136 } 125 137 126 138 void _d_criticalTerm() 127 139 { 140 static bool hasBeenCalled; 141 142 if (hasBeenCalled) 143 return; 144 145 hasBeenCalled = true; 146 128 147 version (Posix) 129 148 { 130 149 _STD_critical_term(); … … 134 153 135 154 extern (C) bool rt_term( ExceptionHandler dg = null ) 136 155 { 156 static bool result; 157 158 if (result) 159 return result; 160 137 161 try 138 162 { 139 thread_joinAll();140 163 _d_isHalting = true; 164 thread_joinAll(); 141 165 _moduleDtor(); 142 166 gc_term(); 143 return true;167 return result = true; 144 168 } 145 169 catch( Exception e ) 146 170 { … … 155 179 { 156 180 _d_criticalTerm(); 157 181 } 158 return false;182 return result = false; 159 183 } 160 184 161 185 version (OSX) … … 215 239 */ 216 240 __libc_stack_end = cast(void*)&argv; 217 241 } 242 218 243 version (Posix) 219 { 220 _STI_monitor_staticctor(); 221 _STI_critical_init(); 222 } 244 _d_criticalInit(); 223 245 224 246 version (Win32) 225 247 { … … 305 327 306 328 void runAll() 307 329 { 308 gc_init(); 309 version (Win32) 310 _minit(); 311 _moduleCtor(); 330 rt_init(); 312 331 if (runModuleUnitTests()) 313 332 tryExec(&runMain); 314 _d_isHalting = true; 315 thread_joinAll(); 316 _moduleDtor(); 317 gc_term(); 333 rt_term(); 318 334 } 319 335 320 336 tryExec(&runAll); 321 337 322 338 version (Posix) 323 { 324 _STD_critical_term(); 325 _STD_monitor_staticdtor(); 326 } 339 _d_criticalTerm(); 340 327 341 return result; 328 342 } -
tango/core/rt/compiler/dmd/object_.d
old new 48 48 import rt.compiler.dmd.rt.aaA; 49 49 debug(PRINTF) import tango.stdc.stdio: printf; 50 50 extern (C) Object _d_newclass(ClassInfo ci); 51 52 version (darwin) 53 import rt.compiler.dmd.darwin.Image; 51 54 } 52 55 53 56 // NOTE: For some reason, this declaration method doesn't work … … 1220 1223 extern (C) ModuleReference *_Dmodule_ref; // start of linked list 1221 1224 } 1222 1225 1223 version( OSX )1224 {1225 extern (C)1226 {1227 extern void* _minfo_beg;1228 extern void* _minfo_end;1229 }1230 }1231 1232 1226 ModuleInfo[] _moduleinfo_dtors; 1233 1227 uint _moduleinfo_dtors_i; 1234 1228 … … 1280 1274 * and __minfo_end. The variables _minfo_beg and _minfo_end 1281 1275 * are of zero size and are in the two bracketing segments, 1282 1276 * 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. 1283 1283 */ 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"); 1286 1285 debug(PRINTF) printf("moduleinfo: ptr = %p, length = %d\n", _moduleinfo_array.ptr, _moduleinfo_array.length); 1287 1286 1288 1287 debug(PRINTF) foreach (m; _moduleinfo_array) -
tango/core/rt/compiler/dmd/posix/deh.d
old new 29 29 import tango.stdc.stdio : printf; 30 30 import tango.stdc.stdlib : exit; 31 31 32 version (darwin) 33 import rt.compiler.dmd.darwin.Image; 34 32 35 extern (C) 33 36 { 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 } 36 44 37 45 int _d_isbaseof(ClassInfo oc, ClassInfo c); 38 46 } … … 99 107 100 108 DHandlerTable *__eh_finddata(void *address) 101 109 { 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) 109 111 { 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; 112 133 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++) 115 139 { 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 } 118 149 } 150 // debug printf("\tnot found\n"); 151 return null; 119 152 } 120 // debug printf("\tnot found\n");121 return null;122 153 } 123 154 124 155










