mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: musl as a framework to test applications' compatibility with POSIX (was: NULL)
Date: Mon, 14 Jan 2013 10:14:17 -0500	[thread overview]
Message-ID: <20130114151417.GN20323@brightrain.aerifal.cx> (raw)
In-Reply-To: <20130114143025.GA12142@cachalot>

On Mon, Jan 14, 2013 at 06:30:25PM +0400, Vasily Kulikov wrote:
> On Mon, Jan 14, 2013 at 09:03 -0500, Rich Felker wrote:
> > On Mon, Jan 14, 2013 at 12:45:27PM +0400, Vasily Kulikov wrote:
> > > In musl libc it can be implemented as -DI_WANT_TO_DETECT_GCCISMS.
> > 
> > At the very least, this would have to be a macro in the reserved
> > namespace. However, I'm skeptical of using musl as a tool for checking
> > this, especially since the check only works on 64-bit systems and does
> > not help the compiler produce a warning/error, but only causes random,
> > hard-to-diagnose crashes. It looks like cppcheck is adding (or has
> > already added?) a test for incorrectly passing NULL to variadic
> > functions, which is probably where the check belongs.
> 
> My thought related to this specific bug was a bit more complex:
> 
> 1) on each call of a variadic function save the list of all types
> 2) on each call to va_arg(ap, T) check whether the current argument was
> pushed as T in the saved list
> 
> It would catch not only NULL/(void *)NULL, but also int/long or
> void*/long bugs.
> 
> Now I see that while it is possible to implement (2) in libc redefining
> va_XXX() macros, but it looks like (1) has to be implemented in compiler.

Both require support by the compiler. It's impossible to implement
va_arg without a compiler builtin. Traditionally it was done with
UB-invoking pointer arithmetic on archs where the arguments are passed
on the stack, but even this is invalid and will break under compiler
optimizations such as inlining or reordering local vars for cache
locality purposes.

Also, unfortunately, it's an ABI issue. Making this change would
create a completely separate ABI.

I think static analysis is really the way to go; unfortunately, it
requires some degree of additional markup to specify the argument
types contract.

Rich


  parent reply	other threads:[~2013-01-14 15:14 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-09 11:02 NULL John Spencer
2013-01-09 12:18 ` NULL Szabolcs Nagy
2013-01-09 13:36   ` NULL John Spencer
2013-01-12  6:32     ` NULL Rob Landley
2013-01-12  6:46       ` NULL Rich Felker
2013-01-12  7:15         ` NULL Luca Barbato
2013-01-12 13:33           ` NULL Rich Felker
2013-01-12 11:39       ` NULL Jens Staal
2013-01-09 13:09 ` NULL croco
2013-01-09 13:47   ` NULL John Spencer
2013-01-09 14:49     ` NULL croco
2013-01-09 14:42 ` NULL Luca Barbato
2013-01-09 14:47   ` NULL Rich Felker
2013-01-09 15:03     ` NULL Luca Barbato
2013-01-09 15:18     ` NULL John Spencer
2013-01-09 15:36       ` NULL Rich Felker
2013-01-09 21:11         ` NULL Rob
2013-01-09 21:53           ` NULL Szabolcs Nagy
2013-01-09 22:17             ` NULL Rob
2013-01-09 23:42         ` NULL Szabolcs Nagy
2013-01-12  6:56         ` NULL Rob Landley
2013-01-12  7:07           ` NULL Bobby Bingham
2013-01-12 13:31           ` NULL Rich Felker
2013-01-13 14:29             ` NULL Rob Landley
2013-01-13 14:56               ` NULL Luca Barbato
2013-01-13 16:29                 ` NULL Rob Landley
2013-01-13 17:14                   ` NULL Luca Barbato
2013-01-13 15:23               ` NULL Strake
2013-01-13 17:17                 ` NULL Luca Barbato
2013-01-13 17:47               ` NULL Szabolcs Nagy
2013-01-13 19:46                 ` NULL Rob Landley
2013-01-14  6:11                   ` NULL Rich Felker
2013-01-14  8:45                     ` musl as a framework to test applications' compatibility with POSIX (was: NULL) Vasily Kulikov
2013-01-14 14:03                       ` Rich Felker
2013-01-14 14:30                         ` Vasily Kulikov
2013-01-14 15:02                           ` Szabolcs Nagy
2013-01-14 15:14                           ` Rich Felker [this message]
2013-01-14 13:19                     ` NULL Rob Landley
2013-01-12  5:56 ` NULL Rob Landley
2013-01-12  6:42   ` NULL Rich Felker

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=20130114151417.GN20323@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /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.
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).