Skip to content

Commit fb78076

Browse files
Peter Zijlstrarostedt
authored andcommitted
recordmcount: Correct st_shndx handling
One should only use st_shndx when >SHN_UNDEF and <SHN_LORESERVE. When SHN_XINDEX, then use .symtab_shndx. Otherwise use 0. This handles the case: st_shndx >= SHN_LORESERVE && st_shndx != SHN_XINDEX. Link: https://lore.kernel.org/lkml/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Reported-by: Mark-PK Tsai <[email protected]> Tested-by: Mark-PK Tsai <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> [handle endianness of sym->st_shndx] Signed-off-by: Mark-PK Tsai <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 3e08a9f commit fb78076

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scripts/recordmcount.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,20 @@ static unsigned int get_symindex(Elf_Sym const *sym, Elf32_Word const *symtab,
192192
Elf32_Word const *symtab_shndx)
193193
{
194194
unsigned long offset;
195+
unsigned short shndx = w2(sym->st_shndx);
195196
int index;
196197

197-
if (sym->st_shndx != SHN_XINDEX)
198-
return w2(sym->st_shndx);
198+
if (shndx > SHN_UNDEF && shndx < SHN_LORESERVE)
199+
return shndx;
199200

200-
offset = (unsigned long)sym - (unsigned long)symtab;
201-
index = offset / sizeof(*sym);
201+
if (shndx == SHN_XINDEX) {
202+
offset = (unsigned long)sym - (unsigned long)symtab;
203+
index = offset / sizeof(*sym);
202204

203-
return w(symtab_shndx[index]);
205+
return w(symtab_shndx[index]);
206+
}
207+
208+
return 0;
204209
}
205210

206211
static unsigned int get_shnum(Elf_Ehdr const *ehdr, Elf_Shdr const *shdr0)

0 commit comments

Comments
 (0)