From 65ce633af3e55721eec16ae53a3100092d9de406 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jan 2023 23:22:22 +0100 Subject: [PATCH 1/2] Avoid sharing cygheaps across Cygwin versions It frequently leads to problems when trying, say, to call from Git for Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data is pretty finicky. For example, using the Git for Windows that is current at time of writing, trying to call MSYS2's Bash from Git for Windows' Bash fails somewhere in `_cmalloc()`, without any error message, and with the rather misleading exit code 127 (a code which is reserved to indicate that a command was not found). Let's just treat these as completely incompatible with one another, by virtue of using a different `CHILD_INFO_MAGIC` constant. One consequence is that spawned MSYS processes using a different MSYS2 runtime will not be visible as such to the parent process, i.e. they cannot share any resources such as pseudo terminals. But that's okay, they are simply treated as if they were regular Win32 programs. This should also help the scenario where interactions between two different versions of Git for Windows lead to those infamous `cygheap base mismatch detected` problems mentioned e.g. in https://github.com/git-for-windows/git/issues/4255 Signed-off-by: Johannes Schindelin --- winsup/cygwin/dcrt0.cc | 2 +- winsup/cygwin/sigproc.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index e32f02b7d0..45f3b0f905 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -545,7 +545,7 @@ get_cygwin_startup_info () child_info *res = (child_info *) si.lpReserved2; if (si.cbReserved2 < EXEC_MAGIC_SIZE || !res - || res->intro != PROC_MAGIC_GENERIC || res->magic != CHILD_INFO_MAGIC) + || res->intro != PROC_MAGIC_GENERIC || res->magic != (CHILD_INFO_MAGIC ^ CYGWIN_VERSION_DLL_COMBINED)) { strace.activate (false); res = NULL; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index fbb1f0ef43..65dc523ca5 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -817,7 +817,7 @@ int child_info::retry_count = 0; by fork/spawn/exec. */ child_info::child_info (unsigned in_cb, child_info_types chtype, bool need_subproc_ready): - cb (in_cb), intro (PROC_MAGIC_GENERIC), magic (CHILD_INFO_MAGIC), + cb (in_cb), intro (PROC_MAGIC_GENERIC), magic (CHILD_INFO_MAGIC ^ CYGWIN_VERSION_DLL_COMBINED), type (chtype), cygheap (::cygheap), cygheap_max (::cygheap_max), flag (0), retry (child_info::retry_count), rd_proc_pipe (NULL), wr_proc_pipe (NULL), sigmask (_my_tls.sigmask) From 4704d291696b2f2521aba2d05d08f69b01e2a455 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Jan 2023 09:32:08 +0100 Subject: [PATCH 2/2] dumper: avoid linker problem when `libbfd` depends on `libsframe` A recent binutils version introduced `libsframe` and made it a dependency of `libbfd`. Which means that we have to link that library into `dumper.exe`, too, if it exists. Signed-off-by: Johannes Schindelin --- winsup/configure.ac | 5 +++++ winsup/utils/Makefile.am | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/winsup/configure.ac b/winsup/configure.ac index 5eb3273d1e..ca2b8c0748 100644 --- a/winsup/configure.ac +++ b/winsup/configure.ac @@ -110,6 +110,11 @@ AC_CHECK_LIB([bfd], [bfd_init], [true], AM_CONDITIONAL(BUILD_DUMPER, [test "x$ac_cv_lib_bfd_bfd_init" = "xyes"]) +AC_CHECK_LIB([sframe], [sframe_decode], + AC_MSG_NOTICE([Detected libsframe; Assuming that libbfd depends on it]), [true]) + +AM_CONDITIONAL(HAVE_LIBSFRAME, [test "x$ac_cv_lib_sframe_sframe_decode" = "xyes"]) + AC_CONFIG_FILES([ Makefile cygwin/Makefile diff --git a/winsup/utils/Makefile.am b/winsup/utils/Makefile.am index e12dfdd007..08f6212324 100644 --- a/winsup/utils/Makefile.am +++ b/winsup/utils/Makefile.am @@ -87,6 +87,10 @@ profiler_CXXFLAGS = -I$(srcdir) -idirafter ${top_srcdir}/cygwin -idirafter ${top profiler_LDADD = $(LDADD) -lntdll cygps_LDADD = $(LDADD) -lpsapi -lntdll +if HAVE_LIBSFRAME +dumper_LDADD += -lsframe +endif + if CROSS_BOOTSTRAP SUBDIRS = mingw endif