c - 如何从ELF中获取COMDAT符号?

标签 c elf

我正在尝试获取某个部分的 COMDAT 符号,我阅读了 ELF 格式文档,但不知道如何做到这一点。

如何识别它是 COMDAT 部分并获取它的符号?

我的代码:

typedef struct
{
   unsigned char    e_ident[EI_NIDENT]; /* Magic number and other info */
   Elf32_Half   e_type;         /* Object file type */
   Elf32_Half   e_machine;      /* Architecture */
   Elf32_Word   e_version;      /* Object file version */
   Elf32_Addr   e_entry;        /* Entry point virtual address */
   Elf32_Off    e_phoff;        /* Program header table file offset */
   Elf32_Off    e_shoff;        /* Section header table file offset */
   Elf32_Word   e_flags;        /* Processor-specific flags */
   Elf32_Half   e_ehsize;       /* ELF header size in bytes */
   Elf32_Half   e_phentsize;        /* Program header table entry size */
   Elf32_Half   e_phnum;        /* Program header table entry count */
   Elf32_Half   e_shentsize;        /* Section header table entry size */
   Elf32_Half   e_shnum;        /* Section header table entry count */
   Elf32_Half   e_shstrndx;     /* Section header string table index */
} Elf32_Ehdr;

typedef struct
{
   Elf32_Word   sh_name;        /* Section name (string tbl index) */
   Elf32_Word   sh_type;        /* Section type */
   Elf32_Word   sh_flags;       /* Section flags */
   Elf32_Addr   sh_addr;        /* Section virtual addr at execution */
   Elf32_Off    sh_offset;      /* Section file offset */
   Elf32_Word   sh_size;        /* Section size in bytes */
   Elf32_Word   sh_link;        /* Link to another section */
   Elf32_Word   sh_info;        /* Additional section information */
   Elf32_Word   sh_addralign;       /* Section alignment */
   Elf32_Word   sh_entsize;     /* Entry size if section holds table */
} Elf32_Shdr;

typedef struct
   {
       Elf32_Word   st_name;        /* Symbol name (string tbl index) */
       Elf32_Addr   st_value;       /* Symbol value */
       Elf32_Word   st_size;        /* Symbol size */
       unsigned char    st_info;        /* Symbol type and binding */
       unsigned char    st_other;       /* Symbol visibility */
       Elf32_Section    st_shndx;       /* Section index */
   } Elf32_Sym;

最佳答案

我可以回答第一个问题COMDAT部分的识别。 COMDAT 部分可以通过其相关部分名称来识别,即 sh_name

COMDAT 部分

COMDAT 节由其节名 (sh_name) 唯一标识。如果链接编辑器遇到具有相同节名称的 SHT_SUNW_COMDAT 类型的多个节,则保留第一个节,并丢弃其余节。应用于已丢弃的 SHT_SUNW_COMDAT 节的任何重定位都将被忽略。丢弃部分中定义的任何符号都将被删除。 http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter7-11598.html定义 COMDAT 如下(复制后不进行更改)

此外,链接编辑器支持节命名约定,当使用 -xF 选项调用编译器时,该约定用于节重新排序。如果函数放置在名为 .sectname%funcname 的 SHT_SUNW_COMDAT 节中,则保留的最终 SHT_SUNW_COMDAT 节将合并到名为 .sectname 的节中。此方法可用于将 SHT_SUNW_COMDAT 部分放入 .text、.data 或任何其他部分作为其最终目标。

关于c - 如何从ELF中获取COMDAT符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31945611/

相关文章:

c - 为什么我的 .c 文件无法识别我的头文件? 2 个错误,XCode

c - 在 shiny 中使用 .C

c - 用于开发最新的 Linux 上游(内核、Gnome 等)软件包的良好 Linux 发行版(和方法)是什么?

从 LibreOffice Basic 调用 C 共享库函数

c - 如何通过管道传输到 ffmpeg RGB 值 10?

linux - 静态 Sprite 图像设置的段 %fs 在哪里?

检查 elf 可执行文件是否在 UNIX 上使用 GUI 或 CUI 运行

c++ - `-fno-semantic-interposition` 与 `-fvisibility=protected` 究竟有何不同?

c++ - 如何对 Linux 共享库进行签名?

c - 用于修改 ELF 二进制文件动态部分的工具