elf - 如何解释elf符号表部分的st_info字段

标签 elf symbol-table

man page有话要说:

st_info   This  member  specifies  the  symbol's   type   and   binding
             attributes:

             STT_NOTYPE  The symbol's type is not defined.

             STT_OBJECT  The symbol is associated with a data object.

             STT_FUNC    The symbol is associated with a function or other
                         executable code.

             STT_SECTION The symbol is associated with a section.   Symbol
                         table  entries  of  this type exist primarily for
                         relocation and normally have STB_LOCAL bindings.

             STT_FILE    By convention, the symbol's name gives  the  name
                         of  the  source  file  associated with the object
                         file.  A file symbol has STB_LOCAL bindings,  its
                         section  index  is  SHN_ABS,  and it precedes the
                         other STB_LOCAL symbols of the  file,  if  it  is
                         present.

             STT_LOPROC  This  value  up  to  and  including STT_HIPROC is
                         reserved for processor-specific semantics.

             STT_HIPROC  This value down to and  including  STT_LOPROC  is
                         reserved for processor-specific semantics.

             STB_LOCAL   Local  symbols are not visible outside the object
                         file containing their definition.  Local  symbols
                         of  the  same  name  may  exist in multiple files
                         without interfering with each other.

             STB_GLOBAL  Global symbols are visible to  all  object  files
                         being  combined.   One  file's  definition  of  a
                         global  symbol  will   satisfy   another   file's
                         undefined reference to the same symbol.

             STB_WEAK    Weak  symbols  resemble global symbols, but their
                         definitions have lower precedence.

             STB_LOPROC  This value up  to  and  including  STB_HIPROC  is
                         reserved for processor-specific semantics.

             STB_HIPROC  This  value  down  to and including STB_LOPROC is
                         reserved for processor-specific semantics.

                         There are macros for packing  and  unpacking  the
                         binding and type fields:

                         ELF32_ST_BIND(info)     or    ELF64_ST_BIND(info)
                         extract a binding from an st_info value.

                         ELF32_ST_TYPE(info) or ELF64_ST_TYPE(info)
                         extract a type from an st_info value.

                         ELF32_ST_INFO(bind, type) or  ELF64_ST_INFO(bind,
                         type)
                         convert  a  binding  and  a  type into an st_info
                         value.

问题是 STT_* 的值和 STB_*重叠。这是 uapi/linux/elf.h 中这些值的声明:
#define STB_LOCAL  0
#define STB_GLOBAL 1
#define STB_WEAK   2

#define STT_NOTYPE  0
#define STT_OBJECT  1
#define STT_FUNC    2
#define STT_SECTION 3
#define STT_FILE    4
#define STT_COMMON  5
#define STT_TLS     6

我想我理解 STB_*值为“绑定(bind)”和STT+*是“类型”,但由于值重叠,给定一个符号表,我怎么知道如何解释这个字段?

最佳答案

how can I tell how to interpret this field?



使用ELF{32,64}_ST_BINDELF{32,64}_ST_TYPE要拆分的宏 st_info到它的组成部分。

查看 /usr/include/elf.h .你会发现类似的东西:
/* How to extract and insert information held in the st_info field.  */
#define ELF32_ST_BIND(val) ...
#define ELF32_ST_TYPE(val) ...

... etc.

关于elf - 如何解释elf符号表部分的st_info字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48181509/

相关文章:

linux - 全局偏移表结构

linux - 判断 elf 文件是可执行文件还是库文件

java - pass1汇编器的符号表

c++ - 在符号表中记录所有权

elf - 如何将ELF文件转换为二进制文件?

更改linux二进制elf文件中的strcpy参数

java - Java 是否有不明确的语法,需要有关标识符的更多信息?

javascript - JavaScript 是否有类似于 php list 命令的语言结构?

使用GDB调试无法查找D程序符号

c - 'names' 字符串在使用 'Symbol' 结构进行 qsort 后消失