* Another Unaligned Access/Code Generation Question
@ 2008-05-22 19:06 Jay.Estabrook
2008-05-22 20:03 ` macro
2008-05-23 6:59 ` tsv
0 siblings, 2 replies; 4+ messages in thread
From: Jay.Estabrook @ 2008-05-22 19:06 UTC (permalink / raw)
Hi again,
In the current Fedora 8 Alpha distro, KDE is getting, I think, a LOT
more use than ever before, due to the GNOME problems. Because of that,
UAs in KDE apps are, or have become, the majority of UAs showing up
in /var/log/messages.
I've tracked down a single point of unaligned access in one of the
kdebase libraries that is continually showing up, as it is called by
MANY of the KDE applications, like kicker and konsole and such.
It is located in code whose name, according to GDB, is:
_ZNK14QLocalePrivate14doubleToStringEdiNS_10DoubleFormEij
And yes, that is almost certainly in C++ code... ;-}
The UA is always from an instruction like:
ldt $f10,-5721(t0)
where register "t0" holds an aligned address in the "gp" area, and thus
the odd offset is what causes the UA.
I tried both GCC -23 and -37, and there was no difference in code.
I tried using "-mbuild-constants", and, while it changed some of the
surrounding code, did not prevent the same (different but still
odd offset) instruction from getting generated.
I'm wondering what kind of C/C++ code could cause such to be generated?
(I know, I know, not much to go on; I could get additional logs.)
I thought it might be register spill code that had run out of INT regs
and went to FP ones, which was why I tried the "mbuild-constants" thing,
but that probably wasn't a good guess, seeing as the name of the routine
IS "doubleToString"... ;-}
Now, granted, this is not a high traffic UA, only occurs a few times
per app, apparently, but it is VERY annoying, since it manifests as MANY
different applications appearing to be the culprit of UAs.
In addition, it apparently is not BAD code - that is, there doesn't
appear to be anything wrong with the results of its "fix up", meaning
the data is probably OK too, and found where pointed at.
I wonder if there's anything I can do about it?
Thanks again for any insights.
--Jay++
^ permalink raw reply [flat|nested] 4+ messages in thread* Another Unaligned Access/Code Generation Question
2008-05-22 19:06 Another Unaligned Access/Code Generation Question Jay.Estabrook
@ 2008-05-22 20:03 ` macro
2008-05-23 6:59 ` tsv
1 sibling, 0 replies; 4+ messages in thread
From: macro @ 2008-05-22 20:03 UTC (permalink / raw)
On Thu, 22 May 2008, Jay Estabrook wrote:
> It is located in code whose name, according to GDB, is:
>
> _ZNK14QLocalePrivate14doubleToStringEdiNS_10DoubleFormEij
>
> And yes, that is almost certainly in C++ code... ;-}
QLocalePrivate::doubleToString(double, int, QLocalePrivate::DoubleForm,
int, unsigned int) const
according to `c++filt'; GDB should be able to demangle it too. :-)
> I'm wondering what kind of C/C++ code could cause such to be generated?
> (I know, I know, not much to go on; I could get additional logs.)
It usually happens when a badly aligned argument is passed down to a
function (or method) as a result of a bad cast. Sloppy code in general.
;-)
> In addition, it apparently is not BAD code - that is, there doesn't
> appear to be anything wrong with the results of its "fix up", meaning
> the data is probably OK too, and found where pointed at.
If you cast a narrower (less strictly aligned) type to a wider (more
strictly aligned) one, it is always bad code. For example you will not
get data corruption from casting char[4] to an unsigned int and in many
cases such code will work, but that's still undefined behaviour -- you are
perfectly fine to expect to get a SIGBUS rather than anything else in this
case. Some people believe all the world is the x86 (they are wrong, of
course, because it is the VAX what all the world is) and do not even have
a slightliest clue about what data alignment is.
> I wonder if there's anything I can do about it?
Find where the piece of unaligned data comes from and how it gets through
to doubleToString(). ;-) A hardware watchpoint might be useful -- any of
the Alpha processors providing them? Ones I used unfortunately did not
have them, but it was long ago and they were only EV45. A software
watchpoint might do, but the experience will be rather painfully slow.
Maciej
^ permalink raw reply [flat|nested] 4+ messages in thread
* Another Unaligned Access/Code Generation Question
2008-05-22 19:06 Another Unaligned Access/Code Generation Question Jay.Estabrook
2008-05-22 20:03 ` macro
@ 2008-05-23 6:59 ` tsv
2008-05-23 14:12 ` Jay.Estabrook
1 sibling, 1 reply; 4+ messages in thread
From: tsv @ 2008-05-23 6:59 UTC (permalink / raw)
Hello Jay,
Jay Estabrook wrote:
> Hi again,
>
> In the current Fedora 8 Alpha distro, KDE is getting, I think, a LOT
> more use than ever before, due to the GNOME problems. Because of that,
> UAs in KDE apps are, or have become, the majority of UAs showing up
> in /var/log/messages.
>
> I've tracked down a single point of unaligned access in one of the
> kdebase libraries that is continually showing up, as it is called by
> MANY of the KDE applications, like kicker and konsole and such.
>
> It is located in code whose name, according to GDB, is:
>
> _ZNK14QLocalePrivate14doubleToStringEdiNS_10DoubleFormEij
>
> And yes, that is almost certainly in C++ code... ;-}
>
> The UA is always from an instruction like:
>
> ldt $f10,-5721(t0)
>
> where register "t0" holds an aligned address in the "gp" area, and thus
> the odd offset is what causes the UA.
>
> I tried both GCC -23 and -37, and there was no difference in code.
>
Please, take a look at kde patches from AC3 distro.
I remember that some there in kde where was a double/float value defined
as sequence of bytes in the middle of char
arrays definitions. Later on it was stored into a data section as
unaligned. I remember adding some long dummy variable
in front of that to force the defined double to be correctly aligned.
As for dbus problem - I was using temporary volatile pointer to the
passed structure (patches are in AC3 tree) and that forced the
compiler to generate the correct code.
I remember I discussed that problem sometime ago with some guy from
debian and Richard (gcc alpha patcher).
It seems that in current case that gcc assumption might be correct - it
expects that the passed pointer to that union is aligned.
At it is supported by declaration of that function. That problem is that
the caller assigns value to that pointer just from some data it has
(I guess some buffer received over network if I remember correctly).
To make it to work correctly it is necessary to use temporary structure
on caller side and do byte copy of data into it and then call our
"problem" method or teach the method to not assume that pointer is
properly aligned.
Again, I remember fixing most of the UAEs during AC2/AC3 preparations.
Thank you,
--
Sergey Tikhonov
Head, R&D department
Solvo Ltd.
Saint-Petersburg, Russia
http://www.solvo.ru
tsv at solvo.ru
^ permalink raw reply [flat|nested] 4+ messages in thread
* Another Unaligned Access/Code Generation Question
2008-05-23 6:59 ` tsv
@ 2008-05-23 14:12 ` Jay.Estabrook
0 siblings, 0 replies; 4+ messages in thread
From: Jay.Estabrook @ 2008-05-23 14:12 UTC (permalink / raw)
Hi, Sergey!
Sergey Tikhonov wrote:
>>
> Please, take a look at kde patches from AC3 distro.
> I remember that some there in kde where was a double/float value defined
> as sequence of bytes in the middle of char
> arrays definitions. Later on it was stored into a data section as
> unaligned. I remember adding some long dummy variable
> in front of that to force the defined double to be correctly aligned.
That sounds just like something that would cause the problem I see.
> As for dbus problem - I was using temporary volatile pointer to the
> passed structure (patches are in AC3 tree) and that forced the
> compiler to generate the correct code.
Yes, exactly; my point was that the two compilers reacted differently
to the same code, and only the final version (with "volatile") would
work on both. I was looking for guidelines that wouold say either
"that's the way to do it", or propose something more reliable... ;-}
> I remember I discussed that problem sometime ago with some guy from
> debian and Richard (gcc alpha patcher).
> It seems that in current case that gcc assumption might be correct - it
> expects that the passed pointer to that union is aligned.
> At it is supported by declaration of that function. That problem is that
> the caller assigns value to that pointer just from some data it has
> (I guess some buffer received over network if I remember correctly).
Yes again; the union allowed an easy way to take an arbitrary address
and pick up an arbitrary-length datum located there.
> To make it to work correctly it is necessary to use temporary structure
> on caller side and do byte copy of data into it and then call our
> "problem" method or teach the method to not assume that pointer is
> properly aligned.
I went with the latter, obviously; in this case, there was only one
place where the "char" store was being done, so only one place to fix.
The other data lengths actually had some funky alignment code in them,
and thus didn't need to be fixed.
Other situations might require other remedies; a different application
went to great lengths to do its own "optimized" memcpy/memset
operations, but in fact on Alpha, they generated UAs. Fortunately, they
left on option to just use GCC's memcpy/memset instead, and presto!
Fixed on Alpha... :-)
> Again, I remember fixing most of the UAEs during AC2/AC3 preparations.
Thanks for all the work you did on making AC2/3 as good as they were.
I'll be looking into those SRPMS you made later today!!! :-) :-)
Thanks again, Sergey.
--Jay++
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-05-23 14:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-22 19:06 Another Unaligned Access/Code Generation Question Jay.Estabrook
2008-05-22 20:03 ` macro
2008-05-23 6:59 ` tsv
2008-05-23 14:12 ` Jay.Estabrook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox