From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by server2.sourceware.org (Postfix) with ESMTPS id 335443938806 for ; Sat, 7 Mar 2020 18:16:27 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 027IBcI0030462 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 7 Mar 2020 13:11:44 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 027IBcI0030462 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1583604705; bh=KJEFUAmdNjBHzRYUAuTCJz04YTDE0yeYFCDZEfaA4iA=; h=To:From:Subject:Date:From; b=q0To3mYURivXWrLRSllxcej7xlcnzxscmdwNB4Lj5e5dAGRgyPtqlU3A+Yqt5vr/f xjFMNl27CxbOy8wc8Des8BKMZFlXP9hGZIRGFWIBzxHZTiM/jv1s3S5o455qvQZ8wW LlzyS9sJzX4lLMYECuUycxeIMe/XOnXkRfixI9pY= Received: from [10.0.0.11] (unknown [192.222.164.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id BED9C1E5F3 for ; Sat, 7 Mar 2020 13:11:38 -0500 (EST) To: Binutils From: Simon Marchi Subject: BFD interface for getting PE import section data Message-ID: <35bcce03-10f0-4e11-3d96-40a3d59cc27e@polymtl.ca> Date: Sat, 7 Mar 2020 13:11:38 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 7 Mar 2020 18:11:38 +0000 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Mar 2020 18:16:28 -0000 Hi, In order for GDB to be able to differentiate Cygwin executables from non-Cygwin Windows executables (in this context [1]), I'd like to access the data of the import section of the PE executables, more specifically the DLL names. We would check if the cygwin DLL is present in this list. I was able to look up and parse enough of the .idata section to get the imported DLL names, using the official doc: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#the-idata-section as well as this page: https://blog.kowalczyk.info/articles/pefileformat.html#9ccef823-67e7-4372-9172-045d7b1fb006 However, this sounds like some facility BFD should provide. Is there a way to get this information that I'm missing? I found this code, that's used by "objdump -p" to print the content of the import tables: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/peXXigen.c;h=e42d646552a0ca1e856e082256cd3d943b54ddf0;hb=HEAD#l1261 However, that code is tightly coupled with the printed, so it's not practical to use it from GDB. In order to avoid code duplication, I suppose that this code could be refactored to provide this information through some programmatic interface, which both GDB and this printing code would use. However, that's a bit too much for me to chew, since I'm not familiar with BFD development. Any pointers would be appreciated. Thanks! Simon [1] https://sourceware.org/ml/gdb-patches/2020-03/msg00195.html