在AIX上与xlC进行链接:选择一个特定的库版本

huangapple go评论68阅读模式
英文:

Linking with xlC on AIX: Choose a specific library version

问题

我试图在AIX开发机上使用xlC编译器动态链接一个C++应用程序与libssl(和libcrypto),但问题是,开发机上安装的SSL版本与目标系统上安装的版本不同,开发机上的libssl版本为1.1,但目标系统上安装的版本为1.0.2。因此,在开发系统上执行应用程序的二进制文件正常工作,但在目标系统上启动应用程序失败,因为它试图加载较新的libssl.so.1.1,而该版本在目标系统上根本不存在:

exec(): 0509-036 由于以下错误无法加载程序/path/to/app:
        0509-150   无法加载依赖模块/usr/lib/libssl.a(libssl.so.1.1)。
        0509-152   在存档中未找到成员libssl.so.1.1

请注意,该应用程序不使用较新版本中定义的任何符号,因此应该能够在没有任何问题的情况下运行libssl.so.1.0.2。

我进行了一些研究,并了解到在AIX上,类似libssl.a的存档文件可以包含库的多个版本。这在我的开发机上的libssl.a上是这样的:

$ ar tv /usr/lib/libssl.a
rw-r--r--     0/0     728674 Sep 22 08:09 2022 libssl.so
rw-r--r--     0/0     510766 Sep 22 08:09 2022 libssl.so.0.9.8
rw-r--r--     0/0     728674 Sep 22 08:09 2022 libssl.so.1.0.0
rw-r--r--     0/0     728674 Sep 22 08:09 2022 libssl.so.1.0.2
rwxr-xr-x     0/0     1030429 Sep 22 08:10 2022 libssl.so.1.1

因此,通常情况下,libssl.so.1.0.2应该在开发机上可用。我无法确定编译器如何选择要链接的库的版本。我猜测它默认选择最新版本,但在这里我不太确定。

是否有可能告诉xlC编译器链接我的应用程序与特定版本的libssl?

英文:

I'm trying to dynamically link a C++ application with libssl (and libcrypto) on an AIX development machine using the xlC compiler. The problem is, that the SSL version installed on the development machine differs from the version installed on the target system in that libssl on the development machine has the version 1.1, but the target system has version 1.0.2 installed. So the execution of the application's binary on the development system works just fine, but the application fails to start on the target system since it tries to load the newer libssl.so.1.1 which simply does not exist there:

exec(): 0509-036 Cannot load program /path/to/app because of the following errors:
        0509-150   Dependent module /usr/lib/libssl.a(libssl.so.1.1) could not be loaded.
        0509-152   Member libssl.so.1.1 is not found in archive 

Note that the application doesn't make any use of symbols defined in the newer version and thus should be able to run with libssl.so.1.0.2 without any problems.

I did some research and understand that on AIX archive files like libssl.a can contain multiple versions of the library. This is the case for libssl.a on my development machine:

$ ar tv /usr/lib/libssl.a
rw-r--r--     0/0     728674 Sep 22 08:09 2022 libssl.so
rw-r--r--     0/0     510766 Sep 22 08:09 2022 libssl.so.0.9.8
rw-r--r--     0/0     728674 Sep 22 08:09 2022 libssl.so.1.0.0
rw-r--r--     0/0     728674 Sep 22 08:09 2022 libssl.so.1.0.2
rwxr-xr-x     0/0     1030429 Sep 22 08:10 2022 libssl.so.1.1

So in general libssl.so.1.0.2 should be available on the development machine. I wasn't able to determine how the compiler chooses the lib's version to link against. My guess is, it defaults to the newest version, but I'm not really sure here.

Is there any possibility to tell the xlC compiler to link my application with a specific version of libssl?

答案1

得分: 1

So in general libssl.so.1.0.2 should be available on the development machine.

通常情况下,开发机器上应该有 libssl.so.1.0.2

That is not the library you can link against.

这不是您可以链接的库。

I wasn't able to determine how the compiler chooses the lib's version to link against.

我无法确定编译器如何选择要链接的库版本。

Read about external library versioning here.

阅读有关外部库版本控制的信息在此处

You can not "just link" against libssl.1.0.2, you must recompile against headers matching that version, or you'll get random crashes due to ABI mismatch.

您不能只是链接到 libssl.1.0.2,您必须重新编译以匹配该版本的标头,否则由于ABI不匹配,您将遇到随机崩溃。

So what you have to do is download, compile and install (into a non-system location, say $HOME/libssl-1.0.2/) libssl-1.0.2, then rebuild all of your object files pointing to that location (using -I $HOME/libssl-1.0.2/include), and finally link against the installed 1.0.2 library (-L $HOME/libssl-1.0.2/lib -lssl).

因此,您需要下载、编译并安装(安装到非系统位置,例如 $HOME/libssl-1.0.2/libssl-1.0.2,然后重新构建所有对象文件,指向该位置(使用 -I $HOME/libssl-1.0.2/include),最后链接到已安装的1.0.2库(-L $HOME/libssl-1.0.2/lib -lssl)。

英文:

> So in general libssl.so.1.0.2 should be available on the development machine.

That is not the library you can link against.

> I wasn't able to determine how the compiler chooses the lib's version to link against.

Read about external library versioning here.

You can not "just link" against libssl.1.0.2, you must recompile against headers matching that version, or you'll get random crashes due to ABI mismatch.

So what you have to do is download, compile and install (into a non-system location, say $HOME/libssl-1.0.2/) libssl-1.0.2, then rebuild all of your object files pointing to that location (using -I $HOME/libssl-1.0.2/include), and finally link against the installed 1.0.2 library (-L $HOME/libssl-1.0.2/lib -lssl).

答案2

得分: 1

随机提示:看起来AIX链接器更喜欢在后面的存档成员共享对象之前解析符号。

在这种情况下,我怀疑较早的共享对象仅适用于加载兼容性。如果您链接到libssl的X版本,那么您应该加载X或更新版本。如果您的构建环境比运行环境更新,您需要一种方式来链接到库的最低运行环境版本(正如较早的帖子中所指示的那样)。

英文:

Random note: it appears the AIX linker prefers to resolve symbols in the first archive member shared object before the latter.

In this case, I suspect the earlier shared objects are load-only for load compatibility. If you link against version X of libssl then you should load against X or later. If your build environment is newer than your run environment, you need a way of linking against minimum run environment version of the library (as the earlier poster instructed.)

huangapple
  • 本文由 发表于 2023年6月16日 16:04:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76488148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定