[binutils-gdb] gprofng: Remove check_Relocs() function

Vladimir Mezentsev vmezents@sourceware.org
Mon Apr 7 01:33:56 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=91fd5244999ecab8f24728a3e033689e1c668f7e

commit 91fd5244999ecab8f24728a3e033689e1c668f7e
Author: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
Date:   Fri Mar 28 13:25:19 2025 +0200

    gprofng: Remove check_Relocs() function
    
    check_Relocs() function is not anylonger required as it can only
    handle Studio compiler relocs, now defunct. Remove this function.
    
    Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>

Diff:
---
 gprofng/src/Stabs.cc | 139 +--------------------------------------------------
 gprofng/src/Stabs.h  |   3 +-
 2 files changed, 2 insertions(+), 140 deletions(-)

diff --git a/gprofng/src/Stabs.cc b/gprofng/src/Stabs.cc
index 21203193823..908dcc4b7b4 100644
--- a/gprofng/src/Stabs.cc
+++ b/gprofng/src/Stabs.cc
@@ -272,7 +272,7 @@ Stabs::Stabs (char *_path, char *_lo_name)
   stabsModules = NULL;
   textsz = 0;
   wsize = Wnone;
-  st_check_symtab = st_check_relocs = false;
+  st_check_symtab = false;
   status = DBGD_ERR_NONE;
 
   if (openElf (false) == NULL)
@@ -412,7 +412,6 @@ Stabs::read_symbols (Vector<Function*> *functions)
   if (openElf (true) == NULL)
     return false;
   check_Symtab ();
-  check_Relocs ();
   if (functions)
     {
       Function *fp;
@@ -1820,142 +1819,6 @@ Stabs::readSymSec (unsigned int sec, Elf *elf)
   dump ();
 }//check_Symtab
 
