xref: /netbsd-src/external/gpl3/gcc.old/dist/libphobos/m4/druntime/os.m4 (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1#
2# Contains macros to detect OS features.
3#
4
5
6# DRUNTIME_OS_THREAD_MODEL
7# ------------------------
8# Detect thread model and substitute DCFG_THREAD_MODEL
9AC_DEFUN([DRUNTIME_OS_THREAD_MODEL],
10[
11  AC_REQUIRE([AC_PROG_GDC])
12  AC_MSG_CHECKING([for thread model used by GDC])
13  d_thread_model=`$GDC -v 2>&1 | sed -n 's/^Thread model: //p'`
14  AC_MSG_RESULT([$d_thread_model])
15
16  # Map from thread model to thread interface.
17  DRUNTIME_CONFIGURE_THREADS([$d_thread_model])
18])
19
20
21# DRUNTIME_CONFIGURE_THREADS(thread_model)
22# ----------------------------------------
23# Map target os to D version identifier
24AC_DEFUN([DRUNTIME_CONFIGURE_THREADS],
25[
26case $1 in
27    aix)    DCFG_THREAD_MODEL="Posix" ;;
28    lynx)   DCFG_THREAD_MODEL="Posix" ;;
29    posix)  DCFG_THREAD_MODEL="Posix" ;;
30    single) DCFG_THREAD_MODEL="Single" ;;
31    win32)  DCFG_THREAD_MODEL="Win32" ;;
32    # TODO: These targets need porting.
33    dce|mipssde|rtems|tpf|vxworks)
34	    DCFG_THREAD_MODEL="Single" ;;
35    *)	    as_fn_error "Thread implementation '$1' not recognised" "$LINENO" 5 ;;
36esac
37AC_SUBST(DCFG_THREAD_MODEL)
38])
39
40
41# DRUNTIME_OS_DETECT
42# ------------------
43# Set the druntime_cv_target_os variable
44AC_DEFUN([DRUNTIME_OS_DETECT],
45[
46  AC_CACHE_CHECK([[for target OS]],
47    [[druntime_cv_target_os]],
48    [[druntime_cv_target_os=`echo $target_os | sed 's/^\([A-Za-z_]+\)/\1/'`]])
49    AS_IF([[test -z "$druntime_cv_target_os"]],
50      [AC_MSG_ERROR([[can't detect target OS]])],
51      [])
52])
53
54
55# DRUNTIME_OS_SOURCES
56# -------------------
57# Detect target OS and add DRUNTIME_OS_AIX DRUNTIME_OS_DARWIN
58# DRUNTIME_OS_FREEBSD DRUNTIME_OS_LINUX DRUNTIME_OS_MINGW
59# DRUNTIME_OS_SOLARIS DRUNTIME_OS_OPENBSD conditionals.
60# If the system is posix, add DRUNTIME_OS_POSIX conditional.
61AC_DEFUN([DRUNTIME_OS_SOURCES],
62[
63  AC_REQUIRE([DRUNTIME_OS_DETECT])
64
65  druntime_target_os_parsed=""
66  case "$druntime_cv_target_os" in
67      aix*)    druntime_target_os_parsed="aix"
68               ;;
69      *android*)
70               druntime_target_os_parsed="android"
71               ;;
72      darwin*) druntime_target_os_parsed="darwin"
73               ;;
74      dragonfly*)
75               druntime_target_os_parsed="dragonflybsd"
76               ;;
77      freebsd*|k*bsd*-gnu)
78               druntime_target_os_parsed="freebsd"
79               ;;
80      openbsd*)
81               druntime_target_os_parsed="openbsd"
82               ;;
83      netbsd*)
84               druntime_target_os_parsed="netbsd"
85               ;;
86      linux*)  druntime_target_os_parsed="linux"
87               ;;
88      mingw*)  druntime_target_os_parsed="mingw"
89             ;;
90      *solaris*) druntime_target_os_parsed="solaris"
91  esac
92  AM_CONDITIONAL([DRUNTIME_OS_AIX],
93                 [test "$druntime_target_os_parsed" = "aix"])
94  AM_CONDITIONAL([DRUNTIME_OS_ANDROID],
95                 [test "$druntime_target_os_parsed" = "android"])
96  AM_CONDITIONAL([DRUNTIME_OS_DARWIN],
97                 [test "$druntime_target_os_parsed" = "darwin"])
98  AM_CONDITIONAL([DRUNTIME_OS_DRAGONFLYBSD],
99                 [test "$druntime_target_os_parsed" = "dragonflybsd"])
100  AM_CONDITIONAL([DRUNTIME_OS_FREEBSD],
101                 [test "$druntime_target_os_parsed" = "freebsd"])
102  AM_CONDITIONAL([DRUNTIME_OS_NETBSD],
103                 [test "$druntime_target_os_parsed" = "netbsd"])
104  AM_CONDITIONAL([DRUNTIME_OS_OPENBSD],
105                 [test "$druntime_target_os_parsed" = "openbsd"])
106  AM_CONDITIONAL([DRUNTIME_OS_LINUX],
107                 [test "$druntime_target_os_parsed" = "linux"])
108  AM_CONDITIONAL([DRUNTIME_OS_MINGW],
109                 [test "$druntime_target_os_parsed" = "mingw"])
110  AM_CONDITIONAL([DRUNTIME_OS_SOLARIS],
111                 [test "$druntime_target_os_parsed" = "solaris"])
112
113  druntime_target_posix="no"
114  case "$druntime_cv_target_os" in
115    aix*|*bsd*|cygwin*|darwin*|gnu*|linux*|skyos*|*solaris*|sysv*)
116      druntime_target_posix="yes"
117      ;;
118  esac
119  AM_CONDITIONAL([DRUNTIME_OS_POSIX], [test "$druntime_target_posix" = "yes"])
120])
121
122
123# DRUNTIME_OS_ARM_EABI_UNWINDER
124# ------------------------
125# Check if using ARM unwinder and substitute DCFG_ARM_EABI_UNWINDER
126# and set DRUNTIME_OS_ARM_EABI_UNWINDER conditional.
127AC_DEFUN([DRUNTIME_OS_ARM_EABI_UNWINDER],
128[
129  AC_LANG_PUSH([C])
130  AC_MSG_CHECKING([for ARM unwinder])
131  AC_TRY_COMPILE([#include <unwind.h>],[
132  #if __ARM_EABI_UNWINDER__
133  #error Yes, it is.
134  #endif
135  ],
136    [AC_MSG_RESULT([no])
137     DCFG_ARM_EABI_UNWINDER=false],
138    [AC_MSG_RESULT([yes])
139     DCFG_ARM_EABI_UNWINDER=true])
140  AC_SUBST(DCFG_ARM_EABI_UNWINDER)
141  AM_CONDITIONAL([DRUNTIME_OS_ARM_EABI_UNWINDER], [test "$DCFG_ARM_EABI_UNWINDER" = "true"])
142  AC_LANG_POP([C])
143])
144
145
146# DRUNTIME_OS_MINFO_BRACKETING
147# ----------------------------
148# Check if the linker provides __start_minfo and __stop_minfo symbols and
149# substitute DCFG_MINFO_BRACKETING.
150AC_DEFUN([DRUNTIME_OS_MINFO_BRACKETING],
151[
152  AC_LANG_PUSH([C])
153  AC_MSG_CHECKING([for minfo section bracketing])
154  AC_LINK_IFELSE([AC_LANG_SOURCE([
155    void* module_info_ptr __attribute__((section ("minfo")));
156    extern void* __start_minfo __attribute__((visibility ("hidden")));
157    extern void* __stop_minfo __attribute__((visibility ("hidden")));
158
159    int main()
160    {
161        // Never run, just to prevent compiler from optimizing access
162        return &__start_minfo == &__stop_minfo;
163    }
164  ])],
165    [AC_MSG_RESULT([yes])
166     DCFG_MINFO_BRACKETING=true],
167    [AC_MSG_RESULT([no])
168     DCFG_MINFO_BRACKETING=false])
169  AC_SUBST(DCFG_MINFO_BRACKETING)
170  AM_CONDITIONAL([DRUNTIME_OS_MINFO_BRACKETING], [test "$DCFG_MINFO_BRACKETING" = "true"])
171  AC_LANG_POP([C])
172])
173
174# DRUNTIME_OS_DLPI_TLS_MODID
175# ----------------------------
176# Check if struct dl_phdr_info includes the dlpi_tls_modid member and
177# substitute DCFG_DLPI_TLS_MODID.
178AC_DEFUN([DRUNTIME_OS_DLPI_TLS_MODID],
179[
180  AC_LANG_PUSH([C])
181  AC_CHECK_MEMBER([struct dl_phdr_info.dlpi_tls_modid],
182		  [DCFG_DLPI_TLS_MODID=true], [DCFG_DLPI_TLS_MODID=false],
183		  [[#include <link.h>]])
184  AC_SUBST(DCFG_DLPI_TLS_MODID)
185  AC_LANG_POP([C])
186])
187
188# DRUNTIME_OS_LINK_SPEC
189# ---------------------
190# Add target-specific link options to link_spec.
191AC_DEFUN([DRUNTIME_OS_LINK_SPEC],
192[
193  case $target in
194    i?86-*-solaris2.* | x86_64-*-solaris2.*)
195      # 64-bit Solaris/x86 ld breaks calls to __tls_get_addr with non-TLS
196      # relocs.  Work around by disabling TLS transitions.  Not necessary
197      # on 32-bit x86, but cannot be distinguished reliably in specs.
198      druntime_ld_prog=`$CC -print-prog-name=ld`
199      druntime_ld_gld=no
200      druntime_ld_relax_transtls=no
201      if test -n "$druntime_ld_prog" \
202         && $druntime_ld_prog -v 2>&1 | grep GNU > /dev/null 2>&1; then
203        druntime_ld_gld=yes
204      else
205        echo 'int main (void) { return 0; }' > conftest.c
206        save_LDFLAGS="$LDFLAGS"
207        LDFLAGS="$LDFLAGS -Wl,-z,relax=transtls"
208        if $CC $CFLAGS $LDFLAGS -o conftest conftest.c > /dev/null 2>&1; then
209          druntime_ld_relax_transtls=yes
210        fi
211        LDFLAGS="$save_LDFLAGS"
212        rm -f conftest.c conftest
213      fi
214      if test "$druntime_ld_relax_transtls" = "yes"; then
215        OS_LINK_SPEC='-z relax=transtls'
216      fi
217      ;;
218  esac
219  AC_SUBST(OS_LINK_SPEC)
220])
221