public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@muc.de>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Fix undefined/miscompiled construct in kernel parameters
Date: Sun, 15 Jun 2003 19:17:40 +0200	[thread overview]
Message-ID: <m3of0zdzuz.fsf@averell.firstfloor.org> (raw)
In-Reply-To: <20030615170013$4ebc@gated-at.bofh.it> (Linus Torvalds's message of "Sun, 15 Jun 2003 19:00:13 +0200")

Linus Torvalds <torvalds@transmeta.com> writes:

> On Sun, 15 Jun 2003, Andi Kleen wrote:
>> 
>> The parse_args call in init/main.c does pointer arithmetic between two 
>> different external symbols. This is undefined in C (only pointer arthmetic
>> in the same symbol is defined) and gets miscompiled on AMD64 with gcc 3.2,
>
> That's silly. You're making the code less readable, with some silly 
> parameters. Why does it get miscompiled on amd64, and let's just fix that 
> one.

Because &arbitary_symbol_a - &arbitary_symbol_b is undefined in C and
the amd64 gcc 3.2 choses to miscompile it (it results in a very big  
number because it converts the 56/40 division to an inversed multiplication
in a wrong way). I actually wrote a compiler bug report first, but the 
compiler developers rightly pointed out that it is undefined.

Note this is not the first time we had such problems, it happened
with __pa(&symbol) too (amd64 has a special macro to work around that).
I don't know why it happens more often on amd64 than on i386, perhaps
it has something to do with the RIP relative addressing or the
negative kernel code model. ppc seems to have similar problems.

Passing an end pointer is not too different from passing an 
max index in my opinion.

Another way would be to use the anonymous asm trick proposed by rth
some time ago for a similar problem (asm("" : "=g" (output) : "0" (input))
to hide the symbols from the compiler), but I didn't do that because
it looked more ugly to me.

If you prefer to do it with the anonymous asm I can do it, but I don't
see a big problem with passing an end pointer.

-Andi

       reply	other threads:[~2003-06-15 17:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20030615131004$6a85@gated-at.bofh.it>
     [not found] ` <20030615170013$4ebc@gated-at.bofh.it>
2003-06-15 17:17   ` Andi Kleen [this message]
2003-06-15 17:24     ` [PATCH] Fix undefined/miscompiled construct in kernel parameters Linus Torvalds
2003-06-15 17:32       ` Andi Kleen
2003-06-15 17:48         ` Roman Zippel
2003-06-15 18:28           ` Andi Kleen
2003-06-15 22:56           ` Richard Henderson
2003-06-15 12:58 Andi Kleen
2003-06-15 16:52 ` Linus Torvalds
2003-06-16  0:23   ` Rusty Russell
2003-06-16  0:49     ` Richard Henderson
2003-06-16  3:55       ` Rusty Russell
2003-06-16  2:44     ` Linus Torvalds

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=m3of0zdzuz.fsf@averell.firstfloor.org \
    --to=ak@muc.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox