dump changes to support latest elf - #351
Conversation
Signed-off-by: Himanshu Choudhary <Himanshu.Choudhary@amd.com>
| size_t take = (avail >= 4) ? 4 : avail; | ||
| std::memcpy(&word, data + offset, take); | ||
| std::ostringstream hex; | ||
| hex << " .long 0x" << std::hex << std::setw(8) |
There was a problem hiding this comment.
warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]
;
^| // offset=0xFFFF for an unresolved relocation) are not mistaken for EOF. | ||
| size_t code_end = page_end; | ||
| for (size_t i = code_start; i < page_end;) { | ||
| uint8_t op = static_cast<uint8_t>(section_data[i]); |
There was a problem hiding this comment.
warning: use auto when initializing with a cast to avoid duplicating the type name [hicpp-use-auto]
| uint8_t op = static_cast<uint8_t>(section_data[i]); | |
| _end;) {auto |
| size_t insn_size = 2; | ||
| for (const auto& arg : it->second.get_args()) | ||
| insn_size += static_cast<size_t>(arg.get_width()) / 8; | ||
| if (insn_size < 2) break; |
There was a problem hiding this comment.
warning: 8 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]
th()) / 8;
^| aiebu::aiebu_assembler::buffer_type type = aiebu::identify_buffer_type(buffer); | ||
| std::string target_arch = result["architecture"].as<std::string>(); | ||
| std::vector<char> buffer; | ||
| aiebu::aiebu_assembler::buffer_type type; |
There was a problem hiding this comment.
warning: variable 'type' is not initialized [cppcoreguidelines-init-variables]
aiebu::aiebu_assembler::buffer_type type;
^There was a problem hiding this comment.
Pull request overview
Updates the aiebu-dump and disassembly pipeline to recognize and handle newer ELF variants/platforms (notably AIE4A/AIE4Z) and newer ABI page layouts, improving compatibility with “latest ELF” outputs in the AIE toolchain.
Changes:
- Extend
aiebu-dumpto accept additional architectures (aie4a/aie4z) and broaden buffer-type handling for newer ELF/binary variants. - Enhance the disassembler to support merged-page ctrltext layouts (ABI version ≥ 0x21) and preserve unknown data bytes by emitting raw directives.
- Extend debug/analyzer codepaths to accept additional ELF buffer types (aie4a/aie4z and config variants).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/cpp/utils/dump/dump.cpp | Adds AIE4A/AIE4Z targets, updates help text, broadens buffer-type mapping and override logic, and adds error handling. |
| src/cpp/tools/debug_tools.cpp | Allows debug tools to run on additional ELF/config buffer types. |
| src/cpp/elf/aie_elf_constants.h | Introduces elf_version_config_v1 (0x20) to distinguish older config ABI format. |
| src/cpp/disassembler/disassembler.cpp | Adds merged-page ctrltext processing based on ABI version and changes data-block fallback emission behavior. |
| src/cpp/analyzer/reporter.cpp | Extends “Not supported” handling to newly introduced config ELF buffer types. |
Suppressed comments (2)
src/cpp/disassembler/disassembler.cpp:384
- In merged-page mode,
page_endis computed aspage_start + page_sizewithout clamping tosection_size. If the section size is not an exact multiple of 8KB, the subsequent reads (section_data[i]up topage_end) can go out of bounds.
for (size_t page_start = 0; page_start < section_size; page_start += page_size) {
const size_t code_start = page_start + elf_section_header_padding;
const size_t page_end = page_start + page_size;
src/cpp/disassembler/disassembler.cpp:395
- When EOF is detected,
code_endis set toi + eof_sizewithout checking thati + eof_sizestays within the current page. If EOF appears near the end of a (possibly truncated) page,process_text_block()can read pastpage_end.
uint8_t op = static_cast<uint8_t>(section_data[i]);
if (op == eof_opcode) {
code_end = i + eof_size;
break;
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Consume up to 4 bytes as one .long word (pad with zero if near end). | ||
| uint32_t word = 0; | ||
| size_t avail = size - offset; | ||
| size_t take = (avail >= 4) ? 4 : avail; | ||
| std::memcpy(&word, data + offset, take); | ||
| std::ostringstream hex; | ||
| hex << " .long 0x" << std::hex << std::setw(8) | ||
| << std::setfill('0') << word; | ||
| m_asm_writer.write_directive(hex.str()); | ||
| state->increment_address(static_cast<uint32_t>(take)); | ||
| offset += take; |
| // Print detected ELF OSABI/version/platform info for ELF files | ||
| //if (buffer.size() >= 52 && | ||
| // static_cast<unsigned char>(buffer[0]) == 0x7f && | ||
| // buffer[1] == 'E' && buffer[2] == 'L' && buffer[3] == 'F') { | ||
| //auto osabi = static_cast<unsigned char>(buffer[7]); | ||
| //auto abiversion = static_cast<unsigned char>(buffer[8]); | ||
| //auto detected_it = aiebu::buffer_type_table.find(type); | ||
| //std::string detected_platform = (detected_it != aiebu::buffer_type_table.end()) | ||
| // ? detected_it->second : "unknown"; | ||
| //std::cout << result["filename"].as<std::string>() << ":\n"; | ||
| //std::cout << boost::format("; ELF OS/ABI: 0x%02x\n") % static_cast<unsigned>(osabi); | ||
| //std::cout << boost::format("; ABI Version: 0x%02x\n") % static_cast<unsigned>(abiversion); | ||
| //std::cout << "; Platform: " << detected_platform << "\n"; | ||
| // Legacy group ELF (OSABI=0x46) is shared by aie2ps/aie4 family — version does not distinguish them | ||
| //if (osabi == 0x46 && target_arch == "unspecified") | ||
| // std::cout << " Note: Legacy ELF (OS/ABI=0x46) detected as aie2ps by default. Use -m aie4/aie4a/aie4z to override.\n"; | ||
| //} |
| // For legacy ELFs (osabi_aie2ps_group=0x46, version=0x02) aie2ps and aie4 share the | ||
| // same OSABI, so the -m option is the only way to distinguish them. | ||
| if (type == aiebu::aiebu_assembler::buffer_type::elf_aie2ps) { |
| if (type == aiebu::aiebu_assembler::buffer_type::elf_aie2ps) { | ||
| if (target_arch == "aie4") | ||
| type = aiebu::aiebu_assembler::buffer_type::elf_aie4; | ||
| else if (target_arch == "aie4a") | ||
| type = aiebu::aiebu_assembler::buffer_type::elf_aie4a; | ||
| else if (target_arch == "aie4z") | ||
| type = aiebu::aiebu_assembler::buffer_type::elf_aie4z; | ||
| } |
Signed-off-by: Himanshu Choudhary <Himanshu.Choudhary@amd.com>
Signed-off-by: Himanshu Choudhary <Himanshu.Choudhary@amd.com>
Problem solved by the commit
dump changes to support latest elf
Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
How problem was solved, alternative solutions (if any) and why they were rejected
Risks (if any) associated the changes in the commit
What has been tested and how, request additional testing if necessary
Documentation impact (if any)