<div dir="ltr">Another problem I encountered is that the Microsoft linker doesn't like it if you chain weak aliases like so:<div><br><div>$ cat t.ll</div><div><div>@my_alias = alias linkonce_odr void ()* @my_inline</div>
<div>@my_alias2 = alias linkonce_odr void ()* @my_alias</div><div>define linkonce_odr void @my_inline() {<br></div><div> ret void</div><div>}</div><div>define i32 @main() {</div><div> call void @my_alias2()</div><div> ret i32 0</div>
<div>}</div></div><div><br></div><div>$ llc t.ll -o tll.obj -filetype=obj && link tll.obj -defaultlib:libcmt.lib -out:t.exe -nologo</div><div><div>tll.obj : error LNK2001: unresolved external symbol _my_alias2</div>
<div>tll.obj : error LNK2001: unresolved external symbol _my_alias</div></div></div><div><br></div><div>To work around this, when should we forward my_alias2 through to my_inline? In clang, LLVM, or MC?</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Oct 9, 2013 at 9:13 AM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: rafael<br>
Date: Wed Oct 9 11:13:15 2013<br>
New Revision: 192300<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192300&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192300&view=rev</a><br>
Log:<br>
Use aliases for more constructors and destructors.<br>
<br>
With this patch we produce alias for cases like<br>
<br>
template<typename T><br>
struct foobar {<br>
foobar() {<br>
}<br>
};<br>
template struct foobar<void>;<br>
<br>
It is safe to use aliases to weak symbols, as long and the alias itself is also<br>
weak.<br>
<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CGCXX.cpp<br>
cfe/trunk/test/CodeGenCXX/destructors.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=192300&r1=192299&r2=192300&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=192300&r1=192299&r2=192300&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Oct 9 11:13:15 2013<br>
@@ -108,32 +108,17 @@ bool CodeGenModule::TryEmitDefinitionAsA<br>
// support aliases with that linkage, fail.<br>
llvm::GlobalValue::LinkageTypes Linkage = getFunctionLinkage(AliasDecl);<br>
<br>
- switch (Linkage) {<br>
- // We can definitely emit aliases to definitions with external linkage.<br>
- case llvm::GlobalValue::ExternalLinkage:<br>
- case llvm::GlobalValue::ExternalWeakLinkage:<br>
- break;<br>
-<br>
- // Same with local linkage.<br>
- case llvm::GlobalValue::InternalLinkage:<br>
- case llvm::GlobalValue::PrivateLinkage:<br>
- case llvm::GlobalValue::LinkerPrivateLinkage:<br>
- break;<br>
-<br>
- // We should try to support linkonce linkages.<br>
- case llvm::GlobalValue::LinkOnceAnyLinkage:<br>
- case llvm::GlobalValue::LinkOnceODRLinkage:<br>
- return true;<br>
-<br>
- // Other linkages will probably never be supported.<br>
- default:<br>
+ // We can't use an alias if the linkage is not valid for one.<br>
+ if (!llvm::GlobalAlias::isValidLinkage(Linkage))<br>
return true;<br>
- }<br>
<br>
llvm::GlobalValue::LinkageTypes TargetLinkage<br>
= getFunctionLinkage(TargetDecl);<br>
<br>
- if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))<br>
+ // Don't create an strong alias to a linker weak symbol. If the linker<br>
+ // decides to drop the symbol, the alias would become undefined.<br>
+ if (llvm::GlobalValue::isWeakForLinker(TargetLinkage) &&<br>
+ !llvm::GlobalValue::isWeakForLinker(Linkage))<br>
return true;<br>
<br>
// Derive the type for the alias.<br>
<br>
Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=192300&r1=192299&r2=192300&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=192300&r1=192299&r2=192300&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)<br>
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Wed Oct 9 11:13:15 2013<br>
@@ -6,10 +6,16 @@<br>
// CHECK: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev<br>
// CHECK: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev<br>
<br>
+// CHECK: @_ZN6test106foobarIvEC1Ev = alias weak_odr void (%"struct.test10::foobar"*)* @_ZN6test106foobarIvEC2Ev<br>
+<br>
+// CHECK: @_ZN6test116foobarIvEC1Ev = alias linkonce_odr void (%"struct.test11::foobar"*)* @_ZN6test116foobarIvEC2Ev<br>
+<br>
// CHECK: @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev<br>
// CHECK: @_ZN5test312_GLOBAL__N_11DD2Ev = alias internal bitcast {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev<br>
// CHECK: @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev<br>
<br>
+// CHECK: @_ZN6PR752617allocator_derivedD1Ev = alias linkonce_odr void (%"struct.PR7526::allocator_derived"*)* @_ZN6PR752617allocator_derivedD2Ev<br>
+<br>
struct A {<br>
int a;<br>
<br>
@@ -44,9 +50,6 @@ namespace PR7526 {<br>
// CHECK: call void @__cxa_call_unexpected<br>
allocator::~allocator() throw() { foo(); }<br>
<br>
- // CHECK-LABEL: define linkonce_odr void @_ZN6PR752617allocator_derivedD1Ev(%"struct.PR7526::allocator_derived"* %this) unnamed_addr<br>
- // CHECK-NOT: call void @__cxa_call_unexpected<br>
- // CHECK: }<br>
void foo() {<br>
allocator_derived ad;<br>
}<br>
@@ -419,3 +422,25 @@ namespace test9 {<br>
// CHECK: ret void<br>
<br>
// CHECK: attributes [[NUW]] = {{[{].*}} nounwind {{.*[}]}}<br>
+<br>
+<br>
+namespace test10 {<br>
+ template<typename T><br>
+ struct foobar {<br>
+ foobar() {<br>
+ }<br>
+ };<br>
+<br>
+ template struct foobar<void>;<br>
+}<br>
+<br>
+namespace test11 {<br>
+ void g();<br>
+ template<typename T><br>
+ struct foobar {<br>
+ foobar() {<br>
+ g();<br>
+ }<br>
+ };<br>
+ foobar<void> x;<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>