From: Matthias Maennich <maennich@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, gprocida@google.com, kernel-team@android.com,
maennich@google.com
Subject: [PATCH v2 8/8] abg-elf-helpers: migrate maybe_adjust_et_rel_sym_addr_to_abs_addr
Date: Tue, 21 Apr 2020 08:35:51 +0200 [thread overview]
Message-ID: <20200421063551.222511-9-maennich@google.com> (raw)
In-Reply-To: <20200421063551.222511-1-maennich@google.com>
Move maybe_adjust_et_rel_sym_addr_to_abs_addr to the elf-helpers.
This function had two overloads
GElf_Addr
maybe_adjust_et_rel_sym_addr_to_abs_addr(GElf_Addr addr, Elf_Scn *section);
GElf_Addr
maybe_adjust_et_rel_sym_addr_to_abs_addr(GElf_Sym *sym);
The former one is only ever called by the latter. Hence consolidate them
into
GElf_Addr
maybe_adjust_et_rel_sym_addr_to_abs_addr(Elf* elf_handle, GElf_Sym* sym);
to combine their functionality and preserve the outer interface. Just we
add the Elf* handle argument as usual as we are out of read_context now.
* src/abg-dwarf-reader.cc(maybe_adjust_et_rel_sym_addr_to_abs_addr):
Move out functions (drop the wrapped overload completely).
* src/abg-elf-helpers.cc(maybe_adjust_et_rel_sym_addr_to_abs_addr):
New function.
* src/abg-elf-helpers.h(maybe_adjust_et_rel_sym_addr_to_abs_addr):
New function declaration.
Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
src/abg-dwarf-reader.cc | 73 ++++-------------------------------------
src/abg-elf-helpers.cc | 40 ++++++++++++++++++++++
src/abg-elf-helpers.h | 3 ++
3 files changed, 49 insertions(+), 67 deletions(-)
diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index dc3332410b1e..c65c01776398 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -6425,7 +6425,8 @@ public:
{
GElf_Addr symbol_value =
- maybe_adjust_et_rel_sym_addr_to_abs_addr(sym);
+ maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle(),
+ sym);
addr_elf_symbol_sptr_map_type::const_iterator it =
fun_addr_sym_map_->find(symbol_value);
@@ -6563,7 +6564,8 @@ public:
else
{
GElf_Addr symbol_value =
- maybe_adjust_et_rel_sym_addr_to_abs_addr(sym);
+ maybe_adjust_et_rel_sym_addr_to_abs_addr(elf_handle(),
+ sym);
addr_elf_symbol_sptr_map_type::const_iterator it =
var_addr_sym_map_->find(symbol_value);
if (it == var_addr_sym_map_->end())
@@ -7147,8 +7149,8 @@ public:
// the symbol value of native_symbol is relative to the
// section that symbol is defined in. We need to translate it
// into an absolute (okay, binary-relative, rather) address.
- GElf_Addr symbol_address =
- maybe_adjust_et_rel_sym_addr_to_abs_addr (&native_symbol);
+ GElf_Addr symbol_address = maybe_adjust_et_rel_sym_addr_to_abs_addr(
+ elf_handle(), &native_symbol);
address_set_sptr set;
if (symbol->is_function())
@@ -7523,69 +7525,6 @@ public:
return addr;
}
- /// Translate a section-relative symbol address (i.e, symbol value)
- /// into an absolute symbol address by adding the address of the
- /// section the symbol belongs to, to the address value.
- ///
- /// This is useful when looking at symbol values coming from
- /// relocatable files (of ET_REL kind). If the binary is not
- /// ET_REL, then the function does nothing and returns the input
- /// address unchanged.
- ///
- /// @param addr the symbol address to possibly translate.
- ///
- /// @param section the section the symbol which value is @p addr
- /// belongs to.
- ///
- /// @return the section-relative address, translated into an
- /// absolute address, if @p section is an ET_REL binary. Otherwise,
- /// return @p addr, unchanged.
- GElf_Addr
- maybe_adjust_et_rel_sym_addr_to_abs_addr(GElf_Addr addr, Elf_Scn *section)
- {
- if (!section)
- return addr;
-
- Elf* elf = elf_handle();
- GElf_Ehdr elf_header;
-
- if (!gelf_getehdr(elf, &elf_header))
- return addr;
-
- if (elf_header.e_type != ET_REL)
- return addr;
-
- GElf_Shdr section_header;
- if (!gelf_getshdr(section, §ion_header))
- return addr;
-
- return addr + section_header.sh_addr;
- }
-
- /// Translate a section-relative symbol address (i.e, symbol value)
- /// into an absolute symbol address by adding the address of the
- /// section the symbol belongs to, to the address value.
- ///
- /// This is useful when looking at symbol values coming from
- /// relocatable files (of ET_REL kind). If the binary is not
- /// ET_REL, then the function does nothing and returns the input
- /// address unchanged.
- ///
- /// @param sym the symbol whose address to possibly needs to be
- /// translated.
- ///
- /// @return the section-relative address, translated into an
- /// absolute address, if @p sym is from an ET_REL binary.
- /// Otherwise, return the address of @p sym, unchanged.
- GElf_Addr
- maybe_adjust_et_rel_sym_addr_to_abs_addr(GElf_Sym *sym)
- {
- Elf_Scn *symbol_section = elf_getscn(elf_handle(), sym->st_shndx);
- GElf_Addr result = sym->st_value;
- result = maybe_adjust_et_rel_sym_addr_to_abs_addr(result, symbol_section);
- return result;
- }
-
/// Test if a given address is in a given section.
///
/// @param addr the address to consider.
diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc
index 895feb6f7768..02ecbcf250ed 100644
--- a/src/abg-elf-helpers.cc
+++ b/src/abg-elf-helpers.cc
@@ -987,5 +987,45 @@ is_dso(Elf* elf_handle)
return elf_header.e_type == ET_DYN;
}
+/// Translate a section-relative symbol address (i.e, symbol value)
+/// into an absolute symbol address by adding the address of the
+/// section the symbol belongs to, to the address value.
+///
+/// This is useful when looking at symbol values coming from
+/// relocatable files (of ET_REL kind). If the binary is not
+/// ET_REL, then the function does nothing and returns the input
+/// address unchanged.
+///
+/// @param elf_handle the elf handle for the binary to consider.
+///
+/// @param sym the symbol whose address to possibly needs to be
+/// translated.
+///
+/// @return the section-relative address, translated into an
+/// absolute address, if @p sym is from an ET_REL binary.
+/// Otherwise, return the address of @p sym, unchanged.
+GElf_Addr
+maybe_adjust_et_rel_sym_addr_to_abs_addr(Elf* elf_handle, GElf_Sym* sym)
+{
+ Elf_Scn* symbol_section = elf_getscn(elf_handle, sym->st_shndx);
+ GElf_Addr addr = sym->st_value;
+
+ if (!symbol_section)
+ return addr;
+
+ GElf_Ehdr elf_header;
+ if (!gelf_getehdr(elf_handle, &elf_header))
+ return addr;
+
+ if (elf_header.e_type != ET_REL)
+ return addr;
+
+ GElf_Shdr section_header;
+ if (!gelf_getshdr(symbol_section, §ion_header))
+ return addr;
+
+ return addr + section_header.sh_addr;
+}
+
} // end namespace elf_helpers
} // end namespace abigail
diff --git a/src/abg-elf-helpers.h b/src/abg-elf-helpers.h
index 6eff245a6a30..647c92703dfa 100644
--- a/src/abg-elf-helpers.h
+++ b/src/abg-elf-helpers.h
@@ -174,6 +174,9 @@ is_executable(Elf* elf_handle);
bool
is_dso(Elf* elf_handle);
+GElf_Addr
+maybe_adjust_et_rel_sym_addr_to_abs_addr(Elf* elf_handle, GElf_Sym* sym);
+
} // end namespace elf_helpers
} // end namespace abigail
--
2.26.1.301.g55bc3eb7cb9-goog
next prev parent reply other threads:[~2020-04-21 6:36 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 11:08 [PATCH 0/8] Refactor dwarf-reader: split out ELF helpers Matthias Maennich
2020-04-20 11:08 ` [PATCH 1/8] abg-dwarf-reader split: create abg-elf-helpers.{h, cc} and test case Matthias Maennich
2020-04-20 15:35 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 2/8] abg-elf-helpers: move some elf helpers from abg-dwarf-reader Matthias Maennich
2020-04-20 15:34 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 3/8] abg-elf-helpers: move some versioning " Matthias Maennich
2020-04-20 15:33 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 4/8] abg-elf-helpers: move some kernel " Matthias Maennich
2020-04-20 14:32 ` Giuliano Procida
2020-04-20 15:30 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 5/8] abg-elf-helpers: consolidate the is_linux_kernel* helpers Matthias Maennich
2020-04-20 15:29 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 6/8] abg-dwarf-reader: migrate more ELF helpers to elf-helpers Matthias Maennich
2020-04-20 15:24 ` Giuliano Procida
2020-04-21 6:14 ` Matthias Maennich
2020-04-21 11:02 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 7/8] abg-elf-helpers: migrate more elf helpers (architecture specific helpers) Matthias Maennich
2020-04-20 15:25 ` Giuliano Procida
2020-04-20 11:08 ` [PATCH 8/8] abg-elf-helpers: migrate maybe_adjust_et_rel_sym_addr_to_abs_addr Matthias Maennich
2020-04-21 6:35 ` [PATCH v2 0/8] Refactor dwarf-reader: split out ELF helpers Matthias Maennich
2020-04-21 6:35 ` [PATCH v2 1/8] abg-dwarf-reader split: create abg-elf-helpers.{h, cc} and test case Matthias Maennich
2020-04-22 9:42 ` Dodji Seketeli
2020-04-21 6:35 ` [PATCH v2 2/8] abg-elf-helpers: move some elf helpers from abg-dwarf-reader Matthias Maennich
2020-04-22 9:44 ` Dodji Seketeli
2020-04-21 6:35 ` [PATCH v2 3/8] abg-elf-helpers: move some versioning " Matthias Maennich
2020-04-22 9:46 ` Dodji Seketeli
2020-04-21 6:35 ` [PATCH v2 4/8] abg-elf-helpers: move some kernel " Matthias Maennich
2020-04-22 9:47 ` Dodji Seketeli
2020-04-21 6:35 ` [PATCH v2 5/8] abg-elf-helpers: consolidate the is_linux_kernel* helpers Matthias Maennich
2020-04-22 9:48 ` Dodji Seketeli
2020-04-21 6:35 ` [PATCH v2 6/8] abg-dwarf-reader: migrate more ELF helpers to elf-helpers Matthias Maennich
2020-04-22 9:53 ` Dodji Seketeli
2020-04-21 6:35 ` [PATCH v2 7/8] abg-elf-helpers: migrate more elf helpers (architecture specific helpers) Matthias Maennich
2020-04-22 9:55 ` Dodji Seketeli
2020-04-21 6:35 ` Matthias Maennich [this message]
2020-04-22 9:56 ` [PATCH v2 8/8] abg-elf-helpers: migrate maybe_adjust_et_rel_sym_addr_to_abs_addr Dodji Seketeli
2020-04-22 9:57 ` [PATCH v2 0/8] Refactor dwarf-reader: split out ELF helpers Dodji Seketeli
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=20200421063551.222511-9-maennich@google.com \
--to=maennich@google.com \
--cc=dodji@seketeli.org \
--cc=gprocida@google.com \
--cc=kernel-team@android.com \
--cc=libabigail@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).