Add -lm to the default libs for Linux & Darwin
libm is a default library for device builds, so default it for host
builds as well.
Also removes duplicate additions of -ldl, -lpthread, -lm and -lrt.
Test: m host
Change-Id: I8f7e799d48a1f427e48dcfb1d0ccba93c5f9780b
diff --git a/cc/linker.go b/cc/linker.go
index 2a6c909..02d3ba5 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -211,11 +211,12 @@
flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
if !ctx.Windows() {
- // Add -ldl, -lpthread and -lrt to host builds to match the default behavior of device
+ // Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of device
// builds
flags.LdFlags = append(flags.LdFlags,
"-ldl",
"-lpthread",
+ "-lm",
)
if !ctx.Darwin() {
flags.LdFlags = append(flags.LdFlags, "-lrt")
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 7e43373..090d490 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -330,7 +330,6 @@
if ctx.Host() {
// -nodefaultlibs (provided with libc++) prevents the driver from linking
// libraries needed with -fsanitize=address. http://b/18650275 (WAI)
- flags.LdFlags = append(flags.LdFlags, "-lm", "-lpthread")
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed")
} else {
flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0")
@@ -387,10 +386,6 @@
if ctx.Host() {
flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all")
flags.LdFlags = append(flags.LdFlags, sanitizeArg)
- if ctx.Os() == android.Linux {
- flags.LdFlags = append(flags.LdFlags, "-lrt")
- }
- flags.LdFlags = append(flags.LdFlags, "-ldl")
// Host sanitizers only link symbols in the final executable, so
// there will always be undefined symbols in intermediate libraries.
_, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags)
diff --git a/cc/stl.go b/cc/stl.go
index a123d77..17cde59 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -134,7 +134,6 @@
if !ctx.toolchain().Bionic() {
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
- flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm")
if ctx.staticBinary() {
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
} else {
diff --git a/cc/test.go b/cc/test.go
index fddbe4a..12cc2ad 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -145,10 +145,8 @@
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
case android.Linux:
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX")
- flags.LdFlags = append(flags.LdFlags, "-lpthread")
case android.Darwin:
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC")
- flags.LdFlags = append(flags.LdFlags, "-lpthread")
}
} else {
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID")