繁体   English   中英

如何读取nm输出?

[英]How to read nm output?

那是我的代码:

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(){
}

我生成main.o并尝试理解nm输出。 在我使用nm main.o --printfile-name -a我得到了这个输出:

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

我理解第二和第三列但是,我真的不知道第一列是什么,无论是地址还是大小? 我知道关于.bbs.comment.data.text段的一些.bbs ,但它是什么.eh_frame.note.GNU-stack.rodata

...我真的不知道第一列是什么,无论是地址还是大小?

我的本地联机帮助页(来自man nm )说

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.

也就是说,第一列是符号的“值”。 要理解这意味着什么,了解ELF和运行时链接器是有帮助的,但通常它只是相关部分的偏移量。

了解ELF的一些内容也有助于解决其他问题: man elf告诉我们.rodata部分是只读数据(即:常量值硬编码到程序中,永远不会改变。字符串文字可能会在这里)。

.eh_frame用于异常处理和其他调用堆栈帧元数据(搜索eh_frame 将此问题作为第一个命中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM