Skip to content

Commit

Permalink
util/sim/elf.py: Handle symbols in .bss section
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Sep 28, 2023
1 parent eee8ee5 commit e62bb24
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions util/sim/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ def get_symbol_size(self, uid):
def get_symbol_contents(self, uid):
addr = self.get_symbol_address(uid)
size = self.get_symbol_size(uid)
fpos = list(self.elf.address_offsets(addr, size))[0]
self.elf.stream.seek(fpos)
return self.elf.stream.read(size)
try:
fpos = list(self.elf.address_offsets(addr, size))[0]
self.elf.stream.seek(fpos)
contents = self.elf.stream.read(size)
except IndexError:
# We assume all segments in our ELF are of type PT_LOAD and
# that the only section whose contents are not stored in
# the ELF file is the .bss section. Therefore, whenever
# `address_offsets()` fails to return a valid offset into the
# file we assume that the address falls in the .bss section.
contents = bytearray([0] * size)
return contents

0 comments on commit e62bb24

Please sign in to comment.