From 52226ad920fc848927070561a96a931157764d5b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 15 Feb 2018 15:54:14 -0800 Subject: [PATCH] Fix injecting data into a .o file Use section.Offset instead of Addr. Test: symbol_inject -i test.o -o test2.o -s symbol -v value Change-Id: I9c54a5a245e7674b8370fc27ba7d0b9995f2ed08 --- cmd/symbol_inject/elf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/symbol_inject/elf.go b/cmd/symbol_inject/elf.go index 1741a5b07..12253f6af 100644 --- a/cmd/symbol_inject/elf.go +++ b/cmd/symbol_inject/elf.go @@ -56,7 +56,7 @@ func calculateElfSymbolOffset(file *elf.File, symbol elf.Symbol) (uint64, error) case elf.ET_REL: // "In relocatable files, st_value holds a section offset for a defined symbol. // That is, st_value is an offset from the beginning of the section that st_shndx identifies." - return file.Sections[symbol.Section].Addr + symbol.Value, nil + return section.Offset + symbol.Value, nil case elf.ET_EXEC, elf.ET_DYN: // "In executable and shared object files, st_value holds a virtual address. To make these // files’ symbols more useful for the dynamic linker, the section offset (file interpretation)