构建现代 (4.x) GCC 以在与主机相同的架构上运行 2.4.x 内核?

发布于 2024-12-12 01:50:14 字数 330 浏览 0 评论 0原文

问题相对简单:如何在与编译器主机相同的架构上构建 4.x 系列的 GCC(以及 binutils 和朋友),以 2.4 ABI 为目标?

主机系统将是 x86 或 x86_64,唯一的要求是只要 ABI 匹配,构建的 ELF 文件就可以在旧内核上运行。 (内核源代码/标头存在)

还需要兼容的 libc 才能链接它。但是,我也可以动态链接它,因为我知道 (g)libc 版本。

任何指示将不胜感激。我对 crosstool-ng 有点熟悉,但它似乎不再支持 2.4 内核(对于明显的原因)。

The question is relatively straight forward: how can I build a GCC of the 4.x series (along with binutils and friends) that targets a 2.4 ABI on the same architecture as the host for the compiler?

The host system would be x86 or x86_64 and the only requirement is that the built ELF files run on an old kernel as long as the ABI matches. (Kernel sources/headers exist)

A compatible libc would be required as well in order to link it in. However, I can dynamically link against it as well, since I know the (g)libc version.

Any pointers would be much appreciated. I'm somewhat familiar with crosstool-ng, but that doesn't even seem to support 2.4 kernels anymore (for obvious reasons).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感悟人生的甜 2024-12-19 01:50:15

最简单的方法可能是在旧操作系统上设置现代工具链。

RHEL 2.1 或 3 可能是最好的,因为直到最近才支持它们。

编译 gcc 4 可能很棘手,因为您还需要数学库。您可能需要采取多阶段方法。

编辑:

要编译较新的 gcc:

  1. 编译最新的 make - 添加到 PATH
  2. 解压 gcc
  3. 将 mpfr、gmp、mpc 解压到 gcc 目录中,
  4. 将版本目录符号链接到基础目录(mpfr、gmp、mpc)。
  5. 构建并安装 gcc

像这样:

cd ~/software
tar xjf $DOWNLOAD/gcc/gcc-core-${GCCVER}.tar.bz2 || failure "unpack gcc failed"
tar xjf $DOWNLOAD/gcc/gcc-g++-${GCCVER}.tar.bz2 || failure "unpack g++ failed"

cd gcc-${GCCVER}

tar xjf $DOWNLOAD/gmp-5.0.2.tar.bz2 || failure "unpack gmp failed"
#tar xjf $DOWNLOAD/gmp-4.3.2.tar.bz2 || failure "unpack gmp failed"
ln -s gmp-* gmp
tar xjf $DOWNLOAD/mpfr-2.4.2.tar.bz2 || failure "unpack mpfr failed"
#tar xjf $DOWNLOAD/mpfr-2.4.2.tar.bz2 || failure "unpack mpfr failed"
ln -s mpfr-* mpfr
tar xzf $DOWNLOAD/mpc-0.9.tar.gz || failure "unpack mpc failed"
ln -s mpc-* mpc

cd ..
mkdir gcc-build
cd gcc-build
../gcc-${GCCVER}/configure --prefix=/opt/tools || failure "configure failed"
make || failure "make failed"
make install || failure "install failed"

Probably the easiest way is to setup a modern tool chain on an old OS.

RHEL 2.1 or 3 might be best, as they were supported until recently.

Compiling gcc 4 may be tricky since you'll need maths libraries as well. You may have to do a multi-stage approach.

EDIT:

For compiling newer gcc:

  1. Compile latest make - add to PATH
  2. Unpack gcc
  3. Unpack mpfr, gmp, mpc into the gcc directory
  4. symlink the versioned directories to the base (mpfr, gmp, mpc).
  5. Build and install gcc

Something like this:

cd ~/software
tar xjf $DOWNLOAD/gcc/gcc-core-${GCCVER}.tar.bz2 || failure "unpack gcc failed"
tar xjf $DOWNLOAD/gcc/gcc-g++-${GCCVER}.tar.bz2 || failure "unpack g++ failed"

cd gcc-${GCCVER}

tar xjf $DOWNLOAD/gmp-5.0.2.tar.bz2 || failure "unpack gmp failed"
#tar xjf $DOWNLOAD/gmp-4.3.2.tar.bz2 || failure "unpack gmp failed"
ln -s gmp-* gmp
tar xjf $DOWNLOAD/mpfr-2.4.2.tar.bz2 || failure "unpack mpfr failed"
#tar xjf $DOWNLOAD/mpfr-2.4.2.tar.bz2 || failure "unpack mpfr failed"
ln -s mpfr-* mpfr
tar xzf $DOWNLOAD/mpc-0.9.tar.gz || failure "unpack mpc failed"
ln -s mpc-* mpc

cd ..
mkdir gcc-build
cd gcc-build
../gcc-${GCCVER}/configure --prefix=/opt/tools || failure "configure failed"
make || failure "make failed"
make install || failure "install failed"
自由如风 2024-12-19 01:50:15

我相信在这种情况下你可能应该构建一个 GCC 交叉编译器,并且你应该编译 GLibc 来处理对旧 2.4 内核的依赖。

但是,您是否只是尝试编译代码,然后将其与旧的 2.4 内核兼容的 Glibc 库链接起来?我想这应该可行。

您是否尝试在旧系统上运行二进制文件(使用最新的 GCC 在最新的系统上以简单的方式获得)?什么没有按预期工作?

问候。

I would believe that you probably should build a GCC cross-compiler in that case, and that you should compile GLibc which would handle the dependency to the old 2.4 kernel.

However, did you simply try to compile your code, and simply link it with the old 2.4-kernel compatible Glibc library ? I would suppose that should work.

And did you try to run your binary (obtained the simple way on a recent system using its recent GCC) on the old system? What is not working as expected?

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文