1

I would like to change the global structures in an ELF file. I would first like to know whether a global variable is a structure or not? But the only information I see is the name and the size of the variable.

3
  • 2
    The details of the type would only be stored in debug information; the information isn't needed when the program is run otherwise. What you're up to seems likely to be misguided — expect failures. The code using the structure will be intimately tied to the structure shape/size that was used when the source was compiled. If you change that, your program will malfunction. Commented Dec 1, 2016 at 6:25
  • 2
    There are no "variables" or "types" in an ELF file. These are source code concepts. The ELF file simply has bulk data and symbols that point to the start of the data. If you like, all the elf file has are char[] and void *. Commented Dec 1, 2016 at 6:38
  • Why are you asking? Your question is unclear (stricto sensu the ELF definition defines its structure) and is likely to be an XY problem. So your should edit your question to motivate it, explain more of it. Commented Dec 1, 2016 at 6:41

1 Answer 1

6

You cannot find it. The ELF format has a very limited type information (and does not know if some global variable is a struct or an int; it knows mostly the sizeof the variable). See elf(5).

However, if you compile your program (and the libraries it is using) for debug support (e.g. with g++ -Wall -g). then the ELF file contains additional debug sections, often using the DWARF format. These information can be removed from an ELF file using the strip command. So see strip(1) & readelf(1) & objdump(1).

But you really want to use the source code. So get the source of the program (since Linux is mostly made of free software, this is generally possible) and recompile it (and of course study the source code of the program). Perhaps you want (but that does require weeks of work) to customize your compiler (e.g. by writing your own GCC plugin, or using GCC MELT, or customizing your Clang compiler) and use that to recompile the code (and process specifically all global variable declarations).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.