How to read nm output?

Here is my code:

int const const_global_init = 2; int const const_global; int global_init = 4; int global; static int static_global_init = 3; static int static_global; static int static_function(){ return 2; } double function_with_param(int a){ static int static_local_init = 3; static int static_local; return 2.2; } int main(){ } 

I generate main.o and I try to understand nm output. After I use nm main.o --printfile-name -a I get the following output:

 main.o:0000000000000000 b .bss main.o:0000000000000000 n .comment main.o:0000000000000004 C const_global main.o:0000000000000000 R const_global_init main.o:0000000000000000 d .data main.o:0000000000000000 r .eh_frame main.o:000000000000000b T function_with_param main.o:0000000000000004 C global main.o:0000000000000000 D global_init main.o:0000000000000027 T main main.o:0000000000000000 a main.c main.o:0000000000000000 n .note.GNU-stack main.o:0000000000000000 r .rodata main.o:0000000000000000 t static_function main.o:0000000000000000 b static_global main.o:0000000000000004 d static_global_init main.o:0000000000000004 b static_local.1733 main.o:0000000000000008 d static_local_init.1732 main.o:0000000000000000 t .text 

I realized the 2nd and 3rd column, but I really donโ€™t know what is in the first column, is it an address or a size? I know something about .bbs , .comment , .data and .text but what are .eh_frame , .note.GNU-stack and .rodata ?

+7
source share
1 answer

... I really don't know what is in the first column, whether it is an address or a size?

My local page (from man nm ) says

 DESCRIPTION GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out. For each symbol, nm shows: ยท The symbol value, in the radix selected by options (see below), or hexadecimal by default. 

that is, the first column is the "value" of the character. To understand what this means, itโ€™s useful to know something about ELF and the runtime linker, but overall itโ€™s just an offset in the corresponding section.

Understanding something about ELF will also help other points: man elf tells us that the .rodata section is .rodata -only data (that is: constant values โ€‹โ€‹that are hard-coded in a program that never change.).

.eh_frame used to handle exceptions and other metadata metadata of the call stack ( eh_frame search has this question as a first hit).

+3
source

Source: https://habr.com/ru/post/1247530/


All Articles