Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <503771F3.2040204@gmail.com>
Date: Fri, 24 Aug 2012 18:22:11 +0600
From: agent <agentprog@...il.com>
To: musl@...ts.openwall.com
Subject: Re: build musl with clang

24.08.2012 17:01, Szabolcs Nagy пишет:
> so the bug is still present
>
> try to make a minimal testcase
>
> eg.
>
> void *f()
> {
> 	char *p;
>
> 	p = malloc(100);
> 	if (p && p[0])
> 		p[0] = 0;
> 	return p;
> }
>
>
> and compile with -O3 -ffreestanding -S
>
> if the check is eliminated then it's a bug

f: # @f
# BB#0: # %entry
subl $12, %esp
movl $100, (%esp)
calll malloc
testl %eax, %eax
je .LBB0_2
# BB#1: # %if.then
movb $0, (%eax)
.LBB0_2: # %if.end
addl $12, %esp
ret

i suppose, 'if' is not elliminated.

but if i create a function f2 with contents of musl's calloc it fails 
the test.

then i noticed in musl's calloc a cycle is wrapped into an 'if' with p 
with negative subscript and tried the following:

void *f1() {
char *p;
int i;

p = malloc(100);
if (p[-1])
p[0] = 0;

return p;
}

and that's i we get:

f1: # @f1
# BB#0: # %if.end
subl $12, %esp
movl $100, (%esp)
calll malloc
movb $0, (%eax)
addl $12, %esp
ret

but if we have if (p && p[-1]) -- 'if' is not optimized out.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.