systemc icon indicating copy to clipboard operation
systemc copied to clipboard

SystemC 2.3.3 - Fatal: (F4) assertion failed: iface != 0

Open sedlakmilan opened this issue 1 year ago • 9 comments

Dear all,

Lately, we have been facing a strange issue, causing a "Fatal: (F4) assertion failed: iface != 0" when running our program on a Windows machine. After removing all functionality and having only the minimum code, we have been able to find out the issue. The code below is possible to build without any problems.

Screenshot 2024-04-26 at 12 02 16

But once you run it, you get: Screenshot 2024-04-26 at 12 04 37

Screenshot 2024-04-26 at 12 04 55

Interestingly, if you run this code on a Linux machine using GCC, the code can run without any troubles...

.... After removing the "some_var" in the Utest class, the code is running...

  • It doesn't matter if the "some_var" is private, protected, public... if it's used, initialized in the constructor, etc.
  • Once we create a simple variable (any type), inside of the Utest class, the code fails to run (Fatal: (F4) ... )
  • If you create a function in the Utest class, the code also runs...

To put it simply, creating a single member variable inside of a class has the result of a "Fatal: (F4) assertion failed: iface != 0", but only on Windows (not Linux with GCC)..

Now, we can fix our full code just by removing the variable, but we just don't understand what the problem is... Is it a bug? Do we do something that is not allowed?... Maybe you have some more details about this?

Thank You. Kind Regards, Milan

sedlakmilan avatar Apr 26 '24 10:04 sedlakmilan

I can confirm this observation on Windows with MSVC. It probably is hitting some memory alignment issues or probably the project configuration doesn't match the SystemC library build. Someone who uses day-to-day SystemC on MSVC on Windows would be able to provide a much better explanation.

AmeyaVS avatar Apr 26 '24 13:04 AmeyaVS

Could you please try whether this issue persists in the latest SystemC PoC library release 3.0.0?

maehne avatar Apr 26 '24 18:04 maehne

Hi, Yes - I tried now the same code, but using SystemC 3.0.0 and the C++ 17 To build the SystemC library, I've used the VS2022 with the Platform Toolset set to v143:

Screenshot 2024-04-26 at 20 53 15

With the "someVar" in the UTest class, I get the same error: Screenshot 2024-04-26 at 21 09 30

Again, If I remove the "someVar", I can run the code... This is the assertion in the SystemC library where it fails (sc_port.h, line 548):

Screenshot 2024-04-26 at 21 15 09

sedlakmilan avatar Apr 26 '24 19:04 sedlakmilan

@maehne , this is observable even with the latest SystemC commit on the main branch: bec1010. on Windows with latest MSVC installation.

AmeyaVS avatar Apr 26 '24 19:04 AmeyaVS

Hello,

I am sharing the reproducer source slightly modified here for reference.

failport.cpp:

#include <iostream>
#include <systemc>
#include <tlm>
#include <tlm_utils/simple_target_socket.h>
#include <tlm_utils/simple_initiator_socket.h>

// Change the value
#define BUGGY_ATTRIBUTE 1

class Dut: public sc_core::sc_module {
public:
	tlm_utils::simple_target_socket<Dut, 16> comm_if { "comm_if" };
	Dut(sc_core::sc_module_name name): sc_module(name) {
		std::cout << "Dut constructor" << std::endl;
		comm_if.register_b_transport(this, &Dut::b_transport);
	}
private:
	void b_transport(tlm::tlm_generic_payload &transaction, sc_core::sc_time &delay) {}
};

class Framework: public sc_core::sc_module, public tlm::tlm_bw_transport_if<>{
public:
	Framework(sc_core::sc_module_name name) {
		std::cout<< "Framework constructor" << std::endl;
		isocket.bind(*this);
		std::cout<< "(before) comm_if size = " << dut.comm_if.size() << std::endl;
		isocket(dut.comm_if);
		std::cout<< "(after) comm_if size = " << dut.comm_if.size() << std::endl;
	}
protected:
	Dut dut{ "dut" };
private:
	tlm::tlm_initiator_socket<16> isocket{ "isocket" };
	tlm::tlm_sync_enum nb_transport_bw(tlm::tlm_generic_payload &tObj, tlm::tlm_phase &phase, sc_core::sc_time &time) override {return tlm::TLM_ACCEPTED;}
	void invalidate_direct_mem_ptr(sc_dt::uint64 startAddress, sc_dt::uint64 endAddress) override {}
};

class UTest: public Framework {
public:
	UTest(sc_core::sc_module_name name) : Framework(name) {
		std::cout<< "UTest constructor" << std::endl;
	}
#if BUGGY_ATTRIBUTE
	int someVar{ 0 };
#endif
};

int sc_main(int argc, char* argv[]) {
	std::cout << "sc_main" << std::endl;
	
	UTest instance("Fatal");
	
	return (0);
}

CMakeLists.txt to build the reproducer:

cmake_minimum_required(VERSION 3.10)

project(issue81 CXX)

include(CTest)

set(CMAKE_PREFIX_PATH $ENV{SYSTEMC_HOME})

find_package(SystemCLanguage CONFIG REQUIRED)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(
  ${PROJECT_NAME}.run
  failport.cpp
  )

target_link_libraries(
  ${PROJECT_NAME}.run
  PRIVATE SystemC::systemc
  )

set_property(
  TARGET ${PROJECT_NAME}.run
  PROPERTY CXX_STANDARD ${SystemC_CXX_STANDARD}
  )

add_test(
  NAME ${PROJECT_NAME}
  COMMAND ./${PROJECT_NAME}.run
  WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
  )

AmeyaVS avatar Apr 26 '24 19:04 AmeyaVS

Thanks for the feedback. Could you please share the command lines log for the build, to facilitate analysis?

lmailletcontoz avatar May 07 '24 16:05 lmailletcontoz

I was following the usual CMake Configure and Build step on the Windows Command line.

cd systemc
mkdir build
cd build
cmake --build . --config Debug -DCMAKE_INSTALL_PREFIX=<Install path>

cmake --build examples --config Debug --target check

Followed the similar step to configure the reproducer.

Are you looking out for exact compilation commands used to build the project sources?

AmeyaVS avatar May 18 '24 15:05 AmeyaVS

Are you looking out for exact compilation commands used to build the project sources? yes, please. The full log with the options would be appreciated.

lmailletcontoz avatar May 21 '24 14:05 lmailletcontoz

Here's the compilation and linker command captured in the MSVC Build Directories:

Compilation Commands:

^C:\USERS\DELL\DOCUMENTS\FORUMS\FAILPORT.CPP
/c /Zi /nologo /W3 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++20 /Fo"ISSUE81.RUN.DIR\DEBUG\\" /Fd"ISSUE81.RUN.DIR\DEBUG\VC143.PDB" /external:W0 /Gd /TP  /external:I "C:/Users/Dell/Documents/install/systemc/include" /vmg C:\USERS\DELL\DOCUMENTS\FORUMS\FAILPORT.CPP

Linker Commands:

^C:\USERS\DELL\DOCUMENTS\FORUMS\BUILD\ISSUE81.RUN.DIR\DEBUG\FAILPORT.OBJ
/OUT:"C:\USERS\DELL\DOCUMENTS\FORUMS\BUILD\DEBUG\ISSUE81.RUN.EXE" /INCREMENTAL /ILK:"ISSUE81.RUN.DIR\DEBUG\ISSUE81.RUN.ILK" /NOLOGO "C:\USERS\DELL\DOCUMENTS\INSTALL\SYSTEMC\LIB\SYSTEMC-D.LIB" KERNEL32.LIB USER32.LIB GDI32.LIB WINSPOOL.LIB SHELL32.LIB OLE32.LIB OLEAUT32.LIB UUID.LIB COMDLG32.LIB ADVAPI32.LIB /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/USERS/DELL/DOCUMENTS/FORUMS/BUILD/DEBUG/ISSUE81.RUN.PDB" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/USERS/DELL/DOCUMENTS/FORUMS/BUILD/DEBUG/ISSUE81.RUN.LIB" /MACHINE:X64  /machine:x64 ISSUE81.RUN.DIR\DEBUG\FAILPORT.OBJ

These commands were extracted from the log files captured from the build directory.

AmeyaVS avatar May 21 '24 14:05 AmeyaVS