Message ID | 20230127170222.9895-3-adrian.hunter@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp939979wrn; Fri, 27 Jan 2023 09:05:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXu8SejY/w+3hObjL7E+6pvLzlpCCB9B+tJXshc2QmsnSJjyyJpeamsAZmQeKRFrTFg+HenQ X-Received: by 2002:a17:907:3e26:b0:870:b53e:86b9 with SMTP id hp38-20020a1709073e2600b00870b53e86b9mr50520356ejc.39.1674839105749; Fri, 27 Jan 2023 09:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674839105; cv=none; d=google.com; s=arc-20160816; b=y9W242Xn//mF7/mMRLWN++St1ziw9c0pIEWGtGey88fF6XSb58YV4+QQrXukaJB9iY MvTROKVCBuX1ikU3DgNNAfT7dTIHzH8EDt5eLQJpleKjUGq8MBWBI86TxeeGnGc8MM1D SOumuQTUuYN/HJ57mYOXgqyM4NeFyykdVufpgl/YmFy3GSuu0+1h6yl6GaWixdX/yh1j 7lfLM+HE+IRbTOTuyqsW5LsXoFfrySA53gHjjCAGgYfMD84frIZB9Y3lJgWLnG27A+7q xGyfCjlZowkJLfZ/hI8vChGdlSd9PKuQSm6PlToxAhFYJxAKkqYKON4c+TgKgZUSEiew TfNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yev6xu07/lV72gEHj/7SRiSStKXYr2YLcvgfuhZG5BQ=; b=tO4XWbREcg2l3LNn/6LqP+C6gPewGU/lTGOAGZRoq6esUuG0dJG0SzZlf9io/ERW/o YVzpKvIsGcadeFalNBlWo3GD9qVoIiI74LWYnbx0X0T3C8mbQUX4nxXgTCz1s1TX8TWW TTR7ymvxvmiJ2LBnDJiYCmBqNYdnI4mBz13gwj/hwJCDd0lUYDjg4urkvS0LPgKf1+fy dsI3kemRwj9t5QjbZO2jUK96PrkGY0IpmyNv2I6tqHl9XhVwqDHxIMoUEt5c6/jUEX1O hVPU+qrPrlK6xRgJmipp2X+zeq5erzA2xUD5szsYBSgcVg47ccGhy3IIpb2WTnE7iUY3 QAmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Jt20okou; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vs15-20020a170907138f00b008785a767444si5119824ejb.955.2023.01.27.09.04.42; Fri, 27 Jan 2023 09:05:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Jt20okou; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234813AbjA0RDL (ORCPT <rfc822;lekhanya01809@gmail.com> + 99 others); Fri, 27 Jan 2023 12:03:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234759AbjA0RDC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 27 Jan 2023 12:03:02 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAEF77FA35; Fri, 27 Jan 2023 09:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674838961; x=1706374961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=djN+DaiLKdmHNtBi7i7A/82f34FiMzl4e3xwGKBci1s=; b=Jt20okou5d6RmZ/HOKZqyVoyd1JNopMXDSmFZfGqcSFPgpcjSaNmjb/l F7IhWjU5jaVNScsPBcfjjJ/b6YLU6/EAwJp179k7iLsIMY/wWhXXQU6Jk sKgcLYasDOhGs/Hike82mt8RCEJ3UpPoLfXemJFe10YUfar8T9qcjJKD1 9UKrnkIEW/B/lHLJZKHT1qcQLD79sph9b/FfaKyXmp5RVwHx3/+GbK9xS IAVLmzu+IcZfkgAcIyI7IWqUwv04bQuTWTBFUfFlDgUA1TotS6Z/FluiQ KdVhs5Dd6IlW4WZpt/JqES4f1XmjYOIir35Ii1uwQqTnij48IDmp5aCMf g==; X-IronPort-AV: E=McAfee;i="6500,9779,10603"; a="310754123" X-IronPort-AV: E=Sophos;i="5.97,251,1669104000"; d="scan'208";a="310754123" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 09:02:39 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10603"; a="726739180" X-IronPort-AV: E=Sophos;i="5.97,251,1669104000"; d="scan'208";a="726739180" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.57.171]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 09:02:37 -0800 From: Adrian Hunter <adrian.hunter@intel.com> To: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>, Ian Rogers <irogers@google.com>, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 2/9] perf symbols: Add support for x86 .plt.sec Date: Fri, 27 Jan 2023 19:02:15 +0200 Message-Id: <20230127170222.9895-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127170222.9895-1-adrian.hunter@intel.com> References: <20230127170222.9895-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE,URI_NOVOWEL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756196090157945817?= X-GMAIL-MSGID: =?utf-8?q?1756196090157945817?= |
Series |
perf symbols: Improve dso__synthesize_plt_symbols() for x86
|
|
Commit Message
Adrian Hunter
Jan. 27, 2023, 5:02 p.m. UTC
The section .plt.sec was originally added for MPX and was first called
.plt.bnd. While MPX has been deprecated, .plt.sec is now also used for IBT.
On x86_64, IBT seems to be enabled by default, but can be switched off
using gcc option -fcf-protection=none. On 32-bit, option -z ibt will
enable IBT.
With .plt.sec, calls are made into .plt.sec instead of .plt, so it
makes more sense to put the symbols there instead of .plt. A notable
difference is that .plt.sec does not have a header entry.
For x86, when synthesizing symbols for plt, use offset and entry size of
.plt.sec instead of .plt when there is a .plt.sec section.
Example on Ubuntu 22.04 gcc 11.3:
Before:
$ cat tstpltlib.c
void fn1(void) {}
void fn2(void) {}
void fn3(void) {}
void fn4(void) {}
$ cat tstplt.c
void fn1(void);
void fn2(void);
void fn3(void);
void fn4(void);
int main()
{
fn4();
fn1();
fn2();
fn3();
return 0;
}
$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc -Wall -Wextra -shared -o libtstpltlib.so tstpltlib.c
$ gcc -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd)
$ readelf -SW tstplt | grep 'plt\|Name'
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[11] .rela.plt RELA 0000000000000698 000698 000060 18 AI 6 24 8
[13] .plt PROGBITS 0000000000001020 001020 000050 10 AX 0 0 16
[14] .plt.got PROGBITS 0000000000001070 001070 000010 10 AX 0 0 16
[15] .plt.sec PROGBITS 0000000000001080 001080 000040 10 AX 0 0 16
$ perf record -e intel_pt//u --filter 'filter main @ ./tstplt' ./tstplt
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.015 MB perf.data ]
$ perf script --itrace=be --ns -F+flags,-event,+addr,-period,-comm,-tid,-cpu,-dso
38970.522546686: tr strt 0 [unknown] => 55fc222a81a9 main+0x0
38970.522546686: tr end call 55fc222a81b1 main+0x8 => 55fc222a80a0 [unknown]
38970.522546687: tr strt 0 [unknown] => 55fc222a81b6 main+0xd
38970.522546687: tr end call 55fc222a81b6 main+0xd => 55fc222a8080 [unknown]
38970.522546688: tr strt 0 [unknown] => 55fc222a81bb main+0x12
38970.522546688: tr end call 55fc222a81bb main+0x12 => 55fc222a80b0 [unknown]
38970.522546688: tr strt 0 [unknown] => 55fc222a81c0 main+0x17
38970.522546688: tr end call 55fc222a81c0 main+0x17 => 55fc222a8090 [unknown]
38970.522546689: tr strt 0 [unknown] => 55fc222a81c5 main+0x1c
38970.522546894: tr end return 55fc222a81cb main+0x22 => 7f3a4dc29d90 __libc_start_call_main+0x80
After:
$ perf script --itrace=be --ns -F+flags,-event,+addr,-period,-comm,-tid,-cpu,-dso
38970.522546686: tr strt 0 [unknown] => 55fc222a81a9 main+0x0
38970.522546686: tr end call 55fc222a81b1 main+0x8 => 55fc222a80a0 fn4@plt+0x0
38970.522546687: tr strt 0 [unknown] => 55fc222a81b6 main+0xd
38970.522546687: tr end call 55fc222a81b6 main+0xd => 55fc222a8080 fn1@plt+0x0
38970.522546688: tr strt 0 [unknown] => 55fc222a81bb main+0x12
38970.522546688: tr end call 55fc222a81bb main+0x12 => 55fc222a80b0 fn2@plt+0x0
38970.522546688: tr strt 0 [unknown] => 55fc222a81c0 main+0x17
38970.522546688: tr end call 55fc222a81c0 main+0x17 => 55fc222a8090 fn3@plt+0x0
38970.522546689: tr strt 0 [unknown] => 55fc222a81c5 main+0x1c
38970.522546894: tr end return 55fc222a81cb main+0x22 => 7f3a4dc29d90 __libc_start_call_main+0x80
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/symbol-elf.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
Comments
Hi Adrian, On Fri, Jan 27, 2023 at 9:02 AM Adrian Hunter <adrian.hunter@intel.com> wrote: > > The section .plt.sec was originally added for MPX and was first called > .plt.bnd. While MPX has been deprecated, .plt.sec is now also used for IBT. > On x86_64, IBT seems to be enabled by default, but can be switched off > using gcc option -fcf-protection=none. On 32-bit, option -z ibt will > enable IBT. > > With .plt.sec, calls are made into .plt.sec instead of .plt, so it > makes more sense to put the symbols there instead of .plt. A notable > difference is that .plt.sec does not have a header entry. > > For x86, when synthesizing symbols for plt, use offset and entry size of > .plt.sec instead of .plt when there is a .plt.sec section. > > Example on Ubuntu 22.04 gcc 11.3: > > Before: > > $ cat tstpltlib.c > void fn1(void) {} > void fn2(void) {} > void fn3(void) {} > void fn4(void) {} > $ cat tstplt.c > void fn1(void); > void fn2(void); > void fn3(void); > void fn4(void); > > int main() > { > fn4(); > fn1(); > fn2(); > fn3(); > return 0; > } > $ gcc --version > gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 > Copyright (C) 2021 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > $ gcc -Wall -Wextra -shared -o libtstpltlib.so tstpltlib.c > $ gcc -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) > $ readelf -SW tstplt | grep 'plt\|Name' > [Nr] Name Type Address Off Size ES Flg Lk Inf Al > [11] .rela.plt RELA 0000000000000698 000698 000060 18 AI 6 24 8 > [13] .plt PROGBITS 0000000000001020 001020 000050 10 AX 0 0 16 > [14] .plt.got PROGBITS 0000000000001070 001070 000010 10 AX 0 0 16 > [15] .plt.sec PROGBITS 0000000000001080 001080 000040 10 AX 0 0 16 On my machine, it's not enabled by default. And it doesn't create .plt.sec even if I pass -fcf-protection=full option. $ gcc --version gcc (Debian 12.2.0-10) 12.2.0 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gcc -Wall -Wextra -shared -fcf-protection=full -o libtstplt.so tstpltlib.c $ gcc -Wall -Wextra -fcf-protection=full -o tstplt tstplt.c -L. -ltstpltlib -Wl,-rpath,$(pwd) $ readelf -SW tstplt | grep 'plt\|Name' [Nr] Name Type Address Off Size ES Flg Lk Inf Al [11] .rela.plt RELA 0000000000000688 000688 000060 18 AI 6 24 8 [13] .plt PROGBITS 0000000000001020 001020 000050 10 AX 0 0 16 [14] .plt.got PROGBITS 0000000000001070 001070 000008 08 AX 0 0 8 [24] .got.plt PROGBITS 0000000000003fe8 002fe8 000038 08 WA 0 0 8 Thanks, Namhyung
On 30/01/23 19:34, Namhyung Kim wrote: > Hi Adrian, > > On Fri, Jan 27, 2023 at 9:02 AM Adrian Hunter <adrian.hunter@intel.com> wrote: >> >> The section .plt.sec was originally added for MPX and was first called >> .plt.bnd. While MPX has been deprecated, .plt.sec is now also used for IBT. >> On x86_64, IBT seems to be enabled by default, but can be switched off >> using gcc option -fcf-protection=none. On 32-bit, option -z ibt will >> enable IBT. >> >> With .plt.sec, calls are made into .plt.sec instead of .plt, so it >> makes more sense to put the symbols there instead of .plt. A notable >> difference is that .plt.sec does not have a header entry. >> >> For x86, when synthesizing symbols for plt, use offset and entry size of >> .plt.sec instead of .plt when there is a .plt.sec section. >> >> Example on Ubuntu 22.04 gcc 11.3: >> >> Before: >> >> $ cat tstpltlib.c >> void fn1(void) {} >> void fn2(void) {} >> void fn3(void) {} >> void fn4(void) {} >> $ cat tstplt.c >> void fn1(void); >> void fn2(void); >> void fn3(void); >> void fn4(void); >> >> int main() >> { >> fn4(); >> fn1(); >> fn2(); >> fn3(); >> return 0; >> } >> $ gcc --version >> gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 >> Copyright (C) 2021 Free Software Foundation, Inc. >> This is free software; see the source for copying conditions. There is NO >> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. >> $ gcc -Wall -Wextra -shared -o libtstpltlib.so tstpltlib.c >> $ gcc -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) >> $ readelf -SW tstplt | grep 'plt\|Name' >> [Nr] Name Type Address Off Size ES Flg Lk Inf Al >> [11] .rela.plt RELA 0000000000000698 000698 000060 18 AI 6 24 8 >> [13] .plt PROGBITS 0000000000001020 001020 000050 10 AX 0 0 16 >> [14] .plt.got PROGBITS 0000000000001070 001070 000010 10 AX 0 0 16 >> [15] .plt.sec PROGBITS 0000000000001080 001080 000040 10 AX 0 0 16 > > On my machine, it's not enabled by default. And it doesn't create .plt.sec > even if I pass -fcf-protection=full option. > > $ gcc --version > gcc (Debian 12.2.0-10) 12.2.0 > Copyright (C) 2022 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > $ gcc -Wall -Wextra -shared -fcf-protection=full -o libtstplt.so tstpltlib.c > $ gcc -Wall -Wextra -fcf-protection=full -o tstplt tstplt.c -L. > -ltstpltlib -Wl,-rpath,$(pwd) > $ readelf -SW tstplt | grep 'plt\|Name' > [Nr] Name Type Address Off Size > ES Flg Lk Inf Al > [11] .rela.plt RELA 0000000000000688 000688 > 000060 18 AI 6 24 8 > [13] .plt PROGBITS 0000000000001020 001020 > 000050 10 AX 0 0 16 > [14] .plt.got PROGBITS 0000000000001070 001070 > 000008 08 AX 0 0 8 > [24] .got.plt PROGBITS 0000000000003fe8 002fe8 > 000038 08 WA 0 0 8 That is interesting. What does it say with -v i.e. gcc -v -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) And what is the distribution?
On Mon, Jan 30, 2023 at 10:35 AM Adrian Hunter <adrian.hunter@intel.com> wrote: > > On 30/01/23 19:34, Namhyung Kim wrote: > > Hi Adrian, > > > > On Fri, Jan 27, 2023 at 9:02 AM Adrian Hunter <adrian.hunter@intel.com> wrote: > >> > >> The section .plt.sec was originally added for MPX and was first called > >> .plt.bnd. While MPX has been deprecated, .plt.sec is now also used for IBT. > >> On x86_64, IBT seems to be enabled by default, but can be switched off > >> using gcc option -fcf-protection=none. On 32-bit, option -z ibt will > >> enable IBT. > >> > >> With .plt.sec, calls are made into .plt.sec instead of .plt, so it > >> makes more sense to put the symbols there instead of .plt. A notable > >> difference is that .plt.sec does not have a header entry. > >> > >> For x86, when synthesizing symbols for plt, use offset and entry size of > >> .plt.sec instead of .plt when there is a .plt.sec section. > >> > >> Example on Ubuntu 22.04 gcc 11.3: > >> > >> Before: > >> > >> $ cat tstpltlib.c > >> void fn1(void) {} > >> void fn2(void) {} > >> void fn3(void) {} > >> void fn4(void) {} > >> $ cat tstplt.c > >> void fn1(void); > >> void fn2(void); > >> void fn3(void); > >> void fn4(void); > >> > >> int main() > >> { > >> fn4(); > >> fn1(); > >> fn2(); > >> fn3(); > >> return 0; > >> } > >> $ gcc --version > >> gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 > >> Copyright (C) 2021 Free Software Foundation, Inc. > >> This is free software; see the source for copying conditions. There is NO > >> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > >> $ gcc -Wall -Wextra -shared -o libtstpltlib.so tstpltlib.c > >> $ gcc -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) > >> $ readelf -SW tstplt | grep 'plt\|Name' > >> [Nr] Name Type Address Off Size ES Flg Lk Inf Al > >> [11] .rela.plt RELA 0000000000000698 000698 000060 18 AI 6 24 8 > >> [13] .plt PROGBITS 0000000000001020 001020 000050 10 AX 0 0 16 > >> [14] .plt.got PROGBITS 0000000000001070 001070 000010 10 AX 0 0 16 > >> [15] .plt.sec PROGBITS 0000000000001080 001080 000040 10 AX 0 0 16 > > > > On my machine, it's not enabled by default. And it doesn't create .plt.sec > > even if I pass -fcf-protection=full option. > > > > $ gcc --version > > gcc (Debian 12.2.0-10) 12.2.0 > > Copyright (C) 2022 Free Software Foundation, Inc. > > This is free software; see the source for copying conditions. There is NO > > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > > > $ gcc -Wall -Wextra -shared -fcf-protection=full -o libtstplt.so tstpltlib.c > > $ gcc -Wall -Wextra -fcf-protection=full -o tstplt tstplt.c -L. > > -ltstpltlib -Wl,-rpath,$(pwd) > > $ readelf -SW tstplt | grep 'plt\|Name' > > [Nr] Name Type Address Off Size > > ES Flg Lk Inf Al > > [11] .rela.plt RELA 0000000000000688 000688 > > 000060 18 AI 6 24 8 > > [13] .plt PROGBITS 0000000000001020 001020 > > 000050 10 AX 0 0 16 > > [14] .plt.got PROGBITS 0000000000001070 001070 > > 000008 08 AX 0 0 8 > > [24] .got.plt PROGBITS 0000000000003fe8 002fe8 > > 000038 08 WA 0 0 8 > > That is interesting. What does it say with -v i.e. > > gcc -v -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-10' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-hWCYKv/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-hWCYKv/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 12.2.0 (Debian 12.2.0-10) COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt-' /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch x86_64-linux-gnu tstplt.c -quiet -dumpdir tstplt- -dumpbase tstplt.c -dumpbase-ext .c -mtune=generic -march=x86-64 -Wall -Wextra -version -fcf-protection=full -fasynchronous-unwind-tables -o /tmp/ccKPWeTD.s GNU C17 (Debian 12.2.0-10) version 12.2.0 (x86_64-linux-gnu) compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-linux-gnu/12/include /usr/local/include /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C17 (Debian 12.2.0-10) version 12.2.0 (x86_64-linux-gnu) compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 0bf64a455b69fb48d1b44a013a099136 COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt-' as -v --64 -o /tmp/cc0IMyNr.o /tmp/ccKPWeTD.s GNU assembler version 2.39.50 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.39.50.20221208 COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/ LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt.' /usr/lib/gcc/x86_64-linux-gnu/12/collect2 -plugin /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper -plugin-opt=-fresolution=/tmp/ccU2c2jz.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie -o tstplt /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L. -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. /tmp/cc0IMyNr.o -ltstpltlib -rpath=/home/namhyung/tmp/plt-test -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt.' > > And what is the distribution? It's a Debian (Testing) with some customization. Thanks, Namhyung
On 31/01/23 00:22, Namhyung Kim wrote: > On Mon, Jan 30, 2023 at 10:35 AM Adrian Hunter <adrian.hunter@intel.com> wrote: >> >> On 30/01/23 19:34, Namhyung Kim wrote: >>> Hi Adrian, >>> >>> On Fri, Jan 27, 2023 at 9:02 AM Adrian Hunter <adrian.hunter@intel.com> wrote: >>>> >>>> The section .plt.sec was originally added for MPX and was first called >>>> .plt.bnd. While MPX has been deprecated, .plt.sec is now also used for IBT. >>>> On x86_64, IBT seems to be enabled by default, but can be switched off >>>> using gcc option -fcf-protection=none. On 32-bit, option -z ibt will >>>> enable IBT. >>>> >>>> With .plt.sec, calls are made into .plt.sec instead of .plt, so it >>>> makes more sense to put the symbols there instead of .plt. A notable >>>> difference is that .plt.sec does not have a header entry. >>>> >>>> For x86, when synthesizing symbols for plt, use offset and entry size of >>>> .plt.sec instead of .plt when there is a .plt.sec section. >>>> >>>> Example on Ubuntu 22.04 gcc 11.3: >>>> >>>> Before: >>>> >>>> $ cat tstpltlib.c >>>> void fn1(void) {} >>>> void fn2(void) {} >>>> void fn3(void) {} >>>> void fn4(void) {} >>>> $ cat tstplt.c >>>> void fn1(void); >>>> void fn2(void); >>>> void fn3(void); >>>> void fn4(void); >>>> >>>> int main() >>>> { >>>> fn4(); >>>> fn1(); >>>> fn2(); >>>> fn3(); >>>> return 0; >>>> } >>>> $ gcc --version >>>> gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 >>>> Copyright (C) 2021 Free Software Foundation, Inc. >>>> This is free software; see the source for copying conditions. There is NO >>>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. >>>> $ gcc -Wall -Wextra -shared -o libtstpltlib.so tstpltlib.c >>>> $ gcc -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) >>>> $ readelf -SW tstplt | grep 'plt\|Name' >>>> [Nr] Name Type Address Off Size ES Flg Lk Inf Al >>>> [11] .rela.plt RELA 0000000000000698 000698 000060 18 AI 6 24 8 >>>> [13] .plt PROGBITS 0000000000001020 001020 000050 10 AX 0 0 16 >>>> [14] .plt.got PROGBITS 0000000000001070 001070 000010 10 AX 0 0 16 >>>> [15] .plt.sec PROGBITS 0000000000001080 001080 000040 10 AX 0 0 16 >>> >>> On my machine, it's not enabled by default. And it doesn't create .plt.sec >>> even if I pass -fcf-protection=full option. >>> >>> $ gcc --version >>> gcc (Debian 12.2.0-10) 12.2.0 >>> Copyright (C) 2022 Free Software Foundation, Inc. >>> This is free software; see the source for copying conditions. There is NO >>> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. >>> >>> $ gcc -Wall -Wextra -shared -fcf-protection=full -o libtstplt.so tstpltlib.c >>> $ gcc -Wall -Wextra -fcf-protection=full -o tstplt tstplt.c -L. >>> -ltstpltlib -Wl,-rpath,$(pwd) >>> $ readelf -SW tstplt | grep 'plt\|Name' >>> [Nr] Name Type Address Off Size >>> ES Flg Lk Inf Al >>> [11] .rela.plt RELA 0000000000000688 000688 >>> 000060 18 AI 6 24 8 >>> [13] .plt PROGBITS 0000000000001020 001020 >>> 000050 10 AX 0 0 16 >>> [14] .plt.got PROGBITS 0000000000001070 001070 >>> 000008 08 AX 0 0 8 >>> [24] .got.plt PROGBITS 0000000000003fe8 002fe8 >>> 000038 08 WA 0 0 8 >> >> That is interesting. What does it say with -v i.e. >> >> gcc -v -Wall -Wextra -o tstplt tstplt.c -L . -ltstpltlib -Wl,-rpath=$(pwd) > > Using built-in specs. > COLLECT_GCC=gcc > COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper > OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa > OFFLOAD_TARGET_DEFAULT=1 > Target: x86_64-linux-gnu > Configured with: ../src/configure -v --with-pkgversion='Debian > 12.2.0-10' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs > --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 > --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 > --program-prefix=x86_64-linux-gnu- --enable-shared > --enable-linker-build-id --libexecdir=/usr/lib > --without-included-gettext --enable-threads=posix --libdir=/usr/lib > --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug > --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new > --enable-gnu-unique-object --disable-vtable-verify --enable-plugin > --enable-default-pie --with-system-zlib > --enable-libphobos-checking=release --with-target-system-zlib=auto > --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet > --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 > --enable-multilib --with-tune=generic > --enable-offload-targets=nvptx-none=/build/gcc-12-hWCYKv/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-hWCYKv/gcc-12-12.2.0/debian/tmp-gcn/usr > --enable-offload-defaulted --without-cuda-driver > --enable-checking=release --build=x86_64-linux-gnu > --host=x86_64-linux-gnu --target=x86_64-linux-gnu > Thread model: posix > Supported LTO compression algorithms: zlib zstd > gcc version 12.2.0 (Debian 12.2.0-10) > COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' > 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt-' > /usr/lib/gcc/x86_64-linux-gnu/12/cc1 -quiet -v -imultiarch > x86_64-linux-gnu tstplt.c -quiet -dumpdir tstplt- -dumpbase tstplt.c > -dumpbase-ext .c -mtune=generic -march=x86-64 -Wall -Wextra -version > -fcf-protection=full -fasynchronous-unwind-tables -o /tmp/ccKPWeTD.s > GNU C17 (Debian 12.2.0-10) version 12.2.0 (x86_64-linux-gnu) > compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version > 4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP > > GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 > ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" > ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/12/include-fixed" > ignoring nonexistent directory > "/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include" > #include "..." search starts here: > #include <...> search starts here: > /usr/lib/gcc/x86_64-linux-gnu/12/include > /usr/local/include > /usr/include/x86_64-linux-gnu > /usr/include > End of search list. > GNU C17 (Debian 12.2.0-10) version 12.2.0 (x86_64-linux-gnu) > compiled by GNU C version 12.2.0, GMP version 6.2.1, MPFR version > 4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP > > GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 > Compiler executable checksum: 0bf64a455b69fb48d1b44a013a099136 > COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' > 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt-' > as -v --64 -o /tmp/cc0IMyNr.o /tmp/ccKPWeTD.s > GNU assembler version 2.39.50 (x86_64-linux-gnu) using BFD version > (GNU Binutils for Debian) 2.39.50.20221208 > COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/ > LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/12/../../../:/lib/:/usr/lib/ > COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' > 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt.' > /usr/lib/gcc/x86_64-linux-gnu/12/collect2 -plugin > /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so > -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper > -plugin-opt=-fresolution=/tmp/ccU2c2jz.res > -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s > -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc > -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m > elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker > /lib64/ld-linux-x86-64.so.2 -pie -o tstplt > /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o > /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o > /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L. > -L/usr/lib/gcc/x86_64-linux-gnu/12 > -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu > -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib > -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu > -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. > /tmp/cc0IMyNr.o -ltstpltlib -rpath=/home/namhyung/tmp/plt-test -lgcc > --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state > --as-needed -lgcc_s --pop-state > /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o > /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crtn.o > COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-fcf-protection=full' '-v' '-o' > 'tstplt' '-L.' '-mtune=generic' '-march=x86-64' '-dumpdir' 'tstplt.' > > >> >> And what is the distribution? > > It's a Debian (Testing) with some customization. Seems to need also options -z ibt and/or -z ibtplt I will send a V2 with updated examples.
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 9328c162d68f..bb1b5cb3ff12 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -379,6 +379,11 @@ static bool get_plt_sizes(struct dso *dso, GElf_Ehdr *ehdr, GElf_Shdr *shdr_plt, return false; } +static bool machine_is_x86(GElf_Half e_machine) +{ + return e_machine == EM_386 || e_machine == EM_X86_64; +} + /* * We need to check if we have a .dynsym, so that we can handle the * .plt, synthesizing its symbols, that aren't on the symtabs (be it @@ -391,8 +396,8 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) uint32_t nr_rel_entries, idx; GElf_Sym sym; u64 plt_offset, plt_header_size, plt_entry_size; - GElf_Shdr shdr_plt; - struct symbol *f; + GElf_Shdr shdr_plt, plt_sec_shdr; + struct symbol *f, *plt_sym; GElf_Shdr shdr_rel_plt, shdr_dynsym; Elf_Data *syms, *symstrs; Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym; @@ -422,10 +427,23 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) return 0; /* Add a symbol for .plt header */ - f = symbol__new(shdr_plt.sh_offset, plt_header_size, STB_GLOBAL, STT_FUNC, ".plt"); - if (!f) + plt_sym = symbol__new(shdr_plt.sh_offset, plt_header_size, STB_GLOBAL, STT_FUNC, ".plt"); + if (!plt_sym) goto out_elf_end; - symbols__insert(&dso->symbols, f); + symbols__insert(&dso->symbols, plt_sym); + + /* Only x86 has .plt.sec */ + if (machine_is_x86(ehdr.e_machine) && + elf_section_by_name(elf, &ehdr, &plt_sec_shdr, ".plt.sec", NULL)) { + if (!get_plt_sizes(dso, &ehdr, &plt_sec_shdr, &plt_header_size, &plt_entry_size)) + return 0; + /* Extend .plt symbol to entire .plt */ + plt_sym->end = plt_sym->start + shdr_plt.sh_size; + /* Use .plt.sec offset */ + plt_offset = plt_sec_shdr.sh_offset; + } else { + plt_offset = shdr_plt.sh_offset + plt_header_size; + } scn_dynsym = ss->dynsym; shdr_dynsym = ss->dynshdr; @@ -474,8 +492,6 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) goto out_elf_end; nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize; - plt_offset = shdr_plt.sh_offset; - plt_offset += plt_header_size; ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA;