Jump to content

Elaboration error while using C++ attribute flag -fvisibility=hidden


Recommended Posts

I've compiled my C++14 systemc 2.3.2 library and when I compile my model code with --visibility=hidden the code will not properly elaborate.

The only apparent requirement is that sc_main have default visibility, for example:

int __attribute__ ((visibility ("default"))) sc_main(int argc, char* argv[])


... your code here ...


You can use any simple module (eg simple counter sc_module) to show that by not using the -fvisibility=hidden flag the code works fine.

when compiled with that flag I get the following error:

terminating with uncaught exception of type sc_core::sc_report: Error: (E118) find event failed: port is not bound: port 'counter.port_0' (sc_in)
In file: ../../../src/sysc/communication/sc_event_finder.cpp:51

My version of g++ is as follows:

g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO


If you need additional information please let me know.


Link to comment
Share on other sites

exporting all my classes of course goes against why you might use the -fvisibility=hidden flag so I'm not sure what the intention would be to use it once you export the world.

Here is my example source code. I tried it with/without the counter class having visibility set to default.

It fails either way.

Compile these with -fvisibility=hidden and the code fails to elaborate. Remove the flag and you get the output:

        SystemC 2.3.2-Accellera --- Apr 28 2019 15:26:09
        Copyright (c) 1996-2017 by all Contributors,
reset active:count 0
reset active:count 0
reset active:count 0
enable active:count 1
enable active:count 2
enable active:count 3
enable active:count 4


// --------------------- sc_main.cc -----------------------------------------------

#include "counter.h"


__attribute__ ((visibility ("default")))   //<--- comment /uncomment line if desired

sc_main(int argc, char* argv[])

  sc_signal<bool> reset, enable;
  sc_signal<sc_uint<4>> count;
  sc_time step(5.0, SC_NS);
  sc_clock clk("clock", sc_time(5.0, SC_NS));

  counter counter("counter");


  reset = true;
  enable = false;
  reset = false;
  enable = true;

  return 0;

// ------------------------------------ counter.h ------------------------------------------------------------------

#pragma once

#include "systemc.h"


__attribute__ ((visibility ("default")))   //<--- comment /uncomment line if desired

counter: public sc_module
  sc_in_clk clock;
  sc_in<bool> reset;
  sc_in<bool> enable;
  sc_out<sc_uint<4>> countOut;

  counter(const sc_core::sc_module_name& name);
  void inc();

  sc_uint<4> count;

// -------------------------------------------- counter.cc ----------------------------------------------------------------------

#include <iostream>
#include "counter.h"

counter::counter(const sc_core::sc_module_name& name):
  sensitive << reset;
  sensitive << clock.pos();

void counter::inc()
  if (reset.read() == 1)
      count = 0;
      std::cout << "reset active:count " << count << std::endl;
  else if (enable.read() == 1)
      count += 1;
      std::cout << "enable active:count " << count << std::endl;

Link to comment
Share on other sites

I'm not suggesting to export all of your classes, but the SystemC class (templates) used in your code.

By reusing the macro annotations for Windows, you can try changing src/sysc/kernel/sc_cmnhdr.h and redefine SC_API for your platform

# define SC_API __attribute__((visibility("default")))

(with this, you can even try building SystemC itself with -fvisibility=hidden).

Link to comment
Share on other sites

By the way thank you for thinking about this problem.


I changed line 170 in  src/sysc/kernel/sc_cmnhdr.h

to set the define as you list above.

compared to the build of the systemc DLL without the change there are a lot of warnings that this particular compiler directive is ignored.

If that is the only changes you were suggesting then it made no difference. I still see that systemc does not see the port binding.

Link to comment
Share on other sites

I gave it a shot locally and noticed that there are indeed quite some compiler warnings due to differences between __declspec(...) and __attribute__((visibility(...))). Most of these warnings can be ignored for now, but are certainly annoying.

Additionally, you need to explicitly mark the following with SC_API as well:

// src/sysc/communication/sc_port.h
template <class IF>
class SC_API sc_port_b
template <class IF>
class SC_API sc_port

// src/sysc/communication/sc_prim_channel.h
class SC_API sc_prim_channel_registry

// src/sysc/communication/sc_signal.h
template< class T, sc_writer_policy POL >
class SC_API sc_signal_t

template< class T, sc_writer_policy POL >
class SC_API sc_signal

// src/sysc/datatypes/sc_proxy.h
template <class X>
class SC_API sc_proxy

// src/sysc/datatypes/sc_proxy.h
extern "C" SC_API int sc_main(int argc, char* argv[])

// src/sysc/utils/sc_temporary.h
template<class T>
class SC_API sc_vpool

For compiling SystemC itself with -fvisibility=hidden, some further changes to the .cpp files are needed.  And some of the above changes might break the Windows DLL support.   But for me, the above changes work with the examples in the SystemC distribution (i.e. "gmake check CXXFLAGS='-fvisibility=hidden").

Long story short: The feature to SystemC build models with limited symbol visibility will require more changes and testing.  I will forward this topic to the Language Working Group for further discussion.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...