gpt4 book ai didi

c - 来自对象符号表的结构成员详细信息

转载 作者:太空宇宙 更新时间:2023-11-04 11:04:56 24 4
gpt4 key购买 nike

试图在 linux 中使用 objdump 命令来显示可执行文件中的符号表信息。我在下面尝试了一个简单的程序。

#include<stdio.h>
int global = 0;
typedef struct global_struct{
int a;
int c;
}global_struct;

global_struct gs;
int main()
{
printf("%d\n",global);
printf("%d\n",gs.a);
return 0;
}

在 gcc 编译器中使用 -g 选项编译objdump 的输出看起来像

00000000004005b0 l     F .text  0000000000000000              __do_global_ctors_aux0000000000000000 l    df *ABS*  0000000000000000              symboltable.c0000000000600870 l     O .got.plt       0000000000000000              _GLOBAL_OFFSET_TABLE_00000000006006ac l       .ctors 0000000000000000              __init_array_end00000000006006ac l       .ctors 0000000000000000              __init_array_start00000000006006d8 l     O .dynamic       0000000000000000              _DYNAMIC0000000000600898  w      .data  0000000000000000              data_start00000000006008b4 g     O .bss   0000000000000008              gs0000000000000000       F *UND*  0000000000000000              printf@@GLIBC_2.2.50000000000400510 g     F .text  0000000000000002              __libc_csu_fini00000000004003e0 g     F .text  0000000000000000              _start0000000000000000  w      *UND*  0000000000000000              __gmon_start__0000000000000000  w      *UND*  0000000000000000              _Jv_RegisterClasses00000000004005e8 g     F .fini  0000000000000000              _fini0000000000000000       F *UND*  0000000000000000              __libc_start_main@@GLIBC_2.200000000006008b0 g     O .bss   0000000000000004              global00000000004005f8 g     O .rodata        0000000000000004              _IO_stdin_used0000000000600898 g       .data  0000000000000000              __data_start0000000000400600 g     O .rodata        0000000000000000              .hidden __dso_handle00000000006006c8 g     O .dtors 0000000000000000              .hidden __DTOR_END__0000000000400520 g     F .text  0000000000000089              __libc_csu_init000000000060089c g       *ABS*  0000000000000000              __bss_start00000000006008c0 g       *ABS*  0000000000000000              _end

我的要求是gs是C结构,我想知道gs{a,b}的数据成员。我如何从目标文件中知道结构成员的详细信息。感谢您的支持

最佳答案

目标文件中没有详细说明结构成员的详细信息。目标文件将只分配足够的内存来保存结构和一个偏移量,告诉链接器在哪里找到它。

编译器在编译时知道基结构指针的偏移量以找到成员,并在每次使用时将它们硬编码到程序文本中。

关于c - 来自对象符号表的结构成员详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25666692/

24 4 0
文章推荐: python - 使用 minidom 获取指定 中的 HTML 链接