Skip to content

dump changes to support latest elf - #351

Open
HimanshuChoudhary-Xilinx wants to merge 3 commits into
Xilinx:main-gefrom
HimanshuChoudhary-Xilinx:aiebu_dump1
Open

dump changes to support latest elf#351
HimanshuChoudhary-Xilinx wants to merge 3 commits into
Xilinx:main-gefrom
HimanshuChoudhary-Xilinx:aiebu_dump1

Conversation

@HimanshuChoudhary-Xilinx

Copy link
Copy Markdown
Collaborator

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)

Signed-off-by: Himanshu Choudhary <Himanshu.Choudhary@amd.com>
Copilot AI lite review requested due to automatic review settings August 14, 2026 13:52

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

size_t take = (avail >= 4) ? 4 : avail;
std::memcpy(&word, data + offset, take);
std::ostringstream hex;
hex << " .long 0x" << std::hex << std::setw(8)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use auto when initializing with a cast to avoid duplicating the type name [hicpp-use-auto]

Suggested change
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'type' is not initialized [cppcoreguidelines-init-variables]

  aiebu::aiebu_assembler::buffer_type type;
                                      ^

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-dump to 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_end is computed as page_start + page_size without clamping to section_size. If the section size is not an exact multiple of 8KB, the subsequent reads (section_data[i] up to page_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_end is set to i + eof_size without checking that i + eof_size stays within the current page. If EOF appears near the end of a (possibly truncated) page, process_text_block() can read past page_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.

Comment on lines +152 to +162
// 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;
Comment on lines +168 to +184
// 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";
//}
Comment on lines +209 to +211
// 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) {
Comment on lines +211 to 218
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants