1From 0dcae7668b878b7db5da83643a8dfd7709865d3b Mon Sep 17 00:00:00 2001
2From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Fri, 22 Jan 2021 00:02:25 +0800
4Subject: [PATCH] avoid link latomic failure on CentOS 8 host
5
6When host (such as CentOS 8) did not install libatomic, there was a
7link failure on native. In fact, only target requires to link atomic,
8the native does not. So link atomic for target only
9
10Upstream-Status: Inappropriate [oe specific]
11
12Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
13Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com>
14
15---
16 base/BUILD.gn               | 2 ++
17 build/config/linux/BUILD.gn | 2 ++
18 2 files changed, 4 insertions(+)
19
20diff --git a/base/BUILD.gn b/base/BUILD.gn
21index 1f0e5cc5f0fae..f75c71d26f727 100644
22--- a/base/BUILD.gn
23+++ b/base/BUILD.gn
24@@ -1544,7 +1544,9 @@ component("base") {
25   # Needed for <atomic> if using newer C++ library than sysroot, except if
26   # building inside the cros_sdk environment - use host_toolchain as a
27   # more robust check for this.
28+  # Only target requires <atomic>
29   if (!use_sysroot && (is_android || is_chromeos || (is_linux && !is_castos)) &&
30+      (current_toolchain != host_toolchain) &&
31       host_toolchain != "//build/toolchain/cros:host") {
32     libs += [ "atomic" ]
33   }
34diff --git a/build/config/linux/BUILD.gn b/build/config/linux/BUILD.gn
35index 131bb71d1d3b8..20f918ab82c9b 100644
36--- a/build/config/linux/BUILD.gn
37+++ b/build/config/linux/BUILD.gn
38@@ -40,7 +40,9 @@ config("runtime_library") {
39     defines = [ "OS_CHROMEOS" ]
40   }
41
42+  # Only target requires <atomic>
43   if ((!is_chromeos || default_toolchain != "//build/toolchain/cros:target") &&
44+      (current_toolchain != host_toolchain) &&
45       (!use_custom_libcxx || current_cpu == "mipsel")) {
46     libs = [ "atomic" ]
47   }
48