|
1 | 1 | // SPDX-License-Identifier: MIT |
2 | | -// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +// Copyright (C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. |
3 | 3 |
|
4 | 4 | #include <cstdint> |
5 | 5 | #include <cctype> |
@@ -64,10 +64,40 @@ load_elf(const std::vector<char>& elf_data) |
64 | 64 | if (!m_elfio.load(istr)) |
65 | 65 | throw error(error::error_code::invalid_input, "Failed to load ELF from buffer\n"); |
66 | 66 |
|
67 | | - // Only AIE2PS/AIE4 legacy ELF and group ELF formats are supported |
| 67 | + // Check ELF version and OS ABI compatibility |
68 | 68 | auto os_abi = m_elfio.get_os_abi(); |
69 | | - if (os_abi != elf_amd_aie2ps_abi) |
70 | | - throw error(error::error_code::invalid_input, "Only aie2ps/aie4 config elf supported\n"); |
| 69 | + auto abi_version = m_elfio.get_abi_version(); |
| 70 | + |
| 71 | + // ELF version and OS ABI compatibility: |
| 72 | + // - Version 0x02 (non-config): aie2ps_group (0x46) or aie2p (0x45) |
| 73 | + // - Version 0x03 (legacy config): aie2ps_group (0x46) |
| 74 | + // - Version 0x10 (aie2p config): aie2p (0x45) |
| 75 | + // - Version 0x20 (config with .target): all OS_ABI values supported |
| 76 | + if (abi_version == elf_version_legacy) { |
| 77 | + // Non-config ELF - aie2ps_group or aie2p |
| 78 | + if (os_abi != osabi_aie2ps_group && os_abi != osabi_aie2p) |
| 79 | + throw error(error::error_code::invalid_input, "Only aie2ps_group or aie2p elf supported for ELF version 0x02\n"); |
| 80 | + } else if (abi_version == elf_version_legacy_config) { |
| 81 | + // Legacy config ELF - only aie2ps_group |
| 82 | + if (os_abi != osabi_aie2ps_group) |
| 83 | + throw error(error::error_code::invalid_input, "Only aie2ps_group elf supported for ELF version 0x03\n"); |
| 84 | + } else if (abi_version == elf_version_aie2p_config) { |
| 85 | + // AIE2P config ELF - only aie2p |
| 86 | + if (os_abi != osabi_aie2p) |
| 87 | + throw error(error::error_code::invalid_input, "Only aie2p elf supported for ELF version 0x10\n"); |
| 88 | + } else if (abi_version == elf_version_config) { |
| 89 | + // New config ELF with .target - all OS_ABI values supported |
| 90 | + if (os_abi != osabi_aie2ps_group && |
| 91 | + os_abi != osabi_aie2ps && |
| 92 | + os_abi != osabi_aie2p && |
| 93 | + os_abi != osabi_aie4 && |
| 94 | + os_abi != osabi_aie4a && |
| 95 | + os_abi != osabi_aie4z) |
| 96 | + throw error(error::error_code::invalid_input, "Only aie2ps/aie2p/aie4 family elf supported for ELF version 0x20\n"); |
| 97 | + } else { |
| 98 | + throw error(error::error_code::invalid_input, "Unsupported ELF ABI version: 0x" |
| 99 | + + ELFIO::to_hex_string(abi_version) + "\n"); |
| 100 | + } |
71 | 101 | } |
72 | 102 |
|
73 | 103 | /** |
@@ -978,19 +1008,49 @@ update_rela_sections(const std::vector<arginfo>& entries, const std::string& ker |
978 | 1008 | std::vector<char> |
979 | 1009 | transform_manager:: |
980 | 1010 | update_kernel_name(const std::string& orig_name, const std::string& new_name) { |
981 | | - // Validate ELF format: only support OS ABI 0x46 (elf_amd_aie2ps_abi) and ABI version 0x3 |
| 1011 | + // Validate ELF format based on version |
982 | 1012 | auto os_abi = m_elfio.get_os_abi(); |
983 | 1013 | auto abi_version = m_elfio.get_abi_version(); |
984 | 1014 |
|
985 | | - if (os_abi != elf_amd_aie2ps_abi) |
986 | | - throw error(error::error_code::invalid_input, |
987 | | - "update_kernel_name only supports OS ABI 0x46 (AIE2PS/AIE4 group), got: 0x" |
988 | | - + ELFIO::to_hex_string(os_abi)); |
989 | | - |
990 | | - if (abi_version != elf_amd_aie2ps_aie4_config_elf_version) |
| 1015 | + // ELF version and OS ABI compatibility: |
| 1016 | + // - Version 0x02 (non-config): aie2ps_group (0x46) or aie2p (0x45) |
| 1017 | + // - Version 0x03 (legacy config): aie2ps_group (0x46) |
| 1018 | + // - Version 0x10 (aie2p config): aie2p (0x45) |
| 1019 | + // - Version 0x20 (config with .target): all OS_ABI values supported |
| 1020 | + if (abi_version == elf_version_legacy) { |
| 1021 | + // Non-config ELF - aie2ps_group or aie2p |
| 1022 | + if (os_abi != osabi_aie2ps_group && os_abi != osabi_aie2p) |
| 1023 | + throw error(error::error_code::invalid_input, |
| 1024 | + "update_kernel_name only supports OS ABI 0x45/0x46 for ELF version 0x02, got: 0x" |
| 1025 | + + ELFIO::to_hex_string(os_abi)); |
| 1026 | + } else if (abi_version == elf_version_legacy_config) { |
| 1027 | + // Legacy config ELF - only aie2ps_group |
| 1028 | + if (os_abi != osabi_aie2ps_group) |
| 1029 | + throw error(error::error_code::invalid_input, |
| 1030 | + "update_kernel_name only supports OS ABI 0x46 for ELF version 0x03, got: 0x" |
| 1031 | + + ELFIO::to_hex_string(os_abi)); |
| 1032 | + } else if (abi_version == elf_version_aie2p_config) { |
| 1033 | + // AIE2P config ELF - only aie2p |
| 1034 | + if (os_abi != osabi_aie2p) |
| 1035 | + throw error(error::error_code::invalid_input, |
| 1036 | + "update_kernel_name only supports OS ABI 0x45 for ELF version 0x10, got: 0x" |
| 1037 | + + ELFIO::to_hex_string(os_abi)); |
| 1038 | + } else if (abi_version == elf_version_config) { |
| 1039 | + // New config ELF with .target - all OS_ABI values supported |
| 1040 | + if (os_abi != osabi_aie2ps_group && |
| 1041 | + os_abi != osabi_aie2ps && |
| 1042 | + os_abi != osabi_aie2p && |
| 1043 | + os_abi != osabi_aie4 && |
| 1044 | + os_abi != osabi_aie4a && |
| 1045 | + os_abi != osabi_aie4z) |
| 1046 | + throw error(error::error_code::invalid_input, |
| 1047 | + "update_kernel_name only supports OS ABI 0x40/0x45/0x46/0x4B/0x56/0x69 for ELF version 0x20, got: 0x" |
| 1048 | + + ELFIO::to_hex_string(os_abi)); |
| 1049 | + } else { |
991 | 1050 | throw error(error::error_code::invalid_input, |
992 | | - "update_kernel_name only supports ABI version 0x3, got: 0x" |
| 1051 | + "update_kernel_name only supports ABI version 0x02/0x03/0x10/0x20, got: 0x" |
993 | 1052 | + ELFIO::to_hex_string(abi_version)); |
| 1053 | + } |
994 | 1054 |
|
995 | 1055 | // Locate required ELF sections |
996 | 1056 | auto symtab = m_elfio.sections[".symtab"]; |
|
0 commit comments