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

Eli Friedman eli.friedman at gmail.com
Tue Nov 13 14:27:35 PST 2012


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?

-Eli



More information about the llvm-commits mailing list