<div dir="ltr">That's what I was looking for. Thank you! Committed a follow-up patch in r241477.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 5, 2015 at 8:24 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><p dir="ltr"><br>
On Jul 5, 2015 2:56 PM, "Rui Ueyama" <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br>
><br>
> Author: ruiu<br>
> Date: Sun Jul  5 16:54:42 2015<br>
> New Revision: 241416<br>
><br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D241416-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mzSLImO_2pboaKi2Bf3UWrrfMJ1AUvTTrS6f_2CwKi8&s=1Ol3_vt9n-mQp8NA1_V87zuyUIvP21_8NpG9l4hOGj8&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=241416&view=rev</a><br>
> Log:<br>
> COFF: Use atomic pointers in preparation for parallelizing.<br>
><br>
> In the new design, mutation of Symbol pointers is the name resolution<br>
> operation. This patch makes them atomic pointers so that they can<br>
> be mutated by multiple threads safely. I'm going to use atomic<br>
> compare-exchange on these pointers.<br>
><br>
> dyn_cast<> doesn't recognize atomic pointers as pointers,<br>
> so we need to call load(). This is unfortunate, but in other places<br>
> automatic type conversion works fine.</p>
</span><p dir="ltr">You might be able to use llvm::simplify_type to work around this problem?</p><div class="HOEnZb"><div class="h5">
<p dir="ltr">><br>
> Modified:<br>
>     lld/trunk/COFF/Driver.cpp<br>
>     lld/trunk/COFF/SymbolTable.cpp<br>
>     lld/trunk/COFF/Symbols.h<br>
>     lld/trunk/COFF/Writer.cpp<br>
><br>
> Modified: lld/trunk/COFF/Driver.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Driver.cpp-3Frev-3D241416-26r1-3D241415-26r2-3D241416-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mzSLImO_2pboaKi2Bf3UWrrfMJ1AUvTTrS6f_2CwKi8&s=zGJC7Y7ZHFIgHVkgUL34JnPDjBPhbu_76cpA66CEJ4Y&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=241416&r1=241415&r2=241416&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/Driver.cpp (original)<br>
> +++ lld/trunk/COFF/Driver.cpp Sun Jul  5 16:54:42 2015<br>
> @@ -220,7 +220,7 @@ StringRef LinkerDriver::findDefaultEntry<br>
>    };<br>
>    for (auto E : Entries) {<br>
>      Symbol *Sym = Symtab.find(E[0]);<br>
> -    if (Sym && !isa<Undefined>(Sym->Body))<br>
> +    if (Sym && !isa<Undefined>(Sym->Body.load()))<br>
>        return E[1];<br>
>    }<br>
>    return "";<br>
> @@ -591,7 +591,7 @@ bool LinkerDriver::link(llvm::ArrayRef<c<br>
>        Symbol *Sym = Symtab.find(From);<br>
>        if (!Sym)<br>
>          continue;<br>
> -      if (auto *U = dyn_cast<Undefined>(Sym->Body))<br>
> +      if (auto *U = dyn_cast<Undefined>(Sym->Body.load()))<br>
>          if (!U->WeakAlias)<br>
>            U->WeakAlias = Symtab.addUndefined(To);<br>
>      }<br>
><br>
> Modified: lld/trunk/COFF/SymbolTable.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_SymbolTable.cpp-3Frev-3D241416-26r1-3D241415-26r2-3D241416-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mzSLImO_2pboaKi2Bf3UWrrfMJ1AUvTTrS6f_2CwKi8&s=pkqx9d5nxUdsRzl7gQAosBrpTQwEhjfX8cdIGk0pIto&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=241416&r1=241415&r2=241416&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/SymbolTable.cpp (original)<br>
> +++ lld/trunk/COFF/SymbolTable.cpp Sun Jul  5 16:54:42 2015<br>
> @@ -77,7 +77,7 @@ std::error_code SymbolTable::readArchive<br>
>    // Add archive member files to ObjectQueue that should resolve<br>
>    // existing undefined symbols.<br>
>    for (Symbol *Sym : LazySyms)<br>
> -    if (auto EC = addMemberFile(cast<Lazy>(Sym->Body)))<br>
> +    if (auto EC = addMemberFile(cast<Lazy>(Sym->Body.load())))<br>
>        return EC;<br>
>    return std::error_code();<br>
>  }<br>
> @@ -126,7 +126,7 @@ bool SymbolTable::reportRemainingUndefin<br>
>    bool Ret = false;<br>
>    for (auto &I : Symtab) {<br>
>      Symbol *Sym = I.second;<br>
> -    auto *Undef = dyn_cast<Undefined>(Sym->Body);<br>
> +    auto *Undef = dyn_cast<Undefined>(Sym->Body.load());<br>
>      if (!Undef)<br>
>        continue;<br>
>      StringRef Name = Undef->getName();<br>
> @@ -140,10 +140,10 @@ bool SymbolTable::reportRemainingUndefin<br>
>      // This odd rule is for compatibility with MSVC linker.<br>
>      if (Name.startswith("__imp_")) {<br>
>        Symbol *Imp = find(Name.substr(strlen("__imp_")));<br>
> -      if (Imp && isa<Defined>(Imp->Body)) {<br>
> +      if (Imp && isa<Defined>(Imp->Body.load())) {<br>
>          if (!Resolve)<br>
>            continue;<br>
> -        auto *D = cast<Defined>(Imp->Body);<br>
> +        auto *D = cast<Defined>(Imp->Body.load());<br>
>          auto *S = new (Alloc) DefinedLocalImport(Name, D);<br>
>          LocalImportChunks.push_back(S->getChunk());<br>
>          Sym->Body = S;<br>
> @@ -320,11 +320,11 @@ std::error_code SymbolTable::addCombined<br>
>      StringRef Name = Body->getName();<br>
>      Symbol *Sym = insert(Body);<br>
><br>
> -    if (isa<DefinedBitcode>(Sym->Body)) {<br>
> +    if (isa<DefinedBitcode>(Sym->Body.load())) {<br>
>        Sym->Body = Body;<br>
>        continue;<br>
>      }<br>
> -    if (auto *L = dyn_cast<Lazy>(Sym->Body)) {<br>
> +    if (auto *L = dyn_cast<Lazy>(Sym->Body.load())) {<br>
>        // We may see new references to runtime library symbols such as __chkstk<br>
>        // here. These symbols must be wholly defined in non-bitcode files.<br>
>        if (auto EC = addMemberFile(L))<br>
><br>
> Modified: lld/trunk/COFF/Symbols.h<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Symbols.h-3Frev-3D241416-26r1-3D241415-26r2-3D241416-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mzSLImO_2pboaKi2Bf3UWrrfMJ1AUvTTrS6f_2CwKi8&s=KqZ_MNXMFwR9dV2dkTNNqXR6KehKikh58fdkbyP_p6o&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=241416&r1=241415&r2=241416&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/Symbols.h (original)<br>
> +++ lld/trunk/COFF/Symbols.h Sun Jul  5 16:54:42 2015<br>
> @@ -16,6 +16,7 @@<br>
>  #include "llvm/ADT/ArrayRef.h"<br>
>  #include "llvm/Object/Archive.h"<br>
>  #include "llvm/Object/COFF.h"<br>
> +#include <atomic><br>
>  #include <memory><br>
>  #include <vector><br>
><br>
> @@ -38,7 +39,7 @@ class SymbolBody;<br>
>  // The resolver updates SymbolBody pointers as it resolves symbols.<br>
>  struct Symbol {<br>
>    explicit Symbol(SymbolBody *P) : Body(P) {}<br>
> -  SymbolBody *Body;<br>
> +  std::atomic<SymbolBody *> Body;<br>
>  };<br>
><br>
>  // The base class for real symbol classes.<br>
> @@ -80,7 +81,7 @@ public:<br>
>    // has chosen the object among other objects having the same name,<br>
>    // you can access P->Backref->Body to get the resolver's result.<br>
>    void setBackref(Symbol *P) { Backref = P; }<br>
> -  SymbolBody *repl() { return Backref ? Backref->Body : this; }<br>
> +  SymbolBody *repl() { return Backref ? Backref->Body.load() : this; }<br>
><br>
>    // Decides which symbol should "win" in the symbol table, this or<br>
>    // the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if<br>
><br>
> Modified: lld/trunk/COFF/Writer.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Writer.cpp-3Frev-3D241416-26r1-3D241415-26r2-3D241416-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=mzSLImO_2pboaKi2Bf3UWrrfMJ1AUvTTrS6f_2CwKi8&s=FicZOI1DZZ-OxLpdGIscX-dzMW9EpIk7XGOMghZwkec&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=241416&r1=241415&r2=241416&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/Writer.cpp (original)<br>
> +++ lld/trunk/COFF/Writer.cpp Sun Jul  5 16:54:42 2015<br>
> @@ -243,7 +243,8 @@ void Writer::createImportTables() {<br>
>        Sec->addChunk(C);<br>
>    }<br>
>    if (!DelayIdata.empty()) {<br>
> -    Defined *Helper = cast<Defined>(Symtab->find("__delayLoadHelper2")->Body);<br>
> +    Symbol *Sym = Symtab->find("__delayLoadHelper2");<br>
> +    Defined *Helper = cast<Defined>(Sym->Body.load());<br>
>      DelayIdata.create(Helper);<br>
>      OutputSection *Sec = createSection(".didat");<br>
>      for (Chunk *C : DelayIdata.getChunks())<br>
> @@ -535,7 +536,7 @@ OutputSection *Writer::createSection(Str<br>
>  // Dest is .reloc section. Add contents to that section.<br>
>  void Writer::addBaserels(OutputSection *Dest) {<br>
>    std::vector<uint32_t> V;<br>
> -  Defined *ImageBase = cast<Defined>(Symtab->find("__ImageBase")->Body);<br>
> +  Defined *ImageBase = cast<Defined>(Symtab->find("__ImageBase")->Body.load());<br>
>    for (OutputSection *Sec : OutputSections) {<br>
>      if (Sec == Dest)<br>
>        continue;<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>
</div></div></blockquote></div><br></div>