Freeze libraries to link before interning them. Otherwise, Blaze is susceptible to a race condition: 1. Node A creates a list ["x"] and interns it 2. Node B creates the same list ["x"] and interns it; it gets back a still mutable reference to the list created by node A 3. Node B finishes, freezes its Starlark data structures and puts a reference to the list (which is secretly created by Node A) into a provider 4. Node A adds "y" to the list 5. Now Node C (depending on Node B) will observe the values of the list as ["x", "y"], even though that's totally not what Node B intended RELNOTES: None. PiperOrigin-RevId: 947612088 Change-Id: I98fd1dadaaa0e0677577627ce63039599a72f66b
diff --git a/cc/private/link/create_libraries_to_link_values.bzl b/cc/private/link/create_libraries_to_link_values.bzl index fa02879..0822758 100644 --- a/cc/private/link/create_libraries_to_link_values.bzl +++ b/cc/private/link/create_libraries_to_link_values.bzl
@@ -14,6 +14,7 @@ """Goes over LibraryToLinks and produces LibraryToLinkValue-s.""" load("//cc/common:cc_helper_internal.bzl", "is_shared_library", "is_versioned_shared_library", "root_relative_path") +load("//cc/private:cc_internal.bzl", _cc_internal = "cc_internal") # Types of LibraryToLinkValues _TYPE = struct( @@ -58,7 +59,7 @@ libraries_to_link_values.append( _ObjectFileGroupInfo( type = _TYPE.OBJECT_FILE_GROUP, - object_files = [object_file], + object_files = _cc_internal.freeze([object_file]), is_whole_archive = False, ), ) @@ -225,7 +226,7 @@ libraries_to_link_values.append( _ObjectFileGroupInfo( type = _TYPE.OBJECT_FILE_GROUP, - object_files = [object], + object_files = _cc_internal.freeze([object]), is_whole_archive = True, ), ) @@ -244,7 +245,7 @@ libraries_to_link_values.append( _ObjectFileGroupInfo( type = _TYPE.OBJECT_FILE_GROUP, - object_files = objects, + object_files = _cc_internal.freeze(objects), is_whole_archive = False, ), )