mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] properly terminate linked link of dsos
@ 2011-10-12 13:42 Arvid Ephraim Picciani
  2011-10-12 14:01 ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Arvid Ephraim Picciani @ 2011-10-12 13:42 UTC (permalink / raw)
  To: musl

---
 src/ldso/dynlink.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 1b55e07..3f271aa 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -375,6 +375,7 @@ static struct dso *load_library(const char *name)
 	p->name = p->buf;
 	strcpy(p->name, name);
 
+    p->tail = 0;
 	tail->next = p;
 	p->prev = tail;
 	tail = p;
-- 
1.7.7



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] properly terminate linked link of dsos
  2011-10-12 13:42 [PATCH] properly terminate linked link of dsos Arvid Ephraim Picciani
@ 2011-10-12 14:01 ` Rich Felker
  2011-10-12 14:25   ` aep
  0 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2011-10-12 14:01 UTC (permalink / raw)
  To: musl

On Wed, Oct 12, 2011 at 03:42:54PM +0200, Arvid Ephraim Picciani wrote:
> ---
>  src/ldso/dynlink.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 
> diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
> index 1b55e07..3f271aa 100644
> --- a/src/ldso/dynlink.c
> +++ b/src/ldso/dynlink.c
> @@ -375,6 +375,7 @@ static struct dso *load_library(const char *name)
>  	p->name = p->buf;
>  	strcpy(p->name, name);
>  
> +    p->tail = 0;
>  	tail->next = p;
>  	p->prev = tail;
>  	tail = p;

See line 357. This patch is a no-op.

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] properly terminate linked link of dsos
  2011-10-12 14:01 ` Rich Felker
@ 2011-10-12 14:25   ` aep
  2011-10-12 14:46     ` aep
  0 siblings, 1 reply; 7+ messages in thread
From: aep @ 2011-10-12 14:25 UTC (permalink / raw)
  To: musl

On Wed, 12 Oct 2011 10:01:41 -0400, Rich Felker wrote:

> See line 357. This patch is a no-op.
>
> Rich


indeed. For the record (as dicussed on irc): calloc doesn't zero the 
memory for me.
Something entirely else is fishy.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] properly terminate linked link of dsos
  2011-10-12 14:25   ` aep
@ 2011-10-12 14:46     ` aep
  2011-10-14  1:03       ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: aep @ 2011-10-12 14:46 UTC (permalink / raw)
  To: musl

clang optimized away the check in calloc.c to false.
I can work around it with a cast to something volatile:

diff --git a/src/malloc/calloc.c b/src/malloc/calloc.c
index 9d57456..22f2c01 100644
--- a/src/malloc/calloc.c
+++ b/src/malloc/calloc.c
@@ -13,8 +13,10 @@ void *calloc(size_t m, size_t n)
         n *= m;
         p = malloc(n);
         if (!p) return 0;
+
+    volatile long long dont_optimize_me = p;
         /* Only do this for non-mmapped chunks */
-       if (((size_t *)p)[-1] & 7) {
+       if (((size_t *)dont_optimize_me)[-1] & 7) {
                 /* Only write words that are not already zero */
                 m = (n + sizeof *z - 1)/sizeof *z;
                 for (z=p; m; m--, z++) if (*z) *z=0;



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] properly terminate linked link of dsos
  2011-10-12 14:46     ` aep
@ 2011-10-14  1:03       ` Rich Felker
  2011-10-14 21:11         ` Isaac Dunham
  0 siblings, 1 reply; 7+ messages in thread
From: Rich Felker @ 2011-10-14  1:03 UTC (permalink / raw)
  To: musl

On Wed, Oct 12, 2011 at 04:46:30PM +0200, aep wrote:
> clang optimized away the check in calloc.c to false.
> I can work around it with a cast to something volatile:

You could instead just change the (size_t *) cast to
(volatile size_t *)...

But I think the problem is much deeper. This "optimization" is
necessarily based on the compiler making an assumption about what the
function named "malloc" does. Compiling the implementation (libc)
itself requires disabling such assumptions; with gcc, this is achieved
with -ffreestanding (-fno-builtin will also work). Can you use the
same or similar option with clang?

I made similar comments on IRC..

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] properly terminate linked link of dsos
  2011-10-14  1:03       ` Rich Felker
@ 2011-10-14 21:11         ` Isaac Dunham
  2011-10-14 22:53           ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: Isaac Dunham @ 2011-10-14 21:11 UTC (permalink / raw)
  To: musl

On Thu, 13 Oct 2011 21:03:17 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> But I think the problem is much deeper. This "optimization" is
> necessarily based on the compiler making an assumption about what the
> function named "malloc" does. Compiling the implementation (libc)
> itself requires disabling such assumptions; with gcc, this is achieved
> with -ffreestanding (-fno-builtin will also work). Can you use the
> same or similar option with clang?

Per the manpage, -ffreestanding and -fno-builtin will work with clang.
-ffreestanding is probably the proper choice, since a new libc is a
freestanding environment.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] properly terminate linked link of dsos
  2011-10-14 21:11         ` Isaac Dunham
@ 2011-10-14 22:53           ` Rich Felker
  0 siblings, 0 replies; 7+ messages in thread
From: Rich Felker @ 2011-10-14 22:53 UTC (permalink / raw)
  To: musl

On Fri, Oct 14, 2011 at 02:11:52PM -0700, Isaac Dunham wrote:
> On Thu, 13 Oct 2011 21:03:17 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> 
> > But I think the problem is much deeper. This "optimization" is
> > necessarily based on the compiler making an assumption about what the
> > function named "malloc" does. Compiling the implementation (libc)
> > itself requires disabling such assumptions; with gcc, this is achieved
> > with -ffreestanding (-fno-builtin will also work). Can you use the
> > same or similar option with clang?
> 
> Per the manpage, -ffreestanding and -fno-builtin will work with clang.
> -ffreestanding is probably the proper choice, since a new libc is a
> freestanding environment.

Indeed, but it sounds like this is not fixing the problem. :(
Can you confirm that calloc.c is compiled properly when -ffreestanding
is used?

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-10-14 22:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-12 13:42 [PATCH] properly terminate linked link of dsos Arvid Ephraim Picciani
2011-10-12 14:01 ` Rich Felker
2011-10-12 14:25   ` aep
2011-10-12 14:46     ` aep
2011-10-14  1:03       ` Rich Felker
2011-10-14 21:11         ` Isaac Dunham
2011-10-14 22:53           ` Rich Felker

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).