0
votes

I'm trying to compile a hello world program in C using gcc

I'm using gcc 9.3.0 & ubuntu 20.04

this is my c program 'hello.c'

#include<stdio.h>

int main() {

        printf("Hello World\n");

        return 0;
}

When I compile gcc hello.c it gives me the error

/tmp/cc55wg43.s: Assembler messages:
/tmp/cc55wg43.s:12: Error: no such instruction: `endbr64'

EDITED:

I have tried installing a cross-compiler. For that I have installed the following packages bison, flex, libgmp3-dev, libmpc-dev, libmpfr-dev, texinfo and I have followed this! instructions

Appending the output from gcc -v hello.c

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/9/cc1 -quiet -v -imultiarch x86_64-linux-gnu hello.c -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc4rg9BM.s
GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)
    compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/9/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)
    compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: bbf13931d8de1abe14040c9909cb6969
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccy9PKJM.o /tmp/cc4rg9BM.s
GNU assembler version 2.24 (x86_64-unknown-linux-gnu) using BFD version (GNU Binutils) 2.24
/tmp/cc4rg9BM.s: Assembler messages:
/tmp/cc4rg9BM.s:12: Error: no such instruction: `endbr64'
2
It looks like your compiler outputs instructions that your assembler does not support yet. More exactly, GCC outputs code with Intel CET enabled, but the assembler does not know about that yet Maybe some parts of the build chain are not up to date? Try to update your packages. - icebp
I have updated and upgraded all the packages and still the issue is there. @user3804799 - BornToCode
Have you built a cross-compiler or installed non-standard GCC from source or anything such? I don't believe for a second that this could happen with pristine Ubuntu GCC + binutils. - Antti Haapala
Your as is version 2.24 but the latest on Ubuntu 20.04 is 2.34, and it is configured for x86_64-linux-gnu instead of x86_64-unknown-linux-gnu. So it looks like this is not the Ubuntu package's version, but perhaps a version you installed yourself that is getting found ahead of Ubuntu's. What do which as and dpkg -l binutils output? What is $PATH set to? What does ls -lL /usr/bin/as output? - Nate Eldredge
@BornToCode the instructions ask you to set the prefix to /usr/local/i386elfgcc - maybe you've accidentally dropped this out from the binutils config and installed binutils in /usr/bin instead :D Or is it just that your path now has /usr/local/i386elfgcc/bin in it before /usr/bin? - Antti Haapala

2 Answers

0
votes

The issue was mentioned by @AnttiHaapala: By the instructions ask you to set the prefix to /usr/local/i386elfgcc - maybe you've accidentally dropped this out from the binutils config and installed binutils in /usr/bin instead

The solution was uninstalling the binutils and install it again

  • sudo apt-get remove binutils

    sudo apt-get remove --auto-remove binutils

    sudo apt install build-essential

Now the binutils version is 2.34, earlier it was 2.24

0
votes

Perhaps your situation is the same as mine: you accidentally installed a lower version of ld and did not delete it cleanly. The solution is to delete the old as, such as rm /usr/local/as