Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1397798 > unrolled thread
| Started by | He Kuang <hekuang@huawei.com> |
|---|---|
| First post | 2016-05-10 09:50 +0200 |
| Last post | 2016-05-10 14:40 +0200 |
| Articles | 7 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit He Kuang <hekuang@huawei.com> - 2016-05-10 09:50 +0200
Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit Adrian Hunter <adrian.hunter@intel.com> - 2016-05-10 10:20 +0200
Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit Hekuang <hekuang@huawei.com> - 2016-05-10 12:00 +0200
Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit Adrian Hunter <adrian.hunter@intel.com> - 2016-05-10 12:40 +0200
Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit Hekuang <hekuang@huawei.com> - 2016-05-10 13:50 +0200
Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit Adrian Hunter <adrian.hunter@intel.com> - 2016-05-10 14:10 +0200
Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit Hekuang <hekuang@huawei.com> - 2016-05-10 14:40 +0200
| From | He Kuang <hekuang@huawei.com> |
|---|---|
| Date | 2016-05-10 09:50 +0200 |
| Subject | [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxaAz-6l0-49@gated-at.bofh.it> |
32-bit programs can be run on 64-bit machines, so we should choose
unwind methods according to 'thread->map' instead of the host
architecture.
This patch adds methods to test whether a dso is 64-bit or 32-bit by
the class info in elf.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
tools/perf/util/symbol-elf.c | 16 +++++++++++++++
tools/perf/util/symbol.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/symbol.h | 2 ++
3 files changed, 67 insertions(+)
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 3f9d679..9f290b9 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -636,6 +636,22 @@ bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;
}
+int elf_is_64_bit(char *name)
+{
+ Elf *elf;
+ int fd;
+
+ fd = open(name, O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
+ if (elf == NULL)
+ return -1;
+
+ return (gelf_getclass(elf) == ELFCLASS64);
+}
+
int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
enum dso_binary_type type)
{
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 4630751..592bf8c 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1395,6 +1395,55 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
}
}
+int dso_is_64_bit(struct dso *dso, struct map *map)
+{
+ char *name;
+ u_int i;
+ bool kmod;
+ char *root_dir = (char *) "";
+ struct machine *machine;
+
+ if (map->groups && map->groups->machine)
+ machine = map->groups->machine;
+ else
+ machine = NULL;
+
+ if (machine)
+ root_dir = machine->root_dir;
+
+ name = malloc(PATH_MAX);
+ if (!name)
+ return -1;
+
+ kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
+ dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
+ dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
+ dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
+
+ /*
+ * Iterate over candidate debug images.
+ * Keep track of "interesting" ones (those which have a symtab, dynsym,
+ * and/or opd section) for processing.
+ */
+ for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
+ enum dso_binary_type symtab_type = binary_type_symtab[i];
+
+ if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
+ continue;
+
+ if (dso__read_binary_type_filename(dso, symtab_type,
+ root_dir, name, PATH_MAX))
+ continue;
+
+ if (!is_regular_file(name))
+ continue;
+
+ return elf_is_64_bit(name);
+ }
+
+ return -1;
+}
+
int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
{
char *name;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 4e6910e..d33fbf4 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -308,6 +308,8 @@ int setup_list(struct strlist **list, const char *list_str,
const char *list_name);
int setup_intlist(struct intlist **list, const char *list_str,
const char *list_name);
+int elf_is_64_bit(char *name);
+int dso_is_64_bit(struct dso *dso, struct map *map);
#ifdef HAVE_LIBELF_SUPPORT
bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
--
1.8.5.2
[toc] | [next] | [standalone]
| From | Adrian Hunter <adrian.hunter@intel.com> |
|---|---|
| Date | 2016-05-10 10:20 +0200 |
| Subject | Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxb3z-70Q-1@gated-at.bofh.it> |
| In reply to | #1397798 |
On 10/05/16 10:40, He Kuang wrote:
> 32-bit programs can be run on 64-bit machines, so we should choose
> unwind methods according to 'thread->map' instead of the host
> architecture.
>
> This patch adds methods to test whether a dso is 64-bit or 32-bit by
> the class info in elf.
What about using dso->is_64_bit set by dso__load_sym() ?
>
> Signed-off-by: He Kuang <hekuang@huawei.com>
> ---
> tools/perf/util/symbol-elf.c | 16 +++++++++++++++
> tools/perf/util/symbol.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
> tools/perf/util/symbol.h | 2 ++
> 3 files changed, 67 insertions(+)
>
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index 3f9d679..9f290b9 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -636,6 +636,22 @@ bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
> return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;
> }
>
> +int elf_is_64_bit(char *name)
> +{
> + Elf *elf;
> + int fd;
> +
> + fd = open(name, O_RDONLY);
> + if (fd < 0)
> + return -1;
> +
> + elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
> + if (elf == NULL)
> + return -1;
> +
> + return (gelf_getclass(elf) == ELFCLASS64);
> +}
> +
> int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
> enum dso_binary_type type)
> {
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 4630751..592bf8c 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -1395,6 +1395,55 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
> }
> }
>
> +int dso_is_64_bit(struct dso *dso, struct map *map)
> +{
> + char *name;
> + u_int i;
> + bool kmod;
> + char *root_dir = (char *) "";
> + struct machine *machine;
> +
> + if (map->groups && map->groups->machine)
> + machine = map->groups->machine;
> + else
> + machine = NULL;
> +
> + if (machine)
> + root_dir = machine->root_dir;
> +
> + name = malloc(PATH_MAX);
> + if (!name)
> + return -1;
> +
> + kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
> + dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
> +
> + /*
> + * Iterate over candidate debug images.
> + * Keep track of "interesting" ones (those which have a symtab, dynsym,
> + * and/or opd section) for processing.
> + */
> + for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
> + enum dso_binary_type symtab_type = binary_type_symtab[i];
> +
> + if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
> + continue;
> +
> + if (dso__read_binary_type_filename(dso, symtab_type,
> + root_dir, name, PATH_MAX))
> + continue;
> +
> + if (!is_regular_file(name))
> + continue;
> +
> + return elf_is_64_bit(name);
> + }
> +
> + return -1;
> +}
> +
> int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
> {
> char *name;
> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> index 4e6910e..d33fbf4 100644
> --- a/tools/perf/util/symbol.h
> +++ b/tools/perf/util/symbol.h
> @@ -308,6 +308,8 @@ int setup_list(struct strlist **list, const char *list_str,
> const char *list_name);
> int setup_intlist(struct intlist **list, const char *list_str,
> const char *list_name);
> +int elf_is_64_bit(char *name);
> +int dso_is_64_bit(struct dso *dso, struct map *map);
>
> #ifdef HAVE_LIBELF_SUPPORT
> bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
>
[toc] | [prev] | [next] | [standalone]
| From | Hekuang <hekuang@huawei.com> |
|---|---|
| Date | 2016-05-10 12:00 +0200 |
| Subject | Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxcCn-8kL-29@gated-at.bofh.it> |
| In reply to | #1397824 |
hi
在 2016/5/10 16:08, Adrian Hunter 写道:
> On 10/05/16 10:40, He Kuang wrote:
>> 32-bit programs can be run on 64-bit machines, so we should choose
>> unwind methods according to 'thread->map' instead of the host
>> architecture.
>>
>> This patch adds methods to test whether a dso is 64-bit or 32-bit by
>> the class info in elf.
> What about using dso->is_64_bit set by dso__load_sym() ?
I've noticed this variable, but it's value is not as its name said:
util/dso.c: 1067 dso->is_64_bit = (sizeof(void *) == 8);
This is only related to the host architecture.
A closer one is 'is_64_bit' in 'struct symsrc', but the value is
assigned after dso
loaded. So I think we should provide individual methods to get that value.
Thanks.
>
>> Signed-off-by: He Kuang <hekuang@huawei.com>
>> ---
>> tools/perf/util/symbol-elf.c | 16 +++++++++++++++
>> tools/perf/util/symbol.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
>> tools/perf/util/symbol.h | 2 ++
>> 3 files changed, 67 insertions(+)
>>
>> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
>> index 3f9d679..9f290b9 100644
>> --- a/tools/perf/util/symbol-elf.c
>> +++ b/tools/perf/util/symbol-elf.c
>> @@ -636,6 +636,22 @@ bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
>> return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;
>> }
>>
>> +int elf_is_64_bit(char *name)
>> +{
>> + Elf *elf;
>> + int fd;
>> +
>> + fd = open(name, O_RDONLY);
>> + if (fd < 0)
>> + return -1;
>> +
>> + elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
>> + if (elf == NULL)
>> + return -1;
>> +
>> + return (gelf_getclass(elf) == ELFCLASS64);
>> +}
>> +
>> int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
>> enum dso_binary_type type)
>> {
>> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
>> index 4630751..592bf8c 100644
>> --- a/tools/perf/util/symbol.c
>> +++ b/tools/perf/util/symbol.c
>> @@ -1395,6 +1395,55 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
>> }
>> }
>>
>> +int dso_is_64_bit(struct dso *dso, struct map *map)
>> +{
>> + char *name;
>> + u_int i;
>> + bool kmod;
>> + char *root_dir = (char *) "";
>> + struct machine *machine;
>> +
>> + if (map->groups && map->groups->machine)
>> + machine = map->groups->machine;
>> + else
>> + machine = NULL;
>> +
>> + if (machine)
>> + root_dir = machine->root_dir;
>> +
>> + name = malloc(PATH_MAX);
>> + if (!name)
>> + return -1;
>> +
>> + kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
>> + dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
>> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
>> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
>> +
>> + /*
>> + * Iterate over candidate debug images.
>> + * Keep track of "interesting" ones (those which have a symtab, dynsym,
>> + * and/or opd section) for processing.
>> + */
>> + for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
>> + enum dso_binary_type symtab_type = binary_type_symtab[i];
>> +
>> + if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
>> + continue;
>> +
>> + if (dso__read_binary_type_filename(dso, symtab_type,
>> + root_dir, name, PATH_MAX))
>> + continue;
>> +
>> + if (!is_regular_file(name))
>> + continue;
>> +
>> + return elf_is_64_bit(name);
>> + }
>> +
>> + return -1;
>> +}
>> +
>> int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
>> {
>> char *name;
>> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
>> index 4e6910e..d33fbf4 100644
>> --- a/tools/perf/util/symbol.h
>> +++ b/tools/perf/util/symbol.h
>> @@ -308,6 +308,8 @@ int setup_list(struct strlist **list, const char *list_str,
>> const char *list_name);
>> int setup_intlist(struct intlist **list, const char *list_str,
>> const char *list_name);
>> +int elf_is_64_bit(char *name);
>> +int dso_is_64_bit(struct dso *dso, struct map *map);
>>
>> #ifdef HAVE_LIBELF_SUPPORT
>> bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
>>
>
[toc] | [prev] | [next] | [standalone]
| From | Adrian Hunter <adrian.hunter@intel.com> |
|---|---|
| Date | 2016-05-10 12:40 +0200 |
| Subject | Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxdf3-KB-1@gated-at.bofh.it> |
| In reply to | #1397920 |
On 10/05/16 12:49, Hekuang wrote:
> hi
>
> 在 2016/5/10 16:08, Adrian Hunter 写道:
>> On 10/05/16 10:40, He Kuang wrote:
>>> 32-bit programs can be run on 64-bit machines, so we should choose
>>> unwind methods according to 'thread->map' instead of the host
>>> architecture.
>>>
>>> This patch adds methods to test whether a dso is 64-bit or 32-bit by
>>> the class info in elf.
>> What about using dso->is_64_bit set by dso__load_sym() ?
>
> I've noticed this variable, but it's value is not as its name said:
>
> util/dso.c: 1067 dso->is_64_bit = (sizeof(void *) == 8);
That is just initialization i.e. before we know what it is we assume it is
the same as the host.
>
> This is only related to the host architecture.
>
> A closer one is 'is_64_bit' in 'struct symsrc', but the value is assigned
> after dso
> loaded. So I think we should provide individual methods to get that value.
Are you saying you don't load dsos? Or that is_64_bit is set incorrectly?
>
> Thanks.
>
>>
>>> Signed-off-by: He Kuang <hekuang@huawei.com>
>>> ---
>>> tools/perf/util/symbol-elf.c | 16 +++++++++++++++
>>> tools/perf/util/symbol.c | 49
>>> ++++++++++++++++++++++++++++++++++++++++++++
>>> tools/perf/util/symbol.h | 2 ++
>>> 3 files changed, 67 insertions(+)
>>>
>>> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
>>> index 3f9d679..9f290b9 100644
>>> --- a/tools/perf/util/symbol-elf.c
>>> +++ b/tools/perf/util/symbol-elf.c
>>> @@ -636,6 +636,22 @@ bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
>>> return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;
>>> }
>>> +int elf_is_64_bit(char *name)
>>> +{
>>> + Elf *elf;
>>> + int fd;
>>> +
>>> + fd = open(name, O_RDONLY);
>>> + if (fd < 0)
>>> + return -1;
>>> +
>>> + elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
>>> + if (elf == NULL)
>>> + return -1;
>>> +
>>> + return (gelf_getclass(elf) == ELFCLASS64);
>>> +}
>>> +
>>> int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
>>> enum dso_binary_type type)
>>> {
>>> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
>>> index 4630751..592bf8c 100644
>>> --- a/tools/perf/util/symbol.c
>>> +++ b/tools/perf/util/symbol.c
>>> @@ -1395,6 +1395,55 @@ static bool dso__is_compatible_symtab_type(struct
>>> dso *dso, bool kmod,
>>> }
>>> }
>>> +int dso_is_64_bit(struct dso *dso, struct map *map)
>>> +{
>>> + char *name;
>>> + u_int i;
>>> + bool kmod;
>>> + char *root_dir = (char *) "";
>>> + struct machine *machine;
>>> +
>>> + if (map->groups && map->groups->machine)
>>> + machine = map->groups->machine;
>>> + else
>>> + machine = NULL;
>>> +
>>> + if (machine)
>>> + root_dir = machine->root_dir;
>>> +
>>> + name = malloc(PATH_MAX);
>>> + if (!name)
>>> + return -1;
>>> +
>>> + kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
>>> + dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
>>> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
>>> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
>>> +
>>> + /*
>>> + * Iterate over candidate debug images.
>>> + * Keep track of "interesting" ones (those which have a symtab, dynsym,
>>> + * and/or opd section) for processing.
>>> + */
>>> + for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
>>> + enum dso_binary_type symtab_type = binary_type_symtab[i];
>>> +
>>> + if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
>>> + continue;
>>> +
>>> + if (dso__read_binary_type_filename(dso, symtab_type,
>>> + root_dir, name, PATH_MAX))
>>> + continue;
>>> +
>>> + if (!is_regular_file(name))
>>> + continue;
>>> +
>>> + return elf_is_64_bit(name);
>>> + }
>>> +
>>> + return -1;
>>> +}
>>> +
>>> int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
>>> {
>>> char *name;
>>> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
>>> index 4e6910e..d33fbf4 100644
>>> --- a/tools/perf/util/symbol.h
>>> +++ b/tools/perf/util/symbol.h
>>> @@ -308,6 +308,8 @@ int setup_list(struct strlist **list, const char
>>> *list_str,
>>> const char *list_name);
>>> int setup_intlist(struct intlist **list, const char *list_str,
>>> const char *list_name);
>>> +int elf_is_64_bit(char *name);
>>> +int dso_is_64_bit(struct dso *dso, struct map *map);
>>> #ifdef HAVE_LIBELF_SUPPORT
>>> bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
>>>
>>
>
>
>
[toc] | [prev] | [next] | [standalone]
| From | Hekuang <hekuang@huawei.com> |
|---|---|
| Date | 2016-05-10 13:50 +0200 |
| Subject | Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxekP-1Bh-33@gated-at.bofh.it> |
| In reply to | #1397971 |
在 2016/5/10 18:34, Adrian Hunter 写道:
> On 10/05/16 12:49, Hekuang wrote:
>> hi
>>
>> 在 2016/5/10 16:08, Adrian Hunter 写道:
>>> On 10/05/16 10:40, He Kuang wrote:
>>>> 32-bit programs can be run on 64-bit machines, so we should choose
>>>> unwind methods according to 'thread->map' instead of the host
>>>> architecture.
>>>>
>>>> This patch adds methods to test whether a dso is 64-bit or 32-bit by
>>>> the class info in elf.
>>> What about using dso->is_64_bit set by dso__load_sym() ?
>> I've noticed this variable, but it's value is not as its name said:
>>
>> util/dso.c: 1067 dso->is_64_bit = (sizeof(void *) == 8);
> That is just initialization i.e. before we know what it is we assume it is
> the same as the host.
>
>> This is only related to the host architecture.
>>
>> A closer one is 'is_64_bit' in 'struct symsrc', but the value is assigned
>> after dso
>> loaded. So I think we should provide individual methods to get that value.
> Are you saying you don't load dsos? Or that is_64_bit is set incorrectly?
>
Yes, I know it's the inital value, but the correct value is
assigned in function dso__load_sym(), and have a look at the call
stack(gdb):
#0 dso__load_sym
#1 in dso__load
#2 in map__load
#3 in map__find_symbol
#4 in thread__find_addr_location
#5 in entry
#6 in get_entries
#7 in _Ux86__unwind__get_entries
#8 in thread__resolve_callchain
I think we should choose the right unwind method before
dso__load_sym(). i.e. line#7, which is called before dso__load_sym().
I'm not very familiar with this, what's your opinion?
Thanks.
>> Thanks.
>>
>>>> Signed-off-by: He Kuang <hekuang@huawei.com>
>>>> ---
>>>> tools/perf/util/symbol-elf.c | 16 +++++++++++++++
>>>> tools/perf/util/symbol.c | 49
>>>> ++++++++++++++++++++++++++++++++++++++++++++
>>>> tools/perf/util/symbol.h | 2 ++
>>>> 3 files changed, 67 insertions(+)
>>>>
>>>> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
>>>> index 3f9d679..9f290b9 100644
>>>> --- a/tools/perf/util/symbol-elf.c
>>>> +++ b/tools/perf/util/symbol-elf.c
>>>> @@ -636,6 +636,22 @@ bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
>>>> return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;
>>>> }
>>>> +int elf_is_64_bit(char *name)
>>>> +{
>>>> + Elf *elf;
>>>> + int fd;
>>>> +
>>>> + fd = open(name, O_RDONLY);
>>>> + if (fd < 0)
>>>> + return -1;
>>>> +
>>>> + elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
>>>> + if (elf == NULL)
>>>> + return -1;
>>>> +
>>>> + return (gelf_getclass(elf) == ELFCLASS64);
>>>> +}
>>>> +
>>>> int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
>>>> enum dso_binary_type type)
>>>> {
>>>> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
>>>> index 4630751..592bf8c 100644
>>>> --- a/tools/perf/util/symbol.c
>>>> +++ b/tools/perf/util/symbol.c
>>>> @@ -1395,6 +1395,55 @@ static bool dso__is_compatible_symtab_type(struct
>>>> dso *dso, bool kmod,
>>>> }
>>>> }
>>>> +int dso_is_64_bit(struct dso *dso, struct map *map)
>>>> +{
>>>> + char *name;
>>>> + u_int i;
>>>> + bool kmod;
>>>> + char *root_dir = (char *) "";
>>>> + struct machine *machine;
>>>> +
>>>> + if (map->groups && map->groups->machine)
>>>> + machine = map->groups->machine;
>>>> + else
>>>> + machine = NULL;
>>>> +
>>>> + if (machine)
>>>> + root_dir = machine->root_dir;
>>>> +
>>>> + name = malloc(PATH_MAX);
>>>> + if (!name)
>>>> + return -1;
>>>> +
>>>> + kmod = dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE ||
>>>> + dso->symtab_type == DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE_COMP ||
>>>> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
>>>> + dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
>>>> +
>>>> + /*
>>>> + * Iterate over candidate debug images.
>>>> + * Keep track of "interesting" ones (those which have a symtab, dynsym,
>>>> + * and/or opd section) for processing.
>>>> + */
>>>> + for (i = 0; i < DSO_BINARY_TYPE__SYMTAB_CNT; i++) {
>>>> + enum dso_binary_type symtab_type = binary_type_symtab[i];
>>>> +
>>>> + if (!dso__is_compatible_symtab_type(dso, kmod, symtab_type))
>>>> + continue;
>>>> +
>>>> + if (dso__read_binary_type_filename(dso, symtab_type,
>>>> + root_dir, name, PATH_MAX))
>>>> + continue;
>>>> +
>>>> + if (!is_regular_file(name))
>>>> + continue;
>>>> +
>>>> + return elf_is_64_bit(name);
>>>> + }
>>>> +
>>>> + return -1;
>>>> +}
>>>> +
>>>> int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
>>>> {
>>>> char *name;
>>>> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
>>>> index 4e6910e..d33fbf4 100644
>>>> --- a/tools/perf/util/symbol.h
>>>> +++ b/tools/perf/util/symbol.h
>>>> @@ -308,6 +308,8 @@ int setup_list(struct strlist **list, const char
>>>> *list_str,
>>>> const char *list_name);
>>>> int setup_intlist(struct intlist **list, const char *list_str,
>>>> const char *list_name);
>>>> +int elf_is_64_bit(char *name);
>>>> +int dso_is_64_bit(struct dso *dso, struct map *map);
>>>> #ifdef HAVE_LIBELF_SUPPORT
>>>> bool elf__needs_adjust_symbols(GElf_Ehdr ehdr);
>>>>
>>
>>
>
[toc] | [prev] | [next] | [standalone]
| From | Adrian Hunter <adrian.hunter@intel.com> |
|---|---|
| Date | 2016-05-10 14:10 +0200 |
| Subject | Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxeEc-27l-59@gated-at.bofh.it> |
| In reply to | #1398018 |
On 10/05/16 14:38, Hekuang wrote: > > > 在 2016/5/10 18:34, Adrian Hunter 写道: >> On 10/05/16 12:49, Hekuang wrote: >>> hi >>> >>> 在 2016/5/10 16:08, Adrian Hunter 写道: >>>> On 10/05/16 10:40, He Kuang wrote: >>>>> 32-bit programs can be run on 64-bit machines, so we should choose >>>>> unwind methods according to 'thread->map' instead of the host >>>>> architecture. >>>>> >>>>> This patch adds methods to test whether a dso is 64-bit or 32-bit by >>>>> the class info in elf. >>>> What about using dso->is_64_bit set by dso__load_sym() ? >>> I've noticed this variable, but it's value is not as its name said: >>> >>> util/dso.c: 1067 dso->is_64_bit = (sizeof(void *) == 8); >> That is just initialization i.e. before we know what it is we assume it is >> the same as the host. >> >>> This is only related to the host architecture. >>> >>> A closer one is 'is_64_bit' in 'struct symsrc', but the value is assigned >>> after dso >>> loaded. So I think we should provide individual methods to get that value. >> Are you saying you don't load dsos? Or that is_64_bit is set incorrectly? >> > > Yes, I know it's the inital value, but the correct value is > assigned in function dso__load_sym(), and have a look at the call > stack(gdb): > > #0 dso__load_sym > #1 in dso__load > #2 in map__load > #3 in map__find_symbol > #4 in thread__find_addr_location > #5 in entry > #6 in get_entries > #7 in _Ux86__unwind__get_entries > #8 in thread__resolve_callchain > > I think we should choose the right unwind method before > dso__load_sym(). i.e. line#7, which is called before dso__load_sym(). > > I'm not very familiar with this, what's your opinion? Have you considered calling map__load() instead of dso_is_64_bit()
[toc] | [prev] | [next] | [standalone]
| From | Hekuang <hekuang@huawei.com> |
|---|---|
| Date | 2016-05-10 14:40 +0200 |
| Subject | Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit |
| Message-ID | <rxf7b-2mv-1@gated-at.bofh.it> |
| In reply to | #1398038 |
在 2016/5/10 19:59, Adrian Hunter 写道: > On 10/05/16 14:38, Hekuang wrote: >> >> 在 2016/5/10 18:34, Adrian Hunter 写道: >>> On 10/05/16 12:49, Hekuang wrote: >>>> hi >>>> >>>> 在 2016/5/10 16:08, Adrian Hunter 写道: >>>>> On 10/05/16 10:40, He Kuang wrote: >>>>>> 32-bit programs can be run on 64-bit machines, so we should choose >>>>>> unwind methods according to 'thread->map' instead of the host >>>>>> architecture. >>>>>> >>>>>> This patch adds methods to test whether a dso is 64-bit or 32-bit by >>>>>> the class info in elf. >>>>> What about using dso->is_64_bit set by dso__load_sym() ? >>>> I've noticed this variable, but it's value is not as its name said: >>>> >>>> util/dso.c: 1067 dso->is_64_bit = (sizeof(void *) == 8); >>> That is just initialization i.e. before we know what it is we assume it is >>> the same as the host. >>> >>>> This is only related to the host architecture. >>>> >>>> A closer one is 'is_64_bit' in 'struct symsrc', but the value is assigned >>>> after dso >>>> loaded. So I think we should provide individual methods to get that value. >>> Are you saying you don't load dsos? Or that is_64_bit is set incorrectly? >>> >> Yes, I know it's the inital value, but the correct value is >> assigned in function dso__load_sym(), and have a look at the call >> stack(gdb): >> >> #0 dso__load_sym >> #1 in dso__load >> #2 in map__load >> #3 in map__find_symbol >> #4 in thread__find_addr_location >> #5 in entry >> #6 in get_entries >> #7 in _Ux86__unwind__get_entries >> #8 in thread__resolve_callchain >> >> I think we should choose the right unwind method before >> dso__load_sym(). i.e. line#7, which is called before dso__load_sym(). >> >> I'm not very familiar with this, what's your opinion? > Have you considered calling map__load() instead of dso_is_64_bit() IMO, map__load() is heavy than dso_is_64_bit() test, because the dso tested by unwind_get_arch(thread, map) may or may not be referenced in the unwind process. For example, a thread can have a large map but that map never appeared in the callcains in perf.data. Or in other words, should we load all symbols for that elf flag or add a new method targeted for that purpose only. Thanks. > > >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web