<html>
<head>
<base href="http://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 --- - clang creates "weak symbol" whereas gcc produces "unique global sybol" symbol type for same source"
href="http://llvm.org/bugs/show_bug.cgi?id=22281">22281</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang creates "weak symbol" whereas gcc produces "unique global sybol" symbol type for same source
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.5
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>aln@esi-group.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>The following code produces different symbol types in the object file when
compiled with clang and gcc. I do not have any error or crashes.
//singleton.cpp
class Singleton
{
public:
static Singleton* getInstance()
{
static Singleton* mInstance=0;
if (!mInstance)
{
mInstance=new Singleton();
}
return mInstance;
}
};
void foo()
{
Singleton* myBar = Singleton::getInstance();
}
//
Compile command:
% clang -o clang.o -c singleton.cpp && gcc -o gcc.o -c singleton.cpp
nm then shows the following for both object files:
% nm clang.o && echo && nm gcc.o
0000000000000000 T _Z3foov
0000000000000000 W _ZN9Singleton11getInstanceEv
U _Znwm
0000000000000000 V _ZZN9Singleton11getInstanceEvE9mInstance
0000000000000000 T _Z3foov
0000000000000000 W _ZN9Singleton11getInstanceEv
U _Znwm
0000000000000000 u _ZZN9Singleton11getInstanceEvE9mInstance
As can be seen _ZZN9Singleton11getInstanceEvE9mInstance is created as "V" =
weak object by clang and "u" = unique global symbol by gcc.
I think this difference is the underlying problem I experience in a larger code
base that uses the singleton pattern. The created executables and dynamic
libraries do not work correctly because the singletons are not unique in the
process. I observed multiple constructor calls while debugging. The singletons
are created in a library and are used across library boarders.
Observed on Fedora 21 with clang 3.5.0-6.fc21 and gcc 4.9.2-1.fc21.
I also observed this behaviour on Fedora 20 but do not recall the actual
compiler versions.</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>