Split local and global cflags

Native compiler flags are currently applied in approximately:
global cflags
local cflags
local include dirs
global include dirs
global conlyflags
local conlyflags
global cppflags
local cppflags

This means that a flag that is enabled in the global cppflags
cannot be disabled in the local cflags, and an Android.bp author
must know to disable it in the local cppflags.  A better order
would be:
global cflags
global conlyflags
global cppflags
local cflags
local conlyflags
local cppflags
local include dirs
global include dirs

We are mixing both the global and local cflags into a single
variable, and similar for conlyflags and cppflags, which
prevents reordering them.  This CL prepares to reorder them
by splitting the global and local cflags into separate variables.

Bug: 143713277
Test: m native
Change-Id: Ic55a8c3516c331dc5f2af9d00e59ceca9d3e6c15
This commit is contained in:
Colin Cross 2019-11-04 09:37:55 -08:00
parent 1f056cd69d
commit 4af21ed26f
26 changed files with 286 additions and 259 deletions

View file

@ -227,7 +227,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
if ctx.Host() && !ctx.Windows() && !binary.static() { if ctx.Host() && !ctx.Windows() && !binary.static() {
if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") { if !ctx.Config().IsEnvTrue("DISABLE_HOST_PIE") {
flags.LdFlags = append(flags.LdFlags, "-pie") flags.Global.LdFlags = append(flags.Global.LdFlags, "-pie")
} }
} }
@ -235,7 +235,7 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
// all code is position independent, and then those warnings get promoted to // all code is position independent, and then those warnings get promoted to
// errors. // errors.
if !ctx.Windows() { if !ctx.Windows() {
flags.CFlags = append(flags.CFlags, "-fPIE") flags.Global.CFlags = append(flags.Global.CFlags, "-fPIE")
} }
if ctx.toolchain().Bionic() { if ctx.toolchain().Bionic() {
@ -244,11 +244,11 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
// However, bionic/linker uses -shared to overwrite. // However, bionic/linker uses -shared to overwrite.
// Linker for x86 targets does not allow coexistance of -static and -shared, // Linker for x86 targets does not allow coexistance of -static and -shared,
// so we add -static only if -shared is not used. // so we add -static only if -shared is not used.
if !inList("-shared", flags.LdFlags) { if !inList("-shared", flags.Local.LdFlags) {
flags.LdFlags = append(flags.LdFlags, "-static") flags.Global.LdFlags = append(flags.Global.LdFlags, "-static")
} }
flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags,
"-nostdlib", "-nostdlib",
"-Bstatic", "-Bstatic",
"-Wl,--gc-sections", "-Wl,--gc-sections",
@ -278,14 +278,14 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
if ctx.Os() == android.LinuxBionic { if ctx.Os() == android.LinuxBionic {
// Use the dlwrap entry point, but keep _start around so // Use the dlwrap entry point, but keep _start around so
// that it can be used by host_bionic_inject // that it can be used by host_bionic_inject
flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags,
"-Wl,--entry=__dlwrap__start", "-Wl,--entry=__dlwrap__start",
"-Wl,--undefined=_start", "-Wl,--undefined=_start",
) )
} }
} }
flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags,
"-pie", "-pie",
"-nostdlib", "-nostdlib",
"-Bdynamic", "-Bdynamic",
@ -295,10 +295,10 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags
} }
} else { } else {
if binary.static() { if binary.static() {
flags.LdFlags = append(flags.LdFlags, "-static") flags.Global.LdFlags = append(flags.Global.LdFlags, "-static")
} }
if ctx.Darwin() { if ctx.Darwin() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-headerpad_max_install_names") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-headerpad_max_install_names")
} }
} }
@ -315,14 +315,14 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
var linkerDeps android.Paths var linkerDeps android.Paths
if deps.LinkerFlagsFile.Valid() { if deps.LinkerFlagsFile.Valid() {
flags.LdFlags = append(flags.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")") flags.Local.LdFlags = append(flags.Local.LdFlags, "$$(cat "+deps.LinkerFlagsFile.String()+")")
linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path()) linkerDeps = append(linkerDeps, deps.LinkerFlagsFile.Path())
} }
if flags.DynamicLinker != "" { if flags.DynamicLinker != "" {
flags.LdFlags = append(flags.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-dynamic-linker,"+flags.DynamicLinker)
} else if ctx.toolchain().Bionic() && !binary.static() { } else if ctx.toolchain().Bionic() && !binary.static() {
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-dynamic-linker") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-dynamic-linker")
} }
builderFlags := flagsToBuilderFlags(flags) builderFlags := flagsToBuilderFlags(flags)

View file

