Skip to content

Instantly share code, notes, and snippets.

@Silva97
Silva97 / get-function-size.c
Created July 11, 2021 15:45
Just an example of how to get the size of a function in bytes using the GCC compiler
// See how it's works using: gcc -S get-function-size.c -o get-function-size.s
// To manually check function size: objdump -d get-function-size
#include <stdio.h>
#define DECLARE_FUNCSIZE(funcname) \
extern unsigned int funcname##_funcsize; \
asm(#funcname "_funcsize: .long . - " #funcname "\n\t")
#define FUNCSIZE(funcname) \
funcname##_funcsize