Revert "Issue 1486: cgo: fix C++ dynamic initialization of static variables when using alwayslink = True (#4438)" (#4551)

This reverts commit 20f7e2bb45dfbd6630f7ce36ad62cb9001a7e2f5 as it
causes a regression (see #4548)
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 7b7a9d2..1e2b4ee 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -9,7 +9,6 @@
 # Names should be added to this file as:
 #     Name <email address>
 
-Andrei Reshetkov <enscogitans.v@gmail.com>
 Benjamin Staffin <benley@gmail.com>
 Brian Silverman <bsilver16384@gmail.com>
 Damien Martin-Guillerez <dmarting@google.com>
diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl
index 86c5147..1c48d02 100644
--- a/go/private/rules/cgo.bzl
+++ b/go/private/rules/cgo.bzl
@@ -93,7 +93,6 @@
     deps_direct = []
     lib_opts = []
     runfiles = go._ctx.runfiles(collect_data = True)
-    seen_alwayslink_libs = {}
 
     # Always include the sandbox as part of the build. Bazel does this, but it
     # doesn't appear in the CompilationContext.
@@ -146,13 +145,7 @@
                         # libclntsh.dylib.12.1, users have to create a unversioned symbolic link,
                         # so it can be treated as a simple shared library too.
                         continue
-
-                if lib.basename.endswith(".lo") and lib.path not in seen_alwayslink_libs:
-                    seen_alwayslink_libs[lib.path] = True
-                    lib_opts.extend(_alwayslink_lib_opts(go, lib.path))
-                else:
-                    lib_opts.append(lib.path)
-
+                lib_opts.append(lib.path)
             clinkopts.extend(cc_link_flags)
 
         elif hasattr(d, "objc"):
@@ -209,11 +202,6 @@
                 libs.append(library_to_link.dynamic_library)
     return libs, flags
 
-def _alwayslink_lib_opts(go, lib_path):
-    if go.mode.goos == "darwin":
-        return ["-Wl,-force_load,{}".format(lib_path)]
-    return ["-Wl,-whole-archive", lib_path, "-Wl,-no-whole-archive"]
-
 def _include_unique(opts, flag, include, seen):
     if include in seen:
         return
diff --git a/tests/core/cgo/cgo_alwayslink_init/BUILD.bazel b/tests/core/cgo/cgo_alwayslink_init/BUILD.bazel
deleted file mode 100644
index ed4766e..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/BUILD.bazel
+++ /dev/null
@@ -1,41 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_test")
-load("@rules_cc//cc:cc_library.bzl", "cc_library")
-load("@rules_cc//cc:cc_test.bzl", "cc_test")
-
-cc_library(
-    name = "lib",
-    srcs = [
-        "lib.cpp",
-        "side_effect.cpp",
-    ],
-    hdrs = [
-        "lib.h",
-    ],
-    alwayslink = True,
-)
-
-# used to check that we don't get a "multiple definition" linker errors, and that the side effect
-# is performed exactly once, even if imported several times through different targets
-cc_library(
-    name = "lib_wrapper",
-    deps = [":lib"],
-)
-
-cc_test(
-    name = "test_side_effect_cc",
-    srcs = ["test_side_effect.cpp"],
-    deps = [
-        ":lib",
-        ":lib_wrapper",
-    ],
-)
-
-go_test(
-    name = "test_side_effect_go",
-    srcs = ["test_side_effect.go"],
-    cdeps = [
-        ":lib",
-        ":lib_wrapper",
-    ],
-    cgo = True,
-)
diff --git a/tests/core/cgo/cgo_alwayslink_init/README.rst b/tests/core/cgo/cgo_alwayslink_init/README.rst
deleted file mode 100644
index ad08898..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/README.rst
+++ /dev/null
@@ -1,18 +0,0 @@
-.. _#1486 : https://github.com/bazel-contrib/rules_go/issues/1486
-
-Cgo and dynamic initialization with `alwayslink = True`
-========================================================
-
-test_side_effect_go
--------------------
-This test verifies that the dynamic initialization of C++ variables with static storage duration in
-`cc_library` targets with `alwayslink = True` is performed when linked into a `go_test` or
-`go_binary` with `cgo = True`. This is a regression test for issue `#1486`_. The test also
-includes a `lib_wrapper` library to ensure that there are no linker errors and that the side effect
-is performed exactly once, even if it is imported multiple times through different targets.
-
-test_side_effect_cc
--------------------
-This is a C++ test included as a reference. It has the same dependencies as `test_side_effect_go`
-and confirms the expected behavior in a pure C++ environment, where the dynamic initialization of
-variables with static storage duration is always performed.
diff --git a/tests/core/cgo/cgo_alwayslink_init/lib.cpp b/tests/core/cgo/cgo_alwayslink_init/lib.cpp
deleted file mode 100644
index 7b0c66f..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/lib.cpp
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "tests/core/cgo/cgo_alwayslink_init/lib.h"
-
-int value = 0;
diff --git a/tests/core/cgo/cgo_alwayslink_init/lib.h b/tests/core/cgo/cgo_alwayslink_init/lib.h
deleted file mode 100644
index e9a9719..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/lib.h
+++ /dev/null
@@ -1 +0,0 @@
-extern int value;
diff --git a/tests/core/cgo/cgo_alwayslink_init/side_effect.cpp b/tests/core/cgo/cgo_alwayslink_init/side_effect.cpp
deleted file mode 100644
index fa70126..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/side_effect.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "tests/core/cgo/cgo_alwayslink_init/lib.h"
-
-namespace {
-
-struct SideEffect {
-  SideEffect() {
-    value += 42;
-  }
-};
-
-SideEffect effect;
-
-}  // namespace
diff --git a/tests/core/cgo/cgo_alwayslink_init/test_side_effect.cpp b/tests/core/cgo/cgo_alwayslink_init/test_side_effect.cpp
deleted file mode 100644
index 2413943..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/test_side_effect.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <iostream>
-
-#include "tests/core/cgo/cgo_alwayslink_init/lib.h"
-
-int main() {
-  const int expected = 42;
-  const int actual = value;
-  if (expected == actual) {
-    return 0;
-  }
-  std::cout << "Expected " << expected << ", got " << actual << '\n';
-  return 1;
-}
diff --git a/tests/core/cgo/cgo_alwayslink_init/test_side_effect.go b/tests/core/cgo/cgo_alwayslink_init/test_side_effect.go
deleted file mode 100644
index 541207f..0000000
--- a/tests/core/cgo/cgo_alwayslink_init/test_side_effect.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package ccstaticinit
-
-// #include "tests/core/cgo/cgo_alwayslink_init/lib.h"
-import "C"
-import "testing"
-
-func TestValue(t *testing.T) {
-	const expected = 42
-	actual := int(C.value)
-	if expected != actual {
-		t.Errorf("Expected %v, got %v", expected, actual)
-	}
-}