aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-06-02 06:10:34 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-06-02 06:10:34 +0200
commit048bcc1604a7e8aca666e219c0fdc3cd5517029e (patch)
treec710fd799f1089cfaf06cf1a520c072c0436dfd1
parent2dd1f9fa5a7427096b74aa85258ec2feeb93c104 (diff)
Fix data race in library metadata protocol logic
-rw-r--r--libbuild2/cc/common.cxx5
-rw-r--r--libbuild2/cc/windows-rpath.cxx8
-rw-r--r--libbuild2/target.hxx6
3 files changed, 14 insertions, 5 deletions
diff --git a/libbuild2/cc/common.cxx b/libbuild2/cc/common.cxx
index c423c37..07a4d48 100644
--- a/libbuild2/cc/common.cxx
+++ b/libbuild2/cc/common.cxx
@@ -382,9 +382,10 @@ namespace build2
for (const prerequisite_target& pt: l.prerequisite_targets[a])
{
// Note: adhoc prerequisites are not part of the library metadata
- // protocol (and we should check for adhoc first to avoid races).
+ // protocol (and we should check for adhoc first to avoid races
+ // during execute).
//
- if (pt == nullptr || pt.adhoc ())
+ if (pt.adhoc () || pt == nullptr)
continue;
if (marked (pt))
diff --git a/libbuild2/cc/windows-rpath.cxx b/libbuild2/cc/windows-rpath.cxx
index 9387078..bd5a928 100644
--- a/libbuild2/cc/windows-rpath.cxx
+++ b/libbuild2/cc/windows-rpath.cxx
@@ -128,7 +128,9 @@ namespace build2
library_cache lib_cache;
for (const prerequisite_target& pt: t.prerequisite_targets[a])
{
- if (pt == nullptr || pt.adhoc ())
+ // Note: during execute so check for ad hoc first to avoid data races.
+ //
+ if (pt.adhoc () || pt == nullptr)
continue;
bool la;
@@ -255,7 +257,9 @@ namespace build2
library_cache lib_cache;
for (const prerequisite_target& pt: t.prerequisite_targets[a])
{
- if (pt == nullptr || pt.adhoc ())
+ // Note: during execute so check for ad hoc first to avoid data races.
+ //
+ if (pt.adhoc () || pt == nullptr)
continue;
bool la;
diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx
index d4ad780..69714fc 100644
--- a/libbuild2/target.hxx
+++ b/libbuild2/target.hxx
@@ -940,7 +940,11 @@ namespace build2
// (e.g., in match data) with a few well-known execeptions (see
// group_recipe and inner_recipe).
//
- // Note that the recipe may modify this list. @@ TMP TSAN issue
+ // Note that the recipe may modify this list during execute. Normally this
+ // would be just blanking out of ad hoc prerequisites, in which case check
+ // for ad hoc first and for not NULL second if accessing prerequisites of
+ // targets that you did not execute (see the library metadata protocol in
+ // cc for an example).
//
mutable action_state<build2::prerequisite_targets> prerequisite_targets;