@ -261,8 +261,7 @@ func init() {
} }
type builderFlags struct { type builderFlags struct {
globalFlags string commonFlags string
arFlags string
asFlags string asFlags string
cFlags string cFlags string
toolingCFlags string // A separate set of cFlags for clang LibTooling tools toolingCFlags string // A separate set of cFlags for clang LibTooling tools
@ -350,7 +349,7 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
} }
commonFlags := strings.Join([]string{ commonFlags := strings.Join([]string{
flags.globalFlags, flags.commonFlags,
flags.systemIncludeFlags, flags.systemIncludeFlags,
}, " ") }, " ")
@ -567,9 +566,6 @@ func TransformObjToStaticLib(ctx android.ModuleContext, objFiles android.Paths,
if !ctx.Darwin() { if !ctx.Darwin() {
arFlags += " -format=gnu" arFlags += " -format=gnu"
} }
if flags.arFlags != "" {
arFlags += " " + flags.arFlags
}
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: ar, Rule: ar,

View file

@ -140,26 +140,34 @@ type PathDeps struct {
DynamicLinker android.OptionalPath DynamicLinker android.OptionalPath
} }
type Flags struct { // LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
GlobalFlags []string // Flags that apply to C, C++, and assembly source files // tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
ArFlags []string // Flags that apply to ar // command line so they can be overridden by the local module flags).
type LocalOrGlobalFlags struct {
CommonFlags []string // Flags that apply to C, C++, and assembly source files
AsFlags []string // Flags that apply to assembly source files AsFlags []string // Flags that apply to assembly source files
YasmFlags []string // Flags that apply to yasm assembly source files
CFlags []string // Flags that apply to C and C++ source files CFlags []string // Flags that apply to C and C++ source files
ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
ConlyFlags []string // Flags that apply to C source files ConlyFlags []string // Flags that apply to C source files
CppFlags []string // Flags that apply to C++ source files CppFlags []string // Flags that apply to C++ source files
ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
LdFlags []string // Flags that apply to linker command lines
}
type Flags struct {
Local LocalOrGlobalFlags
Global LocalOrGlobalFlags
aidlFlags []string // Flags that apply to aidl source files aidlFlags []string // Flags that apply to aidl source files
rsFlags []string // Flags that apply to renderscript source files rsFlags []string // Flags that apply to renderscript source files
LdFlags []string // Flags that apply to linker command lines
libFlags []string // Flags to add libraries early to the link order libFlags []string // Flags to add libraries early to the link order
extraLibFlags []string // Flags to add libraries late in the link order after LdFlags extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
TidyFlags []string // Flags that apply to clang-tidy TidyFlags []string // Flags that apply to clang-tidy
SAbiFlags []string // Flags that apply to header-abi-dumper SAbiFlags []string // Flags that apply to header-abi-dumper
YasmFlags []string // Flags that apply to yasm assembly source files
// Global include flags that apply to C, C++, and assembly source files // Global include flags that apply to C, C++, and assembly source files
// These must be after any module include flags, which will be in GlobalFlags. // These must be after any module include flags, which will be in CommonFlags.
SystemIncludeFlags []string SystemIncludeFlags []string
Toolchain config.Toolchain Toolchain config.Toolchain
@ -1277,17 +1285,17 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
return return
} }
flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags) flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags) flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags) flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...) flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
for _, dir := range deps.IncludeDirs { for _, dir := range deps.IncludeDirs {
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir.String()) flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
} }
for _, dir := range deps.SystemIncludeDirs { for _, dir := range deps.SystemIncludeDirs {
flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir.String()) flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
} }
c.flags = flags c.flags = flags
@ -1296,16 +1304,16 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags = c.sabi.flags(ctx, flags) flags = c.sabi.flags(ctx, flags)
} }
flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags) flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
// Optimization to reduce size of build.ninja // Optimization to reduce size of build.ninja
// Replace the long list of flags for each file with a module-local variable // Replace the long list of flags for each file with a module-local variable
ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " ")) ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " ")) ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " ")) ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
flags.CFlags = []string{"$cflags"} flags.Local.CFlags = []string{"$cflags"}
flags.CppFlags = []string{"$cppflags"} flags.Local.CppFlags = []string{"$cppflags"}
flags.AsFlags = []string{"$asflags"} flags.Local.AsFlags = []string{"$asflags"}
var objs Objects var objs Objects
if c.compiler != nil { if c.compiler != nil {

View file

@ -147,8 +147,8 @@ func (s *cflagArtifactsText) GenerateBuildActions(ctx android.SingletonContext)
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if ccModule, ok := module.(*Module); ok { if ccModule, ok := module.(*Module); ok {
if allowedDir(ctx.ModuleDir(ccModule)) { if allowedDir(ctx.ModuleDir(ccModule)) {
cflags := ccModule.flags.CFlags cflags := ccModule.flags.Local.CFlags
cppflags := ccModule.flags.CppFlags cppflags := ccModule.flags.Local.CppFlags
module := fmt.Sprintf("%s:%s (%s)", module := fmt.Sprintf("%s:%s (%s)",
ctx.BlueprintFile(ccModule), ctx.BlueprintFile(ccModule),
ctx.ModuleName(ccModule), ctx.ModuleName(ccModule),

View file

@ -162,25 +162,41 @@ func generateCLionProject(compiledModule CompiledInterface, ctx android.Singleto
f.WriteString(")\n") f.WriteString(")\n")
// Add all header search path and compiler parameters (-D, -W, -f, -XXXX) // Add all header search path and compiler parameters (-D, -W, -f, -XXXX)
f.WriteString("\n# GLOBAL FLAGS:\n") f.WriteString("\n# GLOBAL ALL FLAGS:\n")
globalParameters := parseCompilerParameters(ccModule.flags.GlobalFlags, ctx, f) globalAllParameters := parseCompilerParameters(ccModule.flags.Global.CommonFlags, ctx, f)
translateToCMake(globalParameters, f, true, true) translateToCMake(globalAllParameters, f, true, true)
f.WriteString("\n# CFLAGS:\n") f.WriteString("\n# LOCAL ALL FLAGS:\n")
cParameters := parseCompilerParameters(ccModule.flags.CFlags, ctx, f) localAllParameters := parseCompilerParameters(ccModule.flags.Local.CommonFlags, ctx, f)
translateToCMake(cParameters, f, true, true) translateToCMake(localAllParameters, f, true, true)
f.WriteString("\n# C ONLY FLAGS:\n") f.WriteString("\n# GLOBAL CFLAGS:\n")
cOnlyParameters := parseCompilerParameters(ccModule.flags.ConlyFlags, ctx, f) globalCParameters := parseCompilerParameters(ccModule.flags.Global.CFlags, ctx, f)
translateToCMake(cOnlyParameters, f, true, false) translateToCMake(globalCParameters, f, true, true)
f.WriteString("\n# CPP FLAGS:\n") f.WriteString("\n# LOCAL CFLAGS:\n")
cppParameters := parseCompilerParameters(ccModule.flags.CppFlags, ctx, f) localCParameters := parseCompilerParameters(ccModule.flags.Local.CFlags, ctx, f)
translateToCMake(cppParameters, f, false, true) translateToCMake(localCParameters, f, true, true)
f.WriteString("\n# SYSTEM INCLUDE FLAGS:\n") f.WriteString("\n# GLOBAL C ONLY FLAGS:\n")
includeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f) globalConlyParameters := parseCompilerParameters(ccModule.flags.Global.ConlyFlags, ctx, f)
translateToCMake(includeParameters, f, true, true) translateToCMake(globalConlyParameters, f, true, false)
f.WriteString("\n# LOCAL C ONLY FLAGS:\n")
localConlyParameters := parseCompilerParameters(ccModule.flags.Local.ConlyFlags, ctx, f)
translateToCMake(localConlyParameters, f, true, false)
f.WriteString("\n# GLOBAL CPP FLAGS:\n")
globalCppParameters := parseCompilerParameters(ccModule.flags.Global.CppFlags, ctx, f)
translateToCMake(globalCppParameters, f, false, true)
f.WriteString("\n# LOCAL CPP FLAGS:\n")
localCppParameters := parseCompilerParameters(ccModule.flags.Local.CppFlags, ctx, f)
translateToCMake(localCppParameters, f, false, true)
f.WriteString("\n# GLOBAL SYSTEM INCLUDE FLAGS:\n")
globalIncludeParameters := parseCompilerParameters(ccModule.flags.SystemIncludeFlags, ctx, f)
translateToCMake(globalIncludeParameters, f, true, true)
// Add project executable. // Add project executable.
f.WriteString(fmt.Sprintf("\nadd_executable(%s ${SOURCE_FILES})\n", f.WriteString(fmt.Sprintf("\nadd_executable(%s ${SOURCE_FILES})\n",

View file

@ -152,12 +152,16 @@ func getArguments(src android.Path, ctx android.SingletonContext, ccModule *Modu
clangPath = ccPath clangPath = ccPath
} }
args = append(args, clangPath) args = append(args, clangPath)
args = append(args, expandAllVars(ctx, ccModule.flags.GlobalFlags)...) args = append(args, expandAllVars(ctx, ccModule.flags.Global.CommonFlags)...)
args = append(args, expandAllVars(ctx, ccModule.flags.CFlags)...) args = append(args, expandAllVars(ctx, ccModule.flags.Local.CommonFlags)...)
args = append(args, expandAllVars(ctx, ccModule.flags.Global.CFlags)...)
args = append(args, expandAllVars(ctx, ccModule.flags.Local.CFlags)...)
if isCpp { if isCpp {
args = append(args, expandAllVars(ctx, ccModule.flags.CppFlags)...) args = append(args, expandAllVars(ctx, ccModule.flags.Global.CppFlags)...)
args = append(args, expandAllVars(ctx, ccModule.flags.Local.CppFlags)...)
} else if !isAsm { } else if !isAsm {
args = append(args, expandAllVars(ctx, ccModule.flags.ConlyFlags)...) args = append(args, expandAllVars(ctx, ccModule.flags.Global.ConlyFlags)...)
args = append(args, expandAllVars(ctx, ccModule.flags.Local.ConlyFlags)...)
} }
args = append(args, expandAllVars(ctx, ccModule.flags.SystemIncludeFlags)...) args = append(args, expandAllVars(ctx, ccModule.flags.SystemIncludeFlags)...)
args = append(args, src.String()) args = append(args, src.String())

View file

@ -265,11 +265,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
esc := proptools.NinjaAndShellEscapeList esc := proptools.NinjaAndShellEscapeList
flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Cflags)...) flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Cflags)...)
flags.CppFlags = append(flags.CppFlags, esc(compiler.Properties.Cppflags)...) flags.Local.CppFlags = append(flags.Local.CppFlags, esc(compiler.Properties.Cppflags)...)
flags.ConlyFlags = append(flags.ConlyFlags, esc(compiler.Properties.Conlyflags)...) flags.Local.ConlyFlags = append(flags.Local.ConlyFlags, esc(compiler.Properties.Conlyflags)...)
flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Asflags)...) flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Asflags)...)
flags.YasmFlags = append(flags.YasmFlags, esc(compiler.Properties.Asflags)...) flags.Local.YasmFlags = append(flags.Local.YasmFlags, esc(compiler.Properties.Asflags)...)
flags.Yacc = compiler.Properties.Yacc flags.Yacc = compiler.Properties.Yacc
@ -277,20 +277,20 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs) localIncludeDirs := android.PathsForModuleSrc(ctx, compiler.Properties.Local_include_dirs)
if len(localIncludeDirs) > 0 { if len(localIncludeDirs) > 0 {
f := includeDirsToFlags(localIncludeDirs) f := includeDirsToFlags(localIncludeDirs)
flags.GlobalFlags = append(flags.GlobalFlags, f) flags.Local.CommonFlags = append(flags.Local.CommonFlags, f)
flags.YasmFlags = append(flags.YasmFlags, f) flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
} }
rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs) rootIncludeDirs := android.PathsForSource(ctx, compiler.Properties.Include_dirs)
if len(rootIncludeDirs) > 0 { if len(rootIncludeDirs) > 0 {
f := includeDirsToFlags(rootIncludeDirs) f := includeDirsToFlags(rootIncludeDirs)
flags.GlobalFlags = append(flags.GlobalFlags, f) flags.Local.CommonFlags = append(flags.Local.CommonFlags, f)
flags.YasmFlags = append(flags.YasmFlags, f) flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
} }
if compiler.Properties.Include_build_directory == nil || if compiler.Properties.Include_build_directory == nil ||
*compiler.Properties.Include_build_directory { *compiler.Properties.Include_build_directory {
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+android.PathForModuleSrc(ctx).String())
flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) flags.Local.YasmFlags = append(flags.Local.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String())
} }
if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() { if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() {
@ -312,16 +312,17 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
} }
if ctx.useVndk() { if ctx.useVndk() {
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_VNDK__") flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_VNDK__")
} }
if ctx.inRecovery() { if ctx.inRecovery() {
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_RECOVERY__") flags.Global.CommonFlags = append(flags.Global.CommonFlags, "-D__ANDROID_RECOVERY__")
} }
if ctx.apexName() != "" { if ctx.apexName() != "" {
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__") flags.Global.CommonFlags = append(flags.Global.CommonFlags,
flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__") "-D__ANDROID_APEX__",
"-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__")
} }
instructionSet := String(compiler.Properties.Instruction_set) instructionSet := String(compiler.Properties.Instruction_set)
@ -336,17 +337,17 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags) CheckBadCompilerFlags(ctx, "release.cflags", compiler.Properties.Release.Cflags)
// TODO: debug // TODO: debug
flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Release.Cflags)...) flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Release.Cflags)...)
CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags) CheckBadCompilerFlags(ctx, "clang_cflags", compiler.Properties.Clang_cflags)
CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags) CheckBadCompilerFlags(ctx, "clang_asflags", compiler.Properties.Clang_asflags)
flags.CFlags = config.ClangFilterUnknownCflags(flags.CFlags) flags.Local.CFlags = config.ClangFilterUnknownCflags(flags.Local.CFlags)
flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Clang_cflags)...) flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Clang_cflags)...)
flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Clang_asflags)...) flags.Local.AsFlags = append(flags.Local.AsFlags, esc(compiler.Properties.Clang_asflags)...)
flags.CppFlags = config.ClangFilterUnknownCflags(flags.CppFlags) flags.Local.CppFlags = config.ClangFilterUnknownCflags(flags.Local.CppFlags)
flags.ConlyFlags = config.ClangFilterUnknownCflags(flags.ConlyFlags) flags.Local.ConlyFlags = config.ClangFilterUnknownCflags(flags.Local.ConlyFlags)
flags.LdFlags = config.ClangFilterUnknownCflags(flags.LdFlags) flags.Local.LdFlags = config.ClangFilterUnknownCflags(flags.Local.LdFlags)
target := "-target " + tc.ClangTriple() target := "-target " + tc.ClangTriple()
if ctx.Os().Class == android.Device { if ctx.Os().Class == android.Device {
@ -360,45 +361,45 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
gccPrefix := "-B" + config.ToolPath(tc) gccPrefix := "-B" + config.ToolPath(tc)
flags.CFlags = append(flags.CFlags, target, gccPrefix) flags.Global.CFlags = append(flags.Global.CFlags, target, gccPrefix)
flags.AsFlags = append(flags.AsFlags, target, gccPrefix) flags.Global.AsFlags = append(flags.Global.AsFlags, target, gccPrefix)
flags.LdFlags = append(flags.LdFlags, target, gccPrefix) flags.Global.LdFlags = append(flags.Global.LdFlags, target, gccPrefix)
hod := "Host" hod := "Host"
if ctx.Os().Class == android.Device { if ctx.Os().Class == android.Device {
hod = "Device" hod = "Device"
} }
flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) flags.Global.CommonFlags = append(flags.Global.CommonFlags, instructionSetFlags)
flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...) flags.Global.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.Global.ConlyFlags...)
flags.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.CppFlags...) flags.Global.CppFlags = append([]string{fmt.Sprintf("${config.%sGlobalCppflags}", hod)}, flags.Global.CppFlags...)
flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags()) flags.Global.AsFlags = append(flags.Global.AsFlags, tc.ClangAsflags())
flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...) flags.Global.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.Global.CppFlags...)
flags.GlobalFlags = append(flags.GlobalFlags, flags.Global.CommonFlags = append(flags.Global.CommonFlags,
tc.ClangCflags(), tc.ClangCflags(),
"${config.CommonClangGlobalCflags}", "${config.CommonClangGlobalCflags}",
fmt.Sprintf("${config.%sClangGlobalCflags}", hod)) fmt.Sprintf("${config.%sClangGlobalCflags}", hod))
if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") { if strings.HasPrefix(android.PathForModuleSrc(ctx).String(), "external/") {
flags.GlobalFlags = append([]string{"${config.ClangExternalCflags}"}, flags.GlobalFlags...) flags.Global.CommonFlags = append([]string{"${config.ClangExternalCflags}"}, flags.Global.CommonFlags...)
} }
if tc.Bionic() { if tc.Bionic() {
if Bool(compiler.Properties.Rtti) { if Bool(compiler.Properties.Rtti) {
flags.CppFlags = append(flags.CppFlags, "-frtti") flags.Local.CppFlags = append(flags.Local.CppFlags, "-frtti")
} else { } else {
flags.CppFlags = append(flags.CppFlags, "-fno-rtti") flags.Local.CppFlags = append(flags.Local.CppFlags, "-fno-rtti")
} }
} }
flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") flags.Global.AsFlags = append(flags.Global.AsFlags, "-D__ASSEMBLY__")
flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags()) flags.Global.CppFlags = append(flags.Global.CppFlags, tc.ClangCppflags())
flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags()) flags.Global.YasmFlags = append(flags.Global.YasmFlags, tc.YasmFlags())
flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainClangCflags()) flags.Global.CommonFlags = append(flags.Global.CommonFlags, tc.ToolchainClangCflags())
cStd := config.CStdVersion cStd := config.CStdVersion
if String(compiler.Properties.C_std) == "experimental" { if String(compiler.Properties.C_std) == "experimental" {
@ -420,15 +421,15 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
cppStd = gnuToCReplacer.Replace(cppStd) cppStd = gnuToCReplacer.Replace(cppStd)
} }
flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...) flags.Local.ConlyFlags = append([]string{"-std=" + cStd}, flags.Local.ConlyFlags...)
flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...) flags.Local.CppFlags = append([]string{"-std=" + cppStd}, flags.Local.CppFlags...)
if ctx.useVndk() { if ctx.useVndk() {
flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...) flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...)
} }
if ctx.inRecovery() { if ctx.inRecovery() {
flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...) flags.Local.CFlags = append(flags.Local.CFlags, esc(compiler.Properties.Target.Recovery.Cflags)...)
} }
// We can enforce some rules more strictly in the code we own. strict // We can enforce some rules more strictly in the code we own. strict
@ -444,7 +445,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
// Can be used to make some annotations stricter for code we can fix // Can be used to make some annotations stricter for code we can fix
// (such as when we mark functions as deprecated). // (such as when we mark functions as deprecated).
if strict { if strict {
flags.CFlags = append(flags.CFlags, "-DANDROID_STRICT") flags.Global.CFlags = append(flags.Global.CFlags, "-DANDROID_STRICT")
} }
if compiler.hasSrcExt(".proto") { if compiler.hasSrcExt(".proto") {
@ -452,12 +453,12 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
} }
if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") { if compiler.hasSrcExt(".y") || compiler.hasSrcExt(".yy") {
flags.GlobalFlags = append(flags.GlobalFlags, flags.Local.CommonFlags = append(flags.Local.CommonFlags,
"-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String()) "-I"+android.PathForModuleGen(ctx, "yacc", ctx.ModuleDir()).String())
} }
if compiler.hasSrcExt(".mc") { if compiler.hasSrcExt(".mc") {
flags.GlobalFlags = append(flags.GlobalFlags, flags.Local.CommonFlags = append(flags.Local.CommonFlags,
"-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String()) "-I"+android.PathForModuleGen(ctx, "windmc", ctx.ModuleDir()).String())
} }
@ -475,7 +476,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags.aidlFlags = append(flags.aidlFlags, "-t") flags.aidlFlags = append(flags.aidlFlags, "-t")
} }
flags.GlobalFlags = append(flags.GlobalFlags, flags.Local.CommonFlags = append(flags.Local.CommonFlags,
"-I"+android.PathForModuleGen(ctx, "aidl").String()) "-I"+android.PathForModuleGen(ctx, "aidl").String())
} }
@ -484,26 +485,26 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
} }
if compiler.hasSrcExt(".sysprop") { if compiler.hasSrcExt(".sysprop") {
flags.GlobalFlags = append(flags.GlobalFlags, flags.Local.CommonFlags = append(flags.Local.CommonFlags,
"-I"+android.PathForModuleGen(ctx, "sysprop", "include").String()) "-I"+android.PathForModuleGen(ctx, "sysprop", "include").String())
} }
if len(compiler.Properties.Srcs) > 0 { if len(compiler.Properties.Srcs) > 0 {
module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName() module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
if inList("-Wno-error", flags.CFlags) || inList("-Wno-error", flags.CppFlags) { if inList("-Wno-error", flags.Local.CFlags) || inList("-Wno-error", flags.Local.CppFlags) {
addToModuleList(ctx, modulesUsingWnoErrorKey, module) addToModuleList(ctx, modulesUsingWnoErrorKey, module)
} else if !inList("-Werror", flags.CFlags) && !inList("-Werror", flags.CppFlags) { } else if !inList("-Werror", flags.Local.CFlags) && !inList("-Werror", flags.Local.CppFlags) {
if warningsAreAllowed(ctx.ModuleDir()) { if warningsAreAllowed(ctx.ModuleDir()) {
addToModuleList(ctx, modulesAddedWallKey, module) addToModuleList(ctx, modulesAddedWallKey, module)
flags.CFlags = append([]string{"-Wall"}, flags.CFlags...) flags.Local.CFlags = append([]string{"-Wall"}, flags.Local.CFlags...)
} else { } else {
flags.CFlags = append([]string{"-Wall", "-Werror"}, flags.CFlags...) flags.Local.CFlags = append([]string{"-Wall", "-Werror"}, flags.Local.CFlags...)
} }
} }
} }
if Bool(compiler.Properties.Openmp) { if Bool(compiler.Properties.Openmp) {
flags.CFlags = append(flags.CFlags, "-fopenmp") flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp")
} }
return flags return flags

