From patchwork Thu Mar 30 16:42:14 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: 77311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1264649vqo; Thu, 30 Mar 2023 09:42:27 -0700 (PDT) X-Google-Smtp-Source: AKy350asJWSHDhpZCX66BOjEOQ3gs6K1JlYZj9vRw7vEiPSsGetCnqQzJL8cp/tlX3FSSQARx9CR X-Received: by 2002:aa7:d058:0:b0:502:22fe:ef3c with SMTP id n24-20020aa7d058000000b0050222feef3cmr17479942edo.41.1680194547676; Thu, 30 Mar 2023 09:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680194547; cv=none; d=google.com; s=arc-20160816; b=y7BQNWukEIrVKs/J9ToOCcljlqRnreUzrq3X74KH04STa7RjvncKcP+K9Bl8M/SBAP yMdjEzCpRVuB0cOlqqAqjWwAEtezgCaNIXRWywlj9YqaJW4Oo8NibuWrIPpW4N7ZzyUW 83sJAhueH3pGT2pPUgkbC0bpEBvwTkC9XOcAfshOeq5mTxH4zclf2fu9I/cbpwOTQ+ow TI4Wlt+1KnEfflDiqsuuq7daZPbFVPnuYXugnjG4AtuhyNJHJB0AawrHT6XzEQ447osi jKGNrFSGbdJxPoZg9+iRlr28VwZM4turTKBhX2B2DXorHWvZuPSBiqiLfUdcpUFjZpQ8 xkIQ== 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=3lzXtgFJlba7B/v7ELQtJxB/toR/XI14jrZTa02Oids=; b=YE0+wCDn2Xx9RqcaFlH+B6NzsNSJ8/ukJTBCljBAfrmJAp2+2Mp86aY1KDYb2IFxik wE+GJsB1VtwewJ3osAdZqD0C7fUQMo5nNOf2M3qOtQmlVrMfGdegkI1h0tmEPJREHkKu nqoZe+gn5Ncpf+in7oK2DxEfl6YrsL1vVPuDLHnY/yLGAWVzawnKKr7Ngm1kf5gLTNXR 3bBPkF2qEGcefZlzHvn6V8HJlXM1SB7vYSbRqIpGhgvQAE0XY6Zq3bPrMqcxiFzYOs4q pSPTXE8hHOUGndl1/QQMmlaIBCHDF/1C0Zzliz8p11/ZjmY+2vFfVh9/Isn5/WCAl0kl OeBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=mWsSvtWT; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w8-20020aa7da48000000b004fe9345386esi143130eds.585.2023.03.30.09.42.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=mWsSvtWT; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 54E7C3858CDB for ; Thu, 30 Mar 2023 16:42:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54E7C3858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680194546; bh=3lzXtgFJlba7B/v7ELQtJxB/toR/XI14jrZTa02Oids=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mWsSvtWTdTYiM0M9tnE8xvHq71eReBKxpq+6bkhjTesp1h9/t8wcXozpqgSFgkc1b 9QAsOzvflOKMLB1TMhR/dQ/9hS129ow6LSRpJpCvhyH+yXTxshwPLqX5bd/THEPtUD U96OtoI2FnZk0ANOuQoY2lPmLuZcCNmiWSkZdJiI= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id AEE0D3858CDA for ; Thu, 30 Mar 2023 16:42:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEE0D3858CDA Received: by mail-pl1-x636.google.com with SMTP id f22so14502966plr.0 for ; Thu, 30 Mar 2023 09:42:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680194536; 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=3lzXtgFJlba7B/v7ELQtJxB/toR/XI14jrZTa02Oids=; b=RTtqatk0Fyo4FHLZENBXDs7yHQbos7D+vZNGresxuhEgc0xD9+psVkwHfCNe9fCsMB KAwOtco7QaKw/gNkHmEqex2E5Em6V+T7+RbpNnJH9xKiSY0/Flf2QxQujZ4bs0imVEJo 1PjSsAeu9HXLDKrPiFkv1xcpjiGSDcmTrmpdcRE+8w2Ig4M3dY20Qx04JgA5usjqHCCo 72rw5vKbOWCTkUz4588wvuKcHknVg3hk75N8i8zbj5dfxGA197dTE48ZXlgfGVdZZcIm Z3GpB5/e3GejZ72l0/1Xz6nq+t2kbNWdX92nX4hlNFD1MIrHzS7N7k7XEmO5AUy5IbnW BtnA== X-Gm-Message-State: AAQBX9f/21GbLVDsG8hM86ieLbKFLYtLnR0oLH3mQK81Aqce8j0+W5Op NUZirUHLyLHKS/+9W3B6EQDxv1KExko= X-Received: by 2002:a17:90a:4bca:b0:23f:6830:568e with SMTP id u10-20020a17090a4bca00b0023f6830568emr24512145pjl.8.1680194536324; Thu, 30 Mar 2023 09:42:16 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.161.135]) by smtp.gmail.com with ESMTPSA id b9-20020a17090a800900b00233db0db3dfsm3510682pjn.7.2023.03.30.09.42.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:42:15 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id A8B917400A8 for ; Thu, 30 Mar 2023 09:42:14 -0700 (PDT) To: binutils@sourceware.org Subject: [PATCH] lto: Don't add indirect symbols for versioned aliases in IR Date: Thu, 30 Mar 2023 09:42:14 -0700 Message-Id: <20230330164214.735462-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3025.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 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: "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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761811677954371421?= X-GMAIL-MSGID: =?utf-8?q?1761811677954371421?= Linker adds indirect symbols for versioned symbol aliases, which are created by ".symver foo, foo@FOO", by checking symbol type, value and section so that references to foo will be replaced by references to foo@FOO if foo and foo@FOO have the same symbol type, value and section. But in IR, since all symbols of the same type have the same value and section, we can't tell if a symbol is an alias of another symbol by their types, values and sections. We shouldn't add indirect symbols for versioned symbol aliases in IR. bfd/ PR ld/30281 * elflink.c (elf_link_add_object_symbols): Don't add indirect symbols for ".symver foo, foo@FOO" aliases in IR. ld/ PR ld/30281 * testsuite/ld-plugin/lto.exp: Add PR ld/30281 test. * testsuite/ld-plugin/pr30281.t: New file. * testsuite/ld-plugin/pr30281.c: Likewise. --- bfd/elflink.c | 9 ++++++++- ld/testsuite/ld-plugin/lto.exp | 9 +++++++++ ld/testsuite/ld-plugin/pr30281.c | 4 ++++ ld/testsuite/ld-plugin/pr30281.t | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-plugin/pr30281.c create mode 100644 ld/testsuite/ld-plugin/pr30281.t diff --git a/bfd/elflink.c b/bfd/elflink.c index bab1a36598e..f10faa5f8bd 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -5382,7 +5382,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) h->unique_global = (flags & BSF_GNU_UNIQUE) != 0; } - if (definition && !dynamic) + /* Don't add indirect symbols for .symver x, x@FOO aliases + in IR. Since all data or text symbols in IR have the + same type, value and section, we can't tell if a symbol + is an alias of another symbol by their types, values and + sections. */ + if (definition + && !dynamic + && (abfd->flags & BFD_PLUGIN) == 0) { char *p = strchr (name, ELF_VER_CHR); if (p != NULL && p[1] != ELF_VER_CHR) diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index 98e811177ef..e7e7952bb1b 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -530,6 +530,15 @@ set lto_link_elf_tests [list \ {} \ "pr29086" \ ] \ + [list \ + "Build pr30281.so" \ + "-shared -Wl,--version-script,pr30281.t \ + -O2 -fPIC -flto-partition=max -flto=2" \ + "-O2 -fPIC -flto-partition=max -flto=2" \ + {pr30281.c} \ + "" \ + "pr30281.so" \ + ] \ ] # PR 14918 checks that libgcc is not spuriously included in a shared link of diff --git a/ld/testsuite/ld-plugin/pr30281.c b/ld/testsuite/ld-plugin/pr30281.c new file mode 100644 index 00000000000..ba9722a389c --- /dev/null +++ b/ld/testsuite/ld-plugin/pr30281.c @@ -0,0 +1,4 @@ +extern __inline __attribute__((__gnu_inline__)) void foo(void) {} +__attribute__((__symver__("foo@GLIBC_2.2.5"))) +int __collector_foo_2_2(void) {} +void foo(void) {} diff --git a/ld/testsuite/ld-plugin/pr30281.t b/ld/testsuite/ld-plugin/pr30281.t new file mode 100644 index 00000000000..3169ad398c9 --- /dev/null +++ b/ld/testsuite/ld-plugin/pr30281.t @@ -0,0 +1,4 @@ +GLIBC_2.2.5 { + global: + foo; +};