Is it possible to change endianness mid-execution on ARM (Android/Linux)?

前端 未结 1 819
名媛妹妹
名媛妹妹 2021-01-19 10:27

I am wondering if it is possible to change the endianness of a running application mid-execution on the ARM platform. As some of you know, ARM is bi-endian (supporting both

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-19 10:54

    It is (on ARMv7 and older hardware at least) certainly possible, but your sentiment is entirely correct - anyone else, please, please, for the sake of sanity, forward-compatibility and angry kernel developers, don't do this in Linux/Android - use REV, REV16, REVSH or VREV on data as appropriate.

    The SETEND instruction, introduced in ARMv6, allows switching the endianness of the current execution state at any privilege level, however from ARMv8 it is deprecated, disabled by default, and likely to disappear entirely in future. Supporting mixed-endianness in hardware is optional in ARMv8.

    Despite being a terrible idea, it's apparently commonplace enough in Android apps currently in the wild (among possible other uses, it's supposedly the fastest way to implement strcmp() on ARM11, and maybe also Cortex-A8) that SETEND emulation for 32-bit tasks has recently had to be added to the arm64 kernel, so chances are your tools should at least be aware of it, too.

    0 讨论(0)
提交回复
热议问题