Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3578617pxf; Mon, 29 Mar 2021 06:12:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqttgZsqMDvyvZ5L7+ZDvBP9M71xVDiH907AbS+kkkea4Jk+UG6ouzAXtQwzpKmlZ8xCyu X-Received: by 2002:a17:906:1c41:: with SMTP id l1mr28159091ejg.299.1617023565738; Mon, 29 Mar 2021 06:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617023565; cv=none; d=google.com; s=arc-20160816; b=GBhDkztkHIzBx5m66KWSTFlxQ4XqX8fI7BvG5VeoJ1aT95hdeQFEfznoRwekxMvy1C 1llBjOKwUPTOb0WQCAWKWZIwKbyD8V8t1OoH97+GMT8B4tXGtDGJHISNP0M5c3ynTuwX iOKNoWlvybF4OolTb0GbFukS8P6bLqcXxVPtw8T1LCaMAvt/IHL5lp+XoIrt2i1Q/zsA kKEUDwCnjTXlC2zErbjyQxTjw0aJ26Z2n6KPl58Su/gza0Po5PI7//SlKo9eiW30eHiY JldgUulvmpDIoCRE2DGSIw7lxM+vgDmPbTdYKP/I80kNQLcfueSJn5H/cXtK4HNt9t7y JcyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oZDdCQupz4vkgN4jX/+oDZiKTMZgeA1Nr2oj7gFHXUw=; b=j1JMNZuKU7q/r2Wdoiid2SBg/EzcOO6XT+P24jZ+KtWZf0HBXrfUEaaIQRnBwjxv8w zBVoWz9TnpaGz+j5hSsPqJA5FsQVyR2X8vgawNWcKqZaI3CA5KHT9jlNsq6RBVUloDym GN2HKcrpVFxBHwO3/e87H+/dclPeZCKcNOMdevJOr+EC9MoEzadFf6+xQEv8Wi5Pfmkz mna5ivXnjOAMCA2zEITwQ7Nsv6O7yf7CmYXcEP3l7TY3Fw+wf665l7icZU60OwqB4aXo mGkvNxjcxabYFvRrfQ9QoDg29cz1+9TFArGRBdUXASK5HeypYQkiyV+xDAu7XOxvaUo+ TSiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UtjTlgk2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si13223948edc.119.2021.03.29.06.12.14; Mon, 29 Mar 2021 06:12:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UtjTlgk2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbhC2NLP (ORCPT + 99 others); Mon, 29 Mar 2021 09:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231649AbhC2NK7 (ORCPT ); Mon, 29 Mar 2021 09:10:59 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1FFCC061574 for ; Mon, 29 Mar 2021 06:10:59 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id k14-20020a9d7dce0000b02901b866632f29so12224976otn.1 for ; Mon, 29 Mar 2021 06:10:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oZDdCQupz4vkgN4jX/+oDZiKTMZgeA1Nr2oj7gFHXUw=; b=UtjTlgk2KrBSVVX6QfFqybggc7ksk53dhIkDOVZdJLFgtMYUA9gC6nXyYennxL34eQ ukCoVjtDKyj6C47EkWxl33OgCt4K7pKTpiw5lyYyn6CMDfX0JHlenryd57YEIl8hUrq3 /L4aVsEvOzrP8FDS/DoEb1JZxJhvtsQfZaaDUM5Ce3DtRn5n9fLglXwuBPzejSfMy2H9 P0wsKEkj8dK+GnX5NzrbHpwDxoCXCAINvd80EXGbCfBDDV4NZAd1ltagmKC4CyT597oi 8l746bhBFVPahHA18J7eblfkwQrxWxmHmCILR8Bd4bS37biQ8BG6D4k88u4ATIr0k7YJ x1Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oZDdCQupz4vkgN4jX/+oDZiKTMZgeA1Nr2oj7gFHXUw=; b=ttAYsCk4c/u70lEGiJqVGRooprJYEwZlaS9oN6G9wzuOZn9Yg/te+g9OOlhhZNGGZl /lI/T0Uyt2k9REz76x1Gh5bg9x02389ysjb/HRCy8k+LV0GhADx6si8RjNIKRK2ks4Qb 10MJfRn0+H5ZuxFQQAabI+Yfi67yGlZKOxFKKF0S31mj8aw4fv26OA0PCt/A9651qBW3 Gc3bPm+Oxxs2YD7hcYFV03K5gm5x3FJGwakp04F/XT7uojwgM2E0ggwmrku/+rjnnX5b a3vhnKepZDW4pKRYb1ifEspCNcjcKTqvPtzNRWsGvOjkBdEWtz+DJQ4V10Oe7sXksNb3 eGqw== X-Gm-Message-State: AOAM530o7oce7OSVBx6NoKt2ncfLVJC+dFTMEWWt49qou8LgjHOsFURE yCWYbe0tvgi7Xd/dh223nP2yHy6c87OL06me7qM= X-Received: by 2002:a05:6830:1515:: with SMTP id k21mr22742403otp.269.1617023459194; Mon, 29 Mar 2021 06:10:59 -0700 (PDT) MIME-Version: 1.0 References: <68eb3576-66dd-9155-aae2-b3cde1ebcbdf@suse.cz> In-Reply-To: From: "H.J. Lu" Date: Mon, 29 Mar 2021 06:10:22 -0700 Message-ID: Subject: Re: perf does not resolve plt symbols from libstdc++ right (.plt.sec problem) To: Richard Biener Cc: Jiri Slaby , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 29, 2021 at 6:06 AM Richard Biener wrote: > > On Mon, 29 Mar 2021, H.J. Lu wrote: > > > On Mon, Mar 29, 2021 at 2:38 AM Richard Biener wrote: > > > > > > On Mon, 29 Mar 2021, Jiri Slaby wrote: > > > > > > > Any ideas on this? > > > > > > > > On 11. 01. 21, 7:31, Jiri Slaby wrote: > > > > > Hi, > > > > > > > > > > this e-mails is a follow-up of my report at: > > > > > https://bugzilla.suse.com/show_bug.cgi?id=1180681 > > > > > > > > > > There is a problem with *@plt symbols in some libraries, they are unresolved > > > > > by perf (memcmp@plt in this case): > > > > > > 0.26% main2 /usr/lib64/libstdc++.so.6.0.28 0xa51a0 > > > > > l [.] 0x00000000000a51a0 > > > > > > > > > > On the other hand, plt symbols in other libraries are fine (memset@plt in > > > > > this case): > > > > > > 0.17% main2 /usr/lib64/libantlr4-runtime.so.4.8 0x4ed10 > > > > > l [.] memset@plt > > > > > > > > > > I dumped memcmp's .plt.rela entries in perf: > > > > > /usr/lib64/libantlr4-runtime.so.4.8: 154th addr=4e9d0 plt_off=4e020 hdr=10 > > > > > entry=10 > > > > > /usr/lib64/libstdc++.so.6.0.28: 772th addr=a1070 plt_off=9e020 hdr=10 > > > > > entry=10 > > > > > > > > > > The difference (offset) of stdc++'s memcmp is 0xa51a0 (correct) - 0xa1070 > > > > > (perf's computed) = 0x4130. > > > > > > > > > > The problem is perf assumes nth entry of .plt.rela to correspond to nth > > > > > function in .plt, but memcmp is in .plt.sec in libstdc++.so: > > > > > > > > > > >Relocation section '.rela.plt' at offset 0x97900 contains 1018 entries: > > > > > > Offset Info Type Symbol's > > > > > Value Symbol's Name + Addend > > > > > > ... > > > > > > 00000000001dc838 0000007800000007 R_X86_64_JUMP_SLOT > > > > > 0000000000000000 memcmp@GLIBC_2.2.5 + 0 > > > > > > > > > > Perf does this with the rela entries: > > > > > https://github.com/torvalds/linux/blob/f5e6c330254ae691f6d7befe61c786eb5056007e/tools/perf/util/symbol-elf.c#L385 > > > > > > > > > > It takes a symbol index from sym.r_info. Then it resolves its name from > > > > > .dynsym, appending "@plt" to it. Then this name is added to perf's symbol > > > > > table along with address which is computed as .rela.plt index multiplied by > > > > > entry size (shdr_plt.sh_entsize) plus plt header (shdr_plt.sh_entsize on > > > > > x86_64 too). > > > > > > > > > > And from this comes (almost) the offset above: > > > > > >$ objdump -h /usr/lib64/libstdc++.so.6|grep -E ' .plt(\.sec)? ' > > > > > > 12 .plt 00003fb0 000000000009e020 000000000009e020 > > > > > 0009e020 2**4 > > > > > > 14 .plt.sec 00003fa0 00000000000a2160 00000000000a2160 > > > > > 000a2160 2**4 > > > > > > > > > > 0xa2160-0x9e020 = 0x4140. I assume the 0x10 difference is that perf adds > > > > > shdr_plt.sh_entsize (0x10) to the offset to skip the first .plt entry > > > > > (header). > > > > > > > > > > Richard writes: > > > > > ====== > > > > > .plt.sec is IIRC the "second" (sec) PLT entry - the one that will be used on > > > > > the second call (and on). This is used / emitted for ELF object > > > > > instrumented for Intel CET. The details escape me for the moment but I hope > > > > > the x86 ABI documents this (and the constraints) in detail. > > > > > > I just checked and the x86_64 psABI doesn't say anything about .plt.sec > > > > The second PLT is documented in section 13.2 Dynamic Linking in x86-64 > > psABI. Please see elf_x86_64_get_synthetic_symtab in binutils for PLT symbol > > processing. > > Hmm, google pointed me to https://gitlab.com/x86-psABIs/ and that > version does not have a section 13 (but the last is section 12 on MPX). > There's also references to a pdf which contain the section but > that's on github and the github page says gitlab is the home... > So I'm a bit confused here. > https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/13 -- H.J.