View file

@ -69,12 +69,12 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
if cov.Properties.CoverageEnabled { if cov.Properties.CoverageEnabled {
flags.Coverage = true flags.Coverage = true
flags.GlobalFlags = append(flags.GlobalFlags, "--coverage", "-O0") flags.Local.CommonFlags = append(flags.Local.CommonFlags, "--coverage", "-O0")
cov.linkCoverage = true cov.linkCoverage = true
// Override -Wframe-larger-than and non-default optimization // Override -Wframe-larger-than and non-default optimization
// flags that the module may use. // flags that the module may use.
flags.CFlags = append(flags.CFlags, "-Wno-frame-larger-than=", "-O0") flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=", "-O0")
} }
// Even if we don't have coverage enabled, if any of our object files were compiled // Even if we don't have coverage enabled, if any of our object files were compiled
@ -112,12 +112,12 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags
} }
if cov.linkCoverage { if cov.linkCoverage {
flags.LdFlags = append(flags.LdFlags, "--coverage") flags.Local.LdFlags = append(flags.Local.LdFlags, "--coverage")
coverage := ctx.GetDirectDepWithTag(getProfileLibraryName(ctx), coverageDepTag).(*Module) coverage := ctx.GetDirectDepWithTag(getProfileLibraryName(ctx), coverageDepTag).(*Module)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path()) deps.WholeStaticLibs = append(deps.WholeStaticLibs, coverage.OutputFile().Path())
flags.LdFlags = append(flags.LdFlags, "-Wl,--wrap,getenv") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--wrap,getenv")
} }
return flags, deps return flags, deps

