Skip to content

Commit 3d3c790

Browse files
os_abi changes from PR# 217 (#217)
Signed-off-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com> Co-authored-by: Sri Latha Ayyannagari <SriLatha.Ayyannagari@amd.com>
1 parent 4a4d119 commit 3d3c790

27 files changed

Lines changed: 926 additions & 81 deletions

README.rst

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,153 @@ Compiled Libraries
7777
Directory ``opt/xilinx/aiebu/lib``
7878
* libaiebu.so
7979
* libaiebu_static.a
80+
81+
ELF Format for AIE Architectures
82+
================================
83+
84+
AIEBU generates ELF files for AIE control code. The ELF header contains OS/ABI
85+
and ABI version fields that identify the target architecture and ELF format version.
86+
87+
OS/ABI Values
88+
-------------
89+
90+
The OS/ABI field (``e_ident[EI_OSABI]``) identifies the target AIE architecture.
91+
Values are chosen with high Hamming distance for robustness against bit flips.
92+
93+
.. list-table:: OS/ABI Values
94+
:header-rows: 1
95+
:widths: 25 15 60
96+
97+
* - Architecture
98+
- Value (Hex)
99+
- Description
100+
* - aie2ps_group
101+
- 0x46 (70)
102+
- Legacy group ELF for AIE2PS/AIE4 family
103+
* - aie2p
104+
- 0x45 (69)
105+
- AIE2P architecture
106+
* - aie2ps
107+
- 0x40 (64)
108+
- AIE2PS specific (config with ``.target``)
109+
* - aie4
110+
- 0x4B (75)
111+
- AIE4 architecture
112+
* - aie4a
113+
- 0x56 (86)
114+
- AIE4A architecture variant
115+
* - aie4z
116+
- 0x69 (105)
117+
- AIE4Z architecture variant
118+
119+
ELF ABI Version
120+
---------------
121+
122+
The ABI version field (``e_ident[EI_ABIVERSION]``) uses major.minor encoding:
123+
upper nibble = major version, lower nibble = minor version.
124+
125+
.. list-table:: ELF ABI Version Values
126+
:header-rows: 1
127+
:widths: 25 15 60
128+
129+
* - Version
130+
- Value (Hex)
131+
- Description
132+
* - Non-config
133+
- 0x02 (0.2)
134+
- Non-config ELF (all architectures)
135+
* - Legacy config (AIE2PS/AIE4)
136+
- 0x03 (0.3)
137+
- Config ELF without ``.target`` directive
138+
* - AIE2P config (legacy)
139+
- 0x10 (1.0)
140+
- Legacy AIE2P config ELF (read-only, no longer written)
141+
* - Config with .target
142+
- 0x20 (2.0)
143+
- Config ELF with ``.target`` directive or AIE2/AIE2P config
144+
145+
Behavior by Target Option
146+
-------------------------
147+
148+
The following table shows how the ``-t`` option and ``.target`` directive
149+
affect ELF version and OS/ABI:
150+
151+
.. list-table:: ELF Output by Target
152+
:header-rows: 1
153+
:widths: 30 20 15 35
154+
155+
* - -t Option
156+
- .target in ASM
157+
- ELF Version
158+
- OS/ABI
159+
* - aie2ps/aie4 (non-config)
160+
- Any (ignored)
161+
- 0x02
162+
- aie2ps_group (0x46)
163+
* - aie2ps_config/aie4_config
164+
- Not present
165+
- 0x03
166+
- aie2ps_group (0x46)
167+
* - aie2ps_config/aie4_config
168+
- Present
169+
- 0x20
170+
- Based on .target value
171+
* - aie2_config/aie2p_config
172+
- N/A (binary input)
173+
- 0x20
174+
- aie2p (0x45)
175+
* - aie2/aie2p (non-config)
176+
- N/A (binary input)
177+
- 0x02
178+
- aie2p (0x45)
179+
180+
**Key points:**
181+
182+
* Non-config ELFs always use version 0x02, regardless of ``.target`` directive
183+
* Config ELFs use version 0x20 only when ``.target`` directive is present
184+
* Version 0x20 enables architecture-specific OS/ABI values
185+
186+
Version and OS/ABI Compatibility
187+
--------------------------------
188+
189+
ELF readers use the ABI version to determine valid OS/ABI values:
190+
191+
* **Version 0x02 (non-config)**: OS/ABI must be ``aie2ps_group`` (0x46) or
192+
``aie2p`` (0x45). Used for all non-config ELFs.
193+
194+
* **Version 0x03 (legacy config)**: OS/ABI must be ``aie2ps_group`` (0x46).
195+
Used for AIE2PS/AIE4 config ELFs without ``.target`` directive.
196+
197+
* **Version 0x10 (AIE2P config - legacy)**: OS/ABI must be ``aie2p`` (0x45).
198+
Legacy config for AIE2P. No longer written by assembler; supported for
199+
reading existing ELF files only.
200+
201+
* **Version 0x20 (config with .target)**: All OS/ABI values are valid
202+
(``aie2ps``, ``aie2p``, ``aie2ps_group``, ``aie4``, ``aie4a``, ``aie4z``).
203+
Used for config ELFs with ``.target`` directive or AIE2/AIE2P config.
204+
205+
The ``.target`` directive in assembly source determines whether the new config
206+
format (version 0x20) is used. For config ELFs, when ``.target`` is present,
207+
the assembler validates it against the ``-t`` command-line option and sets
208+
the specific OS/ABI value. Non-config ELFs always use legacy values regardless
209+
of ``.target`` directive.
210+
211+
Constants Definition
212+
--------------------
213+
214+
All OS/ABI and ELF version constants are defined in a single header file:
215+
216+
``src/cpp/elf/aie_elf_constants.h``
217+
218+
This file contains:
219+
220+
* ``osabi_aie2ps_group`` (0x46) - Legacy group ELF
221+
* ``osabi_aie2p`` (0x45) - AIE2P
222+
* ``osabi_aie2ps`` (0x40) - AIE2PS specific
223+
* ``osabi_aie4`` (0x4B) - AIE4
224+
* ``osabi_aie4a`` (0x56) - AIE4A
225+
* ``osabi_aie4z`` (0x69) - AIE4Z
226+
* ``elf_version_legacy`` (0x02) - Non-config
227+
* ``elf_version_legacy_config`` (0x03) - Legacy config
228+
* ``elf_version_aie2p_config`` (0x10) - Legacy AIE2P config (read-only)
229+
* ``elf_version_config`` (0x20) - Config with .target

src/cpp/analyzer/transform_manager.cpp

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// 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.
33

44
#include <cstdint>
55
#include <cctype>
@@ -64,10 +64,40 @@ load_elf(const std::vector<char>& elf_data)
6464
if (!m_elfio.load(istr))
6565
throw error(error::error_code::invalid_input, "Failed to load ELF from buffer\n");
6666

67-
// Only AIE2PS/AIE4 legacy ELF and group ELF formats are supported
67+
// Check ELF version and OS ABI compatibility
6868
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+
}
71101
}
72102

73103
/**
@@ -978,19 +1008,49 @@ update_rela_sections(const std::vector<arginfo>& entries, const std::string& ker
9781008
std::vector<char>
9791009
transform_manager::
9801010
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
9821012
auto os_abi = m_elfio.get_os_abi();
9831013
auto abi_version = m_elfio.get_abi_version();
9841014

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 {
9911050
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"
9931052
+ ELFIO::to_hex_string(abi_version));
1053+
}
9941054

9951055
// Locate required ELF sections
9961056
auto symtab = m_elfio.sections[".symtab"];

src/cpp/analyzer/transform_manager.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// 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.
33

44
#ifndef AIEBU_TRANSFORM_MANAGER_H_
55
#define AIEBU_TRANSFORM_MANAGER_H_
@@ -10,6 +10,7 @@
1010
#include <elfio/elfio.hpp>
1111
#include "specification/aie2ps/isa.h"
1212
#include "common/symbol.h"
13+
#include "elf/aie_elf_constants.h"
1314

1415
namespace aiebu {
1516

@@ -242,7 +243,14 @@ class transform_manager {
242243
/**
243244
* @brief Load and validate ELF data
244245
* @param elf_data Vector containing ELF binary data
245-
* @throws error if ELF data is invalid or not AIE2PS/AIE4 format
246+
*
247+
* Supported ELF versions:
248+
* - Version 0x02 (non-config): OS ABI 0x45/0x46 (aie2p, aie2ps_group)
249+
* - Version 0x03 (legacy config): OS ABI 0x46 (aie2ps_group)
250+
* - Version 0x10 (aie2p config): OS ABI 0x45 (aie2p)
251+
* - Version 0x20 (config with .target): OS ABI 0x40/0x45/0x46/0x4B/0x56/0x69
252+
*
253+
* @throws error if ELF data is invalid or not supported format
246254
*/
247255
void load_elf(const std::vector<char>& elf_data);
248256

