compare_sizes: fix with symlinks

This commit is contained in:
Théophile Bastian 2018-06-18 11:37:04 +02:00
parent 262d658674
commit 79dac37334
2 changed files with 29 additions and 4 deletions

View file

@ -9,7 +9,7 @@ import os
import subprocess import subprocess
from collections import namedtuple from collections import namedtuple
from shared_python import elf_so_deps from shared_python import elf_so_deps, readlink_rec
''' An ELF object, including the path to the ELF itself, and the path to its ''' An ELF object, including the path to the ELF itself, and the path to its
@ -92,6 +92,8 @@ def objects_list(args):
else: else:
objects = args.object objects = args.object
objects = list(map(readlink_rec, objects))
for obj in objects: for obj in objects:
out.append(ElfObject(obj, matching_eh_elf(args.eh_elfs, obj))) out.append(ElfObject(obj, matching_eh_elf(args.eh_elfs, obj)))
@ -118,6 +120,15 @@ def process_args():
return parser.parse_args() return parser.parse_args()
def get_or_default(obj, field, default=None):
''' Access a field of a subscriptable, returning a default if there is no
such field '''
if field not in obj:
return default
return obj[field]
def main(): def main():
args = process_args() args = process_args()
objs = objects_list(args) objs = objects_list(args)
@ -165,9 +176,13 @@ def main():
elf_sections = get_elf_sections(obj.elf) elf_sections = get_elf_sections(obj.elf)
eh_elf_sections = get_elf_sections(obj.eh_elf) eh_elf_sections = get_elf_sections(obj.eh_elf)
eh_frame_size = elf_sections['.eh_frame']['size'] eh_frame_size = get_or_default(
eh_elf_text_size = eh_elf_sections['.text']['size'] elf_sections, '.eh_frame', {'size': 0})['size']
eh_elf_size = eh_elf_text_size + eh_elf_sections['.rodata']['size'] eh_elf_text_size = get_or_default(
eh_elf_sections, '.text', {'size': 0})['size']
eh_elf_size = eh_elf_text_size + \
get_or_default(
eh_elf_sections, '.rodata', {'size': 0})['size']
total_eh_frame_size += eh_frame_size total_eh_frame_size += eh_frame_size
total_eh_elf_text_size += eh_elf_text_size total_eh_elf_text_size += eh_elf_text_size

View file

@ -6,6 +6,16 @@ import os
from collections import namedtuple from collections import namedtuple
def readlink_rec(path):
''' Returns the canonical path of `path`, resolving multiple layers of
symlinks '''
while os.path.islink(path):
path = os.path.join(
os.path.dirname(path),
os.readlink(path))
return path
def is_newer(file1, file2): def is_newer(file1, file2):
''' Returns True iff file1 is newer than file2 ''' ''' Returns True iff file1 is newer than file2 '''
try: try: