<html>
<head>
</head>
<body text="#000000" bgcolor="#FFFFFF">
I think we should introduce initialization method which will be
called before parallel_for_each (that calls applyRelocation) to
calculate all the needed values once without any<br>
threading issues. As a positive side effect, it will also allow us
to use const modifier for getters in TargetLayout. Thoughts?<br>
<br>
- Denis.<br>
<br>
<div class="moz-cite-prefix">On 04/13/2015 01:18 PM, Denis
Protivensky wrote:<br>
</div>
<blockquote cite="mid:20150413101822.09C9D2A6C02B@llvm.org"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="MS Exchange Server version
08.03.0377.000">
<title>[lld] r234733 - [ARM] Use std::call_once for thread safe
initialization</title>
<!-- Converted from text/plain format -->
<p><font size="2">Author: denis-protivensky<br>
Date: Mon Apr 13 05:18:21 2015<br>
New Revision: 234733<br>
<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project?rev=234733&view=rev">http://llvm.org/viewvc/llvm-project?rev=234733&view=rev</a><br>
Log:<br>
[ARM] Use std::call_once for thread safe initialization<br>
<br>
Thanks to r234628 & r234631<br>
<br>
Modified:<br>
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h<br>
<br>
Modified:
lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h<br>
URL: <a moz-do-not-send="true"
href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h?rev=234733&r1=234732&r2=234733&view=diff">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h?rev=234733&r1=234732&r2=234733&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h
(original)<br>
+++ lld/trunk/lib/ReaderWriter/ELF/ARM/ARMTargetHandler.h Mon
Apr 13 05:18:21 2015<br>
@@ -14,7 +14,6 @@<br>
#include "ARMRelocationHandler.h"<br>
#include "ELFReader.h"<br>
#include "TargetLayout.h"<br>
-#include "llvm/ADT/Optional.h"<br>
<br>
namespace lld {<br>
namespace elf {<br>
@@ -25,24 +24,24 @@ public:<br>
ARMTargetLayout(ARMLinkingContext &ctx) :
TargetLayout<ELFT>(ctx) {}<br>
<br>
uint64_t getGOTSymAddr() {<br>
- if (!_gotSymAddr.hasValue()) {<br>
- AtomLayout *gotAtom =
this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");<br>
- _gotSymAddr = gotAtom ? gotAtom->_virtualAddr : 0;<br>
- }<br>
- return *_gotSymAddr;<br>
+ std::call_once(_gotSymOnce, [this]() {<br>
+ if (AtomLayout *gotAtom =
this->findAbsoluteAtom("_GLOBAL_OFFSET_TABLE_"))<br>
+ _gotSymAddr = gotAtom->_virtualAddr;<br>
+ });<br>
+ return _gotSymAddr;<br>
}<br>
<br>
uint64_t getTPOffset() {<br>
- if (_tpOff.hasValue())<br>
- return *_tpOff;<br>
-<br>
- for (const auto &phdr : *this->_programHeader) {<br>
- if (phdr->p_type == llvm::ELF::PT_TLS) {<br>
- _tpOff = llvm::RoundUpToAlignment(TCB_SIZE,
phdr->p_align);<br>
- return *_tpOff;<br>
+ std::call_once(_tpOffOnce, [this]() {<br>
+ for (const auto &phdr : *this->_programHeader) {<br>
+ if (phdr->p_type == llvm::ELF::PT_TLS) {<br>
+ _tpOff = llvm::RoundUpToAlignment(TCB_SIZE,
phdr->p_align);<br>
+ break;<br>
+ }<br>
}<br>
- }<br>
- llvm_unreachable("TLS segment not found");<br>
+ assert(_tpOff != 0 && "TLS segment not found");<br>
+ });<br>
+ return _tpOff;<br>
}<br>
<br>
bool target1Rel() const { return
this->_ctx.armTarget1Rel(); }<br>
@@ -52,11 +51,10 @@ private:<br>
enum { TCB_SIZE = 0x8 };<br>
<br>
private:<br>
- // Cached value of the GOT origin symbol address.<br>
- llvm::Optional<uint64_t> _gotSymAddr;<br>
-<br>
- // Cached value of the TLS offset from the $tp pointer.<br>
- llvm::Optional<uint64_t> _tpOff;<br>
+ uint64_t _gotSymAddr = 0;<br>
+ uint64_t _tpOff = 0;<br>
+ std::once_flag _gotSymOnce;<br>
+ std::once_flag _tpOffOnce;<br>
};<br>
<br>
class ARMTargetHandler final : public TargetHandler {<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a class="moz-txt-link-abbreviated" href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</font>
</p>
</blockquote>
<br>
</body>
</html>