Skip to content

Commit 1b60832

Browse files
committed
abnativeelf: test EF_MIPS_* flags against themselves
- Instead of testing non-zero, make sure the flags are equal after testing to avoid ambiguity (64R2 and 64R6 will have common bits set on their values). - Test for EF_MIPS_ARCH_R6 first, since its value is greater than EF_MIPS_ARCH_64R2 and EF_MIPS_ARCH_3.
1 parent 81b9028 commit 1b60832

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

native/abnativeelf.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,15 @@ const AOSCArch detect_architecture(Elf *elf_file, GElf_Ehdr &elf_ehdr,
352352
return AOSCArch::NONE;
353353
}
354354
// e_flags-based detection
355-
if (elf_ehdr.e_flags & elf_flags_loongson2f) {
356-
return AOSCArch::LOONGSON2F;
357-
} else if (elf_ehdr.e_flags & elf_flags_loongson3) {
358-
return AOSCArch::LOONGSON3;
359-
} else if (elf_ehdr.e_flags & elf_flags_mips64r6el) {
355+
// WARN: Never test the result with non-zero! For MIPS R2 and MIPS R6,
356+
// this causes ambiguity, since it will be true in both tests if
357+
// they are testing with non-zeroes after the AND operation.
358+
if ((elf_ehdr.e_flags & elf_flags_mips64r6el) == elf_flags_mips64r6el) {
360359
return AOSCArch::MIPS64R6EL;
360+
} else if ((elf_ehdr.e_flags & elf_flags_loongson3) == elf_flags_loongson3) {
361+
return AOSCArch::LOONGSON3;
362+
} else if ((elf_ehdr.e_flags & elf_flags_loongson2f) == elf_flags_loongson2f) {
363+
return AOSCArch::LOONGSON2F;
361364
} else {
362365
return AOSCArch::NONE;
363366
}

0 commit comments

Comments
 (0)