如何找出程序或其他库使用共享对象的哪些功能?在这种特定情况下,我想看看/lib/libgcc1_s.so.1中的哪些函数被其他动态库使用.由于它们是动态链接的,因此objdump -d不会解析函数调用地址.有没有办法在调试器中运行程序或静态重新链接?谢谢,
卢卡
编辑:
nm和readelf不会这样做,我不需要查看共享对象中存在哪些符号,但实际上在链接到它的其他对象中使用了哪些符号.
我最近在GNU ld中发现了链接器选项"-Bsymbolic-functions":
-Bsymbolic
When creating a shared library, bind references to global symbols to the
definition within the shared library, if any. Normally, it is possible
for a program linked against a shared library to override the definition
within the shared library.
This option is only meaningful on ELF platforms which support shared libraries.
-Bsymbolic-functions
When creating a shared library, bind references to global function symbols
to the definition within the shared library, if any.
This option is only meaningful …Run Code Online (Sandbox Code Playgroud) 有关良好的跨平台库的任何建议,以读取DWARF格式的ELF文件调试信息?我想在Python程序中阅读DWARF调试信息.
我刚刚阅读了ELF文件中的init和fini部分并尝试了一下:
#include <stdio.h>
int main(){
puts("main");
return 0;
}
void init(){
puts("init");
}
void fini(){
puts("fini");
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做gcc -Wl,-init,init -Wl,-fini,fini foo.c并运行结果,则不会打印"init"部分:
$ ./a.out
main
fini
Run Code Online (Sandbox Code Playgroud)
init部分没有运行,或者它无法以某种方式打印?
是否有关于init/fini的任何"官方"文档?
man ld 说:
-init=name
When creating an ELF executable or shared object, call
NAME when the executable or shared object is loaded, by
setting DT_INIT to the address of the function. By
default, the linker uses "_init" as the function to call.
Run Code Online (Sandbox Code Playgroud)
这不应该意味着,命名init函数就足够了_init吗?(如果我做gcc抱怨多重定义.)
有很多PE文件浏览器.如果您有兴趣,请列出好的列表:
PE文件格式查看器:
- PE Explorer http://www.pe-explorer.com/
- PE VIew:http: //www.magma.ca/~wjr/
- PEBrowse Professional http://www.smidgeonsoft.prohosting.com/pebrowse-pro-file-viewer.html
- PE浏览专业互动 - http://www.smidgeonsoft.prohosting.com/pebrowse-pro-interactive-debugger.html
我还在Windows上工作,我想查看ELF文件.有没有工具?我正在谷歌搜索,但直到现在都找不到.
我正在用gcc hello.c -o hello -O3编译这段代码
#include <stdio.h>
int main(void) {
printf("Hello world\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我列出我得到的重新安置时:
test@southpark$ readelf -r hello | grep gmon
080495a4 00000106 R_386_GLOB_DAT 00000000 __gmon_start__
080495b4 00000107 R_386_JUMP_SLOT 00000000 __gmon_start__
Run Code Online (Sandbox Code Playgroud)
当我列出这个文件中的符号时,我得到:
test@southpark$ readelf -s hello | grep gmon
1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
48: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Run Code Online (Sandbox Code Playgroud)
gmon_start与gprof有什么共同点吗?即使我没有使用-pg或-g编译/链接,为什么还要对该符号进行重定位?哪个库可以解析这个符号?
我试着更好地理解符号可见性.GCC Wiki(http://gcc.gnu.org/wiki/Visibility)有一节关于"C++异常问题".根据GCC Wiki,由于没有导出的异常,可能会出现运行时错误.没有编译时错误/警告的运行时错误是非常危险的,所以我试图更好地理解问题.我做了一些实验,但我仍然无法重现它.任何想法如何重现问题?
Wiki提到了三个库互相使用,所以我创建了三个小库.
我运行以下命令:
没有vtable的异常类(按预期工作):
make
./dsouser
Run Code Online (Sandbox Code Playgroud)
使用vtable的异常类但它不会导出(甚至不编译):
make HAS_VIRTUAL=1
Run Code Online (Sandbox Code Playgroud)
异常类导出vtable(按预期工作):
make HAS_VIRTUAL=1 EXCEPTION_VISIBLE=1
./dsouser
Run Code Online (Sandbox Code Playgroud)
Makefile文件:
CXX=g++-4.7.1
CFLAGS=-ggdb -O0 -fvisibility=hidden
ifdef EXCEPTION_VISIBLE
CFLAGS+=-DEXCEPTION_VISIBLE
endif
ifdef HAS_VIRTUAL
CFLAGS+=-DHAS_VIRTUAL
endif
all: dsouser
libmydso.so: mydso.cpp mydso.h
$(CXX) $(CFLAGS) -fPIC -shared -Wl,-soname,$@ -o $@ $<
libmydso2.so: mydso2.cpp mydso.h mydso2.h libmydso.so
$(CXX) $(CFLAGS) -L. -fPIC -shared -Wl,-soname,$@ -o $@ $< -lmydso
libmydso3.so: mydso3.cpp mydso.h mydso2.h mydso3.h libmydso2.so
$(CXX) $(CFLAGS) -L. -fPIC -shared -Wl,-soname,$@ -o $@ $< -lmydso -lmydso2
dsouser: dsouser.cpp …Run Code Online (Sandbox Code Playgroud) 我的意思是gcc是否可以将一些源代码版本infor插入到ELF二进制文件中作为部分或类似的东西.我不想更改我的源文件,但在Makefile中添加gcc选项的一些信息.
我写了一个小程序添加到整数和使用"readelf -a executable_name"它显示了elf标题中的入口点地址:
Entry point address: 0x8048330
Run Code Online (Sandbox Code Playgroud)
我的可执行文件如何事先知道这个地址,甚至在加载器加载到内存之前?elf_format.pdf表示该成员提供系统首先转移控制的虚拟地址,从而启动该过程.任何人都可以解释这句话的含义是什么,这里虚拟地址的含义是什么?
另请告诉我,可执行文件的值为0x8048330,作为入口点地址.只是为了交叉检查我编译了另一个程序,为此,入口点地址保持相同的值0x8048330(两种情况下.text部分的偏移量为0x330).
从我的书:
.bss段:
未初始化的全局C变量
共同:
尚未分配的未经初始化的数据对象
我不得不说,我看不出明显的区别.我甚至不太明白什么是无限制的,未分配的数据对象......似乎什么都没有.我使用GNU的readelf工具试着看一些简单的C代码,但找不到一个COMMON符号.我读过像FORTRAN的COMMON类型的东西是一个COMMON符号的例子 - 但我不知道FORTRAN
有人可以为我区分这两个吗?如果可能的话,希望用C的例子?非常感激.
编辑:从这篇文章中,变量c在这里:
int c;
int main() {} ...
Run Code Online (Sandbox Code Playgroud)
应该是COMMON.但是使用objdump -t节目给我说c在.bss中......
困惑