Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/20210607023839.26387-1-mark-pk.tsai@mediatek.com/
Link: https://lkml.kernel.org/r/20210616154126.2794-1-mark-pk.tsai@mediatek.com

Reported-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Tested-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
[handle endianness of sym->st_shndx]
Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Peter Zijlstra and committed by
Steven Rostedt (VMware)
fb780761 3e08a9f9

+10 -5
+10 -5
scripts/recordmcount.h
··· 192 192 Elf32_Word const *symtab_shndx) 193 193 { 194 194 unsigned long offset; 195 + unsigned short shndx = w2(sym->st_shndx); 195 196 int index; 196 197 197 - if (sym->st_shndx != SHN_XINDEX) 198 - return w2(sym->st_shndx); 198 + if (shndx > SHN_UNDEF && shndx < SHN_LORESERVE) 199 + return shndx; 199 200 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); 202 204 203 - return w(symtab_shndx[index]); 205 + return w(symtab_shndx[index]); 206 + } 207 + 208 + return 0; 204 209 } 205 210 206 211 static unsigned int get_shnum(Elf_Ehdr const *ehdr, Elf_Shdr const *shdr0)