View file

@ -34,7 +34,7 @@ func TestGen(t *testing.T) {
aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl") aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module) libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.GlobalFlags) { if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) {
t.Errorf("missing aidl includes in global flags") t.Errorf("missing aidl includes in global flags")
} }
}) })
@ -58,7 +58,7 @@ func TestGen(t *testing.T) {
aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl") aidl := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("aidl")
libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module) libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.GlobalFlags) { if !inList("-I"+filepath.Dir(aidl.Output.String()), libfoo.flags.Local.CommonFlags) {
t.Errorf("missing aidl includes in global flags") t.Errorf("missing aidl includes in global flags")
} }

View file

@ -394,13 +394,13 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla
// all code is position independent, and then those warnings get promoted to // all code is position independent, and then those warnings get promoted to
// errors. // errors.
if !ctx.Windows() { if !ctx.Windows() {
flags.CFlags = append(flags.CFlags, "-fPIC") flags.Global.CFlags = append(flags.Global.CFlags, "-fPIC")
} }
if library.static() { if library.static() {
flags.CFlags = append(flags.CFlags, library.StaticProperties.Static.Cflags...) flags.Local.CFlags = append(flags.Local.CFlags, library.StaticProperties.Static.Cflags...)
} else if library.shared() { } else if library.shared() {
flags.CFlags = append(flags.CFlags, library.SharedProperties.Shared.Cflags...) flags.Local.CFlags = append(flags.Local.CFlags, library.SharedProperties.Shared.Cflags...)
} }
if library.shared() { if library.shared() {
@ -431,7 +431,7 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla
} }
} }
flags.LdFlags = append(f, flags.LdFlags...) flags.Global.LdFlags = append(flags.Global.LdFlags, f...)
} }
return flags return flags
@ -441,8 +441,8 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx) exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
if len(exportIncludeDirs) > 0 { if len(exportIncludeDirs) > 0 {
f := includeDirsToFlags(exportIncludeDirs) f := includeDirsToFlags(exportIncludeDirs)
flags.GlobalFlags = append(flags.GlobalFlags, f) flags.Local.CommonFlags = append(flags.Local.CommonFlags, f)
flags.YasmFlags = append(flags.YasmFlags, f) flags.Local.YasmFlags = append(flags.Local.YasmFlags, f)
} }
flags = library.baseCompiler.compilerFlags(ctx, flags, deps) flags = library.baseCompiler.compilerFlags(ctx, flags, deps)
@ -462,8 +462,8 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d
} }
return ret return ret
} }
flags.GlobalFlags = removeInclude(flags.GlobalFlags) flags.Local.CommonFlags = removeInclude(flags.Local.CommonFlags)
flags.CFlags = removeInclude(flags.CFlags) flags.Local.CFlags = removeInclude(flags.Local.CFlags)
flags = addStubLibraryCompilerFlags(flags) flags = addStubLibraryCompilerFlags(flags)
} }
@ -776,21 +776,21 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
} }
} else { } else {
if unexportedSymbols.Valid() { if unexportedSymbols.Valid() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String()) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-unexported_symbols_list,"+unexportedSymbols.String())
linkerDeps = append(linkerDeps, unexportedSymbols.Path()) linkerDeps = append(linkerDeps, unexportedSymbols.Path())
} }
if forceNotWeakSymbols.Valid() { if forceNotWeakSymbols.Valid() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String()) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-force_symbols_not_weak_list,"+forceNotWeakSymbols.String())
linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path()) linkerDeps = append(linkerDeps, forceNotWeakSymbols.Path())
} }
if forceWeakSymbols.Valid() { if forceWeakSymbols.Valid() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String()) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-force_symbols_weak_list,"+forceWeakSymbols.String())
linkerDeps = append(linkerDeps, forceWeakSymbols.Path()) linkerDeps = append(linkerDeps, forceWeakSymbols.Path())
} }
} }
if library.buildStubs() { if library.buildStubs() {
linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String() linkerScriptFlags := "-Wl,--version-script," + library.versionScriptPath.String()
flags.LdFlags = append(flags.LdFlags, linkerScriptFlags) flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlags)
linkerDeps = append(linkerDeps, library.versionScriptPath) linkerDeps = append(linkerDeps, library.versionScriptPath)
} }
@ -802,7 +802,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
if ctx.Windows() { if ctx.Windows() {
importLibraryPath := android.PathForModuleOut(ctx, pathtools.ReplaceExtension(fileName, "lib")) importLibraryPath := android.PathForModuleOut(ctx, pathtools.ReplaceExtension(fileName, "lib"))
flags.LdFlags = append(flags.LdFlags, "-Wl,--out-implib="+importLibraryPath.String()) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--out-implib="+importLibraryPath.String())
implicitOutputs = append(implicitOutputs, importLibraryPath) implicitOutputs = append(implicitOutputs, importLibraryPath)
} }

View file

@ -181,7 +181,7 @@ func TestLibraryReuse(t *testing.T) {
} }
libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module) libfoo := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Module().(*Module)
if !inList("-DGOOGLE_PROTOBUF_NO_RTTI", libfoo.flags.CFlags) { if !inList("-DGOOGLE_PROTOBUF_NO_RTTI", libfoo.flags.Local.CFlags) {
t.Errorf("missing protobuf cflags") t.Errorf("missing protobuf cflags")
} }
}) })

View file

