自定义ELF程序的动态加载器(program interpreter)
在做嵌入式移植时经常会遇到交叉编译工具链使用的动态加载器与目标硬件系统上的版本或者名字不一致,导致程序无法运行,出现“Text Busy” 之类的错误。
这时候要么就 ln -s lib64/ld-linux-x86-64.so.2 lib64/ld.xxxx.so 这种方式解决,要想永久解决,可以使用gcc 的Wl,-dynamic-linker 来指定ELF 的动态加载器。
例子如下:
gcc -Wl,-dynamic-linker,/lib64/ld-linux-x86-64.so.2
最近发现 -Wl,-dynamic-linker, 的方法对so 的编译好像没有效果,可以使用源码中指定的方法,如下:
const char ldpath[] __attribute__ ((section (".interp"))) = "/lib64/ld-linux-x86-64.so.2";

浙公网安备 33010602011771号