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.
-
2Just standard `ld` should do the trick. – fuz Feb 24 '21 at 16:53
-
It does not work. – Lambda Banquo Feb 24 '21 at 20:51
-
2Please give a specific error description if you want further help. – fuz Feb 24 '21 at 21:28
-
Since you're on an x86-64 ELF platform (GNU/Linux), the system `ld` is what you want. `alias x86_64-elf-ld=ld` if you want to copy/paste build instructions that use that command. – Peter Cordes Feb 25 '21 at 01:39
2 Answers
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.

- 5,382
- 1
- 16
- 22
-
Hi @Lambda Banquo if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is of course no obligation to do this. – Frant Mar 02 '21 at 19:40
You're already on an x86-64 ELF platform (Ubuntu GNU/Linux); the system ld
is x86-64 ELF.
alias x86_64-elf-ld=ld
if you want to copy/paste build instructions that use that command.
You'll probably want your own linker script anyway, so the fact that it defaults to making Linux ELF executables is probably fine.
https://wiki.osdev.org/GCC_Cross-Compiler recommends setting up a cross-GCC if you want to compile C source, but you can also use the system gcc
with the right options (like perhaps -ffreestanding -mgeneral-registers-only
to avoid inventing calls to libc functions, and if you don't want your kernel using XMM registers in places you might have only saved/restored integer registers.)
GNU/Linux or *BSD are good platforms to develop from; they already use ELF which is generally preferred for osdev tutorials / guides. So the native toolchains on those OSes are usable for custom OS development, AFAIK. Unlike MinGW or Cygwin on Windows, where you'd have more work to do to figure out how to get flat binaries with the desired contents, or especially to make multiboot images.

- 328,167
- 45
- 605
- 847