Skip to content

Commit 9ad21c3

Browse files
committed
kbuild: try harder to find symbol names in modpost
The relocation record sometimes contained an address which was not an exactly match for a symbol. Implment some simple logic such that if there is a symbol within 20 bytes of the address contained in the relocation record then print the name of this symbol. With this change modpost could find symbol names for the remaining .init.text symbols in my allyesconfig build for x86_64. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent d1f25e6 commit 9ad21c3

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎scripts/mod/modpost.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,13 @@ static int secref_whitelist(const char *modname, const char *tosec,
776776
* In other cases the symbol needs to be looked up in the symbol table
777777
* based on section and address.
778778
* **/
779-
static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf_Addr addr,
779+
static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
780780
Elf_Sym *relsym)
781781
{
782782
Elf_Sym *sym;
783+
Elf_Sym *near = NULL;
784+
Elf64_Sword distance = 20;
785+
Elf64_Sword d;
783786

784787
if (relsym->st_name != 0)
785788
return relsym;
@@ -790,8 +793,20 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf_Addr addr,
790793
continue;
791794
if (sym->st_value == addr)
792795
return sym;
796+
/* Find a symbol nearby - addr are maybe negative */
797+
d = sym->st_value - addr;
798+
if (d < 0)
799+
d = addr - sym->st_value;
800+
if (d < distance) {
801+
distance = d;
802+
near = sym;
803+
}
793804
}
794-
return NULL;
805+
/* We need a close match */
806+
if (distance < 20)
807+
return near;
808+
else
809+
return NULL;
795810
}
796811

797812
static inline int is_arm_mapping_symbol(const char *str)

‎scripts/mod/modpost.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define Elf_Shdr Elf32_Shdr
1818
#define Elf_Sym Elf32_Sym
1919
#define Elf_Addr Elf32_Addr
20+
#define Elf_Sword Elf64_Sword
2021
#define Elf_Section Elf32_Half
2122
#define ELF_ST_BIND ELF32_ST_BIND
2223
#define ELF_ST_TYPE ELF32_ST_TYPE
@@ -31,6 +32,7 @@
3132
#define Elf_Shdr Elf64_Shdr
3233
#define Elf_Sym Elf64_Sym
3334
#define Elf_Addr Elf64_Addr
35+
#define Elf_Sword Elf64_Sxword
3436
#define Elf_Section Elf64_Half
3537
#define ELF_ST_BIND ELF64_ST_BIND
3638
#define ELF_ST_TYPE ELF64_ST_TYPE

0 commit comments

Comments
 (0)