[llvm-commits] [PATCH] Fix llvm-nm crash on big-endian systems caused by r167853

Eric Christopher echristo at gmail.com
Tue Nov 13 14:44:07 PST 2012


On Tue, Nov 13, 2012 at 2:27 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> On Tue, Nov 13, 2012 at 2:09 PM, Ulrich Weigand
> <Ulrich.Weigand at de.ibm.com> wrote:
> >
> > Hello,
> >
> > this change (part of r167853):
> >
> > +    uint32_t *offsetaddr =
> > +             (uint32_t *)(reinterpret_cast<const support::ulittle32_t*>
> > (offsets)
> > +                          + (offsetindex - 1));
> > +    assert((const char *)offsetaddr <
> > +           Parent->SymbolTable->getBuffer()->getBufferEnd());
> > +    offset = *(offsetaddr);
> >
> > causes crashes when llvm-nm is compiled on a big-endian host; note how
> the
> > "support::ulittle32_t" pointer is cast back right away to a plain
> uint32_t
> > pointer, which gets dereferenced using the host endianness.
> >
> > The attached patch fixes this (fixing the Object/coff-archive.test test
> > case on PowerPC), and removes a const-violation warning as well.
> >
> > OK to commit?
>
> Not really your fault, but am I the only one who finds it a little
> scary we're adding an arbitrary value to a pointer and expecting it to
> point at valid memory?
>

Not really, no, but at least some of how this stuff is written works on
magic constants anyhow. Might be nice to codify a lot of these as
functions/defines/something.

-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121113/a1f47057/attachment.html>


More information about the llvm-commits mailing list