[llvm-bugs] [Bug 24918] New: -fvisibility=hidden and -fvisibility-ms-compat are order dependent

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 23 15:02:02 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24918

            Bug ID: 24918
           Summary: -fvisibility=hidden and -fvisibility-ms-compat are
                    order dependent
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jinxcat2008 at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 14928
  --> https://llvm.org/bugs/attachment.cgi?id=14928&action=edit
The Makefile and source files to reproduce the issue.

The order of the -fvisibility=hidden and -fvisibility-ms-compat flags affects
the resulting binaries and the symbols which are visible in a dynamic library
created from them. This seems to specifically affect templated functions which
contain declarations in a header file and definitions in a source file. The
fact that the template was specialized in the source file also seems necessary
to reproduce the issue. In the larger program where I first noticed the
problem, explicit instantiations, not specializations, also seemed to show
behavior differences.

Here are the files used:

% cat foo.h
class Bar
{
};

class ChildBar : public Bar
{
};

class __attribute__((visibility("default"))) Foo
{
public:
    template< class Bar >
    void bar( const Bar & );
};


% cat foo.cpp
#include "foo.h"

template< class Bar >
void Foo::bar( const Bar & )
{
}

template<>
void Foo::bar( const ChildBar & )
{
}


% cat Makefile
foo.o: foo.cpp
    @clang++ -fvisibility=hidden -fvisibility-ms-compat -c foo.cpp -o foo.o

libfoo.dylib: foo.o
    @clang++ -dynamiclib -o libfoo.dylib foo.o

foo_missing.o: foo.cpp
    @clang++ -fvisibility-ms-compat -fvisibility=hidden -c foo.cpp -o
foo_missing.o

libfoo_missing.dylib: foo_missing.o
    @clang++ -dynamiclib -o libfoo_missing.dylib foo_missing.o

symbols: libfoo.dylib
    @echo Symbols present:
    @nm -g libfoo.dylib

symbols_missing: libfoo_missing.dylib
    @echo Symbols missing:
    @nm -g libfoo_missing.dylib

all: symbols symbols_missing

clean:
    @rm foo.o libfoo.dylib foo_missing.o libfoo_missing.dylib


Run 'make all' from the command line and it will produce the following output:

Symbols present:
0000000000000f90 T __ZN3Foo3barI8ChildBarEEvRKT_
                 U dyld_stub_binder
Symbols missing:
                 U dyld_stub_binder

The exported symbols from the two dylibs should match.

I used these two versions of clang on Mac OSX.

(Mac OSX 10.9.5 - Mavericks)
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

(Mac OSX 10.11 Developer Preview - El Capitan GM Seed)
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150923/92783801/attachment.html>


More information about the llvm-bugs mailing list