zoukankan      html  css  js  c++  java
  • 符号表 symbol table 符号 地址 互推

    https://zh.wikipedia.org/wiki/符号表

    https://en.wikipedia.org/wiki/Symbol_table

    计算机科学中,符号表是一种用于语言翻译器(例如编译器解释器)中的数据结构。在符号表中,程序源代码中的每个标识符都和它的声明或使用信息绑定在一起,比如其数据类型作用域以及内存地址

    实现

    散列表是用来实现符号表的一种常用技术。编译器可能会使用一个很大的符号表来包含所有的符号,或是针对不同的作用域使用层次结构的多个独立的符号表。

    使用

    目标文件中通常会有一个包含了所有外部可见标识符的符号表。在链接不同的目标文件时,链接器会使用这些文件中的符号表来解析所有未解析的符号引用。

    符号表可能只存在于翻译阶段,也可能被嵌入到该阶段的输出文件中,以供后续阶段使用。比如,它可用于交互式的调试器中,也可以在程序执行过程中或结束后提供格式化的诊断报告。

    在逆向工程中,许多任务具会通过符号表来检查全局变量和已知函数的地址。如果可执行文件的符号表被strip这样的工具去除掉了,则逆向工程会更加困难。

    在进行动态内存分配和变量访问时,编译器需要完成许多任务作,其中扩展的栈模型就需要用到符号表。

    示例

    下图是一个小程序的符号表。该表是用GNU Binutils中的nm工具生成的。其中有一个数据类型符号(由类型 "D" 表明)和许多函数(自己定义的以及标准库中的)。第一列是每个符号在内存中的位置,第二列是"符号类型",而第三列则是符号名称。通过传递适当的参数,可以按照地址顺序生成该符号表。

    Example table
    地址类型名称
    00000020 a T_BIT
    00000040 a F_BIT
    00000080 a I_BIT
    20000004 t irqvec
    20000008 t fiqvec
    2000000c t InitReset
    20000018 T _main
    20000024 t End
    20000030 T AT91F_US3_CfgPIO_useB
    2000005c t AT91F_PIO_CfgPeriph
    200000b0 T main
    20000120 T AT91F_DBGU_Printk
    20000190 t AT91F_US_TxReady
    200001c0 t AT91F_US_PutChar
    200001f8 T AT91F_SpuriousHandler
    20000214 T AT91F_DataAbort
    20000230 T AT91F_FetchAbort
    2000024c T AT91F_Undef
    20000268 T AT91F_UndefHandler
    20000284 T AT91F_LowLevelInit
    200002e0 t AT91F_DBGU_CfgPIO
    2000030c t AT91F_PIO_CfgPeriph
    20000360 t AT91F_US_Configure
    200003dc t AT91F_US_SetBaudrate
    2000041c t AT91F_US_Baudrate
    200004ec t AT91F_US_SetTimeguard
    2000051c t AT91F_PDC_Open
    2000059c t AT91F_PDC_DisableRx
    200005c8 t AT91F_PDC_DisableTx
    200005f4 t AT91F_PDC_SetNextTx
    20000638 t AT91F_PDC_SetNextRx
    2000067c t AT91F_PDC_SetTx
    200006c0 t AT91F_PDC_SetRx
    20000704 t AT91F_PDC_EnableRx
    20000730 t AT91F_PDC_EnableTx
    2000075c t AT91F_US_EnableTx
    20000788 T __aeabi_uidiv
    20000788 T __udivsi3
    20000884 T __aeabi_uidivmod
    2000089c T __aeabi_idiv0
    2000089c T __aeabi_ldiv0
    2000089c T __div0
    200009a0 D _data
    200009a0 A _etext
    200009a0 D holaamigosh
    200009a4 A __bss_end__
    200009a4 A __bss_start
    200009a4 A __bss_start__
    200009a4 A _edata
    200009a4 A _end

    In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier (a.k.a. symbol) in a program's source code is associated with information relating to its declaration or appearance in the source. In other words, the entries of a symbol table store the information related to the entry's corresponding symbol.

    Example

    Consider the following program written in C:

    // Declare an external function
    extern double bar(double x);
    
    // Define a public function
    double foo(int count)
    {
        double sum = 0.0;
    
        // Sum all the values bar(1) to bar(count)
        for (int i = 1; i <= count; i++)
            sum += bar((double) i);
        return sum;
    }
    

    A C compiler that parses this code will contain at least the following symbol table entries:

    Symbol nameTypeScope
    bar function, double extern
    x double function parameter
    foo function, double global
    count int function parameter
    sum double block local
    i int for-loop statement

    In addition, the symbol table will also contain entries generated by the compiler for intermediate expression values (e.g., the expression that casts the i loop variable into a double, and the return value of the call to function bar()), statement labels, and so forth.

    https://baike.baidu.com/item/符号表

    中文名
    符号表
    外文名
    The symbol table
    用    于
    语言翻译器
    属    性
    数据结构
    符号表在编译程序工作的过程中需要不断收集、记录和使用源程序中一些语法符号的类型和特征等相关信息。这些信息一般以表格形式存储于系统中。如常数表、变量名表、数组名表、过程名表、标号表等等,统称为符号表。对于符号表组织、构造和管理方法的好坏会直接影响编译系统的运行效率。
     
     
     
     
     
     

    debugging – 如何在GDB中获取内存地址的符号名称?

     
     
     
  • 相关阅读:
    LeetCode题解(2)-- Add Two Numbers
    LeetCode题解(1)--Two Sum
    STL review:vector & string & map & struct
    机器学习导论(一) 基本概念
    Single Number
    Single Number II
    Copy List with Random Pointer
    Word Break
    Populating Next Right Pointers in Each Node II
    Binary Tree Inorder Traversal
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9825721.html
Copyright © 2011-2022 走看看