zoukankan      html  css  js  c++  java
  • 深入理解BSS(Block Started by Symbol)

    理解ELF的BSS section, 可以概括为:

    • Uninitialized global/static data
    • "Block Started by Symbol"
    • "Better Save Space"
    • Has section header but occupies no space

    CSAPP一书对bss的描述如下:

    .bss: 未被初始化的全局的C变量。这一节在o文件中不占实际的空间,只是一个place holder。o文件格式之所以区分初始化的变量和未被初始化的变量是因为处于空间利用率上的考虑。没有被初始化的变量确实没有必要占用实际的磁盘空间。

    关于"Better Save Space", 维基百科上是这么说的, (原文点这里

    Peter van der Linden, a C programmer and author, says, "Some people like to
    remember it as 'Better Save Space.' Since the BSS segment only holds variables
    that don't have any value yet, it doesn't actually need to store the image of
    these variables. The size that BSS will require at runtime is recorded in the
    object file, but BSS (unlike the data segment) doesn't take up any actual space
    in the object file."

    另外, 在Memory Layout of C Programs一文中,对BSS的描述如下:

    Uninitialized data segment, often called the “bss” segment, named after an 
    ancient assembler operator that stood for “block started by symbol.” Data 
    in this segment is initialized by the kernel to arithmetic 0 before the program 
    starts executing
    
    uninitialized data starts at the end of the data segment and contains all global 
    variables and static variables that are initialized to zero or 
    do not have explicit initialization in source code.
    
    For instance a variable declared static int i; would be contained in the BSS segment.
    For instance a global variable declared int j; would be contained in the BSS segment.

    这里明确了那些初始化为0的全局变量和静态变量也是被保存在bss中。 也就是说,bss包含:

    • 所有未被显示地初始化的全局变量和静态变量
    • 所有被显示地初始化为0的全局变量和静态变量
    1 If a variable declared static int i;     it would be contained in the BSS segment.
    2 If a global variable declared int j;     it would be contained in the BSS segment.
    3 If a variable declared static int i = 0; it would be contained in the BSS segment.
    4 If a global variable declared int j = 0; it would be contained in the BSS segment.
  • 相关阅读:
    Vue2.0 【第二季】第2节 Vue.extend构造器的延伸
    Vue2.0 【第二季】第1节 Vue.directive自定义指令
    Vue2.0 【第一季】第8节 v-pre & v-cloak & v-once
    Vue2.0 【第一季】第7节 v-bind指令
    c# tcp协议
    easyui笔记
    asp.net get中文传值乱码
    asp.net 调试,Web 服务器被配置为不列出此目录的内容。
    金蝶API 官方demo报错,解决方案
    hbuilder拍照上传,与asp.net服务器获取并保存
  • 原文地址:https://www.cnblogs.com/idorax/p/6400210.html
Copyright © 2011-2022 走看看