@ -331,65 +331,66 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
} }
if linker.useClangLld(ctx) { if linker.useClangLld(ctx) {
flags.LdFlags = append(flags.LdFlags, fmt.Sprintf("${config.%sGlobalLldflags}", hod)) flags.Global.LdFlags = append(flags.Global.LdFlags, fmt.Sprintf("${config.%sGlobalLldflags}", hod))
if !BoolDefault(linker.Properties.Pack_relocations, true) { if !BoolDefault(linker.Properties.Pack_relocations, true) {
flags.LdFlags = append(flags.LdFlags, "-Wl,--pack-dyn-relocs=none") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=none")
} else if ctx.Device() { } else if ctx.Device() {
// The SHT_RELR relocations is only supported by API level >= 28. // The SHT_RELR relocations is only supported by API level >= 28.
// Do not turn this on if older version NDK is used. // Do not turn this on if older version NDK is used.
if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 28) { if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 28) {
flags.LdFlags = append(flags.LdFlags, "-Wl,--pack-dyn-relocs=android+relr") flags.Global.LdFlags = append(flags.Global.LdFlags,
flags.LdFlags = append(flags.LdFlags, "-Wl,--use-android-relr-tags") "-Wl,--pack-dyn-relocs=android+relr",
"-Wl,--use-android-relr-tags")
} }
} }
} else { } else {
flags.LdFlags = append(flags.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod)) flags.Global.LdFlags = append(flags.Global.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod))
} }
if Bool(linker.Properties.Allow_undefined_symbols) { if Bool(linker.Properties.Allow_undefined_symbols) {
if ctx.Darwin() { if ctx.Darwin() {
// darwin defaults to treating undefined symbols as errors // darwin defaults to treating undefined symbols as errors
flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-undefined,dynamic_lookup")
} }
} else if !ctx.Darwin() && !ctx.Windows() { } else if !ctx.Darwin() && !ctx.Windows() {
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--no-undefined")
} }
if linker.useClangLld(ctx) { if linker.useClangLld(ctx) {
flags.LdFlags = append(flags.LdFlags, toolchain.ClangLldflags()) flags.Global.LdFlags = append(flags.Global.LdFlags, toolchain.ClangLldflags())
} else { } else {
flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags()) flags.Global.LdFlags = append(flags.Global.LdFlags, toolchain.ClangLdflags())
} }
if !ctx.toolchain().Bionic() && !ctx.Fuchsia() { if !ctx.toolchain().Bionic() && !ctx.Fuchsia() {
CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs) CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...) flags.Local.LdFlags = append(flags.Local.LdFlags, linker.Properties.Host_ldlibs...)
if !ctx.Windows() { if !ctx.Windows() {
// Add -ldl, -lpthread, -lm 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 // builds
flags.LdFlags = append(flags.LdFlags, flags.Global.LdFlags = append(flags.Global.LdFlags,
"-ldl", "-ldl",
"-lpthread", "-lpthread",
"-lm", "-lm",
) )
if !ctx.Darwin() { if !ctx.Darwin() {
flags.LdFlags = append(flags.LdFlags, "-lrt") flags.Global.LdFlags = append(flags.Global.LdFlags, "-lrt")
} }
} }
} }
if ctx.Fuchsia() { if ctx.Fuchsia() {
flags.LdFlags = append(flags.LdFlags, "-lfdio", "-lzircon") flags.Global.LdFlags = append(flags.Global.LdFlags, "-lfdio", "-lzircon")
} }
if ctx.toolchain().LibclangRuntimeLibraryArch() != "" { if ctx.toolchain().LibclangRuntimeLibraryArch() != "" {
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs="+config.BuiltinsRuntimeLibrary(ctx.toolchain())+".a") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--exclude-libs="+config.BuiltinsRuntimeLibrary(ctx.toolchain())+".a")
} }
CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags) CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags)
flags.LdFlags = append(flags.LdFlags, proptools.NinjaAndShellEscapeList(linker.Properties.Ldflags)...) flags.Local.LdFlags = append(flags.Local.LdFlags, proptools.NinjaAndShellEscapeList(linker.Properties.Ldflags)...)
if ctx.Host() && !ctx.Windows() { if ctx.Host() && !ctx.Windows() {
rpath_prefix := `\$$ORIGIN/` rpath_prefix := `\$$ORIGIN/`
@ -399,7 +400,7 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
if !ctx.static() { if !ctx.static() {
for _, rpath := range linker.dynamicProperties.RunPaths { for _, rpath := range linker.dynamicProperties.RunPaths {
flags.LdFlags = append(flags.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath) flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath)
} }
} }
} }
@ -409,10 +410,10 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
// to older devices requires the old style hash. Fortunately, we can build with both and // to older devices requires the old style hash. Fortunately, we can build with both and
// it'll work anywhere. // it'll work anywhere.
// This is not currently supported on MIPS architectures. // This is not currently supported on MIPS architectures.
flags.LdFlags = append(flags.LdFlags, "-Wl,--hash-style=both") flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--hash-style=both")
} }
flags.LdFlags = append(flags.LdFlags, toolchain.ToolchainClangLdflags()) flags.Global.LdFlags = append(flags.Global.LdFlags, toolchain.ToolchainClangLdflags())
if Bool(linker.Properties.Group_static_libs) { if Bool(linker.Properties.Group_static_libs) {
flags.GroupStaticLibs = true flags.GroupStaticLibs = true
@ -434,13 +435,13 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
if ctx.Darwin() { if ctx.Darwin() {
ctx.PropertyErrorf("version_script", "Not supported on Darwin") ctx.PropertyErrorf("version_script", "Not supported on Darwin")
} else { } else {
flags.LdFlags = append(flags.LdFlags, flags.Local.LdFlags = append(flags.Local.LdFlags,
"-Wl,--version-script,"+versionScript.String()) "-Wl,--version-script,"+versionScript.String())
flags.LdFlagsDeps = append(flags.LdFlagsDeps, versionScript.Path()) flags.LdFlagsDeps = append(flags.LdFlagsDeps, versionScript.Path())
if linker.sanitize.isSanitizerEnabled(cfi) { if linker.sanitize.isSanitizerEnabled(cfi) {
cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath) cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath)
flags.LdFlags = append(flags.LdFlags, flags.Local.LdFlags = append(flags.Local.LdFlags,
"-Wl,--version-script,"+cfiExportsMap.String()) "-Wl,--version-script,"+cfiExportsMap.String())
flags.LdFlagsDeps = append(flags.LdFlagsDeps, cfiExportsMap) flags.LdFlagsDeps = append(flags.LdFlagsDeps, cfiExportsMap)
} }

View file

@ -133,7 +133,7 @@ func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDe
if !Bool(stub.Properties.Unversioned) { if !Bool(stub.Properties.Unversioned) {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.LdFlags = append(flags.LdFlags, linkerScriptFlag) flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath) flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
} }

View file

@ -82,7 +82,7 @@ func (lto *lto) useClangLld(ctx BaseModuleContext) bool {
func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
// TODO(b/131771163): Disable LTO when using explicit fuzzing configurations. // TODO(b/131771163): Disable LTO when using explicit fuzzing configurations.
// LTO breaks fuzzer builds. // LTO breaks fuzzer builds.
if inList("-fsanitize=fuzzer-no-link", flags.CFlags) { if inList("-fsanitize=fuzzer-no-link", flags.Local.CFlags) {
return flags return flags
} }
@ -94,27 +94,28 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
ltoFlag = "-flto" ltoFlag = "-flto"
} }
flags.CFlags = append(flags.CFlags, ltoFlag) flags.Local.CFlags = append(flags.Local.CFlags, ltoFlag)
flags.LdFlags = append(flags.LdFlags, ltoFlag) flags.Local.LdFlags = append(flags.Local.LdFlags, ltoFlag)
if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) && lto.useClangLld(ctx) { if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) && lto.useClangLld(ctx) {
// Set appropriate ThinLTO cache policy // Set appropriate ThinLTO cache policy
cacheDirFormat := "-Wl,--thinlto-cache-dir=" cacheDirFormat := "-Wl,--thinlto-cache-dir="
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String() cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
flags.LdFlags = append(flags.LdFlags, cacheDirFormat+cacheDir) flags.Local.LdFlags = append(flags.Local.LdFlags, cacheDirFormat+cacheDir)
// Limit the size of the ThinLTO cache to the lesser of 10% of available // Limit the size of the ThinLTO cache to the lesser of 10% of available
// disk space and 10GB. // disk space and 10GB.
cachePolicyFormat := "-Wl,--thinlto-cache-policy=" cachePolicyFormat := "-Wl,--thinlto-cache-policy="
policy := "cache_size=10%:cache_size_bytes=10g" policy := "cache_size=10%:cache_size_bytes=10g"
flags.LdFlags = append(flags.LdFlags, cachePolicyFormat+policy) flags.Local.LdFlags = append(flags.Local.LdFlags, cachePolicyFormat+policy)
} }
// If the module does not have a profile, be conservative and do not inline // If the module does not have a profile, be conservative and do not inline
// or unroll loops during LTO, in order to prevent significant size bloat. // or unroll loops during LTO, in order to prevent significant size bloat.
if !ctx.isPgoCompile() { if !ctx.isPgoCompile() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-inline-threshold=0") flags.Local.LdFlags = append(flags.Local.LdFlags,
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-unroll-threshold=0") "-Wl,-plugin-opt,-inline-threshold=0",
"-Wl,-plugin-opt,-unroll-threshold=0")
} }
} }
return flags return flags

