This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] Make --fix-cortex-a53-843419 work on big endian hosts
ClosedPublic

Authored by peter.smith on Jan 23 2018, 7:24 AM.

Details

Summary

The reinterpret cast to uint32_t to read the little-endian instructions will only work on a little endian system. Use ulittle32_t to always read little-endian (AArch64 instructions are always little endian).

Fixes PR36056: https://bugs.llvm.org/show_bug.cgi?id=36056

An alternative logically equivalent fix is to use read32le into a uint32_t but that is slightly more of a change to the structure of the code. I've uploaded to the PR a prototype fix under https://bugs.llvm.org/attachment.cgi?id=19727 and can use that if you prefer.

Found by Simon Dardis during release candidate testing on a Mips Big Endian system.

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith created this revision.Jan 23 2018, 7:24 AM

+ const ulittle32_t *InstBuf = reinterpret_cast<const ulittle32_t *>(Buf + Off);

This is OK.

+ ulittle32_t Instr1 = *InstBuf++;
+ ulittle32_t Instr2 = *InstBuf++;
+ ulittle32_t Instr3 = *InstBuf++;

But the values should still be uint32_t. The endian.h types should only
ever be used to form pointers.

Cheers,
Rafael

Thanks for pointing that out. I've updated the diff accordingly.

Spoke to soon, forgot to correct the last ulittle32_t that was hiding from me. Now updated.

This revision was not accepted when it landed; it landed in state Needs Review.Jan 23 2018, 11:29 AM
This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.