Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power


#Servers
#Programminglanguages
 View Only
  • 1.  ifstream::tellg visibility error

    Posted 07/26/19 12:33 PM

    Originally posted by: bernardn


     I am getting this linker error with ifstream::tellg and ofstream::tellp:

    ld: 0711-407 ERROR: Symbol std::fpos<char*>::_Stz

    Visibility is not allowed on a reference to an imported symbol.

    This occurs when compiling with -O and -qvisibility=hidden with xlC_r 16.1 and 13.1 on AIX 7.2 (ppc and ppc64). For example:

    $ cat test.cpp

    #include <fstream>

    int main()

    {

        std::ifstream is("foo.txt");

        std::streampos p = is.tellg();

        return 0;

    }

    $ xlC_r -qvisibility=hidden -O test.cpp

    ld: 0711-407 ERROR: Symbol std::fpos<char*>::_Stz

    Visibility is not allowed on a reference to an imported symbol.

    A work-around is to expand tellg to what it actually does, is.rdbuf()->pubseekoff(0, is.cur, is.in), but that's not convenient. 

    Any insight on what's happening? It works fine without -O, and calls to other ifstream/ofstream functions don't appear to be affected.

    Thanks,

    Bernard


    #Ask-Question-Here--General-Compiler-Q-and-A
    #C/C++andFortran


  • 2.  Re: ifstream::tellg visibility error

    Posted 08/02/19 05:07 PM

    Originally posted by: hstong


    Hi Bernard,

    To work around this issue, a possible solution is to apply #pragma GCC visibility push(hidden)/#pragma GCC visibility pop around the declarations in your files as an alternative to using -qvisibility=hidden .

    The relevance of -O in the situation you describe has to do with inlining that causes the reference to (and instantiation of) the symbol in question to appear in your object file. The observed behaviour is that -qvisibility=hidden does not affect the visibility of external references, but since the symbol in question is defined by implicit instantiation, it is affected by the option.

    Another workaround is to add an explicit instantiation declaration early in your file:

    
    extern template class std::fpos<char*>;
    

    I hope this helps. If you require a solution that does not involve changing your source code, it appears that a change to the headers shipped with the compiler will be necessary. To deliver such a change, we will need you to file a PMR or formal service request.

    -- HT


    #Ask-Question-Here--General-Compiler-Q-and-A
    #C/C++andFortran


  • 3.  Re: ifstream::tellg visibility error

    Posted 08/02/19 08:20 PM

    Originally posted by: bernardn


    Thank you HT, your second work-around (the explicit template instantiation) works well.

    Best regards,
    Bernard


    #Ask-Question-Here--General-Compiler-Q-and-A
    #C/C++andFortran