<div dir="ltr">The list of nodes the context object has is a shared resource -- by parsing a file, the parser may add more files to the input list. (That doesn't occur for ELF but may occur for COFF, since a COFF object may contain extra command line parameters which let the linker to read more files.)</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 23, 2015 at 8:17 AM, Jean-Daniel Dupas <span dir="ltr"><<a href="mailto:dev@xenonium.com" target="_blank">dev@xenonium.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Does it not reveal a race condition here ?<br>
An action preformed in background by the thread pool should not affect the behavior of the current thread.<br>
<br>
> Le 23 janv. 2015 à 01:09, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> a écrit :<br>
<div class="HOEnZb"><div class="h5">><br>
> Author: ruiu<br>
> Date: Thu Jan 22 18:09:05 2015<br>
> New Revision: 226883<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=226883&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=226883&view=rev</a><br>
> Log:<br>
> Make access to LinkingContext::getNode safe.<br>
><br>
> Modified:<br>
>    lld/trunk/lib/Driver/Driver.cpp<br>
><br>
> Modified: lld/trunk/lib/Driver/Driver.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226883&r1=226882&r2=226883&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=226883&r1=226882&r2=226883&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/lib/Driver/Driver.cpp (original)<br>
> +++ lld/trunk/lib/Driver/Driver.cpp Thu Jan 22 18:09:05 2015<br>
> @@ -77,8 +77,11 @@ bool Driver::link(LinkingContext &contex<br>
>   if (context.getNodes().empty())<br>
>     return false;<br>
><br>
> -  for (std::unique_ptr<Node> &ie : context.getNodes())<br>
> -    if (FileNode *node = dyn_cast<FileNode>(ie.get()))<br>
> +  // File::parse may add items to the node list which may invalidate<br>
> +  // existing iterators. Avoid using iterator to access elements.<br>
> +  std::vector<std::unique_ptr<Node>> &nodes = context.getNodes();<br>
> +  for (size_t i = 0; i < nodes.size(); ++i)<br>
> +    if (FileNode *node = dyn_cast<FileNode>(nodes[i].get()))<br>
>       context.getTaskGroup().spawn([node] { node->getFile()->parse(); });<br>
><br>
>   std::vector<std::unique_ptr<File>> internalFiles;<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">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>
<br>
</div></div></blockquote></div><br></div>