From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752261AbcEJJ6c (ORCPT ); Tue, 10 May 2016 05:58:32 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:62463 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751190AbcEJJvj (ORCPT ); Tue, 10 May 2016 05:51:39 -0400 Subject: Re: [PATCH v2 5/9] perf tools: Add methods to test dso is 64-bit or 32-bit To: Adrian Hunter , , , , , , , , , , , , , , , , References: <1462866037-30382-1-git-send-email-hekuang@huawei.com> <1462866037-30382-6-git-send-email-hekuang@huawei.com> <573196E5.9080807@intel.com> CC: From: Hekuang Message-ID: <5731AEBB.8060200@huawei.com> Date: Tue, 10 May 2016 17:49:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <573196E5.9080807@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.110.55.166] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.5731AECB.019A,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 87b2d21b98fc669e54f7b9d3dd3ebd06 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> --- >> 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); >> >