Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion runtime_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 -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.

# just to make cmake happy since AIETargets will need to re-export
# make sure not abs path...
Expand Down
64 changes: 64 additions & 0 deletions runtime_lib/ess_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>

typedef unsigned int uint;

__attribute__((weak)) void ess_Write32(uint64_t Addr, uint Data) {

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

syntax error: missing ';' before '{'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

'ess_Write32': not in formal parameter list

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

function returns function

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

syntax error: missing ')' before 'type'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

syntax error: ')'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

syntax error: ')'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

syntax error: missing ')' before '('

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

syntax error: missing ';' before '{'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

'ess_Write32': not in formal parameter list

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

function returns function

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

syntax error: missing ')' before 'type'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

syntax error: ')'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

syntax error: ')'

Check failure on line 27 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

syntax error: missing ')' before '('
(void)Addr;

Check failure on line 28 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

'Addr': undeclared identifier

Check failure on line 28 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

'Addr': undeclared identifier
(void)Data;

Check failure on line 29 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

'Data': undeclared identifier

Check failure on line 29 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

'Data': undeclared identifier
fprintf(stderr, "FATAL: ess_Write32 called outside aiesimulator\n");
abort();
}

__attribute__((weak)) uint ess_Read32(uint64_t Addr) {

Check failure on line 34 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=OFF

syntax error: missing ')' before '('

Check failure on line 34 in runtime_lib/ess_stubs.c

View workflow job for this annotation

GitHub Actions / windows-2022 msvc assert=OFF rtti=ON

syntax error: missing ')' before '('
(void)Addr;
fprintf(stderr, "FATAL: ess_Read32 called outside aiesimulator\n");
abort();
}
Comment on lines +34 to +39
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)) 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();
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.
}
Loading