public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: binutils@sourceware.org
Subject: Re: RFC: readelf: Explain why LLVM bitcode files cannot be read
Date: Fri, 19 Aug 2022 10:06:40 -0600	[thread overview]
Message-ID: <7d833071-ab40-4ac5-2f4e-865afd0d294f@gmail.com> (raw)
In-Reply-To: <87a680iabd.fsf@redhat.com>



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.

Jeff



  reply	other threads:[~2022-08-19 16:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-19 14:20 Nick Clifton
2022-08-19 16:06 ` Jeff Law [this message]
2022-08-22 10:18   ` Nick Clifton
2022-08-23 15:26     ` Richard Earnshaw
2022-08-23 15:30       ` Nick Clifton
2022-08-23 20:35         ` Luis Machado
2022-08-24  9:24           ` Nick Clifton
2022-08-24 10:18             ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7d833071-ab40-4ac5-2f4e-865afd0d294f@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).