-void
-Stabs::check_Relocs ()
-{
-  // We may have many relocation tables to process: .rela.text%foo,
-  // rela.text%bar, etc. On Intel, compilers generate .rel.text sections
-  // which have to be processed as well. A lot of rework is needed here.
-  Symbol *sptr = NULL;
-  if (st_check_relocs)
-    return;
-  st_check_relocs = true;
-
-  Elf *elf = openElf (false);
-  if (elf == NULL)
-    return;
-  for (unsigned int sec = 1; sec < elf->elf_getehdr ()->e_shnum; sec++)
-    {
-      bool use_rela, use_PLT;
-      char *name = elf->get_sec_name (sec);
-      if (name == NULL)
-	continue;
-      if (strncmp (name, NTXT (".rela.text"), 10) == 0)
-	{
-	  use_rela = true;
-	  use_PLT = false;
-	}
-      else if (streq (name, NTXT (".rela.plt")))
-	{
-	  use_rela = true;
-	  use_PLT = true;
-	}
-      else if (strncmp (name, NTXT (".rel.text"), 9) == 0)
-	{
-	  use_rela = false;
-	  use_PLT = false;
-	}
-      else if (streq (name, NTXT (".rel.plt")))
-	{
-	  use_rela = false;
-	  use_PLT = true;
-	}
-      else
-	continue;
-
-      Elf_Internal_Shdr *shdr = elf->get_shdr (sec);
-      if (shdr == NULL)
-	continue;
-
-      // Get ELF data
-      Elf_Data *data = elf->elf_getdata (sec);
-      if (data == NULL)
-	continue;
-      uint64_t ScnSize = data->d_size;
-      uint64_t EntSize = shdr->sh_entsize;
-      if ((ScnSize == 0) || (EntSize == 0))
-	continue;
-      int tot = (int) (ScnSize / EntSize);
-
-      // Get corresponding text section
-      Elf_Internal_Shdr *shdr_txt = elf->get_shdr (shdr->sh_info);
-      if (shdr_txt == NULL)
-	continue;
-      if (!(shdr_txt->sh_flags & SHF_EXECINSTR))
-	    continue;
-
-      // Get corresponding symbol table section
-      Elf_Internal_Shdr *shdr_sym = elf->get_shdr (shdr->sh_link);
-      if (shdr_sym == NULL)
-	continue;
-      Elf_Data *data_sym = elf->elf_getdata (shdr->sh_link);
-
-      // Get corresponding string table section
-      Elf_Data *data_str = elf->elf_getdata (shdr_sym->sh_link);
-      if (data_str == NULL)
-	continue;
-      char *Strtab = (char*) data_str->d_buf;
-      for (int n = 0; n < tot; n++)
-	{
-	  Elf_Internal_Sym sym;
-	  Elf_Internal_Rela rela;
-	  char *symName;
-	  if (use_rela)
-	    elf->elf_getrela (data, n, &rela);
-	  else
-	    {
-	      // GElf_Rela is extended GElf_Rel
-	      elf->elf_getrel (data, n, &rela);
-	      rela.r_addend = 0;
-	    }
-
-	  int ndx = (int) GELF_R_SYM (rela.r_info);
-	  elf->elf_getsym (data_sym, ndx, &sym);
-	  switch (GELF_ST_TYPE (sym.st_info))
-	    {
-	    case STT_FUNC:
-	    case STT_OBJECT:
-	    case STT_NOTYPE:
-	      if (sym.st_name == 0 || sym.st_name >= data_str->d_size)
-		continue;
-	      symName = Strtab + sym.st_name;
-	      break;
-	    case STT_SECTION:
-	      {
-		Elf_Internal_Shdr *secHdr = elf->get_shdr (sym.st_shndx);
-		if (secHdr == NULL)
-		  continue;
-		if (sptr == NULL)
-		  sptr = new Symbol;
-		sptr->value = secHdr->sh_offset + rela.r_addend;
-		long index = SymLst->bisearch (0, -1, &sptr, SymFindCmp);
-		if (index == -1)
-		  continue;
-		Symbol *sp = SymLst->fetch (index);
-		if (sptr->value != sp->value)
-		  continue;
-		symName = sp->name;
-		break;
-	      }
-	    default:
-	      continue;
-	    }
-	  Reloc *reloc = new Reloc;
-	  reloc->name = dbe_strdup (symName);
-	  reloc->type = GELF_R_TYPE (rela.r_info);
-	  reloc->value = use_PLT ? rela.r_offset
-		  : rela.r_offset + shdr_txt->sh_offset;
-	  reloc->addend = rela.r_addend;
-	  if (use_PLT)
-	    RelPLTLst->append (reloc);
-	  else
-	    RelLst->append (reloc);
-	}
-    }
-  delete sptr;
-  RelLst->sort (RelValueCmp);
-} //check_Relocs
-
 void
 Stabs::get_save_addr (bool need_swap_endian)
 {
diff --git a/gprofng/src/Stabs.h b/gprofng/src/Stabs.h
index 42aa6fbc791..88c2b8d64a5 100644
--- a/gprofng/src/Stabs.h
+++ b/gprofng/src/Stabs.h
@@ -130,7 +130,6 @@ class Stabs {
     // Interface with Elf Symbol Table
     void                check_Symtab();
     void                readSymSec(unsigned int sec, Elf *elf);
-    void                check_Relocs();
     void                get_save_addr(bool need_swap_endian);
     Symbol              *map_PC_to_sym(uint64_t pc);
     Symbol              *pltSym;
@@ -146,7 +145,7 @@ class Stabs {
     Map<const char*, Symbol*> *get_elf_symbols();
     Dwarf       *dwarf;
 
-    bool        st_check_symtab, st_check_relocs;
+    bool	st_check_symtab;
     Function	*createFunction(LoadObject *lo, Module *module, Symbol *sym);
     void        fixSymtabAlias();


More information about the Binutils-cvs mailing list