The motivation behind this post is to investigate that which sections variables belong to, i.e. a global variable, static local variable, a constant variable or a static const variable.The answer may vary from different situations due to different strategies adopted by compilers. Thus, this post is some guide about how to find the answers.

Short answer: the easiest way is probably to compile C/C++ code into assemble code using ‘gcc -S’. There are other tools that can be used to inspect object files to find more information, such as nm, objdump, and readelf.

  • nm – a handy utility to list symbols from object files
  • objdump – display information about object files
  • readelf  – read information of ELF file (the binary format in Unix/Linux system)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s