I wanted to read the architecture information about object(.so) files example x86, x86_64, armeabi, armeabi-v7a, mips etc from the file and display these information. I know I can use "file" or other Linux commands to get this info, But I wanted to use the kernel structure to get above values.
I went through the ELF header file but not getting much help.
Can someone please suggest how to proceed for this?
A elf binary contains a elf-header at the beginning of the file. You can read this header by any elf-reader program, and here I will give you the example for readelf
readelf -h <binaryFile>
For more information, you could read the ELF Format Specification to learn about how elf binaries are loaded & executed.
Related
I am trying to print all the Undefined function calls from a shared object file along with file name.
I tried with "nm" command, It print all the undefined function calls .But could not get the file name.
Example:
bash$ nm -u my_test.so
:
U _ZNSs4_Rep20_S_empty_rep_storageE##GLIBCXX_3.4
:
Environment : Ubuntu 18.04 , X86 Arch (Intel processor)
Study in details the specification of the DWARF format (which is the format used by debugging information on Linux). So you could extract the information (but it is not exactly simple) by parsing the DWARF inside your ELF binary.
Consider looking inside the source code of Ian Taylor's libbacktrace. It is doing this extraction of file name from DWARF inside ELF.
Perhaps your real problem is getting precise backtrace information, and then that libbacktrace is exactly what you need!
You might also use gdb : it is extensible and scriptable in Python (or Guile) and you could write your own specialized script.
Perhaps you'll better solve your real problem with some GCC plugin working when you compile your code.
Read How to write shared libraries by Drepper and read more about ELF.
You could for example collect all the undefined symbols in your shared library using nm (or readelf). Then a second script will find the occurrences of these in your source code. It could be even a simple awk script (or some for shell loop using grep), or something as sophisticated as a GCC plugin.
Your example shows (probably) a mangled C++ name. You could use nm -C to get it unmangled. And later write a GCC plugin to find all the GIMPLE CALL instructions using it.
Writing a GCC plugin may take some time, in particular if you are not familiar with GCC internals.
I have builded the U-boot for minnowboard max. I am seeing the files like uboot.rom uboot.bin etc.
what is the difference between uboot.rom and uboot.bin ? Which files I should flash to SPI NOR flash.
This is explained in doc/README.x86. In short, if you are going to be writing U-Boot to SPI NOR then you need to ensure that you have the correct binary blobs in the correct locations AND use BUILD_ROM=y so that u-boot.rom is generated as this is the file that is required on x86 to run on bare metal (rather than say as a coreboot payload).
Edit to address the comment:
The file 'u-boot' is the ELF object that is the result of building all of the U-Boot sources and linking them. This includes all of the extra sections and information an ELF file can contain. This is also by and large not bootable. The u-boot.bin file is the ELF u-boot but passed via objcopy to strip out (by and large, see the Makefile for the various flags or build with V=1) everything except for text/data sections so that we have only what is required to boot. Then u-boot.rom is the combination of objects and formatting that the x86 architecture requires in order to execute and run an image. Building with V=1 will show all of the details here.
Using IAR IDE for building ARM executables from C source, I can see the disassembly, including labels, addresses, opcode and instructions in the relevant window.
I am trying to dump the contents of a range of addresses to a text file, but can't find a way to do that. The window text is not selectable so I cannot use copy/paste. There is no menu associated that enables this.
As an alternative, I can generate the list and assembly files, but these seem to be limited to my code, and do not contain the CRT code or any ROM sections, which I am interested in.
Any way to dump a selected address range?
You want to use ielfdumparm located in your Workbench directory under arm/bin. Here's the help for the tool.
Usage: IElfDump input_file [output_file]
Available command line options:
--all Dump all sections
--code Dump only code sections
--no_header Do not produce a list header
--no_rel_sections
Do not output associated .rel sections
--no_strtab Do not include strtab sections
--output file
-o file Name of text file to create
--raw Use raw text format
--section #|name[,...]
-s #|name[,...] Dump only section(s) with given numbers/names
--source Include source in disassembled code in executables
--use_full_std_template_names
Don't use short names for standard C++ templates
-a All sections, except strtab sections
-f file Read command line options from file
To get a similar output to the debug view, I would suggest --code to avoid dumping your data space, and --source to have it embed your original C woven in with the assembly.
You can specify sections, but it doesn't look like you can specify address range. You may be able to pair this with some of the other ELF tools to extract just a specific address range, and then run this tool on that. Alternatively, this dumps in address order so you could dump the entire ELF file and then just look at the address range you want after the fact.
I use Snagit to capture text that is not selectable.
Snagit is a screen snapshot tool (a very good one). Besides making classic screen shots it supports to capture text and save it as ASCII text. It can also automatically scroll windows to capture long texts.
Maybe it is worth a try. There is a 30-day trial version available.
I need to do some Trace32 debugging and i need to see the symbols of the IFS image.
I generate the IFS image for my ARM A9 platform but dont know how to generate the ELF file.
can somebody help me out ?
thanks.
IFS is a file system with many binaries and scripts. For trace32, when you try to debug any process (including procnto), you'd need the symbols of that process of interest. There is not such thing as ELF for IFS. It's like asking for the ELF of your harddisk.
Use dumpifs. Example:
dumpifs shell.ifs
check this
the -x option can extract the files specified after the image.
How can you extract the sizes of all C structures from an ELF object file with debugging symbols?
Individual struct sizes can be obtained from GDB using "print sizeof(some_struct)", but what I need is to get a listing of all structures.
I've looked at "nm" and "objdump", but I don't see options to do what I'm looking for. Is there a way to do this with standard Unix tools, or do I need to extract the debug symbol section from the ELF file and process it myself? I'm hoping it's not the latter.
Thanks in advance for any advice.
Ray
pahole shows this and other details about structs. Its git repo is at http://www.kernel.org/git/?p=linux/kernel/git/acme/pahole.git;a=summary.
You will have to dig in .debug_info section, objdump will dump it for you if you run it with --dwarf parameter.
You will see your structures there as *DW_TAG_structure_type* and *DW_AT_byte_size* attribute is equivalent to sizeof. Standard Unix tool should be enough to format this data into more readable list.
Install package dwarves, then you have the command "pahole".
Use the "pahole" command against a elf object file, you can get all the structure information, or you can use the "-C" parameter to specific a structure name, for example:
$ pahole vmlinux -C task_struct
Unless someone else known something, I think you will have to process the output of nm .
However, nm only gives you the start of each struct and knows nothing about its end so even that may not work unless each strut is immediately followed by some other symbol. Watch out for this issue!