xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/rt/sections.d (revision b1e838363e3c6fc78a55519254d99869742dd33c)
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 /* NOTE: This file has been patched from the original DMD distribution to
12  * work with the GDC compiler.
13  */
14 module rt.sections;
15 
16 version (OSX)
17     version = Darwin;
18 else version (iOS)
19     version = Darwin;
20 else version (TVOS)
21     version = Darwin;
22 else version (WatchOS)
23     version = Darwin;
24 
25 version (GNU)
26     public import gcc.sections;
27 else version (CRuntime_Glibc)
28     public import rt.sections_elf_shared;
29 else version (CRuntime_Musl)
30     public import rt.sections_elf_shared;
31 else version (FreeBSD)
32     public import rt.sections_elf_shared;
33 else version (NetBSD)
34     public import rt.sections_elf_shared;
version(OpenBSD)35 else version (OpenBSD)
36 {
37     /**
38      * OpenBSD is missing support needed for elf_shared.
39      * See the top of sections_solaris.d for more info.
40      */
41 
42     public import rt.sections_solaris;
43 }
44 else version (DragonFlyBSD)
45     public import rt.sections_elf_shared;
46 else version (Solaris)
47     public import rt.sections_solaris;
version(Darwin)48 else version (Darwin)
49 {
50     version (X86_64)
51         public import rt.sections_osx_x86_64;
52     else version (X86)
53         public import rt.sections_osx_x86;
54     else
55         static assert(0, "unimplemented");
56 }
57 else version (CRuntime_DigitalMars)
58     public import rt.sections_win32;
59 else version (CRuntime_Microsoft)
60     public import rt.sections_win64;
61 else version (CRuntime_Bionic)
62     public import rt.sections_android;
63 else version (CRuntime_UClibc)
64     public import rt.sections_elf_shared;
65 else
66     static assert(0, "unimplemented");
67 
68 import rt.deh, rt.minfo;
69 
isSectionGroup(T)70 template isSectionGroup(T)
71 {
72     enum isSectionGroup =
73         is(typeof(T.init.modules) == immutable(ModuleInfo*)[]) &&
74         is(typeof(T.init.moduleGroup) == ModuleGroup) &&
75         (!is(typeof(T.init.ehTables)) || is(typeof(T.init.ehTables) == immutable(FuncTable)[])) &&
76         is(typeof(T.init.gcRanges) == void[][]) &&
77         is(typeof({ foreach (ref T; T) {}})) &&
78         is(typeof({ foreach_reverse (ref T; T) {}}));
79 }
80 static assert(isSectionGroup!(SectionGroup));
81 static assert(is(typeof(&initSections) == void function() nothrow @nogc));
82 static assert(is(typeof(&finiSections) == void function() nothrow @nogc));
83 static assert(is(typeof(&initTLSRanges) RT == return) &&
84               is(typeof(&initTLSRanges) == RT function() nothrow @nogc) &&
85               is(typeof(&finiTLSRanges) == void function(RT) nothrow @nogc) &&
86               is(typeof(&scanTLSRanges) == void function(RT, scope void delegate(void*, void*) nothrow) nothrow));
87 
version(Shared)88 version (Shared)
89 {
90     static assert(is(typeof(&pinLoadedLibraries) == void* function() nothrow @nogc));
91     static assert(is(typeof(&unpinLoadedLibraries) == void function(void*) nothrow @nogc));
92     static assert(is(typeof(&inheritLoadedLibraries) == void function(void*) nothrow @nogc));
93     static assert(is(typeof(&cleanupLoadedLibraries) == void function() nothrow @nogc));
94 }
95 
scanDataSegPrecisely()96 bool scanDataSegPrecisely() nothrow @nogc
97 {
98     import rt.config;
99     string opt = rt_configOption("scanDataSeg");
100     switch (opt)
101     {
102         case "":
103         case "conservative":
104             return false;
105         case "precise":
106             return true;
107         default:
108             __gshared err = new Error("DRT invalid scanDataSeg option, must be 'precise' or 'conservative'");
109             throw err;
110     }
111 }
112