I build a program and it works well(I mean that I can run this program). But when I use "readelf" to check whether there is debug information,errors come:
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
readelf: Error: test/select: Failed to read file header
My linux distribution is Ubuntu-12. Somebody can help me?
It may not actually be an ELF executable file. There are plenty of things that will run that are not ELF files (such as shell scripts, Perl files, Python py source and pyc compiled files). There are even things that will "run" without having an individual identifiable file at all (aliases or functions in your shell,
bash
built-ins and such).I would first execute:
to see what sort of file it actually is, such as with:
Only if it's recognised as an ELF file should you try to treat it as such.
For what it's worth, I have a backup script which executes just fine but which would fail your
readelf
assumption:As to what you do when you find out it isn't ELF format, that depends on what you're trying to ascertain, something you haven't actually specified. If all you want to do is run
readelf
on it, that won't work unless it's an ELF format file.If you want a particular piece of information about the executable file, you need to tell us both:
file
for example); and