From patchwork Wed Mar 8 07:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 66046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp187980wrd; Tue, 7 Mar 2023 23:29:05 -0800 (PST) X-Google-Smtp-Source: AK7set+atM9W3xlMYYm7j2c+IT7JBGs+3KCoWDCHZj+3F8FKvzNRfnJM9ZTPvUgPWn7cyBmOVAmB X-Received: by 2002:a17:906:9382:b0:8e5:40d0:f831 with SMTP id l2-20020a170906938200b008e540d0f831mr16256897ejx.43.1678260545102; Tue, 07 Mar 2023 23:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678260545; cv=none; d=google.com; s=arc-20160816; b=Wfl55+AeQOLpQf3ebluvqSSuLxmQmsuqdWtKQOAXNgBeU4jTjzGlo1br8O565OEtg2 c65pydBlJ/QVpSgZomA3Q4EunP4U0b0URVOHK1FbdFLy/WXzpvgv5nZh8rqJh9xkbUBs HGUd3UKtAjsAhIjgFV9sathNld9T5RPhV1V20bromC47h9ZAMEHYdJS1iGmmDTcKQe7D /OSvM98S2wbK/uyfedUku24FYTPCcNVbmbZDrqvITK8xI9df9A4Er4Q05wlxDQD1qip7 Rf/Nzet1dTTE6BSLdxVKrcGRrRM9lRtNs40wShJDnd11Kyw6pOHgIgUxxUrL0AwQsE19 Njpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=81O2KVJrVT0IXiQPjpKn5ebkCWBhVC9FaH5iqhrIgRE=; b=isxCswfQDsXFJJck1V52q03Lwz8IkURchWLZlFtg1jxg4sjuLyKbShounkDbcZzgq4 s9UcpgcTYS0JcxRYVTHBaEG1M+orOcYfxOAYN9YagEnTO9d832Hno/CLEzFG+LkiY4c7 9U9zx3gEuIhyW+2Opa0fUmMds5i26YzXS/HmBCcBksa/pI4oVsBQNjSKNG5ea8oqJLoq 6ndhtXpY+74s8UCV39J4rXL1hxW/HyhfwAC4+jd4yhH41iJhlL9gWgkPK+BVEfH0UvB1 k202Gslu72PApUyk9eqH1ywIfS0LsdiRlWvAaTHOzEnm048DkotSJXjH/5wGWX6qn3xf gb7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Fjqohycu; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dt5-20020a170906b78500b008d47cd2ee00si5109355ejb.290.2023.03.07.23.29.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 23:29:05 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Fjqohycu; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A60138515C9 for ; Wed, 8 Mar 2023 07:29:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A60138515C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678260544; bh=81O2KVJrVT0IXiQPjpKn5ebkCWBhVC9FaH5iqhrIgRE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FjqohycuBnm8/YCxPSFzWl3mOQpRodDgJq2c+QRCqhBWn76Yzy0jxFgD4lMaUuUFm EA6MU8+wiY+spwWC6/i/680XkQfkpm5WHfmNHxVtfLG888kCf+sOZmtOiSgTR75KKk xw2oN0K3OxmNcinfSAQKEHFG1/QHKYoUraAzzTzU= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 72D4A3858C30 for ; Wed, 8 Mar 2023 07:28:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72D4A3858C30 Received: by mail-pj1-x102b.google.com with SMTP id nn12so996902pjb.5 for ; Tue, 07 Mar 2023 23:28:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678260534; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=81O2KVJrVT0IXiQPjpKn5ebkCWBhVC9FaH5iqhrIgRE=; b=TENQWoSDPcZvnQ/ZSVaP8oR9Kg/X6hhdaxyTwg+J+CkEPhn0loCdbSj35JVTEhpeGU l1ElLBHRytyou52DLJK/FMmqs8eBPfxbeeiLFHyFZevzNOGYPYHmRwKuriEYWnhGI5Yw 0RHSrcIjnCeFHXZJ9h38/KjLO4m50Eo2AGQ8LoAaWFDxKvtsO2lNel0yc2CWesp2ztUr 9gRqtG+BvHzRqNBTUA9rwTMoE2+X2tfc3uI3dPJoj7MaackuZ1yotlpzGWleqIW1xLW2 vctLiTv67s/5FslzWBvrOIKA7dHnxWfFaAdeWV5mMW79rE5jNeS6ppo33uTIOuYEVXtP T+TA== X-Gm-Message-State: AO0yUKUelkGgrFLfI53Y7aDcNCt8iqQQgBh3fuhwJph0CM3XB/3XDb+g fN3u+VJPUQzyK9ooC1imXYlMM0uq4/E= X-Received: by 2002:a17:90b:4c06:b0:22b:f0d4:9e1e with SMTP id na6-20020a17090b4c0600b0022bf0d49e1emr18431037pjb.8.1678260534015; Tue, 07 Mar 2023 23:28:54 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:4d08:cebd:d73f:b794]) by smtp.gmail.com with ESMTPSA id k61-20020a17090a3ec300b002348d711ebbsm8583935pjc.16.2023.03.07.23.28.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 23:28:53 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 58E40114081B; Wed, 8 Mar 2023 17:58:51 +1030 (ACDT) Date: Wed, 8 Mar 2023 17:58:51 +1030 To: binutils@sourceware.org Subject: Tidy pe_ILF_build_a_bfd a little Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URI_TRY_3LD autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759783729378363637?= X-GMAIL-MSGID: =?utf-8?q?1759783729378363637?= * peicode.h (ILF section, pe_ILF_object_p): Correct comments and update the reference to Microsoft's docs. (pe_ILF_build_a_bfd): Move all symbol creation before flipping the bfd over to in-memory. diff --git a/bfd/peicode.h b/bfd/peicode.h index 43226caf00e..b7b4f4abbb9 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -401,11 +401,11 @@ pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #ifdef COFF_IMAGE_WITH_PE -/* Code to handle Microsoft's Image Library Format. +/* Code to handle Microsoft's Import Library Format. Also known as LINK6 format. Documentation about this format can be found at: - http://msdn.microsoft.com/library/specs/pecoff_section8.htm */ + https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format */ /* The following constants specify the sizes of the various data structures that we have to create in order to build a bfd describing @@ -1074,6 +1074,32 @@ pe_ILF_build_a_bfd (bfd * abfd, abort (); } + /* Now create a symbol describing the imported value. */ + switch (import_type) + { + case IMPORT_CODE: + pe_ILF_make_a_symbol (& vars, "", symbol_name, text, + BSF_NOT_AT_END | BSF_FUNCTION); + + break; + + case IMPORT_DATA: + /* Nothing to do here. */ + break; + + default: + /* XXX code not yet written. */ + abort (); + } + + /* Create an import symbol for the DLL, without the .dll suffix. */ + ptr = (bfd_byte *) strrchr (source_dll, '.'); + if (ptr) + * ptr = 0; + pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0); + if (ptr) + * ptr = '.'; + /* Initialise the bfd. */ memset (& internal_f, 0, sizeof (internal_f)); @@ -1100,39 +1126,13 @@ pe_ILF_build_a_bfd (bfd * abfd, bfd_cache_close (abfd); abfd->iostream = (void *) vars.bim; - abfd->flags |= BFD_IN_MEMORY /* | HAS_LOCALS */; + abfd->flags |= BFD_IN_MEMORY | HAS_SYMS; abfd->iovec = &_bfd_memory_iovec; abfd->where = 0; abfd->origin = 0; abfd->size = 0; obj_sym_filepos (abfd) = 0; - /* Now create a symbol describing the imported value. */ - switch (import_type) - { - case IMPORT_CODE: - pe_ILF_make_a_symbol (& vars, "", symbol_name, text, - BSF_NOT_AT_END | BSF_FUNCTION); - - break; - - case IMPORT_DATA: - /* Nothing to do here. */ - break; - - default: - /* XXX code not yet written. */ - abort (); - } - - /* Create an import symbol for the DLL, without the .dll suffix. */ - ptr = (bfd_byte *) strrchr (source_dll, '.'); - if (ptr) - * ptr = 0; - pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0); - if (ptr) - * ptr = '.'; - /* Point the bfd at the symbol table. */ obj_symbols (abfd) = vars.sym_cache; abfd->symcount = vars.sym_index; @@ -1149,8 +1149,6 @@ pe_ILF_build_a_bfd (bfd * abfd, obj_coff_strings (abfd) = vars.string_table; obj_coff_keep_strings (abfd) = true; - abfd->flags |= HAS_SYMS; - return true; error_return: @@ -1159,7 +1157,7 @@ pe_ILF_build_a_bfd (bfd * abfd, return false; } -/* We have detected a Image Library Format archive element. +/* We have detected an Import Library Format archive element. Decode the element and return the appropriate target. */ static bfd_cleanup @@ -1176,7 +1174,7 @@ pe_ILF_object_p (bfd * abfd) unsigned int magic; /* Upon entry the first six bytes of the ILF header have - already been read. Now read the rest of the header. */ + already been read. Now read the rest of the header. */ if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14) return NULL;