diff options
| author | ruki <[email protected]> | 2026-07-18 19:36:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-07-18 19:36:24 +0800 |
| commit | 6b3632901ad14e99d306232c15cf788f6b081066 (patch) | |
| tree | 9d8f3ad9e9251ab75b2b3c9974ee81c175c5d1cf | |
| parent | 5feeecfdeaac2780a3c838751d28264ee1482cb2 (diff) | |
improve ppc
| -rw-r--r-- | core/src/xmake/binutils/prefix.h | 14 | ||||
| -rw-r--r-- | tests/modules/binutils/test.lua | 16 |
2 files changed, 24 insertions, 6 deletions
diff --git a/core/src/xmake/binutils/prefix.h b/core/src/xmake/binutils/prefix.h index bef683209..c0f6ac356 100644 --- a/core/src/xmake/binutils/prefix.h +++ b/core/src/xmake/binutils/prefix.h @@ -241,9 +241,19 @@ static __tb_inline__ tb_bool_t xm_binutils_arch_is_bigendian(tb_char_t const *ar else if (tb_strncmp(arch, "mips", 4) == 0) { return tb_strstr(arch, "el") == tb_null; } - // PowerPC big-endian variants (ppc, ppc64), the little-endian ones end with "le" (ppc64le, powerpc64le) + // PowerPC endianness: + // - an explicit "le"/"be" suffix always wins (ppc64le/powerpc64le, ppc64be) + // - otherwise 64-bit ppc64/powerpc64 defaults to little-endian: xmake has no separate + // ppc64le arch (find_platform maps powerpc64le -> ppc64) and ppc64le is the dominant + // modern target, so a plain "ppc64" is treated as ppc64le (LE + OpenPOWER ELFv2) + // - 32-bit ppc stays traditional big-endian else if (tb_strncmp(arch, "ppc", 3) == 0 || tb_strncmp(arch, "powerpc", 7) == 0) { - return tb_strstr(arch, "le") == tb_null; + if (tb_strstr(arch, "le")) { + return tb_false; + } else if (tb_strstr(arch, "be")) { + return tb_true; + } + return !xm_binutils_arch_is_64bit(arch); } return tb_false; } diff --git a/tests/modules/binutils/test.lua b/tests/modules/binutils/test.lua index d1e13d75d..fe4a182f2 100644 --- a/tests/modules/binutils/test.lua +++ b/tests/modules/binutils/test.lua @@ -182,18 +182,26 @@ function test_bin2elf(t) t:are_equal(mips64el.machine, 0x08) t:are_equal(mips64el.flags, 0x4) - -- ppc64 is big-endian and uses the ELFv1 ABI (e_flags low bits == 1) + -- xmake has no separate ppc64le arch (find_platform maps powerpc64le -> ppc64) and + -- ppc64le is the dominant modern target, so a plain "ppc64" is treated as ppc64le: + -- little-endian + OpenPOWER ELFv2 ABI (e_flags low bits == 2) local ppc64 = _gen("ppc64") - t:are_equal(ppc64.encode, 2) + t:are_equal(ppc64.encode, 1) t:are_equal(ppc64.machine, 0x15) - t:are_equal(ppc64.flags, 0x1) + t:are_equal(ppc64.flags, 0x2) - -- ppc64le is little-endian and uses the OpenPOWER ELFv2 ABI (e_flags low bits == 2) + -- explicit ppc64le behaves the same local ppc64le = _gen("ppc64le") t:are_equal(ppc64le.encode, 1) t:are_equal(ppc64le.machine, 0x15) t:are_equal(ppc64le.flags, 0x2) + -- explicit big-endian ppc64be keeps the ELFv1 ABI + local ppc64be = _gen("ppc64be") + t:are_equal(ppc64be.encode, 2) + t:are_equal(ppc64be.machine, 0x15) + t:are_equal(ppc64be.flags, 0x1) + os.tryrm(tempdir) end |
