在RPATH中指定$ ORIGIN的推荐GNU链接器选项是什么? [英] What are the recommended GNU linker options to specify $ORIGIN in RPATH?

查看:135
本文介绍了在RPATH中指定$ ORIGIN的推荐GNU链接器选项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的平台是使用GNU构建工具链(GCC等)的Vanilla(非嵌入式)x86-64 Linux.

Assume my platform is vanilla (non-embedded) x86-64 Linux using GNU build toolchain (GCC, etc.).

要在 RPATH 中指定 $ ORIGIN ,我知道链接器选项: -Wl,-rpath,'\ $ \ $ ORIGIN'.

To specify $ORIGIN in RPATH, I know about the linker option: -Wl,-rpath,'\$\$ORIGIN'.

今天,我发现了另一个选择: -Wl,-z,origin .

Today, I discovered another option: -Wl,-z,origin.

使用 -Wl,-rpath,'\ $ \ $ ORIGIN'时是否应该始终包含 -Wl,-z,origin ?

官方GNU ld文档,说:

标记该对象可能包含$ ORIGIN.

Marks the object may contain $ORIGIN.

相关但不同: https://stackoverflow.com/questions/33853271/what-are-the-recommended-gnu-linker-options-to-specify-rpath

推荐答案

我知道链接器选项: -Wl,-rpath,'\ $ \ $ ORIGIN'

您知道错:上面的选项将做您想要的.您需要的选项是 -Wl,-rpath ='$ ORIGIN'.区别:

You know wrong: above option will not do what you want. The option you want is -Wl,-rpath='$ORIGIN'. The difference:

echo "int main() { }" | gcc -xc - -Wl,-rpath,'\$\$ORIGIN' &&
readelf -d a.out | grep ORIGIN

 0x000000000000000f (RPATH)              Library rpath: [\$\$ORIGIN]

echo "int main() { }" | gcc -xc - -Wl,-rpath='$ORIGIN' &&
readelf -d a.out | grep ORIGIN

 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN]

我应该始终包含 -Wl,-z,origin

-Wl,-z,origin FLAGS_1 动态条目中设置 DF_ORIGIN .

从当前的GLIBC主干开始,什么都没有会查看该标志的值,因此,如果您以 GLIBC 为目标(大多数Linux程序都这样做),答案是:它不会不管是否使用 -z origin .

As of current GLIBC trunk, nothing looks at the value of that flag, so if you target GLIBC (most Linux programs do), the answer is: it doesn't matter one bit whether you use -z origin or not.

对于其他libc实现,答案可能有所不同.但是,Solaris libc(整个 $ ORIGIN 的来源)似乎也不需要设置 DF_ORIGIN ,因此完全忽略此设置可能是一个安全的选择.

The answer may be different for other libc implementations. However, Solaris libc (where the whole $ORIGIN is coming from) also does not appear to require the DF_ORIGIN to be set, so it's probably a safe bet to ignore this completely.

这篇关于在RPATH中指定$ ORIGIN的推荐GNU链接器选项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