From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 078C03848412 for ; Tue, 6 Jul 2021 13:31:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 078C03848412 Received: by mail-pj1-x1032.google.com with SMTP id fs7so1543271pjb.2 for ; Tue, 06 Jul 2021 06:31:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kHEVfHzzZXDhdCIT4bsMew40AibWQ2PDo21S3aMfWAg=; b=pVqaZeB/dybgz1hgULQVSi95VV0o+q+OuvQLoSDtEFv8e0jAym3a6eZnRJEZZV9NvQ ocUsYqXT96fTe+8mwc0Ol/yICYvdrQVXVMej8Jsobxm8NPqGw+MKKNCy3m0TgdtAGqIk /HC+CXs+4HbK2KpJiQMNHGrKHQIUsNleNjaY0H3pc5xD7sC2NeYeTjN/A5O7yza3NIN2 WJvtwimJuOvlOhZ7ErJnBbMSBOwmPPvHPUSINTCUWQdxMeyoIl1wMCoLB9HvA5XFVfLS IzzKVDcAIep1saY8XEC04brOpYj667a3hOfuJnPMD+8r+gjcgxFnJSvnYaL5EP7UkmQk O2bw== X-Gm-Message-State: AOAM533jOzhX2IdaIwLqP3Um3Kn0fC5M9fr89JuWK6WeEiSSfs5vrp6w ic6+IOXB/ArE130SrYq/DxuIynRh5GQ= X-Google-Smtp-Source: ABdhPJwp0O2nsmR5R9Gzj53y9xHEPgGkfl6dbXH0ZKV+1iu0o4gp3TLEtBQeIlY2ap20PW2nlIFoUg== X-Received: by 2002:a17:90a:8404:: with SMTP id j4mr581108pjn.66.1625578315117; Tue, 06 Jul 2021 06:31:55 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.115]) by smtp.gmail.com with ESMTPSA id g12sm3198179pjk.25.2021.07.06.06.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 06:31:54 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id A9FE8C0048; Tue, 6 Jul 2021 06:31:52 -0700 (PDT) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] ld: Check archive only for archive member Date: Tue, 6 Jul 2021 06:31:52 -0700 Message-Id: <20210706133152.2201260-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3032.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Tue, 06 Jul 2021 13:31:57 -0000 Since plugin_maybe_claim calls bfd_close on the original input BFD if it isn't an archive member, pass NULL to bfd_plugin_close_file_descriptor to indicate that the BFD isn't an archive member. bfd/ PR ld/18028 * plugin.c (bfd_plugin_close_file_descriptor): Check archive only of abfd != NULL. (try_claim): Pass NULL to bfd_plugin_close_file_descriptor if it isn't an archive member. ld/ PR ld/18028 * plugin.c (plugin_input_file): Add comments for abfd and ibfd. (plugin_object_p): Set input->ibfd to NULL if it isn't an archive member. --- bfd/plugin.c | 25 +++++++++++++------------ ld/plugin.c | 4 +++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bfd/plugin.c b/bfd/plugin.c index b3d6739dabb..6cfa2b66470 100644 --- a/bfd/plugin.c +++ b/bfd/plugin.c @@ -277,27 +277,26 @@ bfd_plugin_open_input (bfd *ibfd, struct ld_plugin_input_file *file) return 1; } -/* Close the plugin file descriptor. */ +/* Close the plugin file descriptor FD. If ABFD isn't NULL, it is an + archive member. */ void bfd_plugin_close_file_descriptor (bfd *abfd, int fd) { - bfd *iobfd; - - iobfd = abfd; - while (iobfd->my_archive - && !bfd_is_thin_archive (iobfd->my_archive)) - iobfd = iobfd->my_archive; - if (iobfd == abfd) + if (abfd == NULL) close (fd); else { - iobfd->archive_plugin_fd_open_count--; + while (abfd->my_archive + && !bfd_is_thin_archive (abfd->my_archive)) + abfd = abfd->my_archive; + + abfd->archive_plugin_fd_open_count--; /* Dup the archive plugin file descriptor for later use, which will be closed by _bfd_archive_close_and_cleanup. */ - if (iobfd->archive_plugin_fd_open_count == 0) + if (abfd->archive_plugin_fd_open_count == 0) { - iobfd->archive_plugin_fd = dup (fd); + abfd->archive_plugin_fd = dup (fd); close (fd); } } @@ -314,7 +313,9 @@ try_claim (bfd *abfd) && current_plugin->claim_file) { current_plugin->claim_file (&file, &claimed); - bfd_plugin_close_file_descriptor (abfd, file.fd); + bfd_plugin_close_file_descriptor ((abfd->my_archive != NULL + ? abfd : NULL), + file.fd); } return claimed; diff --git a/ld/plugin.c b/ld/plugin.c index bb369f46955..b91a958b812 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -102,7 +102,9 @@ typedef struct view_buffer pointer. */ typedef struct plugin_input_file { + /* The dummy BFD. */ bfd *abfd; + /* The original input BFD. Non-NULL if it is an archive member. */ bfd *ibfd; view_buffer_t view_buffer; char *name; @@ -1220,7 +1222,7 @@ plugin_object_p (bfd *ibfd) file.handle = input; input->abfd = abfd; - input->ibfd = ibfd; + input->ibfd = ibfd->my_archive != NULL ? ibfd : NULL; input->view_buffer.addr = NULL; input->view_buffer.filesize = 0; input->view_buffer.offset = 0; -- 2.31.1