diff --git a/runtime_lib/CMakeLists.txt b/runtime_lib/CMakeLists.txt index bc98a76b807..e1ccd13ea24 100644 --- a/runtime_lib/CMakeLists.txt +++ b/runtime_lib/CMakeLists.txt @@ -131,8 +131,12 @@ add_aiert_headers(xaienginecdo_static ) add_aiert_library(xaienginecdo_static ${XAIE_SOURCE_DIR} STATIC) +# Weak stubs for ess_* symbols (provided at runtime by aiesimulator via dlopen). +# Must be linked into the static lib so aiecc resolves these at link time. +target_sources(xaienginecdo_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ess_stubs.c) + 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 __AIECDO__ __AIEDEBUG__ __AIESIM__) # just to make cmake happy since AIETargets will need to re-export # make sure not abs path... diff --git a/runtime_lib/ess_stubs.c b/runtime_lib/ess_stubs.c new file mode 100644 index 00000000000..86b324522d2 --- /dev/null +++ b/runtime_lib/ess_stubs.c @@ -0,0 +1,66 @@ +/* + * Weak stubs for aiesimulator ESS functions. + * + * xaie_sim.c forward-declares these symbols (ess_Write32, ess_Read32, etc.) + * which are provided at runtime by the aiesimulator SystemC process via + * dlopen. When linking aiecc statically, these symbols are unresolved. + * + * These weak definitions satisfy the linker. If aiecc is loaded by + * aiesimulator, the real (strong) symbols override them. If someone + * calls aiecc --aiesim outside of aiesimulator, the sim backend init + * will fail gracefully before these are reached, but the stubs abort() + * as a safety net. + * + * This file is licensed under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + * (c) Copyright 2026 Advanced Micro Devices, Inc. + */ + +#include +#include +#include + +typedef unsigned int uint; + +__attribute__((weak)) void ess_Write32(uint64_t Addr, uint Data) { + (void)Addr; + (void)Data; + fprintf(stderr, "FATAL: ess_Write32 called outside aiesimulator\n"); + abort(); +} + +__attribute__((weak)) uint ess_Read32(uint64_t Addr) { + (void)Addr; + fprintf(stderr, "FATAL: ess_Read32 called outside aiesimulator\n"); + abort(); + __builtin_unreachable(); +} + +__attribute__((weak)) void +ess_WriteCmd(unsigned char Command, unsigned char ColId, unsigned char RowId, + unsigned int CmdWd0, unsigned int CmdWd1, unsigned char *CmdStr) { + (void)Command; + (void)ColId; + (void)RowId; + (void)CmdWd0; + (void)CmdWd1; + (void)CmdStr; + fprintf(stderr, "FATAL: ess_WriteCmd called outside aiesimulator\n"); + abort(); +} + +__attribute__((weak)) void ess_NpiWrite32(uint64_t Addr, uint Data) { + (void)Addr; + (void)Data; + fprintf(stderr, "FATAL: ess_NpiWrite32 called outside aiesimulator\n"); + abort(); +} + +__attribute__((weak)) uint ess_NpiRead32(uint64_t Addr) { + (void)Addr; + fprintf(stderr, "FATAL: ess_NpiRead32 called outside aiesimulator\n"); + abort(); + __builtin_unreachable(); +} diff --git a/tools/aiecc/aiecc.cpp b/tools/aiecc/aiecc.cpp index 7a61ef2a48e..bb5b7635e87 100644 --- a/tools/aiecc/aiecc.cpp +++ b/tools/aiecc/aiecc.cpp @@ -4447,7 +4447,7 @@ static LogicalResult generateCdoArtifacts(ModuleOp moduleOp, /*bigEndian=*/false, /*emitUnified=*/false, /*cdoDebug=*/false, - /*aieSim=*/aiesim, + /*aieSim=*/false, /*xaieDebug=*/false, /*enableCores=*/true))) { llvm::errs() << "Error generating CDO files\n";