-
-
Save andyturk/3dcb7cd881ea8a79e63f to your computer and use it in GitHub Desktop.
makefile to extract symbol sizes from a .elf using sqlite3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifndef READELF | |
$(error report.mk: READELF must be defined (e.g., arm-none-eabi-readelf)) | |
endif | |
ifndef CPPFILT | |
$(error report.mk: CPPFILT must be defined (e.g., arm-none-eabi-c++filt)) | |
endif | |
define SQLITE3_DB | |
create table readelf ( | |
id int primary key, -- just an integer | |
value varchar(16), -- in hexadecimal, no leading 0x | |
size int, -- another int | |
type varchar(32), -- what kind of symol | |
binding varchar(32), -- how the symbol is used | |
visibility varchar(32), -- who can see it? | |
ndx int, -- no idea what this is | |
name varchar(500) -- the symbol name | |
); | |
-- for ARM Cortex-M, addresses in RAM will be 0x2000000 and up | |
-- search for them by using string pattern matching | |
create view ram as | |
select * from readelf | |
where value like "2_______" and type in ("OBJECT", "FUNC"); | |
create view flash as | |
select * from readelf | |
where value not like "2_______" and type in ("OBJECT", "FUNC"); | |
.mode csv | |
.separator "|" | |
.import $(<) readelf | |
.save $(basename $(@)).db | |
.exit | |
endef | |
export SQLITE3_DB | |
define SQLITE3_REPORT | |
.output $(@) | |
.mode columns | |
.headers on | |
.echo off | |
.width 0 0 80 | |
select sum(size) as "Total RAM Used" from ram; | |
select size, value, name as "Largest items in RAM" from ram order by size desc limit 50; | |
select sum(size) as "Total FLASH Used" from flash; | |
select size, value, name as "Largest items in FLASH" from flash order by size desc limit 50; | |
.exit | |
endef | |
export SQLITE3_REPORT | |
%_symbols.txt : %.elf | |
@echo Extracting symbol data from $(<) into $(@) | |
@$(READELF) -Ws $(<) > $(@) | |
%_symbols.csv : %_symbols.txt | |
@echo Converting to $(@) | |
@egrep -e "^[ \t]+[0-9]+" < $(<) | sed -e "s/:/ /" -e "s/ */|/g" -e "s/^|//" | $(CPPFILT) > $(@) | |
%_symbols.db : %_symbols.csv | |
@echo Creating $(@) | |
@echo "$$SQLITE3_DB" | sqlite3 | |
%.report : %.db | |
@echo Generating $(@) | |
@echo "$$SQLITE3_REPORT" | sqlite3 $(<) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment