Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fudge factor from shoehorn #158

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cmake-tool/helpers/elf_sift.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ def get_memory_usage(elf_file: BinaryIO, align: bool) -> int:
the ELF object file `elf_file`.
"""

total: int = 0
elf = elftools.elf.elffile.ELFFile(elf_file)

# We only care about loadable segments (p_type is "PT_LOAD"), and we
# want the size in memory of those segments (p_memsz), which can be
# greater than the size in the file (p_filesz). This is especially
# important for the BSS section. See elf(5).
total = sum([seg['p_memsz'] for seg in elf.iter_segments()
if seg['p_type'] == 'PT_LOAD'])

# There may be gaps between segments; use the min+max vaddr of
# the loaded segments to calculate total usage.
min_vaddr = None
max_vaddr: int = 0
for seg in elf.iter_segments():
if seg['p_type'] == 'PT_LOAD':
if min_vaddr is None:
min_vaddr = seg['p_vaddr']
else:
min_vaddr = min(seg['p_vaddr'], min_vaddr)
max_vaddr = max(seg['p_vaddr'] + seg['p_memsz'], max_vaddr)

total: int = max_vaddr - min_vaddr
return get_aligned_size(total) if align else total


Expand Down
6 changes: 0 additions & 6 deletions cmake-tool/helpers/shoehorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ def main() -> int:
marker += elf_sift.get_memory_usage(elf, align=True)
debug_marker_set(marker, 'end of rootserver')

# Note: sel4test_driver eats (almost) 4 more MiB than it claims to.
# Fixing this is JIRA SELFOUR-2335.
fudge_factor = 4 * 1024 * 1024
marker += elf_sift.get_aligned_size(fudge_factor)
debug_marker_set(marker, 'end of (aligned) fudge factor')

image_start_address = marker

if (image_start_address + image_size) <= region['end']:
Expand Down