<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - -fvisibility=hidden and -fvisibility-ms-compat are order dependent"
   href="https://llvm.org/bugs/show_bug.cgi?id=24918">24918</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fvisibility=hidden and -fvisibility-ms-compat are order dependent
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jinxcat2008@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14928" name="attach_14928" title="The Makefile and source files to reproduce the issue.">attachment 14928</a> <a href="attachment.cgi?id=14928&action=edit" title="The Makefile and source files to reproduce the issue.">[details]</a></span>
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</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>