From c87d262295d9cf119677d23b10917a41ae364bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Tue, 12 Dec 2017 10:50:05 +0100 Subject: [PATCH] size_report: Use the CMake-discovered toolchain instead of ENV vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmake/reports/CMakeLists.txt | 2 ++ cmake/toolchain-gcc.cmake | 1 + scripts/footprint/size_report | 15 ++++++++------- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmake/reports/CMakeLists.txt b/cmake/reports/CMakeLists.txt index 3f65bfc42bb..521bfed76fa 100644 --- a/cmake/reports/CMakeLists.txt +++ b/cmake/reports/CMakeLists.txt @@ -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} ) diff --git a/cmake/toolchain-gcc.cmake b/cmake/toolchain-gcc.cmake index 475a1f50544..e81282c29c5 100644 --- a/cmake/toolchain-gcc.cmake +++ b/cmake/toolchain-gcc.cmake @@ -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) diff --git a/scripts/footprint/size_report b/scripts/footprint/size_report index d99c0dd1d8b..1b44ddc4d9c 100755 --- a/scripts/footprint/size_report +++ b/scripts/footprint/size_report @@ -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: