From: Namhyung Kim <namhyung@kernel.org>
To: Tong Shen <endlessroad@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
linux-perf-users@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] perf tools: Fix Symbol Address for ET_DYN
Date: Mon, 29 Sep 2014 11:33:35 +0900 [thread overview]
Message-ID: <87ppefi29s.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <CAPp4yYzPR-FozYeuDUFqR0hhE5tioSqNy22cZ7WjSdBXoxeNxw@mail.gmail.com> (Tong Shen's message of "Thu, 25 Sep 2014 22:53:22 -0700")
Hi Tong,
On Thu, 25 Sep 2014 22:53:22 -0700, Tong Shen wrote:
>>>>>> +/**
>>>>>> + * is_non_relocatable_dyn - check if ELF file is ET_DYN, but not relocatable
>>>>>> + * @ehdr: ELF header of the ELF file
>>>>>> + * @shdr: a section header in the ELF file
>>>>>> + *
>>>>>> + * For ELF files with type ET_EXEC and ET_REL, we adjust symbol addresses in
>>>>>> + * symbol table in dso__load_sym() so that later we can always locate symbols
>>>>>> + * by sym.st_value + map_address_of_ELF_file.
>>>>>> + *
>>>>>> + * But ELF files with type ET_DYN may need adjusting as well, if they are
>>>>>> + * not relocatable. There's no standard way to tell if an ELF file with type
>>>>>> + * ET_DYN is relocatable. One possible way to do that is checking if
>>>>>> + * sh_addr == sh_offset for .text section.
>>>>>> + */
>>>>>> +static bool is_non_relocatable_dyn(GElf_Ehdr *ehdr, GElf_Shdr *shdr,
>>>>>> + Elf_Data *secstrs) {
>>>>>> + return ehdr->e_type == ET_DYN &&
>>>>>> + elf_sec__is_text(shdr, secstrs) &&
>>>>>> + shdr->sh_offset != shdr->sh_addr;
>>>>>> +}
>>>>>> +
>>>>>> int dso__load_sym(struct dso *dso, struct map *map,
>>>>>> struct symsrc *syms_ss, struct symsrc *runtime_ss,
>>>>>> symbol_filter_t filter, int kmodule)
>>>>>> @@ -914,8 +935,9 @@ int dso__load_sym(struct dso *dso, struct map *map,
>>>>>> goto new_symbol;
>>>>>> }
>>>>>>
>>>>>> - if ((used_opd && runtime_ss->adjust_symbols)
>>>>>> - || (!used_opd && syms_ss->adjust_symbols)) {
>>>>>> + if ((used_opd && runtime_ss->adjust_symbols) ||
>>>>>> + (!used_opd && syms_ss->adjust_symbols) ||
>>>>>> + is_non_relocatable_dyn(&ehdr, &shdr, secstrs)) {
>>>>>> pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " "
>>>>>> "sh_addr: %#" PRIx64 " sh_offset: %#" PRIx64 "\n", __func__,
>>>>>> (u64)sym.st_value, (u64)shdr.sh_addr,
Hmm.. IIUC for normal dso (ET_DYN), shdr->offset == shdr->sh_addr for
text section right? And we always adjust ET_EXEC and ET_REL.. What
about always trying to adjust symbol address then? We may precalculate
adjust offset and subtracting it from symbol values. And the offset of
0 effectively means no adjust. This way we can simplify the logic IMHO.
Thanks,
Namhyung
next prev parent reply other threads:[~2014-09-29 2:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAPp4yYwTHbXiypxR_1WJGS9DYQNJ24t_Ykdo_sfQ48Ak-K3Z7g@mail.gmail.com>
[not found] ` <20140911150123.GH10158@kernel.org>
[not found] ` <CAPp4yYzRwoTBzH1_TwcdvAOryZppV9-BwnX2bOtN1qrEqrdBww@mail.gmail.com>
2014-09-11 20:38 ` [PATCH 1/1] perf tools: Fix Symbol Address for ET_DYN Arnaldo Carvalho de Melo
2014-09-15 18:06 ` Tong Shen
2014-09-25 0:28 ` Tong Shen
2014-09-26 5:45 ` Namhyung Kim
2014-09-26 5:53 ` Tong Shen
2014-09-29 2:33 ` Namhyung Kim [this message]
2014-09-29 18:13 ` Tong Shen
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=87ppefi29s.fsf@sejong.aot.lge.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=endlessroad@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.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