什么是符号表?

发布于 2024-07-04 14:47:50 字数 37 浏览 7 评论 0原文

有人可以描述一下 C 和 C++ 上下文中的符号表是什么吗?

Can someone describe what a symbol table is within the context of C and C++?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

幸福还没到 2024-07-11 14:47:50

这里的符号表有两个常见且相关的含义。

首先,目标文件中有符号表。 通常,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.

萌化 2024-07-11 14:47:50

摘自《计算机系统程序员的视角》一书,第 7 章链接。 “符号和符号表”:

符号表是有关函数和全局变量的信息
程序中定义并引用

以及重要说明(形成同一章):

重要的是要认识到本地链接器符号不相同
作为本地程序变量。 符号表不包含任何
与局部非静态程序变量相对应的符号。 这些
在运行时在堆栈上进行管理,并且不感兴趣
链接器

From the "Computer Systems A Programmer’s Perspective" book, Ch 7 Linking. "Symbols and Symbol Tables":

Symbol table is information about functions and global variables that
are defined and referenced in the program

And important note (form the same chapter):

It is important to realize that local linker symbols are not the same
as local program variables. The symbol table does not contain any
symbols that correspond to local nonstatic program variables. These
are managed at run time on the stack and are not of interest to the
linker

一个人的旅程 2024-07-11 14:47:50

符号表是程序/单元中“符号”的列表。 符号通常是变量或函数的名称。 符号表可用于确定变量或函数在内存中的位置。

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.

暮光沉寂 2024-07-11 14:47:50

查看 符号表 维基百科条目:

语言翻译器(例如编译器或解释器)使用的数据结构,其中程序源代码中的每个标识符(或符号)、常量、过程和函数都与其源代码中的声明或外观相关的信息相关联。< /p>

Check out the Symbol Table wikipedia entry:

data structure used by a language translator such as a compiler or interpreter, where each identifier (or symbol), constant, procedure and function in a program's source code is associated with information relating to its declaration or appearance in the source.

过气美图社 2024-07-11 14:47:50

符号表是编译器创建和维护的重要数据结构,用于存储变量名、函数名、对象、类、接口等各种实体出现的信息。

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.

待"谢繁草 2024-07-11 14:47:50

在Linux中,可以使用命令:

nm [目标文件]

列出该目标文件的符号表。 从此打印输出中,您可以从损坏的名称中破译正在使用的链接器符号。

In Linux, you can use command:

nm [object file]

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.

樱桃奶球 2024-07-11 14:47:50

简而言之,它是将变量分配的名称到其在内存中的地址的映射,包括类型、范围和大小等元数据。 它由编译器使用。

这是一般情况,而不仅仅是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文