From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IkG5CESrAWEVJgAAWB0awg (envelope-from ) for ; Wed, 28 Jul 2021 15:08:52 -0400 Received: by simark.ca (Postfix, from userid 112) id 1328C1EDFB; Wed, 28 Jul 2021 15:08:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 32CAF1E813 for ; Wed, 28 Jul 2021 15:08:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD9C23890014 for ; Wed, 28 Jul 2021 19:08:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD9C23890014 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627499330; bh=n8yMXiuZqSPccP4FKYxu/ro3V5RhK2Q1q9A6uNM6cfo=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QToxnjNNpsvw6JNv1D62bnVIEeV97wtS1JQfz9pDhYvPVM5fX1UGCPUiTbHxPAgaP sM417llwB4TGZFYv6QDqF6PpGiB6lD3jQ5deja3ft/dXN2oJ9SD0Gz1umMhFSrcl7t SHMNwe9SfuDCvbxNzXvBs5Vm8eJ74sp7Bhe7bcJ4= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 7BC3E3853C36 for ; Wed, 28 Jul 2021 19:08:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7BC3E3853C36 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16SJ3amU016955 for ; Wed, 28 Jul 2021 15:08:28 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3a3cba9bbq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Jul 2021 15:08:28 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16SJ3pZw017718 for ; Wed, 28 Jul 2021 15:08:28 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 3a3cba9bb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jul 2021 15:08:28 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16SJ2sIC010165; Wed, 28 Jul 2021 19:08:26 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma01wdc.us.ibm.com with ESMTP id 3a2362fhpx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Jul 2021 19:08:26 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16SJ8PhQ47710582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jul 2021 19:08:25 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E9D5C6061; Wed, 28 Jul 2021 19:08:25 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60CDDC6057; Wed, 28 Jul 2021 19:08:23 +0000 (GMT) Received: from lexx (unknown [9.171.49.56]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 28 Jul 2021 19:08:23 +0000 (GMT) Message-ID: <21185e6d3118c97c9dde66df366bb9ff3b31dede.camel@vnet.ibm.com> Subject: [Patch v2] Handle .TOC. sections during gdb-compile for rs6000 target. To: "gdb-patches@sourceware.org" Date: Wed, 28 Jul 2021 14:08:21 -0500 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-10.el7) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: fSIqqCOCwRiq7x41tlsV6IIWXNdrzoIr X-Proofpoint-ORIG-GUID: ItbRWYJJSPOReI0zxqT7N2Dvq9VsxC7I X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-28_09:2021-07-27, 2021-07-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2107280109 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: will schmidt via Gdb-patches Reply-To: will schmidt Cc: Ulrich Weigand , rogerio , Alan Modra Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" [gdb] Handle .TOC. sections during gdb-compile for rs6000 target. Hi, [V2] Multiple changes and cleanups per feedback. Added logic to iterate through the sections to find one with SEC_ALLOC flags set to serve as a substitite for an absent .toc section. This was/is exercised with the test suite running in a power9 LE environment. Per that testing, I don't believe I've got a case where we had to resort as far as using the bfd_abs_section_ptr as a fallback, so additional scrutiny may be required for that portion of this patch. [V1, updated] When we encounter a .TOC. symbol in the object we are loading, we need to associate this with the .toc section in order to properly resolve other symbols in the object. IF a .toc section is not found, iterate the sections until we find one with the SEC_ALLOC flag. If that also fails, fall back to using bfd_abs_section_ptr. This is part of a short series of patches that allows gdb-compile support to function for the ppc64le target. OK for trunk? Thanks -Will gdb/Changelog: yyyy-mm-dd Will Schmidt * gdb/compile/compile-object-load.c (compile_object_load): Add handling for the .TOC. symbol. diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 1c512801bcd..70742bf9b8e 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -720,10 +720,52 @@ compile_object_load (const compile_file_names &file_names, need for _GLOBAL_OFFSET_TABLE_. Together with -fPIE the data remain PC-relative even with _GLOBAL_OFFSET_TABLE_ as zero. */ sym->value = 0; continue; } + if (strcmp (sym->name, ".TOC.") == 0) + { + /* Handle the .TOC. symbol as the linker would do. Set the .TOC. + sections value and the section to point to the ".toc" section, + and pass the toc->vma value into bfd_set_gp_value(). + If the .toc section is not found, use the first section + with the SEC_ALLOC flag set. Im the unlikely case that + we still do not have a section identified, fall back to using + bfd_abs_section_ptr. */ + asection *toc_fallback = bfd_get_section_by_name(abfd.get(), ".toc"); + if (toc_fallback == NULL) { + for (asection *tsect = abfd->sections; tsect != nullptr; + tsect = tsect->next) { + if (bfd_section_flags (tsect) & SEC_ALLOC) { + if (compile_debug) + fprintf_unfiltered (gdb_stdlog, + "Using section [%s] as .toc fallback.\n", + tsect->name); + toc_fallback = tsect; + break; + } + } + } + if (toc_fallback == NULL) { + /* If we've gotten here, we have not found a section usable + as a backup for the .toc section. Use bfd_abs_section_ptr. */ + if (compile_debug) + fprintf_unfiltered (gdb_stdlog, + "Using bfd_abs_section_ptr as .toc fallback.\n"); + toc_fallback = bfd_abs_section_ptr; + } + sym->section = toc_fallback; + sym->value = 0x8000; + bfd_set_gp_value(abfd.get(), toc_fallback->vma); + if (compile_debug) + fprintf_unfiltered (gdb_stdlog, + "Connectiong ELF symbol \"%s\" to the .toc section (%s)\n", + sym->name, + paddress (target_gdbarch (), sym->value)); + continue; + } + bmsym = lookup_minimal_symbol (sym->name, NULL, NULL); switch (bmsym.minsym == NULL ? mst_unknown : MSYMBOL_TYPE (bmsym.minsym)) { case mst_text: