Skip to content

fix: aiecc --aiesim crashes due to missing define and wrong IO backend#2956

Closed
FIM43-Redeye wants to merge 3 commits intoXilinx:mainfrom
FIM43-Redeye:fix/aiesim-static-lib-define
Closed

fix: aiecc --aiesim crashes due to missing define and wrong IO backend#2956
FIM43-Redeye wants to merge 3 commits intoXilinx:mainfrom
FIM43-Redeye:fix/aiesim-static-lib-define

Conversation

@FIM43-Redeye
Copy link

@FIM43-Redeye FIM43-Redeye commented Mar 12, 2026

Summary

  • Add -D__AIESIM__ to xaienginecdo_static compile definitions so the SIM IO backend compiles in
  • Add weak ess_* stubs for static linking (symbols provided at runtime by aiesimulator)
  • Fix CDO generation to always use XAIE_IO_BACKEND_CDO, not XAIE_IO_BACKEND_SIM

Problem

aiecc --aiesim crashes at CDO generation with two sequential bugs:

Bug 1: xaienginecdo_static is built with __AIECDO__ and __AIEDEBUG__ but not __AIESIM__, so xaie_sim.c compiles with error stubs instead of real SIM IO functions:

XAie_SimIO_Init():497: Driver is not compiled with simulation backend (__AIESIM__)

Bug 2 (exposed after fixing bug 1): generateCdoArtifacts() passes aieSim=true to AIETranslateToCDODirect(), which selects XAIE_IO_BACKEND_SIM. The SIM backend calls ess_* functions that are only available inside a running aiesimulator process. CDO file generation is a compile-time step that writes binary files to disk -- it should always use XAIE_IO_BACKEND_CDO.

Fix

  1. Add -D__AIESIM__ to the static lib's compile definitions in runtime_lib/CMakeLists.txt
  2. Add ess_stubs.c with weak definitions of ess_Write32, ess_Read32, ess_WriteCmd, ess_NpiWrite32, ess_NpiRead32 -- these are forward-declared in xaie_sim.c and provided at runtime by the aiesimulator SystemC process via dlopen
  3. Change aieSim parameter in generateCdoArtifacts() from aiesim to false

Testing

Verified locally end-to-end:

  • aiecc --aiesim --xchesscc --xbridge compiles and generates sim artifacts (no crash)
  • aiesimulator --pkg-dir=<generated>/sim runs the simulation to completion (PASS)
  • Non-aiesim compilation (--no-aiesim) is unaffected

Note

generateAiesim() in aiecc_aiesim.cpp uses findProgramByName("clang++") to build ps.so. In environments without a full Vitis install, aietools/bin/clang++ (a wrapper expecting Vitis-bundled Peano) may shadow the system compiler. This is a separate issue.

Fixes #2955.

The static library xaienginecdo_static (linked into aiecc) is built
with __AIECDO__ and __AIEDEBUG__ but not __AIESIM__. This causes
xaie_sim.c to compile with error stubs instead of real ess_*
implementations, so `aiecc --aiesim` crashes at XAie_SimIO_Init()
with "Driver is not compiled with simulation backend".

The shared library (libxaienginecdo.so) correctly includes __AIESIM__.

Also adds weak ess_* stubs (ess_Write32, ess_Read32, ess_WriteCmd,
ess_NpiWrite32, ess_NpiRead32) for static linking. These symbols are
provided at runtime by the aiesimulator SystemC process via dlopen;
the weak stubs satisfy the linker and abort if called outside the
simulator.

Fixes Xilinx#2955.
Copilot AI review requested due to automatic review settings March 12, 2026 03:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes aiecc --aiesim crashes during CDO generation by ensuring the statically-linked xaienginecdo_static is built with simulation support and can resolve ess_* symbols at link time (while still allowing the simulator’s strong symbols to override at runtime).

Changes:

  • Add __AIESIM__ to xaienginecdo_static compile definitions so the simulation backend is compiled in.
  • Add runtime_lib/ess_stubs.c containing weak ess_* stub definitions to satisfy static link requirements.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
runtime_lib/ess_stubs.c Adds weak ess_* symbol stubs for static linking in aiesim flows.
runtime_lib/CMakeLists.txt Links the stub source into xaienginecdo_static and adds the __AIESIM__ compile definition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.


target_link_libraries(xaienginecdo_static PRIVATE cdo_driver_mlir_aie)
target_compile_definitions(xaienginecdo_static PRIVATE -D__AIECDO__ -D__AIEDEBUG__)
target_compile_definitions(xaienginecdo_static PRIVATE -D__AIECDO__ -D__AIEDEBUG__ -D__AIESIM__)
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

target_compile_definitions() should be given bare preprocessor symbols (e.g. __AIECDO__) rather than -D.... Passing -D__AIECDO__ causes CMake to emit an extra -D prefix (typically -D-D__AIECDO__), which can break compilation and is inconsistent with other CMake files in this repo (e.g. runtime_lib/xaiengine/lib/CMakeLists.txt).

Suggested change
target_compile_definitions(xaienginecdo_static PRIVATE -D__AIECDO__ -D__AIEDEBUG__ -D__AIESIM__)
target_compile_definitions(xaienginecdo_static PRIVATE __AIECDO__ __AIEDEBUG__ __AIESIM__)

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +38
__attribute__((weak)) uint ess_Read32(uint64_t Addr) {
(void)Addr;
fprintf(stderr, "FATAL: ess_Read32 called outside aiesimulator\n");
abort();
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

ess_Read32 is declared to return uint but has no return statement after abort(). This will fail builds that use -Werror=return-type (enabled in the top-level CMake). Mark the function as noreturn (and/or add a return 0;/__builtin_unreachable() after abort()) to satisfy the compiler.

Copilot uses AI. Check for mistakes.
__attribute__((weak)) uint ess_NpiRead32(uint64_t Addr) {
(void)Addr;
fprintf(stderr, "FATAL: ess_NpiRead32 called outside aiesimulator\n");
abort();
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

ess_NpiRead32 is a non-void function but does not return a value after calling abort(). With -Werror=return-type this becomes a hard compile error; make the function noreturn and/or add an explicit dummy return/__builtin_unreachable() after abort().

Suggested change
abort();
abort();
__builtin_unreachable();

Copilot uses AI. Check for mistakes.
When --aiesim is passed, aiecc was forwarding aieSim=true to
AIETranslateToCDODirect, which selected XAIE_IO_BACKEND_SIM.
The SIM backend calls ess_* functions that are only available
inside a running aiesimulator process, so CDO generation crashed.

CDO file generation is a compile-time step that writes binary files
to disk -- it should always use XAIE_IO_BACKEND_CDO regardless of
whether aiesim artifacts are also being generated.
@FIM43-Redeye FIM43-Redeye changed the title fix: add __AIESIM__ to xaienginecdo_static build definitions fix: aiecc --aiesim crashes due to missing define and wrong IO backend Mar 12, 2026
- Drop -D prefix from target_compile_definitions (CMake adds it)
- Add __builtin_unreachable() after abort() in non-void ess stubs
  to satisfy -Werror=return-type
@FIM43-Redeye FIM43-Redeye marked this pull request as draft March 12, 2026 22:16
@FIM43-Redeye
Copy link
Author

Closing in favor of #2964, which correctly fixes this at the aiecc level. Thanks @fifield!

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.

aiecc --aiesim crashes: static lib missing __AIESIM__ define

2 participants