From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 642DD3858C83 for ; Fri, 19 Aug 2022 16:06:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 642DD3858C83 Received: by mail-pl1-x629.google.com with SMTP id y4so4522904plb.2 for ; Fri, 19 Aug 2022 09:06:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=h98EqAocuBs7KhS1CIlsaBt51SbWlWqdWd/hdf3iT9Q=; b=OuJzBp6G0At042fsq4kTNCE5QUK9t64CEZ2j413kgJj+YDCbj6NQH20XrsBaOzEUya 2TAz0weY7Nk/buLK+D7WtpqHfvP5nK3OoHM4Gp8vb4NZTdyx5JMoTX+0qXK8jCx1I/9+ 4F+XKWGplJf96DMtk3F+f5utSPZhx0ZZtKm0fWKB+KYuGV643n0oRtuI4lPfkPnXCnSK rNDyxAFvg/rpbjbOSVckivojnmvJmelpdKU8SRQ2wRDiffh293xZb9vwS4oC7bY/lWUW LXjiZaxtezMwEqMxWh+gjT/Kox9m2T/ueS81n3SRu/WDHET1crl1YyErVZhS4BTBSKv1 P3lg== X-Gm-Message-State: ACgBeo1KDzCpBlomTYvXgVoByU5FFzjLf4lK2WNxZqAsLPqYSMsdAzYI ItNLdxg4hsAqZ3/v05beCZhQAFLfdf8= X-Google-Smtp-Source: AA6agR61yr6R5Q053sljT+3GRU7RH1M3ekYjrPFpaem7fjeM0Gy3QlF0caF53Jf8kn9kQWNjLaXGJA== X-Received: by 2002:a17:90b:3ec3:b0:1fa:a293:c511 with SMTP id rm3-20020a17090b3ec300b001faa293c511mr9259272pjb.156.1660925201839; Fri, 19 Aug 2022 09:06:41 -0700 (PDT) Received: from [172.31.0.204] (c-73-98-188-51.hsd1.ut.comcast.net. [73.98.188.51]) by smtp.gmail.com with ESMTPSA id w27-20020aa79a1b000000b00525442ac579sm3595767pfj.212.2022.08.19.09.06.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Aug 2022 09:06:41 -0700 (PDT) Message-ID: <7d833071-ab40-4ac5-2f4e-865afd0d294f@gmail.com> Date: Fri, 19 Aug 2022 10:06:40 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: RFC: readelf: Explain why LLVM bitcode files cannot be read Content-Language: en-US To: binutils@sourceware.org References: <87a680iabd.fsf@redhat.com> From: Jeff Law In-Reply-To: <87a680iabd.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Aug 2022 16:06:45 -0000 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