From: Jeff Garzik <jeff@garzik.org>
To: Pekka Enberg <penberg@kernel.org>
Cc: linux-sparse@vger.kernel.org,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Christopher Li <sparse@chrisli.org>,
Jeff Garzik <jgarzik@redhat.com>
Subject: Re: [RFC/PATCH] sparse, llvm: Fix string globals access
Date: Fri, 08 Jun 2012 14:13:54 -0400 [thread overview]
Message-ID: <4FD240E2.6040003@garzik.org> (raw)
In-Reply-To: <1339160327-8534-1-git-send-email-penberg@kernel.org>
On 06/08/2012 08:58 AM, Pekka Enberg wrote:
> This patch attempts to fix code generation for global string access:
>
> static char *foo = "Foo !\n";
>
> extern int puts(const char *s);
>
> int main(int argc, char *argv[])
> {
> puts(foo);
>
> return 0;
> }
>
> Unfortunately the generated executable SIGSEGVs:
>
> [penberg@tux sparse]$ ./sparsec foo.c&& ./a.out
> Segmentation fault
>
> Looking at the IR, Sparse/LLVM generates this:
>
> [penberg@tux sparse]$ ./sparse-llvm foo.c | llvm-dis
> ; ModuleID = '<stdin>'
>
> @"<noident>" = private global [7 x i8] c"Foo !\0A\00"
> @foo = private global [7 x i8]* @"<noident>"
>
> define i32 @main(i32, i8**) {
> L0:
> %load_target = load i64* bitcast ([7 x i8]* @"<noident>" to i64*)
> %2 = call i32 @puts(i64 %load_target)
> ret i32 0
> }
>
> declare i32 @puts(i64)
>
> whereas Clang generates the following:
>
> @.str = private unnamed_addr constant [7 x i8] c"Foo !\0A\00", align 1
>
> define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable {
> %1 = tail call i32 @puts(i8* getelementptr inbounds ([7 x i8]* @.str, i64 0, i64 0)) nounwind
> ret i32 0
> }
>
> declare i32 @puts(i8* nocapture) nounwind
>
> I'm not sure what the LLVM backend can do here. Sparse linearizes the code to
> this which is why LLVM backend does the casting:
>
> [penberg@tux sparse]$ ./test-linearize foo.c
> main:
> .L0x7f341f6f1010:
> <entry-point>
> load.64 %r1<- 0[foo]
> call.32 %r2<- puts, %r1
> ret.32 $0
>
> Comments?
>
> Cc: Benjamin Herrenschmidt<benh@kernel.crashing.org>
> Cc: Christopher Li<sparse@chrisli.org>
> Cc: Jeff Garzik<jgarzik@redhat.com>
> NOT-Signed-off-by: Pekka Enberg<penberg@kernel.org>
> ---
> sparse-llvm.c | 8 +++++++-
> 1 files changed, 7 insertions(+), 1 deletions(-)
ACK
next prev parent reply other threads:[~2012-06-08 18:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-08 12:58 [RFC/PATCH] sparse, llvm: Fix string globals access Pekka Enberg
2012-06-08 18:13 ` Jeff Garzik [this message]
2012-06-08 20:39 ` Pekka Enberg
2012-06-08 23:55 ` Xi Wang
2012-06-09 11:00 ` Pekka Enberg
2012-06-09 11:46 ` Xi Wang
2012-06-09 12:08 ` Jeff Garzik
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=4FD240E2.6040003@garzik.org \
--to=jeff@garzik.org \
--cc=benh@kernel.crashing.org \
--cc=jgarzik@redhat.com \
--cc=linux-sparse@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=sparse@chrisli.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 NNTP newsgroup(s).