[allguysindni] Re: [allguysindni] Re: [allguysindni] Re: [allguysindni] 问个问题哈

  • From: new yang <newyearpretty@xxxxxxxxx>
  • To: allguysindni@xxxxxxxxxxxxx
  • Date: Wed, 3 Nov 2010 11:32:24 +0800

APUE里面这么说的,按照这个说法的话,那就是至少在编译的时候,不会去找共享库里边的全局变量。
> 是在load库的时候,把程序的data和bss段重新计算了?
>
> 现在,很多U N I X系统支持共享库。Arnold [1986] 说明了系统V上共享库的一个早期实现,G i n g e l l等[1987]
> 则说明了S u n O
> S上的另一个实现。共享库使得可执行文件中不再需要包含常用的库函数,而只需在所有进程都可存取的存储区中保存这种库例程的一个副本。程序第一次执行或者第一次调用某个库函数时,用动态连接方法将程序与共享库函数相连接。这减少了每个可执行文件的长度,但增加了一些运行时间开销。共享库的另一个优点是可以用库函数的新版本代替老版本而无需对使用该库的程序重新连接编辑。(假定参数的数目和类型都没有发生改变。)不同的系统使用不同的方法使说明程序是否要使用共享库。比较典型的有c
> c ( 1 )和l d ( 1 )命令
> 的可选项。作为长度方面发生变化的例子,下列可执行文件(典型的h e l l o . c程序)先用无共享库方式创建:
> $ ls -1 a.out
> -rwxrwxr-x 1 stevens 104859 Aug :2 52 a1.4out
> $ size a.out
> text data bss dec hex
> 49152 49152 0 98304 18000
> 如果我们再编译此程序使其使用共享库,则可执行文件的正文和数据段的长度都显著减小:
> $ ls -1 a.out
> -rwxrwxr-x 1 stevens 24576 Aug : 226 1a4.out
> $ size a.out
> text data bss dec hex
> 8192 8192 0 16384 4000
>
>
>
> 2010/11/3 Ender.Dai <ender.dai@xxxxxxxxx>
>
>> 2010/11/3 Ender.Dai <ender.dai@xxxxxxxxx>:
>> > 未初始化的全局变量在.bss
>> > 已初始化的全局变量在.data
>> >
>> > 共享库的.text在多个进程间共享,但是.bss和.data则是每个进程有自己的copy
>> >
>>
>> PS: .bss在目标文件中实际上并不存在,只是在elf头中标明有这个段,以及这个段的大小。
>>
>> > 2010/11/3 Pengfei Li <lpfwd007@xxxxxxxxx>:
>> >> 同求高人解答。
>> >> 晓光貌似还没加入邮件列表吧。
>> >>
>> >> 在 2010年11月3日 上午10:50,jun fang <apifan@xxxxxxxxx>写道:
>> >>>
>> >>> 应该是知道的吧,最起码知道它在动态链接库里把,但是还不知道具体在哪
>> >>> 求高人布道
>> >>>
>> >>> 2010/11/3 new yang <newyearpretty@xxxxxxxxx>
>> >>>>
>> >>>> 共享库里边定义的全局变量应该在什么地方,数据段还是?
>> >>>> 如果是数据段,那在编译的时候,其实应该是不知道有这个数据的吧?是在运行时,载入库的时候,加载上去的么?
>> >>>
>> >>
>> >>
>> >
>> >
>> >
>> > --
>> > Invent and fit; have fits and reinvent!
>> > We toast the Lisp programmer who pens his thoughts within nests of
>> parentheses.
>> >
>>
>>
>>
>> --
>> Invent and fit; have fits and reinvent!
>> We toast the Lisp programmer who pens his thoughts within nests of
>> parentheses.
>>
>
>

Other related posts: