summaryrefslogtreecommitdiffstats
path: root/lld/include
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-05-22 23:56:44 +0000
committerLang Hames <lhames@gmail.com>2015-05-22 23:56:44 +0000
commit825e258fc36fcd645d38f38bd835a60616832181 (patch)
tree8117594c99ab62be81b3f9af67a36a8e4497ad38 /lld/include
parent7c78ef7dd9d9ce3bc32ae825210ab440f0529378 (diff)
downloadbcm5719-llvm-825e258fc36fcd645d38f38bd835a60616832181.tar.gz
bcm5719-llvm-825e258fc36fcd645d38f38bd835a60616832181.zip
[lld] Manage atom ordinals in the File class rather than using a static counter.
This is a cleaner fix for the race-condition bug that was originally papered over by r237857. llvm-svn: 238072
Diffstat (limited to 'lld/include')
-rw-r--r--lld/include/lld/Core/File.h9
-rw-r--r--lld/include/lld/Core/Simple.h5
2 files changed, 10 insertions, 4 deletions
diff --git a/lld/include/lld/Core/File.h b/lld/include/lld/Core/File.h
index 43e051101e0..494e5006534 100644
--- a/lld/include/lld/Core/File.h
+++ b/lld/include/lld/Core/File.h
@@ -86,6 +86,11 @@ public:
/// Sets the command line order of the file.
void setOrdinal(uint64_t ordinal) const { _ordinal = ordinal; }
+ /// Returns the ordinal for the next atom to be defined in this file.
+ uint64_t getNextAtomOrdinalAndIncrement() const {
+ return _nextAtomOrdinal++;
+ }
+
/// For allocating any objects owned by this File.
llvm::BumpPtrAllocator &allocator() const {
return _allocator;
@@ -152,7 +157,8 @@ public:
protected:
/// \brief only subclasses of File can be instantiated
File(StringRef p, Kind kind)
- : _path(p), _kind(kind), _ordinal(UINT64_MAX) {}
+ : _path(p), _kind(kind), _ordinal(UINT64_MAX),
+ _nextAtomOrdinal(0) {}
/// \brief Subclasses should override this method to parse the
/// memory buffer passed to this file's constructor.
@@ -170,6 +176,7 @@ private:
mutable std::string _archiveMemberPath;
Kind _kind;
mutable uint64_t _ordinal;
+ mutable uint64_t _nextAtomOrdinal;
std::shared_ptr<MemoryBuffer> _sharedMemoryBuffer;
llvm::Optional<std::error_code> _lastError;
std::mutex _parseMutex;
diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h
index e88043abd3a..3c204f8ba28 100644
--- a/lld/include/lld/Core/Simple.h
+++ b/lld/include/lld/Core/Simple.h
@@ -206,9 +206,8 @@ namespace lld {
class SimpleDefinedAtom : public DefinedAtom {
public:
- explicit SimpleDefinedAtom(const File &f) : _file(f) {
- static std::atomic<uint32_t> lastOrdinal(0);
- _ordinal = lastOrdinal++;
+ explicit SimpleDefinedAtom(const File &f)
+ : _file(f), _ordinal(f.getNextAtomOrdinalAndIncrement()) {
_references.setAllocator(&f.allocator());
}
OpenPOWER on IntegriCloud