From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simark@simark.ca>, Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 3/4] gdb: distinguish GNU and MSVC flavors of the Windows OS ABI
Date: Wed, 15 Jul 2026 12:18:47 +0100 [thread overview]
Message-ID: <b9ac424b-b965-457c-8bf6-e8ef98d1d3fe@palves.net> (raw)
In-Reply-To: <4953c47d-3904-4df4-945b-4693c2df9dad@simark.ca>
On 2026-07-15 02:21, Simon Marchi wrote:
> On 2026-07-14 18:15, Pedro Alves wrote:
>> On 2026-07-14 12:57, Eli Zaretskii wrote:
>> * GDB now distinguishes between the GNU (MinGW) and MSVC Windows ABIs.
>>
>> The "set osabi" command accepts two new values, "Windows-GNU" and
>> "Windows-MSVC". The GNU ABI is for code produced by MinGW
>> toolchains, while the MSVC ABI is for code produced by Microsoft's
>> MSVC compiler (though see the PDB note below), or Clang targeting
>> one of {i686,aarch64,x86_64}-pc-windows-msvc. The existing
>> "Windows" value continues to work and now means "let GDB pick the
>> flavor": GDB uses the configured default OS ABI (from --target) when
>> that is a Windows flavor, and otherwise assumes the GNU flavor. For
>> example, --target=x86_64-pc-windows-msvc defaults to the MSVC ABI,
>> and --target=x86_64-w64-mingw32 defaults to GNU ABI. Similarly for
>> the i686 and AArch64 variants. See "New targets" entry below.
>
> What happens if you build a GDB with --enable-targets=all and load a
> .exe? Is either ABI preferred over the other?
The preferred one is taken out of --target, defaults to GNU.
--enable-targets=foo,bar,all does not affect it.
> Would it be possible to
> "sniff" what ABI it is, for instance with the presence of some
> particular symbol?
>
I had thought about this, but decided to leave it for a future improvement.
For Cygwin, we detect whether the inferior links with cygwin1.dll. That's pretty
reliable, as it is not possible to statically link cygwin1.dll.
For GNU vs MSVC, for C programs, both toolchains link with the same C runtime
$ ldd abi-mingw.exe
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffeeae00000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffeea9a0000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffee8660000)
ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffee8450000)
$ ldd abi-windows-msvc.exe
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffeeae00000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffeea9a0000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffee8660000)
apphelp.dll => /c/WINDOWS/SYSTEM32/apphelp.dll (0x7ffee6b20000)
so that angle does not work.
Symbols that I thought could help identify mingw/gnu:
$ nm -j abi-mingw.exe | sort -u | grep "mingw\|gcc"
.rdata$.refptr.__mingw_app_type
.rdata$.refptr.__mingw_initltsdrot_force
.rdata$.refptr.__mingw_initltsdyn_force
.rdata$.refptr.__mingw_initltssuo_force
.refptr.__mingw_app_type
.refptr.__mingw_initltsdrot_force
.refptr.__mingw_initltsdyn_force
.refptr.__mingw_initltssuo_force
___w64_mingwthr_add_key_dtor
___w64_mingwthr_remove_key_dtor
__gcc_deregister_frame
__gcc_register_frame
__mingw_GetSectionCount
__mingw_GetSectionForAddress
__mingw_SEH_signal_dispatcher
__mingw_TLScallback
__mingw_app_type
__mingw_enum_import_library_names
__mingw_initltsdrot_force
__mingw_initltsdyn_force
__mingw_initltssuo_force
__mingw_invalidParameterHandler
__mingw_module_is_dll
__mingw_raise_matherr
__mingw_setusermatherr
__mingwthr_cs
__mingwthr_cs_init
and maybe _pei386_runtime_relocator, though I read recently some discussion about that mechanism
not being needed anymore or something like that. If we make GNU the default, then this will only
matter for a x86_64-pc-windows-msvc gdb build (and aarch64, etc...), so not that bad, as I expect
such a build to be used to mainly debug windows-msvc programs and libraries.
Symbols that I thought could help identify MSVC ABI could be the unwind entries pointing
to Microsoft's CRT exception handlers:
__CxxFrameHandler
__CxxFrameHandler2
__CxxFrameHandler3
__CxxFrameHandler4
I tested with clang -fno-exceptions and I still see those, but maybe that's not reliable
and we should look for other symbols.
I only tested with clang so far (not MSVC's cl.exe), though I did notice that
with clang I only see a COFF symbol table if I use "-Wl,/debug:dwarf".
If I let clang emit pdb (the default), then there's no coff table, meaning gdb sees no symbols until we teach
it about pdb. The fact that the PE has a matching PDB alone I don't think is reliable way in the long term,
since nothing stops gcc/clang targeting mingw from also emitting PDB. When we're able to read the pdb,
maybe there's some reliable way inside its info.
So in sum, it's possibly doable as an heuristic, but I'd rather do it separately, starting
with the --target default, as it'll take more time and poking to work this all out. I'm more
interested on laying the foundation to build other things on top of at this point.
Pedro Alves
next prev parent reply other threads:[~2026-07-15 11:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 0:45 [PATCH 0/4] Support the Windows/MSVC target in GDB Pedro Alves
2026-07-14 0:45 ` [PATCH 1/4] gdb: recognize *-*-windows* Windows targets Pedro Alves
2026-07-14 0:45 ` [PATCH 2/4] gdb: treat Windows host + Windows target as native Pedro Alves
2026-07-14 0:45 ` [PATCH 3/4] gdb: distinguish GNU and MSVC flavors of the Windows OS ABI Pedro Alves
2026-07-14 11:57 ` Eli Zaretskii
2026-07-14 22:15 ` Pedro Alves
2026-07-15 1:21 ` Simon Marchi
2026-07-15 11:18 ` Pedro Alves [this message]
2026-07-15 13:13 ` Simon Marchi
2026-07-15 14:10 ` Pedro Alves
2026-07-15 15:51 ` Simon Marchi
2026-07-15 11:43 ` Eli Zaretskii
2026-07-14 0:45 ` [PATCH 4/4] gdb: MSVC "long double" is a 64-bit double Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b9ac424b-b965-457c-8bf6-e8ef98d1d3fe@palves.net \
--to=pedro@palves.net \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox