mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Ian Rogers <irogers@google.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/9] perf symbols: Add support for x86 .plt.sec
Date: Mon, 30 Jan 2023 20:35:03 +0200	[thread overview]
Message-ID: <5aeab2b5-7349-d220-652b-75360ef6d723@intel.com> (raw)
In-Reply-To: <CAM9d7chny89+rtP6orSJOKrAqb4GbzCG53KV4O1J9mhKvCcWnQ@mail.gmail.com>

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?



  reply	other threads:[~2023-01-30 18:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 17:02 [PATCH 0/9] perf symbols: Improve dso__synthesize_plt_symbols() for x86 Adrian Hunter
2023-01-27 17:02 ` [PATCH 1/9] perf symbols: Correct plt entry sizes " Adrian Hunter
2023-01-27 17:02 ` [PATCH 2/9] perf symbols: Add support for x86 .plt.sec Adrian Hunter
2023-01-30 17:34   ` Namhyung Kim
2023-01-30 18:35     ` Adrian Hunter [this message]
2023-01-30 22:22       ` Namhyung Kim
2023-01-31 10:14         ` Adrian Hunter
2023-01-27 17:02 ` [PATCH 3/9] perf symbols: Sort plt relocations for x86 Adrian Hunter
2023-01-27 17:02 ` [PATCH 4/9] perf symbols: Record whether a symbol is an alias for an IFUNC symbol Adrian Hunter
2023-01-27 17:02 ` [PATCH 5/9] perf symbols: Add support for IFUNC symbols for x86_64 Adrian Hunter
2023-01-27 17:02 ` [PATCH 6/9] perf symbols: Allow for .plt without header Adrian Hunter
2023-01-27 17:02 ` [PATCH 7/9] perf symbols: Allow for static executables with .plt Adrian Hunter
2023-01-27 17:02 ` [PATCH 8/9] perf symbols: Start adding support for .plt.got for x86 Adrian Hunter
2023-01-27 17:02 ` [PATCH 9/9] perf symbols: Get symbols for .plt.got for x86-64 Adrian Hunter
2023-01-30 23:26   ` Namhyung Kim
2023-01-31 10:17     ` Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5aeab2b5-7349-d220-652b-75360ef6d723@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome