1181254a7Smrg /** 2181254a7Smrg * 3181254a7Smrg * Copyright: Copyright Digital Mars 2000 - 2012. 4181254a7Smrg * License: Distributed under the 5181254a7Smrg * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). 6181254a7Smrg * (See accompanying file LICENSE) 7181254a7Smrg * Authors: Walter Bright, Sean Kelly, Martin Nowak 8*b1e83836Smrg * Source: $(DRUNTIMESRC rt/_sections.d) 9181254a7Smrg */ 10181254a7Smrg 11181254a7Smrg /* NOTE: This file has been patched from the original DMD distribution to 12181254a7Smrg * work with the GDC compiler. 13181254a7Smrg */ 14181254a7Smrg module rt.sections; 15181254a7Smrg 16181254a7Smrg version (OSX) 17181254a7Smrg version = Darwin; 18181254a7Smrg else version (iOS) 19181254a7Smrg version = Darwin; 20181254a7Smrg else version (TVOS) 21181254a7Smrg version = Darwin; 22181254a7Smrg else version (WatchOS) 23181254a7Smrg version = Darwin; 24181254a7Smrg 25181254a7Smrg version (GNU) 26181254a7Smrg public import gcc.sections; 27181254a7Smrg else version (CRuntime_Glibc) 28181254a7Smrg public import rt.sections_elf_shared; 29*b1e83836Smrg else version (CRuntime_Musl) 30*b1e83836Smrg public import rt.sections_elf_shared; 31181254a7Smrg else version (FreeBSD) 32181254a7Smrg public import rt.sections_elf_shared; 33181254a7Smrg else version (NetBSD) 34181254a7Smrg public import rt.sections_elf_shared; version(OpenBSD)35*b1e83836Smrgelse version (OpenBSD) 36*b1e83836Smrg { 37*b1e83836Smrg /** 38*b1e83836Smrg * OpenBSD is missing support needed for elf_shared. 39*b1e83836Smrg * See the top of sections_solaris.d for more info. 40*b1e83836Smrg */ 41*b1e83836Smrg 42*b1e83836Smrg public import rt.sections_solaris; 43*b1e83836Smrg } 44*b1e83836Smrg else version (DragonFlyBSD) 45*b1e83836Smrg public import rt.sections_elf_shared; 46181254a7Smrg else version (Solaris) 47181254a7Smrg public import rt.sections_solaris; version(Darwin)48181254a7Smrgelse version (Darwin) 49181254a7Smrg { 50181254a7Smrg version (X86_64) 51181254a7Smrg public import rt.sections_osx_x86_64; 52181254a7Smrg else version (X86) 53181254a7Smrg public import rt.sections_osx_x86; 54181254a7Smrg else 55181254a7Smrg static assert(0, "unimplemented"); 56181254a7Smrg } 57181254a7Smrg else version (CRuntime_DigitalMars) 58181254a7Smrg public import rt.sections_win32; 59181254a7Smrg else version (CRuntime_Microsoft) 60181254a7Smrg public import rt.sections_win64; 61181254a7Smrg else version (CRuntime_Bionic) 62181254a7Smrg public import rt.sections_android; 63*b1e83836Smrg else version (CRuntime_UClibc) 64*b1e83836Smrg public import rt.sections_elf_shared; 65181254a7Smrg else 66181254a7Smrg static assert(0, "unimplemented"); 67181254a7Smrg 68181254a7Smrg import rt.deh, rt.minfo; 69181254a7Smrg isSectionGroup(T)70181254a7Smrgtemplate isSectionGroup(T) 71181254a7Smrg { 72181254a7Smrg enum isSectionGroup = 73181254a7Smrg is(typeof(T.init.modules) == immutable(ModuleInfo*)[]) && 74181254a7Smrg is(typeof(T.init.moduleGroup) == ModuleGroup) && 75181254a7Smrg (!is(typeof(T.init.ehTables)) || is(typeof(T.init.ehTables) == immutable(FuncTable)[])) && 76181254a7Smrg is(typeof(T.init.gcRanges) == void[][]) && 77181254a7Smrg is(typeof({ foreach (ref T; T) {}})) && 78181254a7Smrg is(typeof({ foreach_reverse (ref T; T) {}})); 79181254a7Smrg } 80181254a7Smrg static assert(isSectionGroup!(SectionGroup)); 81181254a7Smrg static assert(is(typeof(&initSections) == void function() nothrow @nogc)); 82181254a7Smrg static assert(is(typeof(&finiSections) == void function() nothrow @nogc)); 83181254a7Smrg static assert(is(typeof(&initTLSRanges) RT == return) && 84181254a7Smrg is(typeof(&initTLSRanges) == RT function() nothrow @nogc) && 85181254a7Smrg is(typeof(&finiTLSRanges) == void function(RT) nothrow @nogc) && 86181254a7Smrg is(typeof(&scanTLSRanges) == void function(RT, scope void delegate(void*, void*) nothrow) nothrow)); 87181254a7Smrg version(Shared)88181254a7Smrgversion (Shared) 89181254a7Smrg { 90181254a7Smrg static assert(is(typeof(&pinLoadedLibraries) == void* function() nothrow @nogc)); 91181254a7Smrg static assert(is(typeof(&unpinLoadedLibraries) == void function(void*) nothrow @nogc)); 92181254a7Smrg static assert(is(typeof(&inheritLoadedLibraries) == void function(void*) nothrow @nogc)); 93181254a7Smrg static assert(is(typeof(&cleanupLoadedLibraries) == void function() nothrow @nogc)); 94181254a7Smrg } 95181254a7Smrg scanDataSegPrecisely()96181254a7Smrgbool scanDataSegPrecisely() nothrow @nogc 97181254a7Smrg { 98181254a7Smrg import rt.config; 99181254a7Smrg string opt = rt_configOption("scanDataSeg"); 100181254a7Smrg switch (opt) 101181254a7Smrg { 102181254a7Smrg case "": 103181254a7Smrg case "conservative": 104181254a7Smrg return false; 105181254a7Smrg case "precise": 106181254a7Smrg return true; 107181254a7Smrg default: 108181254a7Smrg __gshared err = new Error("DRT invalid scanDataSeg option, must be 'precise' or 'conservative'"); 109181254a7Smrg throw err; 110181254a7Smrg } 111181254a7Smrg } 112