[1/3] gprofng: Remove check_Relocs() function
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
Commit Message
From: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
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>
---
gprofng/src/Stabs.cc | 139 +------------------------------------------
gprofng/src/Stabs.h | 3 +-
2 files changed, 2 insertions(+), 140 deletions(-)
Comments
I committed the three patches below.
Claudiu, thank you for the fixes in gprofng. -Vladimir
On 4/2/25 02:15, claudiu.zissulescu-ianculescu@oracle.com wrote:
> From: Claudiu Zissulescu<claudiu.zissulescu-ianculescu@oracle.com>
>
> 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>
> ---
> gprofng/src/Stabs.cc | 139 +------------------------------------------
> gprofng/src/Stabs.h | 3 +-
> 2 files changed, 2 insertions(+), 140 deletions(-)
On 4/2/25 02:15, claudiu.zissulescu-ianculescu@oracle.com wrote:
> From: Claudiu Zissulescu<claudiu.zissulescu-ianculescu@oracle.com>
>
> This patch refactors a number of gprofng internal functions for using
> more BFD data types and functions.
> Stabs::readSymSec is a function which reads the symbols of an ELF file
> mapping them into an internal structure. To use BFD asymbols, the
> Elf::elf_getsym is changed from custom reading of the symbols from
> .symtab and .dynsym section to BFD enable functions. A new function is
> introduced which returns the number of either static or dynamic symbols,
> named Elf::elf_getSymCount. Both Elf functions are used by
> Stabs::readSymSec refactoring.
>
> Also, this patch removes reading symbols, SUNW_ldnsym section as it is
> only used by now defunct Studio compiler. However, it adds the reading
> of both static and dynamic symbols, previously, only either one was
> processed.
>
> Signed-off-by: Claudiu Zissulescu<claudiu.zissulescu-ianculescu@oracle.com>
> ---
> gprofng/src/DwarfLib.cc | 24 ++++----------
> gprofng/src/Elf.cc | 69 +++++++++++++++++++++--------------------
> gprofng/src/Elf.h | 3 +-
> gprofng/src/Stabs.cc | 42 +++++++++----------------
> gprofng/src/Stabs.h | 2 +-
> 5 files changed, 59 insertions(+), 81 deletions(-)
On 4/2/25 02:15, claudiu.zissulescu-ianculescu@oracle.com wrote:
> From: Claudiu Zissulescu<claudiu.zissulescu-ianculescu@oracle.com>
>
> Remove all duplicate symbols which can be in SymLst. The duplication
> is due to processing of both static and dynamic symbols. The
> Stabs::removeDupSyms function is called before computing symbol
> aliases.
>
> Introduce a new vector function (i.e., truncate()), that truncates a
> vector lenght to the given new count. This functionis used by
> removeDupSyms function.
>
> Signed-off-by: Claudiu Zissulescu<claudiu.zissulescu-ianculescu@oracle.com>
> ---
> gprofng/src/Stabs.cc | 35 +++++++++++++++++++++++++++++++++++
> gprofng/src/Stabs.h | 1 +
> gprofng/src/vec.h | 7 +++++++
> 3 files changed, 43 insertions(+)
@@ -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)
{
@@ -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();