From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sa-prd-fep-048.btinternet.com (mailomta28-sa.btinternet.com [213.120.69.34]) by sourceware.org (Postfix) with ESMTPS id 2DB2A3877024 for ; Mon, 16 Mar 2020 21:29:43 +0000 (GMT) Received: from sa-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.38.7]) by sa-prd-fep-041.btinternet.com with ESMTP id <20200316190337.GKHS1599.sa-prd-fep-041.btinternet.com@sa-prd-rgout-004.btmx-prd.synchronoss.net>; Mon, 16 Mar 2020 19:03:37 +0000 Authentication-Results: btinternet.com; auth=pass (PLAIN) smtp.auth=jonturney@btinternet.com X-Originating-IP: [31.51.205.86] X-OWM-Source-IP: 31.51.205.86 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedugedrudeffedguddulecutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceutffkvffkuffjvffgnffgvefqofdpqfgfvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuffhomhgrihhnpehmihgtrhhoshhofhhtrdgtohhmnecukfhppeefuddrhedurddvtdehrdekieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegludelvddrudeikedruddruddujegnpdhinhgvthepfedurdehuddrvddthedrkeeipdhmrghilhhfrhhomhepoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqecuuefqffgjpeekuefkvffokffogfdprhgtphhtthhopeeoghgusgdqphgrthgthhgvshesshhouhhrtggvfigrrhgvrdhorhhgqedprhgtphhtthhopeeoshhimhhonhdrmhgrrhgthhhisehpohhlhihmthhlrdgtrgeq X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from [192.168.1.117] (31.51.205.86) by sa-prd-rgout-004.btmx-prd.synchronoss.net (5.8.340) (authenticated as jonturney@btinternet.com) id 5E3A27DB06397ED9; Mon, 16 Mar 2020 19:03:37 +0000 Subject: Re: [PATCH 6/7] gdb: select "Cygwin" OS ABI for Cygwin binaries To: Simon Marchi References: <20200316170845.184386-1-simon.marchi@polymtl.ca> <20200316170845.184386-7-simon.marchi@polymtl.ca> Cc: gdb-patches@sourceware.org From: Jon Turney Message-ID: Date: Mon, 16 Mar 2020 19:03:37 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200316170845.184386-7-simon.marchi@polymtl.ca> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.5 required=5.0 tests=FORGED_SPF_HELO, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 21:29:44 -0000 On 16/03/2020 17:08, Simon Marchi wrote: > From: Simon Marchi > > 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)