objtool expects symbol addresses to be offsets from the start of their
section, but in linked object files they are absolute. Subtract the
section's address when it is non-zero to get the section-relative
offset.

Signed-off-by: Shivang Upadhyay <[email protected]>
---
 tools/objtool/elf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index a791f4ea6ec1..493cb9f21dde 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -522,6 +522,12 @@ static int elf_add_symbol(struct elf *elf, struct symbol 
*sym)
                elf->num_files++;
 
        sym->offset = sym->sym.st_value;
+
+       // If section address is given (ex. linked objects), Remove it from
+       // symbol address.
+       if (sym->sec->sh.sh_addr)
+               sym->offset -= sym->sec->sh.sh_addr;
+
        sym->len = sym->sym.st_size;
 
        __sym_for_each(iter, &sym->sec->symbol_tree, sym->offset, sym->offset) {
-- 
2.56.1


Reply via email to