View file

@ -257,7 +257,7 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
} }
func addStubLibraryCompilerFlags(flags Flags) Flags { func addStubLibraryCompilerFlags(flags Flags) Flags {
flags.CFlags = append(flags.CFlags, flags.Global.CFlags = append(flags.Global.CFlags,
// We're knowingly doing some otherwise unsightly things with builtin // We're knowingly doing some otherwise unsightly things with builtin
// functions here. We're just generating stub libraries, so ignore it. // functions here. We're just generating stub libraries, so ignore it.
"-Wno-incompatible-library-redeclaration", "-Wno-incompatible-library-redeclaration",
@ -337,7 +337,7 @@ func (stub *stubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
if useVersionScript { if useVersionScript {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.LdFlags = append(flags.LdFlags, linkerScriptFlag) flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath) flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
} }

View file

@ -87,10 +87,10 @@ func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
} }
func (object *objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { func (object *objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
flags.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags()) flags.Global.LdFlags = append(flags.Global.LdFlags, ctx.toolchain().ToolchainClangLdflags())
if lds := android.OptionalPathForModuleSrc(ctx, object.Properties.Linker_script); lds.Valid() { if lds := android.OptionalPathForModuleSrc(ctx, object.Properties.Linker_script); lds.Valid() {
flags.LdFlags = append(flags.LdFlags, "-Wl,-T,"+lds.String()) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-T,"+lds.String())
flags.LdFlagsDeps = append(flags.LdFlagsDeps, lds.Path()) flags.LdFlagsDeps = append(flags.LdFlagsDeps, lds.Path())
} }
return flags return flags

View file

@ -89,18 +89,18 @@ func (pgo *pgo) props() []interface{} {
} }
func (props *PgoProperties) addProfileGatherFlags(ctx ModuleContext, flags Flags) Flags { func (props *PgoProperties) addProfileGatherFlags(ctx ModuleContext, flags Flags) Flags {
flags.CFlags = append(flags.CFlags, props.Pgo.Cflags...) flags.Local.CFlags = append(flags.Local.CFlags, props.Pgo.Cflags...)
if props.isInstrumentation() { if props.isInstrumentation() {
flags.CFlags = append(flags.CFlags, profileInstrumentFlag) flags.Local.CFlags = append(flags.Local.CFlags, profileInstrumentFlag)
// The profile runtime is added below in deps(). Add the below // The profile runtime is added below in deps(). Add the below
// flag, which is the only other link-time action performed by // flag, which is the only other link-time action performed by
// the Clang driver during link. // the Clang driver during link.
flags.LdFlags = append(flags.LdFlags, "-u__llvm_profile_runtime") flags.Local.LdFlags = append(flags.Local.LdFlags, "-u__llvm_profile_runtime")
} }
if props.isSampling() { if props.isSampling() {
flags.CFlags = append(flags.CFlags, profileSamplingFlag) flags.Local.CFlags = append(flags.Local.CFlags, profileSamplingFlag)
flags.LdFlags = append(flags.LdFlags, profileSamplingFlag) flags.Local.LdFlags = append(flags.Local.LdFlags, profileSamplingFlag)
} }
return flags return flags
} }
@ -170,8 +170,8 @@ func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) F
profileFilePath := profileFile.Path() profileFilePath := profileFile.Path()
profileUseFlags := props.profileUseFlags(ctx, profileFilePath.String()) profileUseFlags := props.profileUseFlags(ctx, profileFilePath.String())
flags.CFlags = append(flags.CFlags, profileUseFlags...) flags.Local.CFlags = append(flags.Local.CFlags, profileUseFlags...)
flags.LdFlags = append(flags.LdFlags, profileUseFlags...) flags.Local.LdFlags = append(flags.Local.LdFlags, profileUseFlags...)
// Update CFlagsDeps and LdFlagsDeps so the module is rebuilt // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
// if profileFile gets updated // if profileFile gets updated

View file

@ -114,13 +114,13 @@ func protoDeps(ctx DepsContext, deps Deps, p *android.ProtoProperties, static bo
} }
func protoFlags(ctx ModuleContext, flags Flags, p *android.ProtoProperties) Flags { func protoFlags(ctx ModuleContext, flags Flags, p *android.ProtoProperties) Flags {
flags.CFlags = append(flags.CFlags, "-DGOOGLE_PROTOBUF_NO_RTTI") flags.Local.CFlags = append(flags.Local.CFlags, "-DGOOGLE_PROTOBUF_NO_RTTI")
flags.proto = android.GetProtoFlags(ctx, p) flags.proto = android.GetProtoFlags(ctx, p)
if flags.proto.CanonicalPathFromRoot { if flags.proto.CanonicalPathFromRoot {
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+flags.proto.SubDir.String()) flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+flags.proto.SubDir.String())
} }
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+flags.proto.Dir.String()) flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+flags.proto.Dir.String())
if String(p.Proto.Plugin) == "" { if String(p.Proto.Plugin) == "" {
var plugin string var plugin string

View file

@ -123,7 +123,7 @@ func rsFlags(ctx ModuleContext, flags Flags, properties *BaseCompilerProperties)
rootRsIncludeDirs := android.PathsForSource(ctx, properties.Renderscript.Include_dirs) rootRsIncludeDirs := android.PathsForSource(ctx, properties.Renderscript.Include_dirs)
flags.rsFlags = append(flags.rsFlags, includeDirsToFlags(rootRsIncludeDirs)) flags.rsFlags = append(flags.rsFlags, includeDirsToFlags(rootRsIncludeDirs))
flags.GlobalFlags = append(flags.GlobalFlags, flags.Local.CommonFlags = append(flags.Local.CommonFlags,
"-I"+android.PathForModuleGen(ctx, "rs").String(), "-I"+android.PathForModuleGen(ctx, "rs").String(),
"-Iframeworks/rs", "-Iframeworks/rs",
"-Iframeworks/rs/cpp", "-Iframeworks/rs/cpp",

View file

@ -70,8 +70,10 @@ func filterOutWithPrefix(list []string, filter []string) (remainder []string) {
func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags { func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
// Assuming that the cflags which clang LibTooling tools cannot // Assuming that the cflags which clang LibTooling tools cannot
// understand have not been converted to ninja variables yet. // understand have not been converted to ninja variables yet.
flags.ToolingCFlags = filterOutWithPrefix(flags.CFlags, config.ClangLibToolingUnknownCflags) flags.Local.ToolingCFlags = filterOutWithPrefix(flags.Local.CFlags, config.ClangLibToolingUnknownCflags)
flags.ToolingCppFlags = filterOutWithPrefix(flags.CppFlags, config.ClangLibToolingUnknownCflags) flags.Global.ToolingCFlags = filterOutWithPrefix(flags.Global.CFlags, config.ClangLibToolingUnknownCflags)
flags.Local.ToolingCppFlags = filterOutWithPrefix(flags.Local.CppFlags, config.ClangLibToolingUnknownCflags)
flags.Global.ToolingCppFlags = filterOutWithPrefix(flags.Global.CppFlags, config.ClangLibToolingUnknownCflags)
return flags return flags
} }

View file

@ -426,8 +426,9 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib
if ctx.Device() && sanitize.Properties.MinimalRuntimeDep { if ctx.Device() && sanitize.Properties.MinimalRuntimeDep {
flags.LdFlags = append(flags.LdFlags, minimalRuntimePath) flags.Local.LdFlags = append(flags.Local.LdFlags,
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib) minimalRuntimePath,
"-Wl,--exclude-libs,"+minimalRuntimeLib)
} }
if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep { if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
return flags return flags
@ -439,15 +440,15 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
// TODO: put in flags? // TODO: put in flags?
flags.RequiredInstructionSet = "arm" flags.RequiredInstructionSet = "arm"
} }
flags.CFlags = append(flags.CFlags, asanCflags...) flags.Local.CFlags = append(flags.Local.CFlags, asanCflags...)
flags.LdFlags = append(flags.LdFlags, asanLdflags...) flags.Local.LdFlags = append(flags.Local.LdFlags, asanLdflags...)
if ctx.Host() { if ctx.Host() {
// -nodefaultlibs (provided with libc++) prevents the driver from linking // -nodefaultlibs (provided with libc++) prevents the driver from linking
// libraries needed with -fsanitize=address. http://b/18650275 (WAI) // libraries needed with -fsanitize=address. http://b/18650275 (WAI)
flags.LdFlags = append(flags.LdFlags, "-Wl,--no-as-needed") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--no-as-needed")
} else { } else {
flags.CFlags = append(flags.CFlags, "-mllvm", "-asan-globals=0") flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-asan-globals=0")
if ctx.bootstrap() { if ctx.bootstrap() {
flags.DynamicLinker = "/system/bin/bootstrap/linker_asan" flags.DynamicLinker = "/system/bin/bootstrap/linker_asan"
} else { } else {
@ -460,33 +461,30 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
} }
if Bool(sanitize.Properties.Sanitize.Hwaddress) { if Bool(sanitize.Properties.Sanitize.Hwaddress) {
flags.CFlags = append(flags.CFlags, hwasanCflags...) flags.Local.CFlags = append(flags.Local.CFlags, hwasanCflags...)
} }
if Bool(sanitize.Properties.Sanitize.Fuzzer) { if Bool(sanitize.Properties.Sanitize.Fuzzer) {
flags.CFlags = append(flags.CFlags, "-fsanitize=fuzzer-no-link") flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize=fuzzer-no-link")
// TODO(b/131771163): LTO and Fuzzer support is mutually incompatible. // TODO(b/131771163): LTO and Fuzzer support is mutually incompatible.
_, flags.LdFlags = removeFromList("-flto", flags.LdFlags) _, flags.Local.LdFlags = removeFromList("-flto", flags.Local.LdFlags)
_, flags.CFlags = removeFromList("-flto", flags.CFlags) _, flags.Local.CFlags = removeFromList("-flto", flags.Local.CFlags)
flags.LdFlags = append(flags.LdFlags, "-fno-lto") flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-lto")
flags.CFlags = append(flags.CFlags, "-fno-lto") flags.Local.CFlags = append(flags.Local.CFlags, "-fno-lto")
// TODO(b/142430592): Upstream linker scripts for sanitizer runtime libraries // TODO(b/142430592): Upstream linker scripts for sanitizer runtime libraries
// discard the sancov_lowest_stack symbol, because it's emulated TLS (and thus // discard the sancov_lowest_stack symbol, because it's emulated TLS (and thus
// doesn't match the linker script due to the "__emutls_v." prefix). // doesn't match the linker script due to the "__emutls_v." prefix).
flags.LdFlags = append(flags.LdFlags, "-fno-sanitize-coverage=stack-depth") flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-coverage=stack-depth")
flags.CFlags = append(flags.CFlags, "-fno-sanitize-coverage=stack-depth") flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-coverage=stack-depth")
// TODO(b/133876586): Experimental PM breaks sanitizer coverage. // TODO(b/133876586): Experimental PM breaks sanitizer coverage.
_, flags.CFlags = removeFromList("-fexperimental-new-pass-manager", flags.CFlags) flags.Local.CFlags = append(flags.Local.CFlags, "-fno-experimental-new-pass-manager")
flags.CFlags = append(flags.CFlags, "-fno-experimental-new-pass-manager")
// Disable fortify for fuzzing builds. Generally, we'll be building with // Disable fortify for fuzzing builds. Generally, we'll be building with
// UBSan or ASan here and the fortify checks pollute the stack traces. // UBSan or ASan here and the fortify checks pollute the stack traces.
_, flags.CFlags = removeFromList("-D_FORTIFY_SOURCE=1", flags.CFlags) flags.Local.CFlags = append(flags.Local.CFlags, "-U_FORTIFY_SOURCE")
_, flags.CFlags = removeFromList("-D_FORTIFY_SOURCE=2", flags.CFlags)
flags.CFlags = append(flags.CFlags, "-U_FORTIFY_SOURCE")
} }
if Bool(sanitize.Properties.Sanitize.Cfi) { if Bool(sanitize.Properties.Sanitize.Cfi) {
@ -496,75 +494,75 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
flags.RequiredInstructionSet = "thumb" flags.RequiredInstructionSet = "thumb"
} }
flags.CFlags = append(flags.CFlags, cfiCflags...) flags.Local.CFlags = append(flags.Local.CFlags, cfiCflags...)
flags.AsFlags = append(flags.AsFlags, cfiAsflags...) flags.Local.AsFlags = append(flags.Local.AsFlags, cfiAsflags...)
// Only append the default visibility flag if -fvisibility has not already been set // Only append the default visibility flag if -fvisibility has not already been set
// to hidden. // to hidden.
if !inList("-fvisibility=hidden", flags.CFlags) { if !inList("-fvisibility=hidden", flags.Local.CFlags) {
flags.CFlags = append(flags.CFlags, "-fvisibility=default") flags.Local.CFlags = append(flags.Local.CFlags, "-fvisibility=default")
} }
flags.LdFlags = append(flags.LdFlags, cfiLdflags...) flags.Local.LdFlags = append(flags.Local.LdFlags, cfiLdflags...)
if ctx.staticBinary() { if ctx.staticBinary() {
_, flags.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.CFlags) _, flags.Local.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.Local.CFlags)
_, flags.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.LdFlags) _, flags.Local.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.Local.LdFlags)
} }
} }
if Bool(sanitize.Properties.Sanitize.Integer_overflow) { if Bool(sanitize.Properties.Sanitize.Integer_overflow) {
flags.CFlags = append(flags.CFlags, intOverflowCflags...) flags.Local.CFlags = append(flags.Local.CFlags, intOverflowCflags...)
} }
if len(sanitize.Properties.Sanitizers) > 0 { if len(sanitize.Properties.Sanitizers) > 0 {
sanitizeArg := "-fsanitize=" + strings.Join(sanitize.Properties.Sanitizers, ",") sanitizeArg := "-fsanitize=" + strings.Join(sanitize.Properties.Sanitizers, ",")
flags.CFlags = append(flags.CFlags, sanitizeArg) flags.Local.CFlags = append(flags.Local.CFlags, sanitizeArg)
flags.AsFlags = append(flags.AsFlags, sanitizeArg) flags.Local.AsFlags = append(flags.Local.AsFlags, sanitizeArg)
if ctx.Host() { if ctx.Host() {
// Host sanitizers only link symbols in the final executable, so // Host sanitizers only link symbols in the final executable, so
// there will always be undefined symbols in intermediate libraries. // there will always be undefined symbols in intermediate libraries.
_, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags) _, flags.Global.LdFlags = removeFromList("-Wl,--no-undefined", flags.Global.LdFlags)
flags.LdFlags = append(flags.LdFlags, sanitizeArg) flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)
} else { } else {
if enableMinimalRuntime(sanitize) { if enableMinimalRuntime(sanitize) {
flags.CFlags = append(flags.CFlags, strings.Join(minimalRuntimeFlags, " ")) flags.Local.CFlags = append(flags.Local.CFlags, strings.Join(minimalRuntimeFlags, " "))
flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...) flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...)
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib)
} }
} }
if Bool(sanitize.Properties.Sanitize.Fuzzer) { if Bool(sanitize.Properties.Sanitize.Fuzzer) {
// When fuzzing, we wish to crash with diagnostics on any bug. // When fuzzing, we wish to crash with diagnostics on any bug.
flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap=all", "-fno-sanitize-recover=all") flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-trap=all", "-fno-sanitize-recover=all")
} else if ctx.Host() { } else if ctx.Host() {
flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all") flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-recover=all")
} else { } else {
flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort") flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort")
} }
// http://b/119329758, Android core does not boot up with this sanitizer yet. // http://b/119329758, Android core does not boot up with this sanitizer yet.
if toDisableImplicitIntegerChange(flags.CFlags) { if toDisableImplicitIntegerChange(flags.Local.CFlags) {
flags.CFlags = append(flags.CFlags, "-fno-sanitize=implicit-integer-sign-change") flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=implicit-integer-sign-change")
} }
} }
if len(sanitize.Properties.DiagSanitizers) > 0 { if len(sanitize.Properties.DiagSanitizers) > 0 {
flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(sanitize.Properties.DiagSanitizers, ",")) flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-trap="+strings.Join(sanitize.Properties.DiagSanitizers, ","))
} }
// FIXME: enable RTTI if diag + (cfi or vptr) // FIXME: enable RTTI if diag + (cfi or vptr)
if sanitize.Properties.Sanitize.Recover != nil { if sanitize.Properties.Sanitize.Recover != nil {
flags.CFlags = append(flags.CFlags, "-fsanitize-recover="+ flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-recover="+
strings.Join(sanitize.Properties.Sanitize.Recover, ",")) strings.Join(sanitize.Properties.Sanitize.Recover, ","))
} }
if sanitize.Properties.Sanitize.Diag.No_recover != nil { if sanitize.Properties.Sanitize.Diag.No_recover != nil {
flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover="+ flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-recover="+
strings.Join(sanitize.Properties.Sanitize.Diag.No_recover, ",")) strings.Join(sanitize.Properties.Sanitize.Diag.No_recover, ","))
} }
blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist) blacklist := android.OptionalPathForModuleSrc(ctx, sanitize.Properties.Sanitize.Blacklist)
if blacklist.Valid() { if blacklist.Valid() {
flags.CFlags = append(flags.CFlags, "-fsanitize-blacklist="+blacklist.String()) flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize-blacklist="+blacklist.String())
flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path()) flags.CFlagsDeps = append(flags.CFlagsDeps, blacklist.Path())
} }

