October 22, 2024
Chicago 12, Melborne City, USA
C#

Error Compiling Binutils for i386-elf on macOS: Malformed Archives


I’m trying to cross-compile binutils for i386-elf on macOS (Sequoia 15.0.1, arm64) but encounter an error when running make. Here are the steps I followed:

  1. Installed required dependencies:

    brew install gmp mpfr libmpc texinfo
    
  2. Downloaded and extracted binutils 2.41:

    mkdir -p ~/src
    cd ~/src
    wget https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.gz
    tar -xzf binutils-2.41.tar.gz
    
  3. Created a build directory:

    mkdir build-binutils
    cd build-binutils
    
  4. Set environment variables:

    export CC=gcc
    export CXX=g++
    export AR=llvm-ar
    
  5. Configured binutils:

    ../binutils-2.41/configure \
      --target=i386-elf \
      --prefix=/usr/local/cross \
      --disable-nls \
      --disable-werror
    
  6. Ran make while compiling the libbfd.la target and encountered the following error:

llvm-ar: error: truncated or malformed archive (terminator characters in archive member "\000\000" not the correct "`\n" values for the archive member header for 0     0     644)
make[4]: *** [libbfd.la] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-bfd] Error 2
make: *** [all] Error 2

Before that I only get source code related warnings.

Suspicions

  • It might be unrelated, but I’m concerned that when I run gcc --version, it shows Clang instead of GCC:
$ gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin24.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • Can you even compile binutils on macOS?

What I’ve tried

I tried:

  • Compiling a different version of binutils.
  • Using a different version of both gcc and clang.
  • Redownloading all dependencies and different versions of them.
  • Configuring and making it with expor AR=ar (the following error occurs):
checking whether gcc supports -Wold-style-definition... ld: multiple errors: archive member '/' not a mach-o file in '/Users/viliamholly/src/binutils-build/libiberty/libiberty.a'; archive member '/' not a mach-o file in '/Users/viliamholly/src/binutils-build/zlib/libz.a'; archive member '/' not a mach-o file in '/Users/viliamholly/src/binutils-build/bfd/.libs/libbfd.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

System Info

  • macOS Sequoia 15.0.1 (arm64)



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video