Re: [PATCH 6/7] gdb: select "Cygwin" OS ABI for Cygwin binaries

Jon Turney
2020-03-16T21:29:43Z

On 16/03/2020 17:08, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
>
> Before this patch, the "Windows" OS ABI is selected for all Windows
> executables, including Cygwin ones. This patch makes GDB differentiate
> Cygwin binaries from non-Cygwin ones, and selects the "Cygwin" OS ABI
> for the Cygwin ones.
>
> To check whether a Windows PE executable is a Cygwin one, we check the
> library list in the .idata section, see if it contains "cygwin1.dll".
>
> I had to add code to parse the .idata section, because BFD doesn't seem
> to expose this information. BFD does parse this information, but only
> to print it in textual form (function pe_print_idata):
>
[...]
> +
> +bool
> +is_linked_with_cygwin_dll (bfd *abfd)
> +{
> + /* The list of DLLs a PE is linked to is in the .idata section. See:
> +
> + https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#the-idata-section
> + */
> + asection *idata_section = bfd_get_section_by_name (abfd, ".idata");
> + if (idata_section == nullptr)
> + return false;

I'm fine with this as-is, but FTR I think this only happens to work
because binutils ld (which is probably the only way to currently build a
cygwin executable) puts the import table in the .idata section.

The strictly correct way to locate the import table is to use the data
directory (as pe_print_idata() does)

(See
https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#optional-header-data-directories-image-only)

(Notwithstanding the MS documentation you linked, I believe MS tools can
put the import table in .rdata)