Jump to content
shoji

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
Aborted

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
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

If you need additional information please let me know.

 

Share this post


Link to post
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,
        ALL RIGHTS RESERVED
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"

int

__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");

  counter.clock(clk);
  counter.reset(reset);
  counter.enable(enable);
  counter.countOut(count);

  reset = true;
  enable = false;
  sc_start(step);
  sc_start(step);
  reset = false;
  enable = true;
  sc_start(step);
  sc_start(step);
  sc_start(step);
  sc_start(step);

  return 0;
}
 

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

#pragma once

#include "systemc.h"

class

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

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


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

private:
  sc_uint<4> count;
};
 

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

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

counter::counter(const sc_core::sc_module_name& name):
  sc_module(name),
  count(0)
{
  SC_METHOD(inc);
  sensitive << reset;
  sensitive << clock.pos();
}


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

Share this post


Link to post
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).

Share this post


Link to post
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.

Share this post


Link to post
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.
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×