@@ -298,7 +306,12 @@ class transform_manager {
298306
* For C++ mangled names, matches the exact identifier (e.g., "DPU" matches "_Z3DPUPcPc"
299307
* but not "_Z4DPU1PcPc"). Automatically updates length prefixes (_Z3DPU -> _Z4XCVB).
300308
* For non-mangled names, does exact string matching.
301-
* Only supports OS ABI 0x46 and ABI version 0x3.
309+
*
310+
* Supported ELF versions:
311+
* - Version 0x02 (non-config): OS ABI 0x45/0x46 (aie2p, aie2ps_group)
312+
* - Version 0x03 (legacy config): OS ABI 0x46 (aie2ps_group)
313+
* - Version 0x10 (aie2p config): OS ABI 0x45 (aie2p)
314+
* - Version 0x20 (config with .target): OS ABI 0x40/0x45/0x46/0x4B/0x56/0x69
302315
*
303316
* @throws error if format unsupported, sections missing, or name not found
304317
*/

src/cpp/assembler/aiebu_assembler.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (C) 2024-2025, Advanced Micro Devices, Inc. All rights reserved.
2+
// Copyright (C) 2024-2026, Advanced Micro Devices, Inc. All rights reserved.
33
#include "assembler.h"
44
#include "elfwriter.h"
55
#include "encoder.h"
@@ -74,8 +74,11 @@ aiebu_assembler(buffer_type type,
7474
elf_data = a.process(buffer1, libs, libpaths, patch_json, buffer2, {}, &artifacts);
7575
m_output_type = aiebu::aiebu_assembler::buffer_type::elf_aie2_config;
7676
}
77-
else if (m_type == buffer_type::asm_aie4)
77+
else if (m_type == buffer_type::asm_aie4 ||
78+
m_type == buffer_type::asm_aie4a ||
79+
m_type == buffer_type::asm_aie4z)
7880
{
81+
// All aie4 family uses same elf_type - specific OSABI determined from .target directive
7982
aiebu::assembler a(assembler::elf_type::aie4_asm);
8083
elf_data = a.process(buffer1, libs, libpaths, patch_json, {}, {}, &artifacts);
8184
m_output_type = aiebu::aiebu_assembler::buffer_type::elf_aie4;
@@ -86,8 +89,11 @@ aiebu_assembler(buffer_type type,
8689
elf_data = a.process(buffer1, libs, libpaths, patch_json, buffer2, {}, &artifacts);
8790
m_output_type = aiebu::aiebu_assembler::buffer_type::elf_aie2ps_config;
8891
}
89-
else if (m_type == buffer_type::aie4_config)
92+
else if (m_type == buffer_type::aie4_config ||
93+
m_type == buffer_type::aie4a_config ||
94+
m_type == buffer_type::aie4z_config)
9095
{
96+
// All aie4 family config uses same elf_type - specific OSABI determined from .target directive
9197
aiebu::assembler a(assembler::elf_type::aie4_config);
9298
elf_data = a.process(buffer1, libs, libpaths, patch_json, buffer2, {}, &artifacts);
9399
m_output_type = aiebu::aiebu_assembler::buffer_type::elf_aie4_config;

0 commit comments

Comments
 (0)