View file

@ -215,12 +215,12 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
// these availability attributes are meaningless for us but cause // these availability attributes are meaningless for us but cause
// build breaks when we try to use code that would not be available // build breaks when we try to use code that would not be available
// in the system's dylib. // in the system's dylib.
flags.CppFlags = append(flags.CppFlags, flags.Local.CppFlags = append(flags.Local.CppFlags,
"-D_LIBCPP_DISABLE_AVAILABILITY") "-D_LIBCPP_DISABLE_AVAILABILITY")
} }
if !ctx.toolchain().Bionic() { if !ctx.toolchain().Bionic() {
flags.CppFlags = append(flags.CppFlags, "-nostdinc++") flags.Local.CppFlags = append(flags.Local.CppFlags, "-nostdinc++")
flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++") flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
if ctx.Windows() { if ctx.Windows() {
if stl.Properties.SelectedStl == "libc++_static" { if stl.Properties.SelectedStl == "libc++_static" {
@ -231,9 +231,9 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
// Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj // Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj
// exception model for 32-bit. // exception model for 32-bit.
if ctx.Arch().ArchType == android.X86 { if ctx.Arch().ArchType == android.X86 {
flags.CppFlags = append(flags.CppFlags, "-fsjlj-exceptions") flags.Local.CppFlags = append(flags.Local.CppFlags, "-fsjlj-exceptions")
} }
flags.CppFlags = append(flags.CppFlags, flags.Local.CppFlags = append(flags.Local.CppFlags,
// Disable visiblity annotations since we're using static // Disable visiblity annotations since we're using static
// libc++. // libc++.
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
@ -243,23 +243,23 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
} }
} else { } else {
if ctx.Arch().ArchType == android.Arm { if ctx.Arch().ArchType == android.Arm {
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,libunwind_llvm.a") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,libunwind_llvm.a")
} }
} }
case "libstdc++": case "libstdc++":
// Nothing // Nothing
case "ndk_system": case "ndk_system":
ndkSrcRoot := android.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include") ndkSrcRoot := android.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include")
flags.CFlags = append(flags.CFlags, "-isystem "+ndkSrcRoot.String()) flags.Local.CFlags = append(flags.Local.CFlags, "-isystem "+ndkSrcRoot.String())
case "ndk_libc++_shared", "ndk_libc++_static": case "ndk_libc++_shared", "ndk_libc++_static":
if ctx.Arch().ArchType == android.Arm { if ctx.Arch().ArchType == android.Arm {
// Make sure the _Unwind_XXX symbols are not re-exported. // Make sure the _Unwind_XXX symbols are not re-exported.
flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,libunwind.a") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,libunwind.a")
} }
case "": case "":
// None or error. // None or error.
if !ctx.toolchain().Bionic() { if !ctx.toolchain().Bionic() {
flags.CppFlags = append(flags.CppFlags, "-nostdinc++") flags.Local.CppFlags = append(flags.Local.CppFlags, "-nostdinc++")
flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++") flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
} }
default: default:

View file

@ -220,20 +220,20 @@ func (test *testDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
flags.CFlags = append(flags.CFlags, "-DGTEST_HAS_STD_STRING") flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_HAS_STD_STRING")
if ctx.Host() { if ctx.Host() {
flags.CFlags = append(flags.CFlags, "-O0", "-g") flags.Local.CFlags = append(flags.Local.CFlags, "-O0", "-g")
switch ctx.Os() { switch ctx.Os() {
case android.Windows: case android.Windows:
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS") flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_WINDOWS")
case android.Linux: case android.Linux:
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX") flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX")
case android.Darwin: case android.Darwin:
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_MAC") flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_MAC")
} }
} else { } else {
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_LINUX_ANDROID") flags.Local.CFlags = append(flags.Local.CFlags, "-DGTEST_OS_LINUX_ANDROID")
} }
return flags return flags

