+2018-04-26 Pedro Alves <palves@redhat.com>
+
+ * minsyms.c (lookup_minimal_symbol_by_pc_section_1): Rename to ...
+ (lookup_minimal_symbol_by_pc_section): ... this. Replace
+ 'want_trampoline' parameter by a lookup_msym_prefer parameter.
+ Handle it.
+ (lookup_minimal_symbol_by_pc_section): Delete old implementation.
+ (lookup_minimal_symbol_by_pc): Adjust.
+ (in_gnu_ifunc_stub): Prefer GNU ifunc symbols.
+ (lookup_solib_trampoline_symbol_by_pc): Adjust.
+ * minsyms.h (lookup_msym_prefer): New enum.
+ (lookup_minimal_symbol_by_pc_section): Replace 'want_trampoline'
+ parameter by a lookup_msym_prefer parameter.
+
2018-04-26 Pedro Alves <palves@redhat.com>
* elfread.c (elf_gnu_ifunc_record_cache): Check if the symbol name
there are text and trampoline symbols at the same address.
Otherwise prefer mst_text symbols. */
-static struct bound_minimal_symbol
-lookup_minimal_symbol_by_pc_section_1 (CORE_ADDR pc_in,
- struct obj_section *section,
- int want_trampoline)
+bound_minimal_symbol
+lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *section,
+ lookup_msym_prefer prefer)
{
int lo;
int hi;
struct minimal_symbol *best_symbol = NULL;
struct objfile *best_objfile = NULL;
struct bound_minimal_symbol result;
- enum minimal_symbol_type want_type, other_type;
+ enum minimal_symbol_type want_type;
- want_type = want_trampoline ? mst_solib_trampoline : mst_text;
- other_type = want_trampoline ? mst_text : mst_solib_trampoline;
+ if (section == NULL)
+ {
+ section = find_pc_section (pc_in);
+ if (section == NULL)
+ return {};
+ }
+
+ switch (prefer)
+ {
+ case lookup_msym_prefer::TEXT:
+ want_type = mst_text;
+ break;
+ case lookup_msym_prefer::TRAMPOLINE:
+ want_type = mst_solib_trampoline;
+ break;
+ case lookup_msym_prefer::GNU_IFUNC:
+ want_type = mst_text_gnu_ifunc;
+ break;
+ }
/* We can not require the symbol found to be in section, because
e.g. IRIX 6.5 mdebug relies on this code returning an absolute
preceding symbol too. If they are otherwise
identical prefer that one. */
if (hi > 0
- && MSYMBOL_TYPE (&msymbol[hi]) == other_type
+ && MSYMBOL_TYPE (&msymbol[hi]) != want_type
&& MSYMBOL_TYPE (&msymbol[hi - 1]) == want_type
&& (MSYMBOL_SIZE (&msymbol[hi])
== MSYMBOL_SIZE (&msymbol[hi - 1]))
return result;
}
-struct bound_minimal_symbol
-lookup_minimal_symbol_by_pc_section (CORE_ADDR pc, struct obj_section *section)
-{
- if (section == NULL)
- {
- /* NOTE: cagney/2004-01-27: This was using find_pc_mapped_section to
- force the section but that (well unless you're doing overlay
- debugging) always returns NULL making the call somewhat useless. */
- section = find_pc_section (pc);
- if (section == NULL)
- {
- struct bound_minimal_symbol result;
-
- memset (&result, 0, sizeof (result));
- return result;
- }
- }
- return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0);
-}
-
/* See minsyms.h. */
struct bound_minimal_symbol
lookup_minimal_symbol_by_pc (CORE_ADDR pc)
{
- struct obj_section *section = find_pc_section (pc);
-
- if (section == NULL)
- {
- struct bound_minimal_symbol result;
-
- memset (&result, 0, sizeof (result));
- return result;
- }
- return lookup_minimal_symbol_by_pc_section_1 (pc, section, 0);
+ return lookup_minimal_symbol_by_pc_section (pc, NULL);
}
/* Return non-zero iff PC is in an STT_GNU_IFUNC function resolver. */
int
in_gnu_ifunc_stub (CORE_ADDR pc)
{
- struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc (pc);
-
+ bound_minimal_symbol msymbol
+ = lookup_minimal_symbol_by_pc_section (pc, NULL,
+ lookup_msym_prefer::GNU_IFUNC);
return msymbol.minsym && MSYMBOL_TYPE (msymbol.minsym) == mst_text_gnu_ifunc;
}
static struct minimal_symbol *
lookup_solib_trampoline_symbol_by_pc (CORE_ADDR pc)
{
- struct obj_section *section = find_pc_section (pc);
- struct bound_minimal_symbol msymbol;
-
- if (section == NULL)
- return NULL;
- msymbol = lookup_minimal_symbol_by_pc_section_1 (pc, section, 1);
+ bound_minimal_symbol msymbol
+ = lookup_minimal_symbol_by_pc_section (pc, NULL,
+ lookup_msym_prefer::TRAMPOLINE);
if (msymbol.minsym != NULL
&& MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline)
struct minimal_symbol *lookup_minimal_symbol_by_pc_name
(CORE_ADDR, const char *, struct objfile *);
+enum class lookup_msym_prefer
+{
+ /* Prefer mst_text symbols. */
+ TEXT,
+
+ /* Prefer mst_solib_trampoline symbols when there are text and
+ trampoline symbols at the same address. Otherwise prefer
+ mst_text symbols. */
+ TRAMPOLINE,
+
+ /* Prefer mst_text_gnu_ifunc symbols when there are text and ifunc
+ symbols at the same address. Otherwise prefer mst_text
+ symbols. */
+ GNU_IFUNC,
+};
+
/* Search through the minimal symbol table for each objfile and find
the symbol whose address is the largest address that is still less
than or equal to PC, and which matches SECTION.
instead.
The result has a non-NULL 'minsym' member if such a symbol is
- found, or NULL if PC is not in a suitable range. */
+ found, or NULL if PC is not in a suitable range.
+
+ See definition of lookup_msym_prefer for description of PREFER. By
+ default mst_text symbols are preferred. */
struct bound_minimal_symbol lookup_minimal_symbol_by_pc_section
- (CORE_ADDR,
- struct obj_section *);
+ (CORE_ADDR,
+ struct obj_section *,
+ lookup_msym_prefer prefer = lookup_msym_prefer::TEXT);
/* Backward compatibility: search through the minimal symbol table
for a matching PC (no section given).