亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1986 | 回復(fù): 5
打印 上一主題 下一主題

怎么理解APUE2里對BSS的描述? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-06-06 23:09 |只看該作者 |倒序?yàn)g覽
Note from Figure 7.6 that the contents of the uninitialized data segment are not stored in the program file on disk. This is because the kernel sets it to 0 before the program starts running. The only portions of the program that need to be saved in the program file are the text segment and the initialized data.

The size(1) command reports the sizes (in bytes) of the text, data, and bss segments. For example:

    $ size /usr/bin/cc /bin/sh
       text     data   bss     dec     hex   filename
      79606     1536   916   82058   1408a   /usr/bin/cc
     619234    21120 18260  658614   a0cb6   /bin/sh



The fourth and fifth columns are the total of the three sizes, displayed in decimal and hexadecimal, respectively.

========================================
我怎么覺得暈暈的,例子里的兩個(gè)bin文件中不是有bss段嗎?

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2007-06-06 23:18 |只看該作者
想明白了,size給的是空間的大小,APUE里說的應(yīng)該是這段空間的內(nèi)容并沒有放在磁盤文件中。


====
[xxxxx@xx tmp]$ cat helloworld.c
#include <stdio.h>
int tmp[1000]={0};
int
main ()
{
  //int i;
  printf ("Hello world.\n");
  return 0;
}
[xxxxx@xx tmp]$ make helloworld   
cc     helloworld.c   -o helloworld
[xxxxx@xx tmp]$ size helloworld
   text    data     bss     dec     hex filename
    831     256    [red]4032[/red]    5119    13ff helloworld
========
編譯器把賦成0初值的全局變量放到BSS里了?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2007-06-06 23:22 |只看該作者
還有為啥多出來的是4032-4=4028?怎么不是1000*4?

注:4是沒加"int tmp[1000]={0};"時(shí)的bss size。

[xxxxx@xx tmp]$ cat helloworld.c
#include <stdio.h>
//int tmp[1000]={0};
int
main ()
{
  //int i;
  printf ("Hello world.\n");
  return 0;
}
[xxxxx@xx tmp]$ make helloworld  
cc     helloworld.c   -o helloworld
[xxxxx@xx tmp]$ size helloworld  
   text    data     bss     dec     hex filename
    831     256       4    1091     443 helloworld

論壇徽章:
95
程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-09-05 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-09-17 06:20:00程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-09-18 06:20:002015亞冠之阿爾艾因
日期:2015-09-18 10:35:08月度論壇發(fā)貼之星
日期:2015-09-30 22:25:002015亞冠之阿爾沙巴布
日期:2015-10-03 08:57:39程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-10-05 06:20:00每日論壇發(fā)貼之星
日期:2015-10-05 06:20:002015年亞冠紀(jì)念徽章
日期:2015-10-06 10:06:482015亞冠之塔什干棉農(nóng)
日期:2015-10-19 19:43:35程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-10-21 06:20:00每日論壇發(fā)貼之星
日期:2015-09-14 06:20:00
4 [報(bào)告]
發(fā)表于 2007-06-06 23:24 |只看該作者
原帖由 mjdcl 于 2007-6-6 23:18 發(fā)表
想明白了,size給的是空間的大小,APUE里說的應(yīng)該是這段空間的內(nèi)容并沒有放在磁盤文件中。


====
[xxxxx@xx tmp]$ cat helloworld.c
#include <stdio.h>
int tmp[1000]={0};
int
main ()
{
  / ...

不一定是全局變量,但肯定是和其有關(guān)的一些信息,例如需要占用多少空間等等。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2007-06-06 23:58 |只看該作者

  1. /**
  2. * 前兩個(gè)是初使化了的數(shù)據(jù)
  3. * 后兩個(gè)則是未初使化的數(shù)據(jù),對static的數(shù)據(jù)也是一樣.
  4. * 初始化的數(shù)據(jù)被存放在數(shù)據(jù)段,未初始化的則被放在bss.
  5. */
  6. char buffer[] = "This is a buffer";
  7. int array[] = {1, 3, 5, 7, 9};
  8. char info[256];
  9. int values[4];

  10. int main()
  11. {
  12.         info[0] = '1';
  13.         values[1] = 4;
  14.         return 0;
  15. }
復(fù)制代碼


用mingw, gcc -S getSize.c 產(chǎn)生的匯編代碼

  1.         .file        "getSize.c"
  2. .globl _buffer
  3.         .data          # 這里就是全局初始化了的數(shù)據(jù)
  4. _buffer:
  5.         .ascii "This is a buffer\0"
  6. .globl _array
  7.         .align 4
  8. _array:
  9.         .long        1
  10.         .long        3
  11.         .long        5
  12.         .long        7
  13.         .long        9
  14.         .def        ___main;        .scl        2;        .type        32;        .endef
  15.         .text
  16. .globl _main
  17.         .def        _main;        .scl        2;        .type        32;        .endef
  18. _main:
  19.         pushl        %ebp
  20.         movl        %esp, %ebp
  21.         subl        $8, %esp
  22.         andl        $-16, %esp
  23.         movl        $0, %eax
  24.         addl        $15, %eax
  25.         addl        $15, %eax
  26.         shrl        $4, %eax
  27.         sall        $4, %eax
  28.         movl        %eax, -4(%ebp)
  29.         movl        -4(%ebp), %eax
  30.         call        __alloca
  31.         call        ___main
  32.         movb        $49, _info
  33.         movl        $4, _values+4
  34.         movl        $0, %eax
  35.         leave
  36.         ret
  37.         .comm        _info, 256         # 256         這里就是未初始化的數(shù)據(jù).
  38.         .comm        _values, 16         # 16           這里的256和16表示的應(yīng)當(dāng)是數(shù)據(jù)對齊,你info gas確認(rèn)一下
復(fù)制代碼


初始化的數(shù)據(jù)占據(jù)空間,而對于未初始化的數(shù)據(jù),則只有等到程序開始執(zhí)行之后,對其初始化為0

至于多出來的應(yīng)當(dāng)時(shí)考慮數(shù)據(jù)對齊后的結(jié)果吧.

[ 本帖最后由 coldwarm 于 2007-6-6 23:59 編輯 ]

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2007-06-07 01:09 |只看該作者
你的編譯器是什么? behavior 不太對,f應(yīng)該在data段。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP