Can I read source code from an elf file?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I've a question.
If I've an .elf file, Can I read the source code?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

elf file is binary and it does not include source code.

however you can make a disassembly listing, which is source code, and which should compile through an assembler back into binary.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, but why if I do avr-objdump -S file.elf
I can view all my C code and the disassembly code????

There's a way to prevent this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

ok, but why if I do avr-objdump -S file.elf
I can view all my C code and the disassembly code????

There's a way to prevent this?


Yes, remove the -g option when you compile the files. Also note that the source itself is not built into the ELF, only pointers to the files and line numbers involved. If the source files are still in place and you objdump -S then it goes to those files and reads then to interleave source and disassembled code. If you take that ELF file to another PC and objdump -S it will no longer find the source files.

However removing the -g (probably -gdwarf-2 in fact) at build time will stop it putting filenames/line numbers into the ELF in the first place.

Another option is to continue to use -g and make ELF's that contain debug info for your own use but before you distribute the file use avr-strip to strip the debug info from it.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Quote:

ok, but why if I do avr-objdump -S file.elf
I can view all my C code and the disassembly code????

There's a way to prevent this?


Yes, remove the -g option when you compile the files. Also note that the source itself is not built into the ELF, only pointers to the files and line numbers involved. If the source files are still in place and you objdump -S then it goes to those files and reads then to interleave source and disassembled code. If you take that ELF file to another PC and objdump -S it will no longer find the source files.

However removing the -g (probably -gdwarf-2 in fact) at build time will stop it putting filenames/line numbers into the ELF in the first place.

Another option is to continue to use -g and make ELF's that contain debug info for your own use but before you distribute the file use avr-strip to strip the debug info from it.

Cliff

ok, now I've understood.
Indeed I've tried to copy the .elf file on another pc and avr-objdump don't print the C code but only the labels.
Thanks for the explanation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd still drop the -g or avr-strip if I were you - the less info you can give the "intruders" the better.