RFC: readelf: Explain why LLVM bitcode files cannot be read

Jeff Law jeffreyalaw@gmail.com
Fri Aug 19 16:06:40 GMT 2022

On 8/19/2022 8:20 AM, Nick Clifton via Binutils wrote:
> Hi Guys,
>    When the LLVM compiler produces a bitcode object file it uses its own
>    format, rather than ELF.  But since the file looks like a normal
>    object file a user might try to run readelf on it:
>      % echo "void lto_function(){}" > foo.c
>      % clang -flto -O2 -c foo.c
>      % readelf -a foo.o
>      readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
>    I am proposing the patch below so that readelf will produce a more
>    helpful error message:
>      % readelf -a foo.o
>      readelf: Error: This is a LLVM bitcode file - try using llvm-bcanalyzer
>    One thing I am not sure about in the patch is the LLVM bitcode magic
>    number.  I do not know if this is defined in a header file somewhere,
>    nor if there might be more than one possible value for the magic.  I
>    did not want to add any new dependencies to readelf however, so for
>    now the patch just defines the number locally.
>    Any comments/thoughts ?
I think the same issue arises with golang -- its .o files are not ELF, 
but can be read by the golang variants of objdump, nm, etc. So you might 
want to look at doing something similar for golang as well.


More information about the Binutils mailing list