From patchwork Thu Mar 16 00:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 70532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp212878wrt; Wed, 15 Mar 2023 17:58:36 -0700 (PDT) X-Google-Smtp-Source: AK7set9mC+kCIKAvVStmbuiaM2j5AordbO/d5AroDDkUsFiYIB1WO6r+ltDbTg519uIlYpHkqKEy X-Received: by 2002:aa7:dd0e:0:b0:4fc:c7c8:e78d with SMTP id i14-20020aa7dd0e000000b004fcc7c8e78dmr4644995edv.31.1678928316776; Wed, 15 Mar 2023 17:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678928316; cv=none; d=google.com; s=arc-20160816; b=UNtDdfVNHvnzboCh6A7x3Jgcs8zRATCRFJE+fE2jX//ofp2QA3OyxD5YhNiKOnf1S3 0d41cJ72rMWO7HOWyyAynTqHVEplvl0dLy+n/gNucJeG7lZyCYd4GGNUmKayKBik0alM vMZY5BL7+mE+KZ3vL60x1CvPdZKZhWsT0Qttv5Supd7LapDVtHU4SQW5IrX/YjllLPbG +rLu9IRq0H+tiQUHzhCGILy1f0FBc66O99/wbfXvrpB10oTHxTX3tgyLA5LjfgAtUkxg lYwhCrwnmEXVl37dn70a4KNbxpZ0BGwAujh1tFlqQFwcJQ3HbRC/gd09b53nlXF/7QnE EnFA== 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-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VBicf7FEuMaNwHidrX6OKX7m0WWuuVFNUIc1iO/jsDI=; b=vCVNu5YCWAMl9WrFtR5vN7GVy96qg0O5m4UIFZytSOcp9j6UijrPqHcWwsow4A3fTl b1vcCPQAauPRXN9T2q1sEsEFMVzP8fuW7WEuWjCdT4TbGgEhnAmfbmLDPQSWVzpTAKUJ nqUFH544FzBbcU7b6/AcIDWYuGLwFVzg9oe+CBVxo9Mbslr/mKr60wyb+ynCOlo7RGCN aEdgD6VBIJmq5Vd7XincfJ0UtXUXarhFefyIN6yj0ELphI5XP903+kL6c+uay5W7HELj tRy1whg7xursh6bsXuhRHWtRIVK2WEmuPUh2TG4yasC/P2+yM+1jOq8XnCH4GodQuKFn EZcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b="wjtEBKA/"; 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 u22-20020aa7d0d6000000b004f99c6d2467si7415520edo.139.2023.03.15.17.58.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 17:58:36 -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="wjtEBKA/"; 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 8EF49385802F for ; Thu, 16 Mar 2023 00:58:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EF49385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678928315; bh=VBicf7FEuMaNwHidrX6OKX7m0WWuuVFNUIc1iO/jsDI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wjtEBKA/+Ev/YLU4UDHxc9dPa+W7TnR+Z+6ZJoeIocUDmQPejoKRaRZhYLqij961J HEJwuLIUAUvWTGoe/p6j6qG9PU74iLI23YCT3FvmsqA8a7K82PXT8DDryAVe3k5az5 W/LoN6X4GXuTolec/22rZ9po0ay8sDIC6Zhcpp0w= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 05C4C3858D38 for ; Thu, 16 Mar 2023 00:58:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05C4C3858D38 Received: by mail-pj1-x102a.google.com with SMTP id lr16-20020a17090b4b9000b0023f187954acso21078pjb.2 for ; Wed, 15 Mar 2023 17:58:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678928304; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VBicf7FEuMaNwHidrX6OKX7m0WWuuVFNUIc1iO/jsDI=; b=XKbS0L3s/ll5SOMLQdtCGk38bs1LbKGp8f7BostxlrZxUrZ8vvZMwF2OlsZKynJKNd 7HsezT7w03Qhp60Rl5HFKOYxJKOAjFs0Iau4szDMNUaQxcerbj2jvA+XPoa1n9Zg0ZS2 IrtCe5elg7Pvcoiyy4lbbfcHWMI0c9qazI8lhl0bOLCY5jO3/QdYri+b8M7FlV5JzXkV VrIB1lH92Bwj97dep869sk7O/CFn7n7Mcx/iKC+zFnR+7Ghbs+pb2pu6tqkcX3C3wTob u2KPHsdU73FICILKCXxuY6u3yJ1FIsLp8WRogiwVMCYwtvCFSrPxujPhBkY+mGoQhg4M W6pA== X-Gm-Message-State: AO0yUKXTw9i6noA/yKu76xWAQc2qTB0XVbH7ucwkzGDxRYR92Jf1NTK4 xuSjcIgVeyPR/9GH0/NZV9DExENOpOs= X-Received: by 2002:a17:903:70e:b0:19e:b6b0:697 with SMTP id kk14-20020a170903070e00b0019eb6b00697mr1136506plb.52.1678928303815; Wed, 15 Mar 2023 17:58:23 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id lk15-20020a17090308cf00b001898ee9f723sm4242718plb.2.2023.03.15.17.58.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 17:58:23 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D147811403C8; Thu, 16 Mar 2023 11:28:20 +1030 (ACDT) Date: Thu, 16 Mar 2023 11:28:20 +1030 To: binutils@sourceware.org Subject: PR30217, dynamic relocations using local dynamic symbols Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.3 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: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra 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?1760483938436710125?= X-GMAIL-MSGID: =?utf-8?q?1760483938436710125?= glibc's ld.so ignores local dynamic symbols. It's been that way forever. We therefore can't use them on dynamic relocations. Fixing that problem uncovered another problem in sorting of dynamic relocs, caused no doubt by copying make_iplt_section (where we don't want reloc sorting by the generic gold function, we want iplt relocs last) to make_lplt_section (where we do want sorting). PR 30217 * powerpc.cc (branch_needs_plt_entry): New function. (Target_powerpc::plt_off): Use it here.. (Target_powerpc::Scan::global): ..and here to correct PLT16 reloc handling for forced-local global symbols. (Output_data_plt_powerpc::add_entry): Rename "stash" parameter "is_local". Emit relative relocs for globals that are forced local, and don't set_needs_dynsym_entry. (Target_powerpc::make_lplt_section): Don't create a separate reloc section, use rela_dyn. (Target_powerpc::make_brlt_section): Likewise. diff --git a/gold/powerpc.cc b/gold/powerpc.cc index 4144a8800c3..a847dadf900 100644 --- a/gold/powerpc.cc +++ b/gold/powerpc.cc @@ -636,6 +636,24 @@ enum Got_type GOT_TYPE_SMALL_TPREL = 7 }; +// gsym->needs_plt_entry purpose is to decide whether a non-branch +// reloc should reference a plt entry. It can't be used to decide +// whether branches need a plt entry. In fact the call to +// needs_plt_entry here is not needed; All cases where it might +// return true ought to be covered already. However, since this +// function is used to decide between plt_ and lplt_ sections in +// plt_off, make certain that every case where make_plt_entry puts +// entries in plt_ is covered here. +static bool +branch_needs_plt_entry(const Symbol* gsym) +{ + return (((!gsym->is_defined() + || gsym->is_from_dynobj() + || gsym->is_preemptible()) + && !gsym->final_value_is_known()) + || gsym->needs_plt_entry()); +} + template class Target_powerpc : public Sized_target { @@ -927,7 +945,7 @@ class Target_powerpc : public Sized_target if (gsym->type() == elfcpp::STT_GNU_IFUNC && gsym->can_use_relative_reloc(false)) *sec = this->iplt_section(); - else if (!parameters->doing_static_link()) + else if (branch_needs_plt_entry(gsym)) *sec = this->plt_section(); else *sec = this->lplt_section(); @@ -4133,7 +4151,7 @@ class Output_data_plt_powerpc : public Output_section_data_build template void Output_data_plt_powerpc::add_entry(Symbol* gsym, - bool stash) + bool is_local) { if (!gsym->has_plt_offset()) { @@ -4143,13 +4161,24 @@ Output_data_plt_powerpc::add_entry(Symbol* gsym, gsym->set_plt_offset(off); if (this->rel_) { - gsym->set_needs_dynsym_entry(); - unsigned int dynrel = elfcpp::R_POWERPC_JMP_SLOT; - this->rel_->add_global(gsym, dynrel, this, off, 0); + if (is_local) + { + unsigned int dynrel = elfcpp::R_POWERPC_RELATIVE; + if (size == 64 && this->targ_->abiversion() < 2) + dynrel = elfcpp::R_POWERPC_JMP_SLOT; + this->rel_->add_symbolless_global_addend(gsym, dynrel, + this, off, 0); + } + else + { + gsym->set_needs_dynsym_entry(); + unsigned int dynrel = elfcpp::R_POWERPC_JMP_SLOT; + this->rel_->add_global(gsym, dynrel, this, off, 0); + } } off += this->plt_entry_size(); this->set_current_data_size(off); - if (stash) + if (is_local) { Local_plt_ent sym(gsym); this->sym_ents_.push_back(sym); @@ -4493,13 +4522,7 @@ Target_powerpc::make_lplt_section(Symbol_table* symtab, { Reloc_section* lplt_rel = NULL; if (parameters->options().output_is_position_independent()) - { - lplt_rel = new Reloc_section(false); - this->rela_dyn_section(layout); - if (this->rela_dyn_->output_section()) - this->rela_dyn_->output_section() - ->add_output_section_data(lplt_rel); - } + lplt_rel = this->rela_dyn_section(layout); this->lplt_ = new Output_data_plt_powerpc(this, symtab, lplt_rel, "** LPLT"); @@ -4609,11 +4632,7 @@ Target_powerpc::make_brlt_section(Layout* layout) { // When PIC we can't fill in .branch_lt but must initialise at // runtime via dynamic relocations. - this->rela_dyn_section(layout); - brlt_rel = new Reloc_section(false); - if (this->rela_dyn_->output_section()) - this->rela_dyn_->output_section() - ->add_output_section_data(brlt_rel); + brlt_rel = this->rela_dyn_section(layout); } this->brlt_section_ = new Output_data_brlt_powerpc(this, brlt_rel); @@ -9009,7 +9028,7 @@ Target_powerpc::Scan::global( case elfcpp::R_PPC64_PLT16_LO_DS: if (!pushed_ifunc) { - if (!parameters->doing_static_link()) + if (branch_needs_plt_entry(gsym)) target->make_plt_entry(symtab, layout, gsym); else target->make_local_plt_entry(symtab, layout, gsym); @@ -9028,11 +9047,7 @@ Target_powerpc::Scan::global( unsigned int r_sym = elfcpp::elf_r_sym(reloc.get_r_info()); target->push_branch(ppc_object, data_shndx, reloc.get_r_offset(), r_type, r_sym, reloc.get_r_addend()); - if (gsym->needs_plt_entry() - || (!gsym->final_value_is_known() - && (gsym->is_undefined() - || gsym->is_from_dynobj() - || gsym->is_preemptible()))) + if (branch_needs_plt_entry(gsym)) target->make_plt_entry(symtab, layout, gsym); } // Fall through.