objtool: Fix off-by-one in symbol_by_offset()
PATCH 1/1 objtool: Fix off-by-one in symbol_by_offset()
Sometimes, WARN_FUNC() and other users of symbol_by_offset() will associate the first instruction of a symbol with the symbol preceding it.
This is because symbol->offset + symbol->len is already outside of the symbol's range.
--- tools/objtool/elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/elf.c +1 -1
@@ -105,7 +105,7 @@ static int symbol_by_offset(const void *key, const struct rb_node *node)if (*o < s->offset)return -1 ; -if (*o > s->offset + s->len) +if (*o >= s->offset + s->len)return 1 ;return 0 ;
Signature · 1 line
2.21.1
Quoted 16 lines · Julien Thierry
Sometimes,
WARN_FUNC()and other users ofsymbol_by_offset()will associate the first instruction of a symbol with the symbol preceding it.
This is becausesymbol->offset+symbol->lenis already outside of the symbol's range.Signed-off-by Julien Thierry <[email protected]>--- tools/objtool/elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/objtool/elf.c +0
-0
tools/objtool/elf.c static int symbol_by_offset(const void *key, const struct rb_node *node) · line 111
Quoted 8 lines
tools/objtool/elf.c +1
-1@@ -105,7 +105,7 @@ static int symbol_by_offset(const void *key, const struct rb_node *node)if (*o < s->offset)return -1 ; -if (*o > s->offset + s->len) +if (*o >= s->offset + s->len)return 1 ;return 0 ;
Thanks - looks like this fixes 2a362ecc3ec9 ("objtool: Optimize find_symbol_*() and read_symbols()").
Signature · 1 line
Josh
Quoted 7 lines · Julien Thierry
Sometimes,
WARN_FUNC()and other users ofsymbol_by_offset()will associate the first instruction of a symbol with the symbol preceding it.
This is becausesymbol->offset+symbol->lenis already outside of the symbol's range.Signed-off-by Julien Thierry <[email protected]>