[Bug middle-end/22592] New: -fvisibility-inlines-hidden broken differently

matz at suse dot de gcc-bugzilla@gcc.gnu.org
Thu Jul 21 16:20:00 GMT 2005


This is another instance of the visibility stuff being broken.  This time 
because a function isn't emitted, but called in a way as if it was. 
This code: 
--------------------------------- 
struct A { 
  virtual bool operator== (const A &a) const; 
  virtual bool operator!= (const A &a) const; 
}; 
inline bool A::operator!= ( const A &a) const 
{ return !(*this == a); } 
bool breakme(const A& newPath, A &b) 
{ return A(newPath) != b; } 
--------------------------------- 
 
Compile with (4.0.2 pre): 
% g++ -fPIC -DPIC -I/usr/lib/qt3/include -fvisibility=hidden \ 
-fvisibility-inlines-hidden -Wall -O2 -o libbla.so -shared testcase.ii 
ld: /tmp/ccWAn1go.o: relocation R_X86_64_PC32 against `A::operator!=(A const&) 
const' can not be used when making a shared object; recompile with -fPIC 
 
The chain of events goes like so: 
1) the operator is virtual, hence initially the call is through the vtable 
2) inlining happens before that is optimized, hence the operator call 
   is not inlined 
3) the virtual call is optimized to a direct call of the operator!=, because 
   of the explicit copy operation GCC knows the final type of the object 
   on which it is called (namely "A"), and hence can transform the indirect 
   to a direct call 
4) the call is emitted such that it expects a local (hidden) definition 
   of the function in the DSO (i.e. not over PLT but direct call) 
5) But no copy of that function is emitted in this DSO, because the 
   out-of-line copies of such inline function are generated only in the .o 
   file which contains the key method of the class (the first virtual func 
   in this case).  So nothing can be made hidden, and it anyway wouldn't 
   work even if, as there simply is nothing to call in this DSO. 
 
I believe this is a different error from all the other visibility problems 
like bug 19664 or bug 20218.  I don't know what GCC should do here. 
 
It either needs to emit an out-of-line copy of this operator, or generate the 
call over a PLT.  The first solution would be better, but could mean 
that we need to emit such out-of-line copies in every .o file where they 
are referenced.  The second solution might even not work at all, as probably 
the main library (containing the key method and hence the out-of-line 
versions) is also compiled with -fvisibility-inlines-hidden, and hence 
wouldn't even export those function which a call over PLT could resolve to. 
 
So, it seems that cgraph needs to be changed somehow to emit this function 
if referenced.  Hence CCing Honza.

-- 
           Summary: -fvisibility-inlines-hidden broken differently
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: matz at suse dot de
                CC: gcc-bugs at gcc dot gnu dot org,jh at suse dot cz
  GCC host triplet: x86_64-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22592



More information about the Gcc-bugs mailing list