Shared Libraries: Understanding Dynamic Loading

questions:

when a executable starts,

1. how to resolve symbols in that are in shared library.

2. can we upgrade/replace shared lib when executable is running? (can we upgrade executable when it is running?)

3. do we need restart executable after we upgrade shared lib so it can use new lib?

4. do we need recompile executable with new shared lib?

answers:

1. when executable starts, the dynamic linker is firstly executed. The programs ld.so and ld-linux.so* (dynamic linker) find and load the shared objects (shared libraries) needed by a program, prepare the program to run, and then run it.

dynamic linker read ELF of executable, to determine which lib to load, where to find shared lib. Here is good article about it.

2. As here said (answered by Anders Waldenborg), we can if we do it right. we can first remove lib, then put the new lib. To note, the new lib is not used by running executable now, the old one is used and hasn't been deleted actually, please see the link for detail. For upgrade executable, we need first remove it and restart.

3. I think yes, we need a restart. As 1 suggests, the symbol is resolved at the beginning, before executable starts. So after a upgrade shared lib, it will not be mapped to executable until next symbol resolve which is when it starts.

4. I think no, and it's one of reasons to use shared libs. I remember I've upgrade shared libs to test without recompile executable.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值