Add MSYS configuration files (#728) * Add MSYS configuration files MSYS behaves very similiar to Cygwin, e.g. also __CYGWIN__ is defined. Now 'make check' passes on MSYS without extra patches. * Fix warning extra tokens at end of #endif in closures.c Extra tokens converted into a comment. Also nearby indentations corrected. * Fix missing prototype warning mkostemp() on Cygwin Cygwin requires also _GNU_SOURCE to be defined to enable mkostemp() prototype. * Fix warning label ‘out’ defined but not used in ffi functions Define same preprocessor conditions for goto and label visibility. * Fix warning label ‘out’ defined but not used and related indentations. Define same preprocessor conditions for goto and label visibility. Correct also related indentations. Co-authored-by: Hannes Müller <>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
diff --git a/configure.ac b/configure.ac
index 75cc455..fba64d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -391,7 +391,7 @@ AC_ARG_ENABLE(exec-static-tramp,
if test "$enable_exec_static_tramp" != no; then
case "$target" in
- *-cygwin*)
+ *-cygwin* | *-msys*)
# Only define static trampolines if we are using the cygwin runtime.
# Will this need to be changed for mingw?
if test "x$GCC" = "xyes"; then
diff --git a/configure.host b/configure.host
index 5cd5fc4..f23716f 100644
--- a/configure.host
+++ b/configure.host
@@ -6,7 +6,7 @@
# THIS TABLE IS SORTED. KEEP IT THAT WAY.
# Most of the time we can define all the variables all at once...
case "${host}" in
- aarch64*-*-cygwin* | aarch64*-*-mingw* | aarch64*-*-win* )
+ aarch64*-*-cygwin* | aarch64*-*-msys* | aarch64*-*-mingw* | aarch64*-*-win* )
TARGET=ARM_WIN64; TARGETDIR=aarch64
if test "${ax_cv_c_compiler_vendor}" = "microsoft"; then
MSVC=1
@@ -30,7 +30,7 @@ case "${host}" in
SOURCES="ffi.c arcompact.S"
;;
- arm*-*-cygwin* | arm*-*-mingw* | arm*-*-win* )
+ arm*-*-cygwin* | arm*-*-msys* | arm*-*-mingw* | arm*-*-win* )
TARGET=ARM_WIN32; TARGETDIR=arm
if test "${ax_cv_c_compiler_vendor}" = "microsoft"; then
MSVC=1
@@ -83,8 +83,8 @@ case "${host}" in
TARGET=X86_FREEBSD; TARGETDIR=x86
;;
- i?86-*-cygwin* | i?86-*-mingw* | i?86-*-win* | i?86-*-os2* | i?86-*-interix* \
- | x86_64-*-cygwin* | x86_64-*-mingw* | x86_64-*-win* )
+ i?86-*-cygwin* | i?86-*-msys* | i?86-*-mingw* | i?86-*-win* | i?86-*-os2* | i?86-*-interix* \
+ | x86_64-*-cygwin* | x86_64-*-msys* | x86_64-*-mingw* | x86_64-*-win* )
TARGETDIR=x86
if test $ac_cv_sizeof_size_t = 4; then
TARGET=X86_WIN32
diff --git a/src/aarch64/ffi.c b/src/aarch64/ffi.c
index 76d2938..83e5653 100644
--- a/src/aarch64/ffi.c
+++ b/src/aarch64/ffi.c
@@ -832,14 +832,14 @@ ffi_prep_closure_loc (ffi_closure *closure,
start = ffi_closure_SYSV;
#if FFI_EXEC_TRAMPOLINE_TABLE
-#ifdef __MACH__
-#ifdef HAVE_PTRAUTH
+# ifdef __MACH__
+# ifdef HAVE_PTRAUTH
codeloc = ptrauth_auth_data(codeloc, ptrauth_key_function_pointer, 0);
-#endif
+# endif
void **config = (void **)((uint8_t *)codeloc - PAGE_MAX_SIZE);
config[0] = closure;
config[1] = start;
-#endif
+# endif
#else
static const unsigned char trampoline[16] = {
0x90, 0x00, 0x00, 0x58, /* ldr x16, tramp+16 */
@@ -848,7 +848,7 @@ ffi_prep_closure_loc (ffi_closure *closure,
};
char *tramp = closure->tramp;
-#if defined(FFI_EXEC_STATIC_TRAMP)
+# if defined(FFI_EXEC_STATIC_TRAMP)
if (ffi_tramp_is_present(closure))
{
/* Initialize the static trampoline's parameters. */
@@ -859,7 +859,7 @@ ffi_prep_closure_loc (ffi_closure *closure,
ffi_tramp_set_parms (closure->ftramp, start, closure);
goto out;
}
-#endif
+# endif
/* Initialize the dynamic trampoline. */
memcpy (tramp, trampoline, sizeof(trampoline));
@@ -869,15 +869,17 @@ ffi_prep_closure_loc (ffi_closure *closure,
ffi_clear_cache(tramp, tramp + FFI_TRAMPOLINE_SIZE);
/* Also flush the cache for code mapping. */
-#ifdef _WIN32
+# ifdef _WIN32
// Not using dlmalloc.c for Windows ARM64 builds
// so calling ffi_data_to_code_pointer() isn't necessary
unsigned char *tramp_code = tramp;
- #else
+# else
unsigned char *tramp_code = ffi_data_to_code_pointer (tramp);
- #endif
+# endif
ffi_clear_cache (tramp_code, tramp_code + FFI_TRAMPOLINE_SIZE);
+# if defined(FFI_EXEC_STATIC_TRAMP)
out:
+# endif
#endif
closure->cif = cif;
diff --git a/src/arm/ffi.c b/src/arm/ffi.c
index 985dbee..cfd3e9d 100644
--- a/src/arm/ffi.c
+++ b/src/arm/ffi.c
@@ -626,7 +626,7 @@ ffi_prep_closure_loc (ffi_closure * closure,
config[1] = closure_func;
#else
-#if defined(FFI_EXEC_STATIC_TRAMP)
+# if defined(FFI_EXEC_STATIC_TRAMP)
if (ffi_tramp_is_present(closure))
{
/* Initialize the static trampoline's parameters. */
@@ -637,31 +637,33 @@ ffi_prep_closure_loc (ffi_closure * closure,
ffi_tramp_set_parms (closure->ftramp, closure_func, closure);
goto out;
}
-#endif
+# endif
/* Initialize the dynamic trampoline. */
-#ifndef _WIN32
+# ifndef _WIN32
memcpy(closure->tramp, ffi_arm_trampoline, 8);
-#else
+# else
// cast away function type so MSVC doesn't set the lower bit of the function pointer
memcpy(closure->tramp, (void*)((uintptr_t)ffi_arm_trampoline & 0xFFFFFFFE), FFI_TRAMPOLINE_CLOSURE_OFFSET);
-#endif
+# endif
-#if defined(__QNX__)
+# if defined(__QNX__)
msync (closure->tramp, 8, MS_INVALIDATE_ICACHE); /* clear data map */
msync (codeloc, 8, MS_INVALIDATE_ICACHE); /* clear insn map */
-#elif defined(_WIN32)
+# elif defined(_WIN32)
FlushInstructionCache(GetCurrentProcess(), closure->tramp, FFI_TRAMPOLINE_SIZE);
-#else
+# else
__clear_cache(closure->tramp, closure->tramp + 8); /* clear data map */
__clear_cache(codeloc, codeloc + 8); /* clear insn map */
-#endif
-#ifdef _WIN32
+# endif
+# ifdef _WIN32
*(void(**)(void))(closure->tramp + FFI_TRAMPOLINE_CLOSURE_FUNCTION) = closure_func;
-#else
+# else
*(void (**)(void))(closure->tramp + 8) = closure_func;
-#endif
+# endif
+# if defined(FFI_EXEC_STATIC_TRAMP)
out:
+# endif
#endif
closure->cif = cif;
diff --git a/src/closures.c b/src/closures.c
index e2bc651..3b7a0ac 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -27,7 +27,7 @@
DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------- */
-#if defined __linux__ && !defined _GNU_SOURCE
+#if (defined __linux__ || defined __CYGWIN__) && !defined _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
@@ -142,17 +142,17 @@ ffi_tramp_is_present (__attribute__((unused)) void *ptr)
#endif
#if FFI_MMAP_EXEC_WRIT && defined(__linux__) && !defined(__ANDROID__)
-# if !defined FFI_MMAP_EXEC_SELINUX
-/* When defined to 1 check for SELinux and if SELinux is active,
- don't attempt PROT_EXEC|PROT_WRITE mapping at all, as that
- might cause audit messages. */
-# define FFI_MMAP_EXEC_SELINUX 1
+# if !defined FFI_MMAP_EXEC_SELINUX
+/* When defined to 1 check for SELinux and if SELinux is active,
+ don't attempt PROT_EXEC|PROT_WRITE mapping at all, as that
+ might cause audit messages. */
+# define FFI_MMAP_EXEC_SELINUX 1
# endif /* !defined FFI_MMAP_EXEC_SELINUX */
# if !defined FFI_MMAP_PAX
-/* Also check for PaX MPROTECT */
-# define FFI_MMAP_PAX 1
+/* Also check for PaX MPROTECT */
+# define FFI_MMAP_PAX 1
# endif /* !defined FFI_MMAP_PAX */
-#endif FFI_MMAP_EXEC_WRIT && defined(__linux__) && !defined(__ANDROID__)
+#endif /* FFI_MMAP_EXEC_WRIT && defined(__linux__) && !defined(__ANDROID__) */
#if FFI_CLOSURES
diff --git a/src/loongarch64/ffi.c b/src/loongarch64/ffi.c
index ed9c15f..140be3b 100644
--- a/src/loongarch64/ffi.c
+++ b/src/loongarch64/ffi.c
@@ -538,7 +538,9 @@ ffi_prep_closure_loc (ffi_closure *closure, ffi_cif *cif,
__builtin___clear_cache (codeloc, codeloc + FFI_TRAMPOLINE_SIZE);
+#if defined(FFI_EXEC_STATIC_TRAMP)
out:
+#endif
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index 3da6716..b82d8c0 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -614,7 +614,9 @@ ffi_prep_closure_loc (ffi_closure* closure,
tramp[9] = 0xe9;
*(unsigned *)(tramp + 10) = (unsigned)dest - ((unsigned)codeloc + 14);
+#if defined(FFI_EXEC_STATIC_TRAMP)
out:
+#endif
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
diff --git a/src/x86/ffi64.c b/src/x86/ffi64.c
index 22d43f5..6a8e37f 100644
--- a/src/x86/ffi64.c
+++ b/src/x86/ffi64.c
@@ -799,7 +799,9 @@ ffi_prep_closure_loc (ffi_closure* closure,
memcpy (tramp, trampoline, sizeof(trampoline));
*(UINT64 *)(tramp + sizeof (trampoline)) = (uintptr_t)dest;
+#if defined(FFI_EXEC_STATIC_TRAMP)
out:
+#endif
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
diff --git a/src/x86/ffiw64.c b/src/x86/ffiw64.c
index 263aa5b..8271658 100644
--- a/src/x86/ffiw64.c
+++ b/src/x86/ffiw64.c
@@ -263,7 +263,9 @@ EFI64(ffi_prep_closure_loc)(ffi_closure* closure,
memcpy (tramp, trampoline, sizeof(trampoline));
*(UINT64 *)(tramp + sizeof (trampoline)) = (uintptr_t)ffi_closure_win64;
+#if defined(FFI_EXEC_STATIC_TRAMP)
out:
+#endif
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
diff --git a/testsuite/lib/target-libpath.exp b/testsuite/lib/target-libpath.exp
index 6b7beba..e33a656 100644
--- a/testsuite/lib/target-libpath.exp
+++ b/testsuite/lib/target-libpath.exp
@@ -175,7 +175,7 @@ proc set_ld_library_path_env_vars { } {
} else {
setenv DYLD_LIBRARY_PATH "$ld_library_path"
}
- if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
+ if { [istarget *-*-cygwin*] || [ istarget *-*-msys* ] || [istarget *-*-mingw*] } {
if { $orig_path_saved } {
setenv PATH "$ld_library_path:$orig_path"
} else {
@@ -271,7 +271,7 @@ proc get_shlib_extension { } {
if { [ istarget *-*-darwin* ] } {
set shlib_ext "dylib"
- } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-mingw* ] } {
+ } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-msys* ] || [ istarget *-*-mingw* ] } {
set shlib_ext "dll"
} elseif { [ istarget hppa*-*-hpux* ] } {
set shlib_ext "sl"