From 0bdc12256ef7c35bb771aa7fa3124935b56aa5e6 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Mon, 22 Jan 2018 15:16:01 +1100 Subject: [PATCH] cmake: Add "size" target, update idf_size.py for different linker behaviour --- tools/cmake/idf_functions.cmake | 15 +++++++++++++++ tools/idf_size.py | 19 +++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/cmake/idf_functions.cmake b/tools/cmake/idf_functions.cmake index 101f8e10f..c6e2233b3 100644 --- a/tools/cmake/idf_functions.cmake +++ b/tools/cmake/idf_functions.cmake @@ -128,4 +128,19 @@ function(add_map_file exe_target) set(mapfile "${basename}.map") target_link_libraries(${exe_target} "-Wl,--gc-sections -Wl,--cref -Wl,--Map=${mapfile} -Wl,--start-group") set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${mapfile}") + + # add size targets, depend on map file, run idf_size.py + add_custom_target(size + DEPENDS ${exe_target} + COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py ${mapfile} + ) + add_custom_target(size-files + DEPENDS ${exe_target} + COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py --files ${mapfile} + ) + add_custom_target(size-components + DEPENDS ${exe_target} + COMMAND ${PYTHON} ${IDF_PATH}/tools/idf_size.py --archives ${mapfile} + ) + endfunction(add_map_file) diff --git a/tools/idf_size.py b/tools/idf_size.py index 1893082ff..d67cfa25a 100755 --- a/tools/idf_size.py +++ b/tools/idf_size.py @@ -82,7 +82,6 @@ def load_sections(map_file): is a dict with details about this section, including a "sources" key which holds a list of source file line information for each symbol linked into the section. """ scan_to_header(map_file, "Linker script and memory map") - scan_to_header(map_file, "END GROUP") sections = {} section = None sym_backup = None @@ -102,16 +101,24 @@ def load_sections(map_file): # source file line, ie # 0x0000000040080400 0xa4 /home/gus/esp/32/idf/examples/get-started/hello_world/build/esp32/libesp32.a(cpu_start.o) - RE_SOURCE_LINE = r"\s*(?P\S*).* +0x(?P
[\da-f]+) +0x(?P[\da-f]+) (?P.+\.a)\((?P.+\.o)\)" - - m = re.match(RE_SOURCE_LINE, line, re.M) + RE_SOURCE_LINE = r"\s*(?P\S*).* +0x(?P
[\da-f]+) +0x(?P[\da-f]+) (?P.+\.a)\((?P.+\.ob?j?)\)" + m = re.match(RE_SOURCE_LINE, line) + if not m: + # cmake build system links some object files directly, not part of any archive + RE_SOURCE_LINE = r".*? +0x(?P
[\da-f]+) +0x(?P[\da-f]+) (?P.+\.ob?j?)" + m = re.match(RE_SOURCE_LINE, line) if section is not None and m is not None: # input source file details sym_name = m.group("sym_name") if len(m.group("sym_name")) > 0 else sym_backup + try: + archive = m.group("archive") + except IndexError: + archive = "(exe)" + source = { "size" : int(m.group("size"), 16), "address" : int(m.group("address"), 16), - "archive" : os.path.basename(m.group("archive")), - "object_file" : m.group("object_file"), + "archive" : os.path.basename(archive)), + "object_file" : os.path.basename(m.group("object_file")), "sym_name" : sym_name, } source["file"] = "%s:%s" % (source["archive"], source["object_file"])