From patchwork Wed Aug 30 15:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 137174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp4621122vqm; Wed, 30 Aug 2023 08:55:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPLWBecUsmxpMgqwT+uHrryt08bZzkYh3IcfGea6uG1dhjT1iCBk+CL6uXypGaT/UvAs9a X-Received: by 2002:a2e:b174:0:b0:2b9:5eae:814f with SMTP id a20-20020a2eb174000000b002b95eae814fmr1951832ljm.50.1693410922239; Wed, 30 Aug 2023 08:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693410922; cv=none; d=google.com; s=arc-20160816; b=xQEgwrt+X+/GTvnIrdL19zyJ7WINqKKgRqO/acgXKSF1/FAlhZsGSKliM6kYX/F53M hL3VhoLJQ6kI9Vws0ocQqGasTDVISEY02YnZAZp+vyXH/UWMJeTg69SbVSt+RgHRwzAD G6asgNhltqLQukhgV0LPME2QySkdSFEkJ4b33ecHdhmvaGSLUZq4cpkwxQYzMRv0rjCz LaCNnurAGPIXWkgLoGTAKXxa9lsw0QICduXPj9usOm7TuHZxIBS0N7KDnOPadYjokmEq drdqRzv8r3zRtuqMQDtcm1a7+kEYEGuQV5fwbQ6w+JImICKnw+tyc0M+BmnsyyYTl8o2 KNYQ== 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-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=yah1K1VHisshXER/xpqCrJsRDRHxorSx/x4pFSanXnw=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=g/vYftXp8vQDWVTlsvXEImkrNbW6JfPe0vDX0aKvWWw4Yq9aSCw7GN+rohQNzeUSBe PFm3kHMKlD9FBzIq58XF1fvQ5jdoesuKqAI1tCH/pmokLVAsPfogDxJIDzX3B7npsFsK a+QXuB+gU6nm26fAFjoYNn330YfhP511Yip211GW8Ff0Dboh9rKOpxEH4ZvvAXU+1kNf 1kueeMO18bNiMOaror4ZN73h8DsYT6QG8kJJ6ImVuOIstiTM9PE2hkphOPkpFQgskAwi Gb97FnYFFgOqzyFW+YC84SP/qEiP9w0TYZq9BdNfa1e3HlYjQDvnAwmmQLmILLMkNO1D 1kaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=V5hhRSpR; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b13-20020a170906038d00b00993860a6d39si5646507eja.355.2023.08.30.08.55.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 08:55:22 -0700 (PDT) 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=V5hhRSpR; 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 0557B3858D20 for ; Wed, 30 Aug 2023 15:55:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0557B3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693410921; bh=yah1K1VHisshXER/xpqCrJsRDRHxorSx/x4pFSanXnw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=V5hhRSpRI/eA5iGkY7aTv2yCu7EvJ7fMmB3fN0Pdsu3jnpui+GKLvVbKVH67veP6x 0fal3cY4/eJ5jEdBGS735C9+jTP9luuACY1gsZWVn8Xj5kbCgGfhmoNHVwUz8nBbQ8 4fZgk8PSYMkW603IkvB72Q6yjdBOdP8K9Yt8LwBc= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id B26213858D20 for ; Wed, 30 Aug 2023 15:55:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B26213858D20 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68c0d4cc3a4so3593488b3a.1 for ; Wed, 30 Aug 2023 08:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693410910; x=1694015710; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yah1K1VHisshXER/xpqCrJsRDRHxorSx/x4pFSanXnw=; b=PIfhbq5pbw7flYVqxIMxK+ZPv6aU21zKra/fMPupRp3Sx7SxS/0fiwNfXt8ocsE42b urTVlshcPpQWD5wXUiFIpVnzSd094rjLk6JZX9NGLP4fWfM36SvkgBesF0XimThKFjrV /sw/4dOz5Ab77T3FIh/kTpCcoSmYdmO4WCoApzRwpVHpjhdpplM16xZ0W/5gf8QbLtYR K9kqi3/cMjpuaVw40u7BQ546Jib2F73PZLOxuJYiwuFeMfWih/EIlK5dBh/cQlTB27kO Lmg28gymLDDkSn6LeNAlAujKZQ8RuSzhqXOSRgPunh2wbx4JQ1OlzFQWzvSdmUkr2LJE sShA== X-Gm-Message-State: AOJu0YzQZKYjGt7NGIB3OyWmZYVoa7WIMm7QFxLJur5drkwC1NM9+WAU S+ApE1RtBqTyAY3uix38v1d+16eCtS8= X-Received: by 2002:a05:6a21:8197:b0:148:c3ea:fb6c with SMTP id pd23-20020a056a21819700b00148c3eafb6cmr2303976pzb.36.1693410910084; Wed, 30 Aug 2023 08:55:10 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.161.42]) by smtp.gmail.com with ESMTPSA id jj14-20020a170903048e00b001bde6fa0a39sm11250284plb.167.2023.08.30.08.55.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 08:55:09 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 33AC17401C1 for ; Wed, 30 Aug 2023 08:55:08 -0700 (PDT) To: binutils@sourceware.org Subject: [PATCH] elf: Check DT_SYMTAB only on non-IR object Date: Wed, 30 Aug 2023 08:55:08 -0700 Message-ID: <20230830155508.549330-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3025.1 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 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Binutils" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775670051361515950 X-GMAIL-MSGID: 1775670051361515950 Check DT_SYMTAB only on non-IR object of archive member to avoid crash on LLVM IR object with NULL elf_tdata. PR ld/30811 * elflink.c (elf_link_is_defined_archive_symbol): Check DT_SYMTAB only on non-IR object. --- bfd/elflink.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index c4f286e3d90..ca162145f7e 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -3571,12 +3571,6 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef) if (! bfd_check_format (abfd, bfd_object)) return false; - if (elf_use_dt_symtab_p (abfd)) - { - bfd_set_error (bfd_error_wrong_format); - return false; - } - /* Select the appropriate symbol table. If we don't know if the object file is an IR object, give linker LTO plugin a chance to get the correct symbol table. */ @@ -3592,10 +3586,19 @@ elf_link_is_defined_archive_symbol (bfd * abfd, carsym * symdef) abfd = abfd->plugin_dummy_bfd; hdr = &elf_tdata (abfd)->symtab_hdr; } - else if ((abfd->flags & DYNAMIC) == 0 || elf_dynsymtab (abfd) == 0) - hdr = &elf_tdata (abfd)->symtab_hdr; else - hdr = &elf_tdata (abfd)->dynsymtab_hdr; + { + if (elf_use_dt_symtab_p (abfd)) + { + bfd_set_error (bfd_error_wrong_format); + return false; + } + + if ((abfd->flags & DYNAMIC) == 0 || elf_dynsymtab (abfd) == 0) + hdr = &elf_tdata (abfd)->symtab_hdr; + else + hdr = &elf_tdata (abfd)->dynsymtab_hdr; + } symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;