View file

@ -55,22 +55,22 @@ func moduleToLibName(module string) (string, error) {
func flagsToBuilderFlags(in Flags) builderFlags { func flagsToBuilderFlags(in Flags) builderFlags {
return builderFlags{ return builderFlags{
globalFlags: strings.Join(in.GlobalFlags, " "), commonFlags: strings.Join(append(android.CopyOf(in.Global.CommonFlags), in.Local.CommonFlags...), " "),
arFlags: strings.Join(in.ArFlags, " "), asFlags: strings.Join(append(android.CopyOf(in.Global.AsFlags), in.Local.AsFlags...), " "),
asFlags: strings.Join(in.AsFlags, " "), yasmFlags: strings.Join(append(android.CopyOf(in.Global.YasmFlags), in.Local.YasmFlags...), " "),
cFlags: strings.Join(in.CFlags, " "), cFlags: strings.Join(append(android.CopyOf(in.Global.CFlags), in.Local.CFlags...), " "),
toolingCFlags: strings.Join(in.ToolingCFlags, " "), toolingCFlags: strings.Join(append(android.CopyOf(in.Global.ToolingCFlags), in.Local.ToolingCFlags...), " "),
toolingCppFlags: strings.Join(in.ToolingCppFlags, " "), toolingCppFlags: strings.Join(append(android.CopyOf(in.Global.ToolingCppFlags), in.Local.ToolingCppFlags...), " "),
conlyFlags: strings.Join(in.ConlyFlags, " "), conlyFlags: strings.Join(append(android.CopyOf(in.Global.ConlyFlags), in.Local.ConlyFlags...), " "),
cppFlags: strings.Join(in.CppFlags, " "), cppFlags: strings.Join(append(android.CopyOf(in.Global.CppFlags), in.Local.CppFlags...), " "),
ldFlags: strings.Join(append(android.CopyOf(in.Global.LdFlags), in.Local.LdFlags...), " "),
aidlFlags: strings.Join(in.aidlFlags, " "), aidlFlags: strings.Join(in.aidlFlags, " "),
rsFlags: strings.Join(in.rsFlags, " "), rsFlags: strings.Join(in.rsFlags, " "),
ldFlags: strings.Join(in.LdFlags, " "),
libFlags: strings.Join(in.libFlags, " "), libFlags: strings.Join(in.libFlags, " "),
extraLibFlags: strings.Join(in.extraLibFlags, " "), extraLibFlags: strings.Join(in.extraLibFlags, " "),
tidyFlags: strings.Join(in.TidyFlags, " "), tidyFlags: strings.Join(in.TidyFlags, " "),
sAbiFlags: strings.Join(in.SAbiFlags, " "), sAbiFlags: strings.Join(in.SAbiFlags, " "),
yasmFlags: strings.Join(in.YasmFlags, " "),
toolchain: in.Toolchain, toolchain: in.Toolchain,
coverage: in.Coverage, coverage: in.Coverage,
tidy: in.Tidy, tidy: in.Tidy,

View file

@ -124,7 +124,7 @@ func (stub *vendorPublicLibraryStubDecorator) link(ctx ModuleContext, flags Flag
objs Objects) android.Path { objs Objects) android.Path {
if !Bool(stub.Properties.Unversioned) { if !Bool(stub.Properties.Unversioned) {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String() linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.LdFlags = append(flags.LdFlags, linkerScriptFlag) flags.Local.LdFlags = append(flags.Local.LdFlags, linkerScriptFlag)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath) flags.LdFlagsDeps = append(flags.LdFlagsDeps, stub.versionScriptPath)
} }
return stub.libraryDecorator.link(ctx, flags, deps, objs) return stub.libraryDecorator.link(ctx, flags, deps, objs)

View file

@ -68,7 +68,7 @@ func (xom *xom) flags(ctx ModuleContext, flags Flags) Flags {
if !disableXom || (xom.Properties.Xom != nil && *xom.Properties.Xom) { if !disableXom || (xom.Properties.Xom != nil && *xom.Properties.Xom) {
// XOM is only supported on AArch64 when using lld. // XOM is only supported on AArch64 when using lld.
if ctx.Arch().ArchType == android.Arm64 && ctx.useClangLld(ctx) { if ctx.Arch().ArchType == android.Arm64 && ctx.useClangLld(ctx) {
flags.LdFlags = append(flags.LdFlags, "-Wl,-execute-only") flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-execute-only")
} }
} }