From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x636.google.com with SMTP id f22so14502966plr.0 for ; Thu, 30 Mar 2023 09:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680194536; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3lzXtgFJlba7B/v7ELQtJxB/toR/XI14jrZTa02Oids=; b=EHCIkqUPwgSajlXjf2f4HCB+l2ZvV+f4P55aak72FHIZbBf+0BfcLIyyqrv56p0J7j 587B+BFisi2DHn1ec8GNn9UYPctMHKL9oRK8QqrlGRCN4xHDgq9FeSsxaBSU/gQMv0If d1MdmCK/c5ZYX+WjpN/j+fTOti5lGGgWxiQgEa2+lRAFuuxXV1f+j8X6M+nK+WAv6Aih /XyYSOJjITy010x+ZLY/f5JCpYvhdjMiX14RDXNsgLylDbwQIpcmpg3VjSuxAL7Oac4l A7nIkO+hcsH5BjzSv/jMbH5wboHCkVpWQ0EcBDflD9aGSNOU76e47LMASkGqwPnapetV ur6A== 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-Google-Smtp-Source: AKy350b5MyGx4/XkIFpAbvoOVmnqRcoBpPwBmkjtJZ8JMTuymlrWlOujEYOItoKM/0X5QAopSAiMJw== 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) From: "H.J. Lu" 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; +}; -- 2.39.2