diff mbox series

[V2,3/5] Force MAPPING_TYPE__IDENTIY for PIE

Message ID 2ed246c95cac628cffc1628c115a4b791459f8fe.1724698250.git.scclevenger@os.amperecomputing.com (mailing list archive)
State New, archived
Headers show
Series arm-cs-trace-disasm.py/perf must accommodate non-zero DSO text offset | expand

Commit Message

Steve Clevenger Aug. 26, 2024, 9:35 p.m. UTC
Changes in V2:
  - Updated mailing list distribution

Use dso__is_pie() to check whether the DSO file is a Position
Independent Executable (PIE). If PIE, change the MAPPING_TYPE to
MAPPING_TYPE__IDENTITY so a zero map pgoff (text offset) is passed
into the script.


Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
---
 tools/perf/util/map.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Leo Yan Aug. 27, 2024, 7:55 p.m. UTC | #1
On 8/26/2024 10:35 PM, Steve Clevenger wrote:
> 
> Changes in V2:
>   - Updated mailing list distribution
> 
> Use dso__is_pie() to check whether the DSO file is a Position
> Independent Executable (PIE). If PIE, change the MAPPING_TYPE to
> MAPPING_TYPE__IDENTITY so a zero map pgoff (text offset) is passed
> into the script.
> 
> 
> Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
> ---
>  tools/perf/util/map.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index e1d14936a60d..df7c06fc373e 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -171,8 +171,11 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
>                 assert(!dso__kernel(dso));
>                 map__init(result, start, start + len, pgoff, dso);
> 
> +               if (map->pgoff && !no_dso)
> +                       no_dso = dso__is_pie(dso);      // PIE check

Here the logic is whatever the `pgoff` is (zero or non-zero), we need to
always set the mapping type as MAPPING_TYPE__IDENTITY. It is no need to check
pgoff and is no matter with 'no_dso'. So we can simply check dso__is_pie() and
set IDENTITY flag for the true case.

    if (dso__is_pie(dso)) {
            map__set_mapping_type(map, MAPPING_TYPE__IDENTITY);
    } else if (anon || no_dso) {
            ...
    }

BTW, please rebase the series on the top of the perf-tools-next branch [1], I
saw this patch has merging conflict on it.

Thanks,
Leo

[1] https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
    branch: perf-tools-next
> +
>                 if (anon || no_dso) {
> -                       map->mapping_type = MAPPING_TYPE__IDENTITY;
> +                       map__set_mapping_type(map, MAPPING_TYPE__IDENTITY);
> 
>                         /*
>                          * Set memory without DSO as loaded. All map__find_*
> --
> 2.25.1
>
Steve Clevenger Aug. 28, 2024, 1:41 a.m. UTC | #2
On 8/27/2024 12:55 PM, Leo Yan wrote:
> On 8/26/2024 10:35 PM, Steve Clevenger wrote:
>>
>> Changes in V2:
>>   - Updated mailing list distribution
>>
>> Use dso__is_pie() to check whether the DSO file is a Position
>> Independent Executable (PIE). If PIE, change the MAPPING_TYPE to
>> MAPPING_TYPE__IDENTITY so a zero map pgoff (text offset) is passed
>> into the script.
>>
>>
>> Signed-off-by: Steve Clevenger <scclevenger@os.amperecomputing.com>
>> ---
>>  tools/perf/util/map.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
>> index e1d14936a60d..df7c06fc373e 100644
>> --- a/tools/perf/util/map.c
>> +++ b/tools/perf/util/map.c
>> @@ -171,8 +171,11 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
>>                 assert(!dso__kernel(dso));
>>                 map__init(result, start, start + len, pgoff, dso);
>>
>> +               if (map->pgoff && !no_dso)
>> +                       no_dso = dso__is_pie(dso);      // PIE check
> 
> Here the logic is whatever the `pgoff` is (zero or non-zero), we need to
> always set the mapping type as MAPPING_TYPE__IDENTITY. It is no need to check
> pgoff and is no matter with 'no_dso'. So we can simply check dso__is_pie() and
> set IDENTITY flag for the true case.
> 
>     if (dso__is_pie(dso)) {
>             map__set_mapping_type(map, MAPPING_TYPE__IDENTITY);
>     } else if (anon || no_dso) {
>             ...
>     }
> 
> BTW, please rebase the series on the top of the perf-tools-next branch [1], I
> saw this patch has merging conflict on it.
> 
> Thanks,
> Leo

Hi Leo,

I combined the dso__is_pie() call onto the end of the existing 'if'
statement you now show as an 'else if'. Please see V3 of the patch series.

Steve

> 
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git
>     branch: perf-tools-next
>> +
>>                 if (anon || no_dso) {
>> -                       map->mapping_type = MAPPING_TYPE__IDENTITY;
>> +                       map__set_mapping_type(map, MAPPING_TYPE__IDENTITY);
>>
>>                         /*
>>                          * Set memory without DSO as loaded. All map__find_*
>> --
>> 2.25.1
>>
diff mbox series

Patch

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index e1d14936a60d..df7c06fc373e 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -171,8 +171,11 @@  struct map *map__new(struct machine *machine, u64 start, u64 len,
 		assert(!dso__kernel(dso));
 		map__init(result, start, start + len, pgoff, dso);
 
+		if (map->pgoff && !no_dso)
+			no_dso = dso__is_pie(dso);	// PIE check
+
 		if (anon || no_dso) {
-			map->mapping_type = MAPPING_TYPE__IDENTITY;
+			map__set_mapping_type(map, MAPPING_TYPE__IDENTITY);
 
 			/*
 			 * Set memory without DSO as loaded. All map__find_*