Search code examples
assemblykernelx86-64osdevbinutils

How do I install x86_64-elf-ld on ubuntu 20.04?


I am trying to write an OS kernel and I need a certain dependency for compiling the assembly to an iso binary. The dependency is x86_64-elf-ld. I cannot find any resources for installing it on ubuntu online so I thought I would ask the internet.


Solution

  • If really needed, you can build x86_64-elf-ld from latest binutils source code with the following commands:

    wget https://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.xz
    tar Jxf binutils-2.36.1.tar.xz
    mkdir binutils
    pushd binutils
     ../binutils-2.36.1/configure --prefix=/usr/local --target=x86_64-elf --program-prefix=x86_64-elf- 
    make all
    sudo make install
    popd
    
    ls -ail /usr/local/bin/x86_64-elf-*
    13136197 -rwxr-xr-x 1 root root  5946864 Feb 27 23:53 /usr/local/bin/x86_64-elf-addr2line
    13136193 -rwxr-xr-x 2 root root  6194776 Feb 27 23:53 /usr/local/bin/x86_64-elf-ar
    13136205 -rwxr-xr-x 2 root root  9218448 Feb 27 23:53 /usr/local/bin/x86_64-elf-as
    13136202 -rwxr-xr-x 1 root root  5890200 Feb 27 23:53 /usr/local/bin/x86_64-elf-c++filt
    13136199 -rwxr-xr-x 1 root root   262680 Feb 27 23:53 /usr/local/bin/x86_64-elf-elfedit
    13136206 -rwxr-xr-x 1 root root  6624808 Feb 27 23:53 /usr/local/bin/x86_64-elf-gprof
    13136209 -rwxr-xr-x 4 root root 10380024 Feb 27 23:53 /usr/local/bin/x86_64-elf-ld
    13136209 -rwxr-xr-x 4 root root 10380024 Feb 27 23:53 /usr/local/bin/x86_64-elf-ld.bfd
    13136200 -rwxr-xr-x 2 root root  5996448 Feb 27 23:53 /usr/local/bin/x86_64-elf-nm
    13136196 -rwxr-xr-x 2 root root  6900392 Feb 27 23:53 /usr/local/bin/x86_64-elf-objcopy
    13136192 -rwxr-xr-x 2 root root 10369928 Feb 27 23:53 /usr/local/bin/x86_64-elf-objdump
    13136195 -rwxr-xr-x 2 root root  6194800 Feb 27 23:53 /usr/local/bin/x86_64-elf-ranlib
    13136198 -rwxr-xr-x 2 root root  4391904 Feb 27 23:53 /usr/local/bin/x86_64-elf-readelf
    13136191 -rwxr-xr-x 1 root root  5936152 Feb 27 23:53 /usr/local/bin/x86_64-elf-size
    13136194 -rwxr-xr-x 1 root root  5932576 Feb 27 23:53 /usr/local/bin/x86_64-elf-strings
    13136201 -rwxr-xr-x 2 root root  6900384 Feb 27 23:53 /usr/local/bin/x86_64-elf-strip
    

    Please note that you may have to install one or more of the following packages on Ubuntu or Debian first: build-essential, flex, bison, libisl-dev, texinfo texlive.