* clang/musl progress and a small bug.
@ 2012-05-25 21:40 Richard Pennington
2012-05-25 23:17 ` Rich Felker
2012-05-26 10:28 ` aep
0 siblings, 2 replies; 4+ messages in thread
From: Richard Pennington @ 2012-05-25 21:40 UTC (permalink / raw)
To: musl
Hi,
clang's libcompiler-rt doesn't have support for crtbegin.o and crtend.o so
global constructors and destructors didn't work out of the box. If I link with
the NetBSD versions of crtbegin.c and crtend.c in place of the musl crti.s and
crtn.s everything works fine. For now, I've added them to the musl build under
crt.
I think I found a bug while running my library regression test. The zero test
failed in the following code:
TEST_TRACE(C99 7.20.3.1)
p = calloc(100, sizeof(char));
TEST(p != NULL, "calloc() returned a pointer");
int flag = 1;
for (i = 0; i < 100; ++i) {
if (p[i] != 0) {
flag = 0;
}
}
TEST(flag, "calloc() returned zeroed memory");
The TEST() macro is kind of like assert but it prints out the message and
counts failures and successes:
PASS: 001stdlib.c:74: Stdlib(Stdlib): calloc() returned a pointer
FAIL: 001stdlib.c:81: Stdlib(Stdlib): calloc() returned zeroed memory
Stdlib unit tests completed
32 tests run
1 test failed
Am I missing something?
-Rich
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: clang/musl progress and a small bug.
2012-05-25 21:40 clang/musl progress and a small bug Richard Pennington
@ 2012-05-25 23:17 ` Rich Felker
2012-07-26 18:24 ` John Spencer
2012-05-26 10:28 ` aep
1 sibling, 1 reply; 4+ messages in thread
From: Rich Felker @ 2012-05-25 23:17 UTC (permalink / raw)
To: musl
On Fri, May 25, 2012 at 04:40:51PM -0500, Richard Pennington wrote:
> Hi,
>
> clang's libcompiler-rt doesn't have support for crtbegin.o and crtend.o so
> global constructors and destructors didn't work out of the box. If I link with
> the NetBSD versions of crtbegin.c and crtend.c in place of the musl crti.s and
> crtn.s everything works fine. For now, I've added them to the musl build under
> crt.
These files are provided by gcc, not by the libc. I'm not very
familiar with how they work, so I'm not sure what's best to do... I'll
try to figure them out better.
> I think I found a bug while running my library regression test. The zero test
> failed in the following code:
>
> TEST_TRACE(C99 7.20.3.1)
> p = calloc(100, sizeof(char));
> TEST(p != NULL, "calloc() returned a pointer");
> int flag = 1;
> for (i = 0; i < 100; ++i) {
> if (p[i] != 0) {
> flag = 0;
> }
> }
> TEST(flag, "calloc() returned zeroed memory");
>
> The TEST() macro is kind of like assert but it prints out the message and
> counts failures and successes:
>
> PASS: 001stdlib.c:74: Stdlib(Stdlib): calloc() returned a pointer
> FAIL: 001stdlib.c:81: Stdlib(Stdlib): calloc() returned zeroed memory
> Stdlib unit tests completed
> 32 tests run
> 1 test failed
>
> Am I missing something?
I'm guessing clang miscompiled calloc.c due to not respecting
-ffreestanding. There was a related issue reported a while back by
someone experimenting with clang and musl but I don't know what came
of it. Basically I think the issue is that clang is treating the
malloc call calloc makes as a call to the standard malloc, and
optimizing out inspections calloc makes on the returned memory because
it's "indeterminate" and thus undefined behavior. This contradicts the
meaning of -ffreestanding which is to behave as a freestanding C
environment where malloc and other library functions are not special.
I'm not sure how to work around the issue without making the code
behave a lot worse. If you can determine this is the issue, I think it
really calls for a bug report to clang...
Rich
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: clang/musl progress and a small bug.
2012-05-25 23:17 ` Rich Felker
@ 2012-07-26 18:24 ` John Spencer
0 siblings, 0 replies; 4+ messages in thread
From: John Spencer @ 2012-07-26 18:24 UTC (permalink / raw)
To: musl, Richard Pennington
On 05/26/2012 01:17 AM, Rich Felker wrote:
> On Fri, May 25, 2012 at 04:40:51PM -0500, Richard Pennington wrote:
>
>> I think I found a bug while running my library regression test. The zero test
>> failed in the following code:
>>
>> TEST_TRACE(C99 7.20.3.1)
>> p = calloc(100, sizeof(char));
>> TEST(p != NULL, "calloc() returned a pointer");
>> int flag = 1;
>> for (i = 0; i< 100; ++i) {
>> if (p[i] != 0) {
>> flag = 0;
>> }
>> }
>> TEST(flag, "calloc() returned zeroed memory");
>>
>> The TEST() macro is kind of like assert but it prints out the message and
>> counts failures and successes:
>>
>> PASS: 001stdlib.c:74: Stdlib(Stdlib): calloc() returned a pointer
>> FAIL: 001stdlib.c:81: Stdlib(Stdlib): calloc() returned zeroed memory
>> Stdlib unit tests completed
>> 32 tests run
>> 1 test failed
>>
>> Am I missing something?
> I'm guessing clang miscompiled calloc.c due to not respecting
> -ffreestanding. There was a related issue reported a while back by
> someone experimenting with clang and musl but I don't know what came
> of it. Basically I think the issue is that clang is treating the
> malloc call calloc makes as a call to the standard malloc, and
> optimizing out inspections calloc makes on the returned memory because
> it's "indeterminate" and thus undefined behavior. This contradicts the
> meaning of -ffreestanding which is to behave as a freestanding C
> environment where malloc and other library functions are not special.
>
> I'm not sure how to work around the issue without making the code
> behave a lot worse. If you can determine this is the issue, I think it
> really calls for a bug report to clang...
>
> Rich
>
has this issue been reported on the LLVM list finally ?
imo this is a major blocker
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: clang/musl progress and a small bug.
2012-05-25 21:40 clang/musl progress and a small bug Richard Pennington
2012-05-25 23:17 ` Rich Felker
@ 2012-05-26 10:28 ` aep
1 sibling, 0 replies; 4+ messages in thread
From: aep @ 2012-05-26 10:28 UTC (permalink / raw)
To: musl
On Fri, 25 May 2012 16:40:51 -0500, Richard Pennington wrote:
> clang's libcompiler-rt doesn't have support for crtbegin.o and
> crtend.o so
> global constructors and destructors didn't work out of the box.
Are you sure that you actually need them, and that those aren't just
the names of the gcc specific version of it?
Not having global dtors in libcompiler-rt at all, sounds kinda broken.
Last time i tried, i think musl was just missing some hooks in that
area.
However, i mixed in clangs C++ lib, so maybe this works different.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-07-26 18:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-25 21:40 clang/musl progress and a small bug Richard Pennington
2012-05-25 23:17 ` Rich Felker
2012-07-26 18:24 ` John Spencer
2012-05-26 10:28 ` aep
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).