如何链接到特定的 glibc 版本? [英] How can I link to a specific glibc version?

查看:77
本文介绍了如何链接到特定的 glibc 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Ubuntu Lucid 10.04 PC 上编译某些东西时,它会链接到 glibc.Lucid 使用 2.11 的 glibc.当我在另一台装有旧 glibc 的 PC 上运行这个二进制文件时,命令失败,说没有 glibc 2.11 ...

When I compile something on my Ubuntu Lucid 10.04 PC it gets linked against glibc. Lucid uses 2.11 of glibc. When I run this binary on another PC with an older glibc, the command fails saying there's no glibc 2.11...

据我所知,glibc 使用符号版本控制.我可以强制 gcc 链接到特定的符号版本吗?

As far as I know glibc uses symbol versioning. Can I force gcc to link against a specific symbol version?

在我的具体使用中,我尝试为 ARM 编译一个 gcc 交叉工具链.

In my concrete use I try to compile a gcc cross toolchain for ARM.

推荐答案

你说得对,glibc 使用了符号版本控制.如果您好奇,此处 中介绍了 glibc 2.1 中引入的符号版本控制实现,并且是here.

You are correct in that glibc uses symbol versioning. If you are curious, the symbol versioning implementation introduced in glibc 2.1 is described here and is an extension of Sun's symbol versioning scheme described here.

一种选择是静态链接您的二进制文件.这可能是最简单的选择.

One option is to statically link your binary. This is probably the easiest option.

您也可以在 chroot 构建环境中构建二进制文件,或使用 glibc-new =>glibc- 交叉编译器.

You could also build your binary in a chroot build environment, or using a glibc-new => glibc-old cross-compiler.

根据 http://www.trevorpounds.com 博客文章 链接到旧版本符号 (glibc),可以强制任何符号链接到旧版本,只要它是有效的使用相同的 .symver 伪操作,首先用于定义版本化符号.以下示例摘自 博客发布.

According to the http://www.trevorpounds.com blog post Linking to Older Versioned Symbols (glibc), it is possible to to force any symbol to be linked against an older one so long as it is valid by using the same .symver pseudo-op that is used for defining versioned symbols in the first place. The following example is excerpted from the blog post.

以下示例使用 glibc 的真实路径,但确保它链接到较旧的 2.2.5 版本.

The following example makes use of glibc’s realpath, but makes sure it is linked against an older 2.2.5 version.

#include <limits.h>
#include <stdlib.h>
#include <stdio.h>

__asm__(".symver realpath,realpath@GLIBC_2.2.5");
int main()
{
    const char* unresolved = "/lib64";
    char resolved[PATH_MAX+1];

    if(!realpath(unresolved, resolved))
        { return 1; }

    printf("%s
", resolved);

    return 0;
}

这篇关于如何链接到特定的 glibc 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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