How to report the memory usage of the code?

You can use -Wl,--print-memory-usage option to print a summary of memory usage after linking.