diff options
| -rw-r--r-- | core/src/xmake/binutils/elf/bin2elf.c | 20 | ||||
| -rw-r--r-- | core/src/xmake/binutils/elf/prefix.h | 20 | ||||
| -rw-r--r-- | core/src/xmake/binutils/prefix.h | 13 |
3 files changed, 29 insertions, 24 deletions
diff --git a/core/src/xmake/binutils/elf/bin2elf.c b/core/src/xmake/binutils/elf/bin2elf.c index ee18e6113..ad580ba84 100644 --- a/core/src/xmake/binutils/elf/bin2elf.c +++ b/core/src/xmake/binutils/elf/bin2elf.c @@ -60,9 +60,10 @@ static tb_bool_t xm_binutils_bin2elf_bwrit_symbol_64(tb_stream_ref_t ostream, xm return tb_stream_bwrit(ostream, (tb_byte_t const *)s, sizeof(*s)); } -// read the identity (class/endianness/machine/e_flags) from a reference ELF object. -// returns tb_true and updates the out-params on success; leaves them untouched on any failure -// (missing file, too small, bad magic), so the caller keeps its arch-derived defaults. +/* read the identity (class/endianness/machine/e_flags) from a reference ELF object. + * returns tb_true and updates the out-params on success; leaves them untouched on any failure + * (missing file, too small, bad magic), so the caller keeps its arch-derived defaults. + */ static tb_bool_t xm_binutils_bin2elf_read_refobj(tb_char_t const *refobj, tb_bool_t *pis_64bit, tb_bool_t *pis_bigendian, tb_uint16_t *pe_machine, tb_uint32_t *pe_flags) { tb_assert_and_check_return_val(refobj && pis_64bit && pis_bigendian && pe_machine && pe_flags, tb_false); @@ -736,10 +737,11 @@ tb_int_t xm_binutils_bin2elf(lua_State *lua) { // get zeroend (optional, default: false) tb_bool_t zeroend = lua_toboolean(lua, 6); - // get the reference object (optional): a real object emitted by the target toolchain. - // we mirror its class/endianness/machine/e_flags so the output matches exactly, instead of - // guessing from the (sometimes ambiguous) arch name. when absent/unreadable we fall back to - // deriving everything from the arch name. + /* get the reference object (optional): a real object emitted by the target toolchain. + * we mirror its class/endianness/machine/e_flags so the output matches exactly, instead of + * guessing from the (sometimes ambiguous) arch name. when absent/unreadable we fall back to + * deriving everything from the arch name. + */ tb_char_t const *refobj = lua_isstring(lua, 7) ? lua_tostring(lua, 7) : tb_null; // do dump @@ -760,8 +762,8 @@ tb_int_t xm_binutils_bin2elf(lua_State *lua) { break; } - // resolve class/endian/machine/flags: derive from the arch name, then mirror the - // reference object if one was given and is a readable ELF (it wins over the heuristic) + /* resolve class/endian/machine/flags: derive from the arch name, then mirror the + * reference object if one was given and is a readable ELF (it wins over the heuristic) */ tb_bool_t is_64bit = xm_binutils_elf_is_64bit(arch); tb_bool_t is_bigendian = xm_binutils_elf_is_bigendian(arch); tb_uint16_t e_machine = xm_binutils_elf_get_machine(arch); diff --git a/core/src/xmake/binutils/elf/prefix.h b/core/src/xmake/binutils/elf/prefix.h index c26d678d2..9f18864df 100644 --- a/core/src/xmake/binutils/elf/prefix.h +++ b/core/src/xmake/binutils/elf/prefix.h @@ -349,18 +349,20 @@ static __tb_inline__ tb_uint32_t xm_binutils_elf_get_flags(tb_char_t const *arch else if (tb_strncmp(arch, "loongarch", 9) == 0 || tb_strncmp(arch, "loong64", 7) == 0) { return XM_EF_LOONGARCH_ABI_DOUBLE_FLOAT | XM_EF_LOONGARCH_OBJABI_V1; } - // PowerPC64: encode the ELF ABI version in e_flags. - // little-endian ppc64le uses the OpenPOWER ELFv2 ABI, big-endian ppc64 uses ELFv1, - // matching the gcc/clang defaults (-mabi=elfv2 on LE, -mabi=elfv1 on BE). - // 32-bit PowerPC does not carry an ABI version (e_flags == 0). + /* PowerPC64: encode the ELF ABI version in e_flags. + * little-endian ppc64le uses the OpenPOWER ELFv2 ABI, big-endian ppc64 uses ELFv1, + * matching the gcc/clang defaults (-mabi=elfv2 on LE, -mabi=elfv1 on BE). + * 32-bit PowerPC does not carry an ABI version (e_flags == 0). + */ else if (tb_strncmp(arch, "ppc64", 5) == 0 || tb_strncmp(arch, "powerpc64", 9) == 0) { return xm_binutils_arch_is_bigendian(arch)? XM_EF_PPC64_ABI_V1 : XM_EF_PPC64_ABI_V2; } - // MIPS: mark the object as CPIC so it links against both PIC and non-PIC objects, and - // tag the 32-bit variants with the o32 ABI to match the common GNU toolchains (n64 is - // implied by ELFCLASS64, so mips64/mips64el carry no ABI bit). the ISA level (top nibble) - // and fp/NaN bits are left at 0 (== "any") on purpose: overclaiming them would make the - // linker reject otherwise-compatible objects. + /* MIPS: mark the object as CPIC so it links against both PIC and non-PIC objects, and + * tag the 32-bit variants with the o32 ABI to match the common GNU toolchains (n64 is + * implied by ELFCLASS64, so mips64/mips64el carry no ABI bit). the ISA level (top nibble) + * and fp/NaN bits are left at 0 (== "any") on purpose: overclaiming them would make the + * linker reject otherwise-compatible objects. + */ else if (tb_strncmp(arch, "mips", 4) == 0) { tb_uint32_t flags = XM_EF_MIPS_CPIC; if (!xm_binutils_arch_is_64bit(arch)) { diff --git a/core/src/xmake/binutils/prefix.h b/core/src/xmake/binutils/prefix.h index c0f6ac356..ba7b06f12 100644 --- a/core/src/xmake/binutils/prefix.h +++ b/core/src/xmake/binutils/prefix.h @@ -241,12 +241,13 @@ 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 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 + /* 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) { if (tb_strstr(arch, "le")) { return tb_false; |
