compiler-explorer / compiler-explorer

Run compilers interactively from your web browser and interact with the assembly
https://godbolt.org/
BSD 2-Clause "Simplified" License
16.59k stars 1.77k forks source link

install binutils-multiarch on host #1353

Open shawnl opened 5 years ago

shawnl commented 5 years ago

if I pass -target aarch64-linux-gnu to clang in C mode I get

    #1 with x86-64 clang (trunk)

/usr/bin/ld: unrecognised emulation mode: aarch64linux

Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe

clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

Compiler returned: 1

But this works with Zig (-target aarch64v8-linux-gnu), because it uses its own lld.

On Debian the package needed is "binutils-multiarch"--a binutils built with all targets enabled-- but I am not sure what you are running.

https://godbolt.org/z/DDbRCS

mattgodbolt commented 5 years ago

Fix merged in. Will build and deploy the containers and then restart beta and test it works as we hope.

mattgodbolt commented 5 years ago

For what it's worth if you deselect the "11010" button in your original link things work ( https://godbolt.org/z/x96luv ) . But I suspect you wanted to check the binary output?

shawnl commented 5 years ago

I wanted the hex dump so I could count the bits.

mattgodbolt commented 5 years ago

The version of CE with the package installed is now live on the beta site. Unfortunately it did not work: https://godbolt.org/beta/z/DDbRCS Installing the binutils-multiarch does this:

Adding 'diversion of /usr/bin/x86_64-linux-gnu-nm to /usr/bin/x86_64-linux-gnu-nm.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-objdump to /usr/bin/x86_64-linux-gnu-objdump.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-objcopy to /usr/bin/x86_64-linux-gnu-objcopy.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-strings to /usr/bin/x86_64-linux-gnu-strings.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-strip to /usr/bin/x86_64-linux-gnu-strip.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-size to /usr/bin/x86_64-linux-gnu-size.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-ar to /usr/bin/x86_64-linux-gnu-ar.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-ranlib to /usr/bin/x86_64-linux-gnu-ranlib.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-addr2line to /usr/bin/x86_64-linux-gnu-addr2line.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-gprof to /usr/bin/x86_64-linux-gnu-gprof.single by binutils-multiarch'
Adding 'diversion of /usr/bin/x86_64-linux-gnu-readelf to /usr/bin/x86_64-linux-gnu-readelf.single by binutils-multiarch'

Note that /usr/bin/ld is not present, and so wasn't updated.

Running ld --verbose to list emulations:

GNU ld (GNU Binutils for Ubuntu) 2.30
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   elf_iamcu
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe
shawnl commented 5 years ago

damn. We still need it for the objdump, but yes it did not fix the problem. I guess the easy way would be to install lld and then be able to use -fuse-ld=lld

mattgodbolt commented 5 years ago

Which version of lld though? Isn't there one in each clang already? I don't even use the system objdump: I build my own as part of binutils, so I imagine the installed binutils multiarch won't be being used in binary mode either :/

mattgodbolt commented 5 years ago

-fuse-lld is no panacea, opening more worm-cans than it solves: https://godbolt.org/z/NXgfez

ld.lld: error: cannot open crt1.o: No such file or directory
ld.lld: error: cannot open crti.o: No such file or directory
ld.lld: error: cannot open crtbegin.o: No such file or directory
ld.lld: error: unable to find library -lstdc++
ld.lld: error: unable to find library -lm
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc
ld.lld: error: cannot open crtend.o: No such file or directory
ld.lld: error: cannot open crtn.o: No such file or directory
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
mattgodbolt commented 5 years ago

I wonder if I can enable more targets in binutils: https://github.com/compiler-explorer/gcc-builder/blob/master/build/build.sh#L164-L184 is the spot where it's done.

GitMensch commented 1 year ago

I wonder if I can enable more targets in binutils

I think this was done now in the meantime with --enable-multiarch and therefore this issue may be closed, no?