什么是符号表?
有人可以描述一下 C 和 C++ 上下文中的符号表是什么吗?
Can someone describe what a symbol table is within the context of C and C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有人可以描述一下 C 和 C++ 上下文中的符号表是什么吗?
Can someone describe what a symbol table is within the context of C and C++?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
这里的符号表有两个常见且相关的含义。
首先,目标文件中有符号表。 通常,C 或 C++ 编译器将单个源文件编译为扩展名为 .obj 或 .o 的目标文件。 它包含链接器可以将其处理为工作应用程序或共享库的可执行代码和数据的集合。 目标文件中有一个称为符号表的数据结构,它将目标文件中的不同项映射到链接器可以理解的名称。 如果您从代码中调用函数,编译器不会将例程的最终地址放入目标文件中。 相反,它将一个占位符值放入代码中,并添加一条注释,告诉链接器从它正在处理的所有目标文件中查找各种符号表中的引用,并将最终位置粘贴在那里。
其次,共享库或 DLL 中还有符号表。 它由链接器生成,用于命名库用户可见的所有函数和数据项。 这允许系统进行运行时链接,将对这些名称的开放引用解析为库在内存中加载的位置。
如果您想了解更多信息,我建议 John Levine 的优秀书籍 链接器和加载器。
There are two common and related meaning of symbol tables here.
First, there's the symbol table in your object files. Usually, a C or C++ compiler compiles a single source file into an object file with a .obj or .o extension. This contains a collection of executable code and data that the linker can process into a working application or shared library. The object file has a data structure called a symbol table in it that maps the different items in the object file to names that the linker can understand. If you call a function from your code, the compiler doesn't put the final address of the routine in the object file. Instead, it puts a placeholder value into the code and adds a note that tells the linker to look up the reference in the various symbol tables from all the object files it's processing and stick the final location there.
Second, there's also the symbol table in a shared library or DLL. This is produced by the linker and serves to name all the functions and data items that are visible to users of the library. This allows the system to do run-time linking, resolving open references to those names to the location where the library is loaded in memory.
If you want to learn more, I suggest John Levine's excellent book Linkers and Loaders.
摘自《计算机系统程序员的视角》一书,第 7 章链接。 “符号和符号表”:
以及重要说明(形成同一章):
From the "Computer Systems A Programmer’s Perspective" book, Ch 7 Linking. "Symbols and Symbol Tables":
And important note (form the same chapter):
符号表是程序/单元中“符号”的列表。 符号通常是变量或函数的名称。 符号表可用于确定变量或函数在内存中的位置。
The symbol table is the list of "symbols" in a program/unit. Symbols are most often the names of variables or functions. The symbol table can be used to determine where in memory variables or functions will be located.
查看 符号表 维基百科条目:
Check out the Symbol Table wikipedia entry:
符号表是编译器创建和维护的重要数据结构,用于存储变量名、函数名、对象、类、接口等各种实体出现的信息。
Symbol table is an important data structure created and maintained by compilers in order to store information about the occurrence of various entities such as variable names, function names, objects, classes, interfaces, etc.
在Linux中,可以使用命令:
列出该目标文件的符号表。 从此打印输出中,您可以从损坏的名称中破译正在使用的链接器符号。
In Linux, you can use command:
to list the symbol table of that object file. From this printout, you may then decipher the in-use linker symbols from their mangled names.
简而言之,它是将变量分配的名称到其在内存中的地址的映射,包括类型、范围和大小等元数据。 它由编译器使用。
这是一般情况,而不仅仅是 C[++]*。 从技术上讲,它并不总是包含直接内存地址。 这取决于编译器的目标语言、平台等。
Briefly, it is the mapping of the name you assign a variable to its address in memory, including metadata like type, scope, and size. It is used by the compiler.
That's in general, not just C[++]*. Technically, it doesn't always include direct memory address. It depends on what language, platform, etc. the compiler is targeting.