Merge changes from topic "crt_cflags"
* changes:
Remove no_default_compiler_flags property
Move -fomit-frame-pointer to armCflags
Consolidate ldflags that are used on all devices
Remove -Wl,--gc-sections from target flags
Consolidate cflags that are set on all devices
Consolidate global cflags
diff --git a/cc/cc.go b/cc/cc.go
index 02aaf19..60c8f41 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -159,10 +159,6 @@
// Minimum sdk version supported when compiling against the ndk
Sdk_version string
- // don't insert default compiler flags into asflags, cflags,
- // cppflags, conlyflags, ldflags, or include_dirs
- No_default_compiler_flags *bool
-
AndroidMkSharedLibs []string `blueprint:"mutated"`
HideFromMake bool `blueprint:"mutated"`
PreventInstall bool `blueprint:"mutated"`
@@ -199,7 +195,6 @@
staticBinary() bool
clang() bool
toolchain() config.Toolchain
- noDefaultCompilerFlags() bool
useSdk() bool
sdkVersion() string
useVndk() bool
@@ -452,10 +447,6 @@
return false
}
-func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
- return Bool(ctx.mod.Properties.No_default_compiler_flags)
-}
-
func (ctx *moduleContextImpl) useSdk() bool {
if ctx.ctx.Device() && !ctx.useVndk() {
return ctx.mod.Properties.Sdk_version != ""
diff --git a/cc/compiler.go b/cc/compiler.go
index 0a2d7bd..c40e179 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -232,16 +232,14 @@
flags.YasmFlags = append(flags.YasmFlags, f)
}
- if !ctx.noDefaultCompilerFlags() {
- flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String())
- flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String())
+ flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String())
+ flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String())
- if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() {
- flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
- "${config.CommonGlobalIncludes}",
- tc.IncludeFlags(),
- "${config.CommonNativehelperInclude}")
- }
+ if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() {
+ flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
+ "${config.CommonGlobalIncludes}",
+ tc.IncludeFlags(),
+ "${config.CommonNativehelperInclude}")
}
if ctx.useSdk() {
@@ -318,48 +316,46 @@
hod = "Device"
}
- if !ctx.noDefaultCompilerFlags() {
- flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
- flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...)
+ flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
+ flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...)
- if flags.Clang {
- flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags())
- flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...)
- flags.GlobalFlags = append(flags.GlobalFlags,
- tc.ClangCflags(),
- "${config.CommonClangGlobalCflags}",
- fmt.Sprintf("${config.%sClangGlobalCflags}", hod))
- } else {
- flags.CppFlags = append([]string{"${config.CommonGlobalCppflags}"}, flags.CppFlags...)
- flags.GlobalFlags = append(flags.GlobalFlags,
- tc.Cflags(),
- "${config.CommonGlobalCflags}",
- fmt.Sprintf("${config.%sGlobalCflags}", hod))
- }
-
- if Bool(ctx.AConfig().ProductVariables.Brillo) {
- flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__")
- }
-
- if ctx.Device() {
- if Bool(compiler.Properties.Rtti) {
- flags.CppFlags = append(flags.CppFlags, "-frtti")
- } else {
- flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
- }
- }
-
- flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
-
- if flags.Clang {
- flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags())
- } else {
- flags.CppFlags = append(flags.CppFlags, tc.Cppflags())
- }
-
- flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags())
+ if flags.Clang {
+ flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags())
+ flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...)
+ flags.GlobalFlags = append(flags.GlobalFlags,
+ tc.ClangCflags(),
+ "${config.CommonClangGlobalCflags}",
+ fmt.Sprintf("${config.%sClangGlobalCflags}", hod))
+ } else {
+ flags.CppFlags = append([]string{"${config.CommonGlobalCppflags}"}, flags.CppFlags...)
+ flags.GlobalFlags = append(flags.GlobalFlags,
+ tc.Cflags(),
+ "${config.CommonGlobalCflags}",
+ fmt.Sprintf("${config.%sGlobalCflags}", hod))
}
+ if Bool(ctx.AConfig().ProductVariables.Brillo) {
+ flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__")
+ }
+
+ if ctx.Device() {
+ if Bool(compiler.Properties.Rtti) {
+ flags.CppFlags = append(flags.CppFlags, "-frtti")
+ } else {
+ flags.CppFlags = append(flags.CppFlags, "-fno-rtti")
+ }
+ }
+
+ flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__")
+
+ if flags.Clang {
+ flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags())
+ } else {
+ flags.CppFlags = append(flags.CppFlags, tc.Cppflags())
+ }
+
+ flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags())
+
if flags.Clang {
flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainClangCflags())
} else {
diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go
index 390936a..13e9a08 100644
--- a/cc/config/arm64_device.go
+++ b/cc/config/arm64_device.go
@@ -23,49 +23,26 @@
var (
arm64Cflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
- "-fno-strict-aliasing",
- "-fstack-protector-strong",
- "-ffunction-sections",
"-fdata-sections",
- "-funwind-tables",
- "-Wa,--noexecstack",
- "-Werror=format-security",
- "-D_FORTIFY_SOURCE=2",
"-fno-short-enums",
- "-no-canonical-prefixes",
- "-fno-canonical-system-headers",
// Help catch common 32/64-bit errors.
- "-Werror=pointer-to-int-cast",
- "-Werror=int-to-pointer-cast",
"-Werror=implicit-function-declaration",
"-fno-strict-volatile-bitfields",
// TARGET_RELEASE_CFLAGS
- "-DNDEBUG",
- "-O2 -g",
- "-Wstrict-aliasing=2",
"-fgcse-after-reload",
"-frerun-cse-after-loop",
"-frename-registers",
}
arm64Ldflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
"-Wl,-m,aarch64_elf64_le_vec",
"-Wl,--hash-style=gnu",
"-Wl,--fix-cortex-a53-843419",
"-fuse-ld=gold",
"-Wl,--icf=safe",
- "-Wl,--no-undefined-version",
}
arm64Cppflags = []string{
diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go
index 7110ccb..2c439f0 100644
--- a/cc/config/arm_device.go
+++ b/cc/config/arm_device.go
@@ -28,29 +28,18 @@
}
armCflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
- "-ffunction-sections",
"-fdata-sections",
- "-funwind-tables",
- "-fstack-protector-strong",
- "-Wa,--noexecstack",
- "-Werror=format-security",
- "-D_FORTIFY_SOURCE=2",
"-fno-short-enums",
- "-no-canonical-prefixes",
- "-fno-canonical-system-headers",
"-fno-builtin-sin",
"-fno-strict-volatile-bitfields",
// TARGET_RELEASE_CFLAGS
- "-DNDEBUG",
- "-g",
- "-Wstrict-aliasing=2",
"-fgcse-after-reload",
"-frerun-cse-after-loop",
"-frename-registers",
+
+ "-fomit-frame-pointer",
}
armCppflags = []string{
@@ -58,21 +47,12 @@
}
armLdflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
"-Wl,--icf=safe",
"-Wl,--hash-style=gnu",
- "-Wl,--no-undefined-version",
"-Wl,-m,armelf",
}
armArmCflags = []string{
- "-O2",
- "-fomit-frame-pointer",
"-fstrict-aliasing",
"-funswitch-loops",
}
@@ -80,8 +60,6 @@
armThumbCflags = []string{
"-mthumb",
"-Os",
- "-fomit-frame-pointer",
- "-fno-strict-aliasing",
}
armArchVariantCflags = map[string][]string{
diff --git a/cc/config/global.go b/cc/config/global.go
index dae218c..7362f2e 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -34,9 +34,19 @@
"-Winit-self",
"-Wpointer-arith",
- // COMMON_RELEASE_CFLAGS
+ // Make paths in deps files relative
+ "-no-canonical-prefixes",
+
"-DNDEBUG",
"-UDEBUG",
+
+ "-fno-exceptions",
+ "-Wno-multichar",
+
+ "-O2",
+ "-g",
+
+ "-fno-strict-aliasing",
}
commonGlobalConlyflags = []string{}
@@ -44,16 +54,37 @@
deviceGlobalCflags = []string{
"-fdiagnostics-color",
- // TARGET_ERROR_FLAGS
+ "-fno-canonical-system-headers",
+ "-ffunction-sections",
+ "-funwind-tables",
+ "-fstack-protector-strong",
+ "-Wa,--noexecstack",
+ "-D_FORTIFY_SOURCE=2",
+
+ "-Wstrict-aliasing=2",
+
"-Werror=return-type",
"-Werror=non-virtual-dtor",
"-Werror=address",
"-Werror=sequence-point",
"-Werror=date-time",
+ "-Werror=format-security",
+ }
+
+ deviceGlobalLdflags = []string{
+ "-Wl,-z,noexecstack",
+ "-Wl,-z,relro",
+ "-Wl,-z,now",
+ "-Wl,--build-id=md5",
+ "-Wl,--warn-shared-textrel",
+ "-Wl,--fatal-warnings",
+ "-Wl,--no-undefined-version",
}
hostGlobalCflags = []string{}
+ hostGlobalLdflags = []string{}
+
commonGlobalCppflags = []string{
"-Wsign-promo",
}
@@ -91,7 +122,9 @@
pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " "))
pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " "))
pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " "))
+ pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " "))
pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " "))
+ pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " "))
pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " "))
pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " "))
diff --git a/cc/config/mips64_device.go b/cc/config/mips64_device.go
index e05dbf1..487b11a 100644
--- a/cc/config/mips64_device.go
+++ b/cc/config/mips64_device.go
@@ -22,32 +22,15 @@
var (
mips64Cflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
- "-O2",
"-fomit-frame-pointer",
- "-fno-strict-aliasing",
"-funswitch-loops",
"-Umips",
- "-ffunction-sections",
"-fdata-sections",
- "-funwind-tables",
- "-fstack-protector-strong",
- "-Wa,--noexecstack",
- "-Werror=format-security",
- "-D_FORTIFY_SOURCE=2",
- "-no-canonical-prefixes",
- "-fno-canonical-system-headers",
// Help catch common 32/64-bit errors.
- "-Werror=pointer-to-int-cast",
- "-Werror=int-to-pointer-cast",
"-Werror=implicit-function-declaration",
// TARGET_RELEASE_CFLAGS
- "-DNDEBUG",
- "-g",
- "-Wstrict-aliasing=2",
"-fgcse-after-reload",
"-frerun-cse-after-loop",
"-frename-registers",
@@ -62,14 +45,7 @@
}
mips64Ldflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
"-Wl,--allow-shlib-undefined",
- "-Wl,--no-undefined-version",
}
mips64ArchVariantCflags = map[string][]string{
diff --git a/cc/config/mips_device.go b/cc/config/mips_device.go
index 78e95b6..f178b97 100644
--- a/cc/config/mips_device.go
+++ b/cc/config/mips_device.go
@@ -22,27 +22,12 @@
var (
mipsCflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
- "-O2",
"-fomit-frame-pointer",
- "-fno-strict-aliasing",
"-funswitch-loops",
"-Umips",
- "-ffunction-sections",
"-fdata-sections",
- "-funwind-tables",
- "-fstack-protector-strong",
- "-Wa,--noexecstack",
- "-Werror=format-security",
- "-D_FORTIFY_SOURCE=2",
- "-no-canonical-prefixes",
- "-fno-canonical-system-headers",
// TARGET_RELEASE_CFLAGS
- "-DNDEBUG",
- "-g",
- "-Wstrict-aliasing=2",
"-fgcse-after-reload",
"-frerun-cse-after-loop",
"-frename-registers",
@@ -58,14 +43,7 @@
}
mipsLdflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
"-Wl,--allow-shlib-undefined",
- "-Wl,--no-undefined-version",
}
mipsToolchainLdflags = []string{
diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go
index a98001e..1eab9dd 100644
--- a/cc/config/x86_64_device.go
+++ b/cc/config/x86_64_device.go
@@ -22,47 +22,19 @@
var (
x86_64Cflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
- "-O2",
- "-Wa,--noexecstack",
- "-Werror=format-security",
- "-D_FORTIFY_SOURCE=2",
- "-Wstrict-aliasing=2",
- "-ffunction-sections",
"-finline-functions",
"-finline-limit=300",
"-fno-short-enums",
- "-fstrict-aliasing",
"-funswitch-loops",
- "-funwind-tables",
- "-fstack-protector-strong",
- "-no-canonical-prefixes",
- "-fno-canonical-system-headers",
// Help catch common 32/64-bit errors.
- "-Werror=pointer-to-int-cast",
- "-Werror=int-to-pointer-cast",
"-Werror=implicit-function-declaration",
-
- // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk
- "-O2",
- "-g",
- "-fno-strict-aliasing",
}
x86_64Cppflags = []string{}
x86_64Ldflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
- "-Wl,--gc-sections",
"-Wl,--hash-style=gnu",
- "-Wl,--no-undefined-version",
}
x86_64ArchVariantCflags = map[string][]string{
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index 6d361b5..8d805c9 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -25,9 +25,6 @@
var (
darwinCflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
-
"-fdiagnostics-color",
"-fPIC",
@@ -38,10 +35,6 @@
"-D__STDC_FORMAT_MACROS",
"-D__STDC_CONSTANT_MACROS",
- // HOST_RELEASE_CFLAGS
- "-O2", // from build/core/combo/select.mk
- "-g", // from build/core/combo/select.mk
- "-fno-strict-aliasing", // from build/core/combo/select.mk
"-isysroot ${macSdkRoot}",
"-mmacosx-version-min=${macMinVersion}",
"-DMACOSX_DEPLOYMENT_TARGET=${macMinVersion}",
diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go
index 53d2265..8aea64d 100644
--- a/cc/config/x86_device.go
+++ b/cc/config/x86_device.go
@@ -22,28 +22,10 @@
var (
x86Cflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
- "-O2",
- "-Wa,--noexecstack",
- "-Werror=format-security",
- "-D_FORTIFY_SOURCE=2",
- "-Wstrict-aliasing=2",
- "-ffunction-sections",
"-finline-functions",
"-finline-limit=300",
"-fno-short-enums",
- "-fstrict-aliasing",
"-funswitch-loops",
- "-funwind-tables",
- "-fstack-protector-strong",
- "-no-canonical-prefixes",
- "-fno-canonical-system-headers",
-
- // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk
- "-O2",
- "-g",
- "-fno-strict-aliasing",
}
x86ClangCflags = append(x86Cflags, []string{
@@ -58,15 +40,7 @@
x86Cppflags = []string{}
x86Ldflags = []string{
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--build-id=md5",
- "-Wl,--warn-shared-textrel",
- "-Wl,--fatal-warnings",
- "-Wl,--gc-sections",
"-Wl,--hash-style=gnu",
- "-Wl,--no-undefined-version",
}
x86ArchVariantCflags = map[string][]string{
diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go
index 277361b..9f0bbbd 100644
--- a/cc/config/x86_linux_bionic_host.go
+++ b/cc/config/x86_linux_bionic_host.go
@@ -22,15 +22,11 @@
var (
linuxBionicCflags = ClangFilterUnknownCflags([]string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
-
"-fdiagnostics-color",
"-Wa,--noexecstack",
"-fPIC",
- "-no-canonical-prefixes",
"-U_FORTIFY_SOURCE",
"-D_FORTIFY_SOURCE=2",
@@ -43,14 +39,8 @@
"-fno-short-enums",
"-funswitch-loops",
"-funwind-tables",
- "-no-canonical-prefixes",
"-fno-canonical-system-headers",
- // HOST_RELEASE_CFLAGS
- "-O2", // from build/core/combo/select.mk
- "-g", // from build/core/combo/select.mk
- "-fno-strict-aliasing", // from build/core/combo/select.mk
-
// Tell clang where the gcc toolchain is
"--gcc-toolchain=${LinuxBionicGccRoot}",
@@ -65,7 +55,6 @@
"-Wl,--build-id=md5",
"-Wl,--warn-shared-textrel",
"-Wl,--fatal-warnings",
- "-Wl,--gc-sections",
"-Wl,--hash-style=gnu",
"-Wl,--no-undefined-version",
diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go
index 88bd514..4f05068 100644
--- a/cc/config/x86_linux_host.go
+++ b/cc/config/x86_linux_host.go
@@ -22,15 +22,11 @@
var (
linuxCflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
-
"-fdiagnostics-color",
"-Wa,--noexecstack",
"-fPIC",
- "-no-canonical-prefixes",
"-U_FORTIFY_SOURCE",
"-D_FORTIFY_SOURCE=2",
@@ -40,11 +36,6 @@
//See bug 12708004.
"-D__STDC_FORMAT_MACROS",
"-D__STDC_CONSTANT_MACROS",
-
- // HOST_RELEASE_CFLAGS
- "-O2", // from build/core/combo/select.mk
- "-g", // from build/core/combo/select.mk
- "-fno-strict-aliasing", // from build/core/combo/select.mk
}
linuxLdflags = []string{
diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go
index 270084e..c9bafe6 100644
--- a/cc/config/x86_windows_host.go
+++ b/cc/config/x86_windows_host.go
@@ -22,9 +22,6 @@
var (
windowsCflags = []string{
- "-fno-exceptions", // from build/core/combo/select.mk
- "-Wno-multichar", // from build/core/combo/select.mk
-
"-DUSE_MINGW",
"-DWIN32_LEAN_AND_MEAN",
"-Wno-unused-parameter",
@@ -43,11 +40,6 @@
"-D_FILE_OFFSET_BITS=64",
"--sysroot ${WindowsGccRoot}/${WindowsGccTriple}",
-
- // HOST_RELEASE_CFLAGS
- "-O2", // from build/core/combo/select.mk
- "-g", // from build/core/combo/select.mk
- "-fno-strict-aliasing", // from build/core/combo/select.mk
}
windowsIncludeFlags = []string{
diff --git a/cc/linker.go b/cc/linker.go
index 1cf3f61..fae5542 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -196,38 +196,42 @@
func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
toolchain := ctx.toolchain()
- if !ctx.noDefaultCompilerFlags() {
- if Bool(linker.Properties.Allow_undefined_symbols) {
- if ctx.Darwin() {
- // darwin defaults to treating undefined symbols as errors
- flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup")
- }
- } else if !ctx.Darwin() {
- flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
+ hod := "Host"
+ if ctx.Os().Class == android.Device {
+ hod = "Device"
+ }
+
+ flags.LdFlags = append(flags.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod))
+ if Bool(linker.Properties.Allow_undefined_symbols) {
+ if ctx.Darwin() {
+ // darwin defaults to treating undefined symbols as errors
+ flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup")
}
+ } else if !ctx.Darwin() {
+ flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined")
+ }
- if flags.Clang {
- flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags())
- } else {
- flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
- }
+ if flags.Clang {
+ flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags())
+ } else {
+ flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
+ }
- if !ctx.toolchain().Bionic() {
- CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
+ if !ctx.toolchain().Bionic() {
+ CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
- flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
+ flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
- if !ctx.Windows() {
- // 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")
- }
+ if !ctx.Windows() {
+ // 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/makevars.go b/cc/makevars.go
index 295b4ac..f84ae24 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -174,6 +174,7 @@
toolchain.Cppflags(),
}, " "))
ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
+ fmt.Sprintf("${config.%sGlobalLdflags}", hod),
toolchain.Ldflags(),
toolchain.ToolchainLdflags(),
productExtraLdflags,
@@ -219,6 +220,7 @@
toolchain.ClangCppflags(),
}, " "))
ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{
+ fmt.Sprintf("${config.%sGlobalLdflags}", hod),
toolchain.ClangLdflags(),
toolchain.ToolchainClangLdflags(),
productExtraLdflags,
diff --git a/cc/object.go b/cc/object.go
index 402b105..2246dd3 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -53,7 +53,7 @@
func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
- if !ctx.noDefaultCompilerFlags() && ctx.toolchain().Bionic() {
+ if ctx.useVndk() && ctx.toolchain().Bionic() {
// Needed for VNDK builds where bionic headers aren't automatically added.
deps.LateSharedLibs = append(deps.LateSharedLibs, "libc")
}