Skip to content

Commit 4d181d6

Browse files
Jordan Yatesnashif
authored andcommitted
scripts: build: elf_parser: retrieve section directly
Retrieve the section holding the symbol data directly from the symbol information, instead of trying to find a section that contains data at the correct address. The later approach does not work for relocatable files, which contain multiple sections all containing data in overlapping temporary memory addresses (usually starting at 0). Signed-off-by: Jordan Yates <[email protected]>
1 parent 1767621 commit 4d181d6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

scripts/build/elf_parser.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,14 @@ def symbol_data(self, sym):
147147
"""
148148
Retrieve the raw bytes associated with a symbol from the elf file.
149149
"""
150+
# Symbol data parameters
150151
addr = sym.entry.st_value
151-
len = sym.entry.st_size
152-
for section in self.elf.iter_sections():
153-
start = section['sh_addr']
154-
end = start + section['sh_size']
155-
156-
if (start <= addr) and (addr + len) <= end:
157-
offset = addr - section['sh_addr']
158-
return bytes(section.data()[offset:offset + len])
152+
length = sym.entry.st_size
153+
# Section associated with the symbol
154+
section = self.elf.get_section(sym.entry['st_shndx'])
155+
offset = addr - section['sh_addr']
156+
# Extract bytes
157+
return bytes(section.data()[offset:offset + length])
159158

160159
def _symbols_find_value(self, names):
161160
symbols = {}

0 commit comments

Comments
 (0)