From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id B59073858290 for ; Tue, 23 Aug 2022 17:34:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B59073858290 Received: by mail-pf1-x42a.google.com with SMTP id w138so11495050pfc.10 for ; Tue, 23 Aug 2022 10:34:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=imvECvIne0C/cRxsX0T5xHJqW9xOE3R1lZZxXEXoPHg=; b=GK0K2HzUnhMv6FMbZZBU3gpg0DZb2iDp6MCyOulX/cgEGSuTsQzp7mBNb6/U2Pxca7 scR6ujCppU9ZQy7c9xZCk2XqI460HZzi3TW60tbKYKpS2S147VCrBqZkMEXOP47yQg+k WSOi6K2IivBTCcc9Ady3mjCvWyBe+TkHYhCrkzheFY+1Mv+kDc9oIs5UkZWwcYQQKcrn XA4LTLFlozgmeu7akmyulecjcTMUccNVE9M7L/q3rYlX6219XMyIHvXNe8QcWgLFK3LK QOzIDHxTsV67blwezOUN2buLMQ/Pf5uphmdna6ktUUKorgLI0Hfd4tVItwuSE5F/GJka SfXA== X-Gm-Message-State: ACgBeo3avstZKwCrtaPdcYm3iXsLgmNEQ2rN6RC3qmIeieqOs6nXfEi5 tAacKYb1kcJ059LbYlr3SwXMZQV7qa8= X-Google-Smtp-Source: AA6agR64YDYtCCt8EpPSSl7V1BDBJs13evSt1w8nLLr7R+y2n6piCHrXHfvIHyHo2yyUJ5mGqunWIg== X-Received: by 2002:aa7:838a:0:b0:536:101a:9ccf with SMTP id u10-20020aa7838a000000b00536101a9ccfmr20956175pfm.18.1661276074457; Tue, 23 Aug 2022 10:34:34 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.56.38.79]) by smtp.gmail.com with ESMTPSA id n10-20020a1709026a8a00b0016c78f9f024sm10746251plk.104.2022.08.23.10.34.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 10:34:33 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id DB7F6C028F for ; Tue, 23 Aug 2022 10:34:32 -0700 (PDT) From: "H.J. Lu" To: binutils@sourceware.org Subject: [PATCH] x86: Ignore protected visibility in shared libraries on Solaris Date: Tue, 23 Aug 2022 10:34:32 -0700 Message-Id: <20220823173432.36035-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3023.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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-List-Received-Date: Tue, 23 Aug 2022 17:34:37 -0000 On x86, the PLT entry in executable may be used as function address for functions in shared libraries. If functions are protected, the function address used in executable can be different from the function address used in shared library. This will lead to incorrect run-time behavior if function pointer equality is needed. By default, x86 linker issues an error in this case. On Solaris, linker issued an error for struct tm *tb = (kind == CPP_time_kind::FIXED ? gmtime : localtime) (&tt); where gmtime is a protected function in libc.so. Use gmtime's PLT entry in executable as function address is safe since function pointer equality isn't needed. Ignore protected visibility in shared libraries on Solaris to disable linker error. If function pointer equality is needed, linker will silently generate executable with incorrect run-time behavior on Solaris. PR ld/29512 * elf32-i386.c (elf_i386_scan_relocs): Ignore protected visibility in shared libraries on Solaris. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. --- bfd/elf32-i386.c | 3 ++- bfd/elf64-x86-64.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 52b1db44546..9717e2c5ed6 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -1808,7 +1808,8 @@ elf_i386_scan_relocs (bfd *abfd, || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) h->plt.refcount = 1; - if (h->pointer_equality_needed + if (htab->elf.target_os != is_solaris + && h->pointer_equality_needed && h->type == STT_FUNC && eh->def_protected && !SYMBOL_DEFINED_NON_SHARED_P (h) diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 62a9a22317a..f3b54400013 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -2251,7 +2251,8 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info, || (sec->flags & (SEC_CODE | SEC_READONLY)) != 0) h->plt.refcount = 1; - if (h->pointer_equality_needed + if (htab->elf.target_os != is_solaris + && h->pointer_equality_needed && h->type == STT_FUNC && eh->def_protected && !SYMBOL_DEFINED_NON_SHARED_P (h) -- 2.37.2