<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 18, 2020 at 12:28 PM Gleb Popov <<a href="mailto:6yearold@gmail.com">6yearold@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello.</div><div><br></div><div>I'm posting this question here, because there seem to be no LLD-specific mailing list. Sorry in advance if this is wrong one.</div><div><br></div><div>I compile two C source with following command:</div><div><br></div><div>clang -flto -o %name.bc %name.c</div><div><br></div><div>LLVM is augmented with my custom pass, which amongst other things create a global with appending linkage:</div><div><br></div><div>@myvar = appending constant [1 x [1 x i8]*] ...</div><div><br></div><div>I also have another pass plugged into LTO pipeline, which turns this global  into internal one in the final module. I was hoping that LLD would first link bitcodes like llvm-link, appending @myvar's from both modules into a single one, then run my pass, and only then perform linking at object level.<br></div><div><br></div><div>However, LLD complains about duplicated symbol "myvar" and doesn't even run any passes.</div><div><br></div><div>I've tracked the problem down to <span>BitcodeFile::parse</span>() function from <a href="https://github.com/llvm/llvm-project/blob/master/lld/COFF/InputFiles.cpp#L918" target="_blank">https://github.com/llvm/llvm-project/blob/master/lld/COFF/InputFiles.cpp#L918</a> - it doesn't take linkage type into account. <br></div><div><br></div><div>Can anything be done about this problem? Or was my approach broken from the beginning?<br></div><div><br></div><div>Thanks in advance.<br></div></div></blockquote><div><br></div><div><br></div><div>The following patch has fixed the problem for me:</div><div><br></div><div>diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp<br>index 33ce7d8109f..d1d74fa54bf 100644<br>--- a/lib/Object/ModuleSymbolTable.cpp<br>+++ b/lib/Object/ModuleSymbolTable.cpp<br>@@ -201,7 +201,7 @@ uint32_t ModuleSymbolTable::getSymbolFlags(Symbol S) const {<br>     Res |= BasicSymbolRef::SF_Executable;<br>   if (isa<GlobalAlias>(GV))<br>     Res |= BasicSymbolRef::SF_Indirect;<br>-  if (GV->hasPrivateLinkage())<br>+  if (GV->hasPrivateLinkage() || GV->hasAppendingLinkage())<br>     Res |= BasicSymbolRef::SF_FormatSpecific;<br>   if (!GV->hasLocalLinkage())<br>     Res |= BasicSymbolRef::SF_Global;</div><div><br></div><div>Is it a sane approach? Can it be upstreamed?<br> </div></div></div>