在一个.so文件链接对老年人符号版本 [英] Linking against older symbol version in a .so file

查看:124
本文介绍了在一个.so文件链接对老年人符号版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在x86_64的Linux使用gcc和ld我需要对一个库的较新版本的链接(glibc的2.14),但执行需要用较旧版本(2.5)的系统上运行。由于唯一的不兼容符号的memcpy(需要memcpy@GLIBC_2.2.5但提供memcpy@GLIBC_2.14库),我想告诉大家,而不是采取了memcpy的默认版本,它应该采取一个旧版本我指定的链接

Using gcc and ld on x86_64 linux I need to link against a newer version of a library (glibc 2.14) but the executable needs to run on a system with an older version (2.5). Since the only incompatible symbol is memcpy (needing memcpy@GLIBC_2.2.5 but the library providing memcpy@GLIBC_2.14), I would like to tell the linker that instead of taking the default version for memcpy, it should take an old version I specify.

我发现了一个很arkward办法做到这一点:只需在链接器命令行指定旧.so文件的副本。这工作得很好,但我不喜欢有多个.so文件(我只能让它通过指定所有旧的图书馆我链接到也有引用memcpy的工作)住进了svn的想法和我的构建系统所需

I found a quite arkward way to do it: simply specify a copy of the old .so file at the linker command line. This works fine, but I don't like the idea of having multiple .so files (I could only make it work by specifying all old libraries I link to that also have references to memcpy) checked into the svn and needed by my build system.

所以,我正在寻找一种方式来告诉链接器把旧版本符号。

So I am searching for a way to tell the linker to take the old versioned symbol.

这不工作(井)对我来说是替代品:

Alternatives that don't work (well) for me are:


  • 使用ASM .symver(如看到 http://www.trevorpounds.com/blog/?p=103 ),因为这需要我,以确保symver命令是之前的所有code正在使用的memcpy,这将是非常困难(复杂codeBase的与第三方code)

  • 保持与老库的建设环境;只是因为我想我的桌面系统上开发,这将是对我们的网络中同步周围的东西皮塔。

  • Using asm .symver (as seen on http://www.trevorpounds.com/blog/?p=103) since this would require me to make sure the symver is before all the code that is using memcpy, which would be very hard (complex codebase with 3rd party code)
  • Maintaining a build environment with the old libraries; simply because I want to develop on my desktop system and it would be a pita to sync stuff around in our network.

在考虑全部链接程序的工作,它似乎并不像一个很难的事情来imlpement,毕竟它有一些code找出一个符号的默认版本了。

When thinking about all the jobs a linker does, it doesn't seem like a hard thing to imlpement, after all it has some code to figure out the default version of a symbol too.

这是在相同的复杂程度为简单的链接器命令行任何其他的想法(比如创建一个简单的链接脚本等)也欢迎,只要他们不喜欢编辑生成的二进制怪异的黑客...

Any other ideas that are on the same complexity level as a simple linker command line (like creating a simple linker script etc.) are welcome too, as long as they are not weird hacks like editing the resulting binary...

编辑:
为了节省这为未来的读者中,除了下面的想法,我发现选项 - 包装来的链接,这可能是有用的,有时太

edit: To conserve this for the future readers, additionally to the below ideas I found the option --wrap to the linker, which might be useful sometimes too.

推荐答案

只是链接静态MEMCPY - memcpy.o拉出的libc.a AR点¯x/path/to/libc.a memcpy.o的(任何版本 - 的memcpy是pretty多一个独立的功能),包括它在你的最后一个环节。需要注意的是静态链接可能会变得复杂的授权问题,如果你的项目被分配给公众,而不是开源。

Just link memcpy statically - pull memcpy.o out of libc.a ar x /path/to/libc.a memcpy.o (whatever version - memcpy is pretty much a standalone function) and include it in your final link. Note that static linking may complicate licensing issues if your project is distributed to the public and not open-source.

另外,你可以简单地自己实现的memcpy,虽然手动调整程序集版本glibc中很可能是更有效的。

Alternatively, you could simply implement memcpy yourself, though the hand-tuned assembly version in glibc is likely to be more efficient

注意 memcpy@GLIBC_2.2.5 映射到memmove与(在memcpy的持续复制旧版本一个predictable方向,这导致当应该使用memmove与它有时会被误用),这是版本凹凸的唯一原因 - 你可以简单地替换memmove与memcpy的在code为这个特定的情况下,

Note that memcpy@GLIBC_2.2.5 is mapped to memmove (old versions of memcpy consistently copied in a predictable direction, which led to it sometimes being misused when memmove should have been used), and this is the only reason for the version bump - you could simply replace memcpy with memmove in your code for this specific case.

或者你可以去静态链接,或者你可以确保你的网络上的所有系统都具有相同或更好的版本比你的构建机器。

Or you could go to static linking, or you could ensure that all systems on your network have the same or better version than your build machine.

这篇关于在一个.so文件链接对老年人符号版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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