How can differentiate between a rv64imafd and rv64imafdc binary without executing them? I am using few compiler flags for changing the extensions but I'm not sure how to verify it. I don't want to dump the executable every time for testing on my imafd board.
I tried to study objdump of both the files and even though there was a clear difference between the opcodes, but it is not enough.
Let me know if I can share more information on this regard.
Even if you compile with the rv64imafd flag, your executable can be rv64imadfc if you link to a library (or a crt file) compiled with rv64imadfc.
This seems to be the case because your final executable contains the c flag even if you compile to rv64imafd.
If you are using https://github.com/riscv/riscv-gnu-toolchain
The build defaults to targeting rv64gc so you are linking against rv64gc libraries. if you used --enable-multilib you are linking against rv64imafdc.
In order to generate an rv64imafd executable you have three choices:
use the nostdlib and nostartfiles options and pass the necessary files (compiled with rv64imafd) by hand.
build a toolchain with -march=rv64imafd -mabi=lp64d
modify t-elf-multilib to also generate rv64imafd and build the toolchain with --enable-multilib option.
objdump or a program that does an equivalent level of decoding is probably necessary to confirm no compressed instructions are present in the binary. However ELF executables made by the GNU toolchain use the flags of the elf binary to encode if it was compiled with compressed instructions enabled.
$readelf -h no_compressed.o
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
...
Flags: 0x4, double-float ABI
...
$ readelf -h compressed.o
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
...
Flags: 0x5, RVC, double-float ABI
...
Related
I'm trying to patch the MuJoCo binaries using patchelf.
I've ran patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) ./bin/basic. And running patchelf --print-interpreter bin/basic gives me /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/ld-linux-x86-64.so.2.
Now, if I run ./bin/basic I get the output: bash: ./bin/basic: cannot execute binary file: Exec format error
Running ldd ./bin/basic gives me: not a dynamic executable, which I thought was strange.
Running file ./bin/basic yields:
./bin/basic: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /nix/store/33idnvrkvfgd5lsx2pwgwwi955adl6sk-glibc-2.31/lib/ld-linux-x86-64.so.2, for GNU/Linux 3.7.0, not stripped
This looks alright to me. I thought there might be something wrong with the header so I tried readelf -h bin/basic, this gives me:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x232f70
Start of program headers: 64 (bytes into file)
Start of section headers: 293584 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 12
Size of section headers: 64 (bytes)
Number of section headers: 28
Section header string table index: 26
So this is what I've got so far:
file and readelf -h both think it's a dynamically linked executable
Trying to run it fails
ldd Thinks it's not a dynamically linked executable
Does anyone have an idea what could be the issue here?
I suspect that there is something invalid about the elf file which file and readelf is not picking up on.
Is there a tool I can use to search for such issues with an elf file?
Looks like you're trying to use an AArch64 binary on an x86_64 system.
I am building a debugging system to debug a exe(e.g. coredump) which is crashed in remote system. The debug symbols along with the core dump (e.g. coredump.dbg, coredump_core.dump) is sent to host system. In host system when I use GDB to analyze a dump I am getting all these errors mentioned below. Some body please help how the shared libraries has to be sent to host. If yes, then how?
How should I link the shared libraries in debug symbols in host system
following are the errors
1.readelf -a coredump.dbg
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x400720
Start of program headers: 64 (bytes into file)
Start of section headers: 14864 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 36
Section header string table index: 35
readelf: Error: Unable to read in 0x900 bytes of section headers
readelf: Error: Section headers are not available!
2.gdb coredump.dbg coredump_core.dump
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
**"/root/coredump.dbg": not in executable format: File format not recognized
"/root/coredump_core.dump" is not a core dump: File format not recognized
(gdb)**
3.file coredump.dbg
coredump.dbg: ERROR: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked (uses shared libs)error reading (Invalid argument)
How should I link the shared libraries in debug symbols in host system
Your problem has nothing to do with any shared libraries (you may have a problem with them as well, but you should solve the immediate problem first).
Your immediate problem is that your binary: coredump.dbg has been corrupted in some way. This is the key message from readelf: Error: Unable to read in 0x900 bytes of section headers.
This could happen in a few different ways:
You have a buggy linker (that is very unlikely).
You are using some combination of objcopy and/or strip, and are not doing it correctly.
You transfer the file between target and host in a way that corrupts it (using e.g. ASCII-mode FTP transfer).
I'm trying to compile a 32Bit version of a linux library on a 64Bit Ubuntu 12.04LTS running inside a VM (VirtualBox).
So far I've downloaded the source, unzipped it and performed the following steps to build the lib:
libtoolize --force
automake --add-missing
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make
sudo make install
With this I've been able to build an compile the library but, once I run "readelf -h" on the compiled lib I get the following output:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x1ac0
Start of program headers: 64 (bytes into file)
Start of section headers: 53904 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 7
Size of section headers: 64 (bytes)
Number of section headers: 35
Section header string table index: 32
So I'm stuck with a 64Bit Version of the library and have not yet found a way to force the build and installation of a 32Bit Version. I'd be grateful for hints on how to solve this problem.
You only set --build in your options for ./configure. That means that ./configure should behave as if the program is being compiled on a 32-bit computer. If you want it to run on a 32-bit computer as well, you should use --host=i386-linux-gnu. So the real configure command you want to run is:
./configure --build=i386-linux-gnu --host=i386-linux-gnu
I have an embedded ARM system which runs a Linux with kernel 2.6.20.7. The kernel was compiled with gcc 4.0.2 and I want to compile programs for this system. I have tried several Toolchains (Codesourcery etc.) but no luck. I can compile the program but as soon as I run it on the embedded system I get an "Illegal instruction" error. Now I want to create my own gcc toolchain. First I want to find out the ABI and for which target I have to build my gcc toolchain.
I have downloaded a program from the embedded system and run 'readelf -h':
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0x8520
Start of program headers: 52 (bytes into file)
Start of section headers: 3772 (bytes into file)
Flags: 0x602, has entry point, GNU EABI, software FP, VFP
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 25
Section header string table index: 24
Does someone know how this information can be translated to an --target= Parameter to build a gcc toolchain? It is an ARM system and it runs Linux, so it must be something like --target=arm-linux-..., right? But what comes next?
In my vc2005 solution , when build it ,some warning will displayed such as "warning LNK4099: PDB 'libbmt.pdb' was not found...", But I don't know to to disable it.
It cannot be disabled, as it is on Microsoft's list of unignorable warnings.
If you have the source for the libraries you are using, you can rebuild them in Debug mode and copy the generated *.pdb files to the same directory as the libs you are linking.
If you do not have the source, there is a workaround, but it involves hex-editing the linker: https://connect.microsoft.com/VisualStudio/feedback/details/176188/can-not-disable-warning-lnk4099
Essentially, hex edit your link.exe (after backing it up!) to zap the
occurrence of 4099 in the list of non-ignorable warnings. I did it and
the hundred or so 4099 warnings disappeared! [L]ook
for the hex bytes 03 10 00 00 (which is 4099 as a 32-bit little-endian
hex value). Change it to (say) FF FF 00 00, save the file and you're
done.
I don't know about VS2005 but in newer versions you can ignore specific link warnings by adding /ignore:4099