I am learning x86_64 assembly. But I have run into the following problem:
I am assembling a program with gcc -g -c exercise1.s -o exercise1.o and linking it with ld -g -o exercise1 exercise1.o -m elf_x86_64
However when I try to run the program I get the following error: bash: ./exercise1: cannot execute binary file: Exec format error
Running uname -a I get Linux lubuntu 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux and arch outputs x86_64.
file outputs exercise1: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), corrupted program header size, with debug_info, not stripped.
To me it seems that I am trying to run a 64-bit program on a 64-bit kernel on a 64-bit CPU. Why is it not working?
Related
I'm trying to execute a 32 bits binary, that is my scenario:
Host compiled: Kali (64 bits)
Host executed: Debian 7 (32 bits)
Host compiled is the machine where I'm compiled to 32 bits the .c
Host executed is the machine where I'm executing the 32 bits binary
I have the package gcc-multipart installed and compiled using this command: gcc -m32 binary.c -o program -pthread
File Result:
program: ELF 32 bits LSB pie executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2
When a try to execute in Debian, this error ocurrs /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.33' not found`
I'm looking for some solutions, try to re-install/upgrade the libc6, but did not work.
When I check location of gcc I get correct output. But when I try to get gcc version I get command not found.
I have added the path to $PATH
echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/ptladmin/bin:/usr/libexec/gcc
whereis gcc
gcc: /usr/libexec/gcc
gcc --version
-bash: gcc: command not found
I am trying to install a pakcage I keep getting configure: error: no acceptable C compiler found in $PATH
uname -a
Linux deehxpy011ccpra 2.6.18-419.el5 #1 SMP Wed Feb 22 22:40:57 EST 2017 x86_64 x86_64 x86_64 GNU/Linux
I am trying to run a package that is precompiled (supposedly for 'linux64') but get the following error message:
t.kuilman#steroid:~/Peeper/bin/netchop-3.1/bin$ ./netChop
-bash: ./netChop: cannot execute binary file: Exec format error
I checked how this file is compiled (see below) and it turns out to be an ELF 64-bit LSB executable.
t.kuilman#steroid:~/Peeper/bin/netchop-3.1/bin$ file ./netChop
./netChop: ELF 64-bit LSB executable, no machine, version 1 (SYSV), statically linked, for GNU/Linux 2.4.1, for SuSE 9.1, stripped
t.kuilman#steroid:~/Peeper/bin/netchop-3.1/bin$ ldd ./netChop
not a dynamic executable
t.kuilman#steroid:~/Peeper/bin/netchop-3.1/bin$ uname -a
Linux steroid 3.13.0-76-generic #120-Ubuntu SMP Mon Jan 18 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
How can I get this file to run on my system (Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-76-generic x86_64))?
This executable is likely either corrupt, or built in some non-standard way:
ELF 64-bit LSB executable, no machine, version 1 (SYSV) ...
A normal statically linked Linux executable should look like this:
ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux)
Note machine ("no machine" vs. "x86-64") and OS ABI ("SYSV" vs. "GNU/Linux") differences.
In any case, there is nothing you can do about it, other than complain to the producer of the package.
My Linux Server information is:
[root#centos nan]# uname -a
Linux centos 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
By default, the gcc will generate the 64-bit executable file, so I use the "-m32" flags to build 32-bit executable file.
After running the following command:
[root#centos nan]# gcc -m32 -o a a.c
/usr/bin/ld: crt1.o: No such file: No such file or directory
collect2: ld returned 1 exit status
So how to build 32-bit executable file in 64-bit Linux?
getting following error with the command g++ -o test -L . -l pq
libpq.so: file not recognized: File format not recognized
#file libpq.so
libpq.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), not stripped
gcc version 4.1.2 20070115 (SUSE Linux)
I am getting the same error if I try to use -l dbodbc instead of -l pq.
Note that test.c is a simple hello world program.
Thanks in Advance.
file /usr/bin/g++ tells you that g++ itself is a 64-bit executable, i.e. it runs on a 64-bit machine, it doesn't tell you that g++ can compile 64-bit code (it's very unlikely but it could be a cross compiler for a completely different processor!) Use g++ -v or g++ -dumpmachine to find out what target it generates executables for.
G++ doesn't actually use that library, it just passes the -l option to the linker, so the error is coming from the linker, ld
If ld and objdump are both saying they can't recognize the library but the same file is fine on a different machine, I would try updating or reinstalling the binutils package, which provides both ld and objdump.
You might have a 32-bit binutils installed, so its ld and objdump wouldn't understand the x86_64 library. Ensure you have the 64-bit (i.e. x86_64) binutils RPM installed.