From: Sam Ravnborg <sam@ravnborg.org>
To: Russell King <rmk+lkml@arm.linux.org.uk>
Cc: Jaswinder Singh Rajput <jaswinder@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>,
Catalin Marinas <catalin.marinas@arm.com>,
Tony Luck <tony.luck@intel.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Greg Ungerer <gerg@snapgear.com>,
Ralf Baechle <ralf@linux-mips.org>,
Michael Abbott <michael@araneidae.co.uk>,
Andrew Morton <akpm@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>,
David Howells <dhowells@redhat.com>
Subject: Re: [GIT PULL] headers_check fixes
Date: Sun, 7 Jun 2009 09:16:06 +0200 [thread overview]
Message-ID: <20090607071606.GA11256@uranus.ravnborg.org> (raw)
In-Reply-To: <20090606214711.GA4813@flint.arm.linux.org.uk>
On Sat, Jun 06, 2009 at 10:47:11PM +0100, Russell King wrote:
> Right, below is a patch to unifdef.c which allows it to work out if
> an #if expression always evaluates true or false for symbols which
> are being undefined/always defined.
>
> The patch is slightly more complicated than I'd hoped because unifdef
> needs to see lines fully evaluated - doing otherwise causes it to
> mark the line as "dirty" and copy it over no matter what.
>
> What follows this email is the diff of what effect it has on the
> headers copied over - as can be seen, all resulting changes are of
> net benefit.
Result is great - thanks for implmenting this!
I have applied the following (no code changes, only a few more
details in the changelog).
Sam
commit 3a8a10760f9626856848ae815e9436a2e04a4082
Author: Russell King <rmk+lkml@arm.linux.org.uk>
Date: Sat Jun 6 22:47:11 2009 +0100
kbuild: fix headers_exports with boolean expression
When we had code like this in a header unifdef failed to
deduct that the expression was always false - and we had code exported
that was not intended for userspace.
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
int a;
#endif
This commit implment support in unidef which allows it to work out if
an #if expression always evaluates true or false for symbols which
are being undefined/always defined.
The patch is slightly more complicated than I'd hoped because unifdef
needs to see lines fully evaluated - doing otherwise causes it to
mark the line as "dirty" and copy it over no matter what.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
diff --git a/scripts/unifdef.c b/scripts/unifdef.c
index 05a31a6..30d459f 100644
--- a/scripts/unifdef.c
+++ b/scripts/unifdef.c
@@ -678,8 +678,10 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
if (*cp == '!') {
debug("eval%d !", ops - eval_ops);
cp++;
- if (eval_unary(ops, valp, &cp) == LT_IF)
+ if (eval_unary(ops, valp, &cp) == LT_IF) {
+ *cpp = cp;
return (LT_IF);
+ }
*valp = !*valp;
} else if (*cp == '(') {
cp++;
@@ -700,13 +702,16 @@ eval_unary(const struct ops *ops, int *valp, const char **cpp)
return (LT_IF);
cp = skipcomment(cp);
sym = findsym(cp);
- if (sym < 0)
- return (LT_IF);
- *valp = (value[sym] != NULL);
cp = skipsym(cp);
cp = skipcomment(cp);
if (*cp++ != ')')
return (LT_IF);
+ if (sym >= 0)
+ *valp = (value[sym] != NULL);
+ else {
+ *cpp = cp;
+ return (LT_IF);
+ }
keepthis = false;
} else if (!endsym(*cp)) {
debug("eval%d symbol", ops - eval_ops);
@@ -741,11 +746,11 @@ eval_table(const struct ops *ops, int *valp, const char **cpp)
const struct op *op;
const char *cp;
int val;
+ Linetype lhs, rhs;
debug("eval%d", ops - eval_ops);
cp = *cpp;
- if (ops->inner(ops+1, valp, &cp) == LT_IF)
- return (LT_IF);
+ lhs = ops->inner(ops+1, valp, &cp);
for (;;) {
cp = skipcomment(cp);
for (op = ops->op; op->str != NULL; op++)
@@ -755,14 +760,32 @@ eval_table(const struct ops *ops, int *valp, const char **cpp)
break;
cp += strlen(op->str);
debug("eval%d %s", ops - eval_ops, op->str);
- if (ops->inner(ops+1, &val, &cp) == LT_IF)
- return (LT_IF);
- *valp = op->fn(*valp, val);
+ rhs = ops->inner(ops+1, &val, &cp);
+ if (op->fn == op_and && (lhs == LT_FALSE || rhs == LT_FALSE)) {
+ debug("eval%d: and always false", ops - eval_ops);
+ if (lhs == LT_IF)
+ *valp = val;
+ lhs = LT_FALSE;
+ continue;
+ }
+ if (op->fn == op_or && (lhs == LT_TRUE || rhs == LT_TRUE)) {
+ debug("eval%d: or always true", ops - eval_ops);
+ if (lhs == LT_IF)
+ *valp = val;
+ lhs = LT_TRUE;
+ continue;
+ }
+ if (rhs == LT_IF)
+ lhs = LT_IF;
+ if (lhs != LT_IF)
+ *valp = op->fn(*valp, val);
}
*cpp = cp;
debug("eval%d = %d", ops - eval_ops, *valp);
- return (*valp ? LT_TRUE : LT_FALSE);
+ if (lhs != LT_IF)
+ lhs = (*valp ? LT_TRUE : LT_FALSE);
+ return lhs;
}
/*
@@ -773,12 +796,15 @@ eval_table(const struct ops *ops, int *valp, const char **cpp)
static Linetype
ifeval(const char **cpp)
{
+ const char *cp = *cpp;
int ret;
int val;
debug("eval %s", *cpp);
keepthis = killconsts ? false : true;
- ret = eval_table(eval_ops, &val, cpp);
+ ret = eval_table(eval_ops, &val, &cp);
+ if (ret != LT_IF)
+ *cpp = cp;
debug("eval = %d", val);
return (keepthis ? LT_IF : ret);
}
next prev parent reply other threads:[~2009-06-07 7:13 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-04 12:23 [PATCH 0/6] headers_check fix patches 20090604 Jaswinder Singh Rajput
2009-06-04 12:27 ` [PATCH 1/6] headers_check fix: arm, hwcap.h Jaswinder Singh Rajput
2009-06-04 12:29 ` [PATCH 2/6] headers_check fix: ia64, fpswa.h Jaswinder Singh Rajput
2009-06-04 12:31 ` [PATCH 3/6] headers_check fix: m68k, swab.h Jaswinder Singh Rajput
2009-06-04 12:35 ` [PATCH 4/6] headers_check fix: mips, ioctl.h Jaswinder Singh Rajput
2009-06-04 12:37 ` [PATCH 5/6] headers_check fix: mn10300, ptrace.h Jaswinder Singh Rajput
2009-06-04 12:38 ` [PATCH 6/6] headers_check fix: mn10300, setup.h Jaswinder Singh Rajput
2009-06-04 12:46 ` [PATCH 4/6] headers_check fix: mips, ioctl.h Ralf Baechle
2009-06-04 20:09 ` Sam Ravnborg
2009-06-05 9:34 ` Arnd Bergmann
2009-06-05 12:04 ` Ralf Baechle
2009-06-04 20:22 ` [PATCH 2/6] headers_check fix: ia64, fpswa.h Sam Ravnborg
2009-06-08 16:33 ` Luck, Tony
2009-06-08 17:48 ` [PATCH] ia64: unexport fpswa.h Sam Ravnborg
2009-06-05 9:26 ` [PATCH 2/6] headers_check fix: ia64, fpswa.h Arnd Bergmann
2009-06-04 12:53 ` [PATCH 1/6] headers_check fix: arm, hwcap.h Russell King
2009-06-04 15:45 ` Jaswinder Singh Rajput
2009-06-04 20:16 ` Sam Ravnborg
2009-06-05 20:10 ` Russell King
2009-06-05 20:17 ` Robert P. J. Day
2009-06-05 20:48 ` Russell King
2009-06-05 21:24 ` Sam Ravnborg
2009-06-06 8:50 ` Jaswinder Singh Rajput
2009-06-06 9:12 ` Russell King
2009-06-06 9:34 ` Jaswinder Singh Rajput
2009-06-04 20:12 ` [PATCH 0/6] headers_check fix patches 20090604 Sam Ravnborg
2009-06-05 2:00 ` Jaswinder Singh Rajput
2009-06-06 8:10 ` Jaswinder Singh Rajput
2009-06-06 8:43 ` Sam Ravnborg
2009-06-06 9:09 ` Jaswinder Singh Rajput
2009-06-06 12:54 ` [GIT PULL] headers_check fixes Jaswinder Singh Rajput
2009-06-06 13:02 ` Russell King
2009-06-06 13:34 ` Jaswinder Singh Rajput
2009-06-06 13:41 ` Russell King
2009-06-06 14:39 ` Jaswinder Singh Rajput
2009-06-06 21:47 ` Russell King
2009-06-06 21:51 ` Russell King
2009-06-06 22:12 ` Sam Ravnborg
2009-06-06 23:24 ` Russell King
2009-06-07 7:09 ` Sam Ravnborg
2009-06-07 7:16 ` Sam Ravnborg [this message]
2009-06-07 10:15 ` Jaswinder Singh Rajput
-- strict thread matches above, loose matches on Subject: below --
2009-06-01 7:20 Jaswinder Singh Rajput
2009-01-26 18:01 [git pull] " Ingo Molnar
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=20090607071606.GA11256@uranus.ravnborg.org \
--to=sam@ravnborg.org \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=dhowells@redhat.com \
--cc=geert@linux-m68k.org \
--cc=gerg@snapgear.com \
--cc=jaswinder@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@araneidae.co.uk \
--cc=mingo@elte.hu \
--cc=ralf@linux-mips.org \
--cc=rmk+lkml@arm.linux.org.uk \
--cc=tony.luck@intel.com \
--cc=torvalds@linux-foundation.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