size_report: Use the CMake-discovered toolchain instead of ENV vars

size_report was using the environment variables NM and OBJDUMP to find
it's toolchain dependencies. It is not clear how well this will work
on different platforms; OSX, Windows. So we now pass the paths of
these dependencies from the build system to the script.

PS: This ensures that size_report uses the cross-compiler's GNU bin
tool instead of the host GNU bin tools. This is presumably beneficial
as it has been required for other GNU bin tools like GDB.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
Sebastian Bøe 2017-12-12 10:50:05 +01:00 committed by Anas Nashif
parent 47595b1c10
commit c87d262295
3 changed files with 11 additions and 7 deletions

View File

@ -7,6 +7,8 @@ foreach(report ram_report rom_report)
${PYTHON_EXECUTABLE}
$ENV{ZEPHYR_BASE}/scripts/footprint/size_report
${flag_for_${report}}
--objdump ${CMAKE_OBJDUMP}
--nm ${CMAKE_NM}
-o ${PROJECT_BINARY_DIR}
DEPENDS ${logical_target_for_zephyr_elf}
)

View File

@ -9,6 +9,7 @@ set(CMAKE_AR ${CROSS_COMPILE}ar CACHE INTERNAL " " FORCE)
set(CMAKE_RANLILB ${CROSS_COMPILE}ranlib CACHE INTERNAL " " FORCE)
set(CMAKE_READELF ${CROSS_COMPILE}readelf CACHE INTERNAL " " FORCE)
set(CMAKE_GDB ${CROSS_COMPILE}gdb CACHE INTERNAL " " FORCE)
set(CMAKE_NM ${CROSS_COMPILE}nm CACHE INTERNAL " " FORCE)
assert_exists(CMAKE_READELF)

View File

@ -40,15 +40,18 @@ parser.add_option("-r", "--ram",
parser.add_option("-F", "--rom",
action="store_true", dest="rom", default=False,
help="print ROM statistics")
parser.add_option("-s", "--objdump", type="string", dest="bin_objdump",
help="Path to the GNU binary utility objdump")
parser.add_option("-n", "--nm", type="string", dest="bin_nm",
help="Path to the GNU binary utility nm")
(options, args) = parser.parse_args()
# Return a dict containing symbol_name: path/to/file/where/it/originates
# for all symbols from the .elf file. Optionnaly strips the path according
# to the passed sub-path
def load_symbols_and_paths(elf_file, path_to_strip = None):
def load_symbols_and_paths(bin_nm, elf_file, path_to_strip = None):
symbols_paths = {}
bin_nm = os.environ.get("NM", "nm")
nm_out = subprocess.check_output([bin_nm, elf_file, "-S", "-l", "--size-sort", "--radix=d"])
for line in nm_out.decode('utf8').split('\n'):
fields = line.replace('\t', ' ').split(' ')
@ -104,7 +107,7 @@ def get_footprint_from_bin_and_statfile(bin_file, stat_file, total_flash, total_
"percent_ram": total_percent_ram}
return res
def generate_target_memory_section(out, kernel_name, source_dir, features_json):
def generate_target_memory_section(bin_objdump, bin_nm, out, kernel_name, source_dir, features_json):
features_path_data = None
try:
features_path_data = json.loads(open(features_json, 'r').read())
@ -115,7 +118,6 @@ def generate_target_memory_section(out, kernel_name, source_dir, features_json):
elf_file_abs = os.path.join(out, kernel_name+'.elf')
# First deal with size on flash. These are the symbols flagged as LOAD in objdump output
bin_objdump = os.environ.get("OBJDUMP", "objdump")
size_out = subprocess.check_output([bin_objdump, "-hw", elf_file_abs])
loaded_section_total = 0
loaded_section_names = []
@ -137,7 +139,7 @@ def generate_target_memory_section(out, kernel_name, source_dir, features_json):
bin_size = os.stat(bin_file_abs).st_size
# Get the path associated to each symbol
symbols_paths = load_symbols_and_paths(elf_file_abs, source_dir)
symbols_paths = load_symbols_and_paths(bin_nm, elf_file_abs, source_dir)
# A set of helper function for building a simple tree with a path-like
# hierarchy.
@ -177,7 +179,6 @@ def generate_target_memory_section(out, kernel_name, source_dir, features_json):
# Extract the list of symbols a second time but this time using the objdump tool
# which provides more info as nm
bin_objdump = os.environ.get("OBJDUMP", "objdump")
symbols_out = subprocess.check_output([bin_objdump, "-tw", elf_file_abs])
flash_symbols_total = 0
data_nodes = {}
@ -334,7 +335,7 @@ if options.outdir and os.path.exists(binary):
fp = get_footprint_from_bin_and_statfile("%s/%s.bin" %(options.outdir, options.binary),
"%s/%s.stat" %(options.outdir,options.binary), 0, 0 )
base = os.environ['ZEPHYR_BASE']
ram, data = generate_target_memory_section(options.outdir, options.binary, base + '/', None)
ram, data = generate_target_memory_section(options.bin_objdump, options.bin_nm, options.outdir, options.binary, base + '/', None)
if options.rom:
print_tree(data, fp['total_flash'], options.depth)
if options.ram: