Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3575162pxf; Mon, 29 Mar 2021 06:08:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1fy6hPr7I73dTajzvrOPHWTL6k9K3vWMnvMqKyaMUXLfmAR5VC4cTGCeSmIHV/iznQbiS X-Received: by 2002:a05:6402:d07:: with SMTP id eb7mr27728621edb.242.1617023309795; Mon, 29 Mar 2021 06:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617023309; cv=none; d=google.com; s=arc-20160816; b=0Jml2Zto26U63yxnXNpdjKsmaJDdgV9P6Dm4FRcomkBRU3fdTuMfVTSe2UQ5K8kHPa Cd7HzfdcjAn9C/XZ5BqBLPj6FpRFtTHUs9zL9kKH7jKpFk5HVvcaGMeoub5MSvdN9XYc JVGUUO1hhwL0XtpmKCu0WCUTUxdZzKoBbASMA0B8O7OJ+LJ4bU4zslpjslUnc0MrEmn5 4IvMm10aO65HgW5/eEUJ3p6oAvzYNHDF2gvFxk71+ubL8Cs4Tewpes7vE2Fu1jL0srsw oUbFrmnzPCWYL6BgdDWCCrpuYUXQMnLDxTJphIhZm7u+pHFMxqN4iREFifovE6/baU1j HY9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=eJZT4UwF7dkvyJKyWhl9+2yE/VBgBdb0tgJEep2ykq0=; b=uTRGNl1BjWfdiHP4QDRmc1b14SMmjxFA9JyHasM4nYlYkM+XaQZ+5bASXi6R9SAs41 /33CPkQTfcP3mv3VzxnNloUQ80NW7XNWPdMVK402+g3BikvNgkBI/zUmQm7rZKsywtqy 6uD9mgbgTmfjz/kBPnFgx/LJpZFwqVvAjqsuuoF7FEGm/0woRJ4Pwzg9COYRv25lkoOC YJcVvunA6mJhTumLQWEuySYdWGlGVzeDmbIneJvyuUsqsmgbrvCvvjWul7Leu6uY+2nr Q5AoYvW1SrKCE/eqF6AJMb8jCebv0nJ8Eh1hGSlUqUzSB2Lwr6Yk4lIOGmRsaROaU3Gd NkWA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m5si13076926ejn.599.2021.03.29.06.08.07; Mon, 29 Mar 2021 06:08:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbhC2NHC (ORCPT + 99 others); Mon, 29 Mar 2021 09:07:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:52008 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230213AbhC2NGe (ORCPT ); Mon, 29 Mar 2021 09:06:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 365C7B473; Mon, 29 Mar 2021 13:06:33 +0000 (UTC) Date: Mon, 29 Mar 2021 15:06:32 +0200 (CEST) From: Richard Biener To: "H.J. Lu" cc: Jiri Slaby , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , LKML Subject: Re: perf does not resolve plt symbols from libstdc++ right (.plt.sec problem) In-Reply-To: Message-ID: References: <68eb3576-66dd-9155-aae2-b3cde1ebcbdf@suse.cz> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-1609908220-831296595-1617023193=:17979" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1609908220-831296595-1617023193=:17979 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT 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. Richard. -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg) ---1609908220-831296595-1617023193=:17979--