| 1 |
/** |
| 2 |
* |
| 3 |
* Copyright: Copyright Digital Mars 2000 - 2012. |
| 4 |
* License: Distributed under the |
| 5 |
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). |
| 6 |
* (See accompanying file LICENSE) |
| 7 |
* Authors: Walter Bright, Sean Kelly, Martin Nowak |
| 8 |
* Source: $(DRUNTIMESRC rt/_sections.d) |
| 9 |
*/ |
| 10 |
|
| 11 |
module rt.sections; |
| 12 |
|
| 13 |
version (OSX) |
| 14 |
version = Darwin; |
| 15 |
else version (iOS) |
| 16 |
version = Darwin; |
| 17 |
else version (TVOS) |
| 18 |
version = Darwin; |
| 19 |
else version (WatchOS) |
| 20 |
version = Darwin; |
| 21 |
|
| 22 |
version (GNU) |
| 23 |
public import gcc.sections; |
| 24 |
else version (CRuntime_Glibc) |
| 25 |
public import rt.sections_elf_shared; |
| 26 |
else version (CRuntime_Musl) |
| 27 |
public import rt.sections_elf_shared; |
| 28 |
else version (FreeBSD) |
| 29 |
public import rt.sections_elf_shared; |
| 30 |
else version (NetBSD) |
| 31 |
public import rt.sections_elf_shared; |
| 32 |
else version (OpenBSD) |
| 33 |
{ |
| 34 |
/** |
| 35 |
* OpenBSD is missing support needed for elf_shared. |
| 36 |
* See the top of sections_solaris.d for more info. |
| 37 |
*/ |
| 38 |
|
| 39 |
public import rt.sections_solaris; |
| 40 |
} |
| 41 |
else version (DragonFlyBSD) |
| 42 |
public import rt.sections_elf_shared; |
| 43 |
else version (Solaris) |
| 44 |
public import rt.sections_solaris; |
| 45 |
else version (Darwin) |
| 46 |
{ |
| 47 |
version (X86_64) |
| 48 |
public import rt.sections_osx_x86_64; |
| 49 |
else version (X86) |
| 50 |
public import rt.sections_osx_x86; |
| 51 |
else |
| 52 |
static assert(0, "unimplemented"); |
| 53 |
} |
| 54 |
else version (CRuntime_Microsoft) |
| 55 |
public import rt.sections_win64; |
| 56 |
else version (CRuntime_Bionic) |
| 57 |
public import rt.sections_elf_shared; |
| 58 |
else version (CRuntime_UClibc) |
| 59 |
public import rt.sections_elf_shared; |
| 60 |
else |
| 61 |
static assert(0, "unimplemented"); |
| 62 |
|
| 63 |
import rt.deh, rt.minfo; |
| 64 |
|
| 65 |
template isSectionGroup(T) |
| 66 |
{ |
| 67 |
enum isSectionGroup = |
| 68 |
is(typeof(T.init.modules) == immutable(ModuleInfo*)[]) && |
| 69 |
is(typeof(T.init.moduleGroup) == ModuleGroup) && |
| 70 |
(!is(typeof(T.init.ehTables)) || is(typeof(T.init.ehTables) == immutable(FuncTable)[])) && |
| 71 |
is(typeof(T.init.gcRanges) == void[][]) && |
| 72 |
is(typeof({ foreach (ref T; T) {}})) && |
| 73 |
is(typeof({ foreach_reverse (ref T; T) {}})); |
| 74 |
} |
| 75 |
static assert(isSectionGroup!(SectionGroup)); |
| 76 |
static assert(is(typeof(&initSections) == void function() nothrow @nogc)); |
| 77 |
static assert(is(typeof(&finiSections) == void function() nothrow @nogc)); |
| 78 |
static assert(is(typeof(&initTLSRanges) RT == return) && |
| 79 |
is(typeof(&initTLSRanges) == RT function() nothrow @nogc) && |
| 80 |
is(typeof(&finiTLSRanges) == void function(RT) nothrow @nogc) && |
| 81 |
is(typeof(&scanTLSRanges) == void function(RT, scope void delegate(void*, void*) nothrow) nothrow)); |
| 82 |
|
| 83 |
version (Windows) |
| 84 |
{ |
| 85 |
} |
| 86 |
else version (Shared) |
| 87 |
{ |
| 88 |
static assert(is(typeof(&pinLoadedLibraries) == void* function() nothrow @nogc)); |
| 89 |
static assert(is(typeof(&unpinLoadedLibraries) == void function(void*) nothrow @nogc)); |
| 90 |
static assert(is(typeof(&inheritLoadedLibraries) == void function(void*) nothrow @nogc)); |
| 91 |
static assert(is(typeof(&cleanupLoadedLibraries) == void function() nothrow @nogc)); |
| 92 |
} |
| 93 |
|
| 94 |
bool scanDataSegPrecisely() nothrow @nogc |
| 95 |
{ |
| 96 |
import rt.config; |
| 97 |
string opt = rt_configOption("scanDataSeg"); |
| 98 |
switch (opt) |
| 99 |
{ |
| 100 |
case "": |
| 101 |
case "conservative": |
| 102 |
return false; |
| 103 |
case "precise": |
| 104 |
return true; |
| 105 |
default: |
| 106 |
__gshared err = new Error("DRT invalid scanDataSeg option, must be 'precise' or 'conservative'"); |
| 107 |
throw err; |
| 108 |
} |
| 109 |
} |