diff --git a/cc/builder.go b/cc/builder.go index a568a297a..ee53f41d6 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -158,6 +158,16 @@ var ( Description: "tidy $out", }, "cFlags", "tidyFlags") + + yasmCmd = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm") + + yasm = pctx.AndroidStaticRule("yasm", + blueprint.RuleParams{ + Command: "$yasmCmd $asFlags -o $out $in", + CommandDeps: []string{"$yasmCmd"}, + Description: "yasm $out", + }, + "asFlags") ) func init() { @@ -183,6 +193,7 @@ type builderFlags struct { yaccFlags string protoFlags string tidyFlags string + yasmFlags string toolchain config.Toolchain clang bool tidy bool @@ -240,6 +251,19 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and objFiles[i] = objFile + if srcFile.Ext() == ".asm" { + ctx.ModuleBuild(pctx, android.ModuleBuildParams{ + Rule: yasm, + Output: objFile, + Input: srcFile, + OrderOnly: deps, + Args: map[string]string{ + "asFlags": flags.yasmFlags, + }, + }) + continue + } + var moduleCflags string var ccCmd string tidy := flags.tidy && flags.clang diff --git a/cc/cc.go b/cc/cc.go index df4e5cf24..a4f8e58b7 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -101,6 +101,7 @@ type Flags struct { LdFlags []string // Flags that apply to linker command lines libFlags []string // Flags to add libraries early to the link order TidyFlags []string // Flags that apply to clang-tidy + YasmFlags []string // Flags that apply to yasm assembly source files Toolchain config.Toolchain Clang bool diff --git a/cc/compiler.go b/cc/compiler.go index def8d58c5..04f536f7f 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -147,6 +147,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag flags.CppFlags = append(flags.CppFlags, esc(compiler.Properties.Cppflags)...) flags.ConlyFlags = append(flags.ConlyFlags, esc(compiler.Properties.Conlyflags)...) flags.AsFlags = append(flags.AsFlags, esc(compiler.Properties.Asflags)...) + flags.YasmFlags = append(flags.YasmFlags, esc(compiler.Properties.Asflags)...) flags.YaccFlags = append(flags.YaccFlags, esc(compiler.Properties.Yaccflags)...) // Include dir cflags @@ -281,6 +282,8 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag } else { flags.CppFlags = append(flags.CppFlags, tc.Cppflags()) } + + flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags()) } if flags.Clang { diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index 020a0dd46..995c8c62f 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -66,6 +66,8 @@ type Toolchain interface { ClangLdflags() string ClangInstructionSetFlags(string) (string, error) + YasmFlags() string + Is64Bit() bool ShlibSuffix() string @@ -127,6 +129,10 @@ func (toolchainBase) ClangAsflags() string { return "" } +func (toolchainBase) YasmFlags() string { + return "" +} + func (toolchainBase) SanitizerRuntimeLibraryArch() string { return "" } diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index 918ddf740..2a6fe2a99 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -166,6 +166,9 @@ func init() { pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " ")) pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " ")) + // Yasm flags + pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64") + // Extended cflags // Architecture variant cflags @@ -245,6 +248,10 @@ func (t *toolchainX86_64) ClangLdflags() string { return "${config.X86_64Ldflags}" } +func (t *toolchainX86_64) YasmFlags() string { + return "${config.X86_64YasmFlags}" +} + func (toolchainX86_64) SanitizerRuntimeLibraryArch() string { return "x86_64" } diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index 6b5556428..23518b6ee 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -188,6 +188,9 @@ func init() { pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " ")) pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " ")) + // Yasm flags + pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86") + // Extended cflags // Architecture variant cflags @@ -267,6 +270,10 @@ func (t *toolchainX86) ClangLdflags() string { return "${config.X86Ldflags}" } +func (t *toolchainX86) YasmFlags() string { + return "${config.X86YasmFlags}" +} + func (toolchainX86) SanitizerRuntimeLibraryArch() string { return "i686" } diff --git a/cc/util.go b/cc/util.go index 1cb3dd7d8..9f958d191 100644 --- a/cc/util.go +++ b/cc/util.go @@ -97,6 +97,7 @@ func flagsToBuilderFlags(in Flags) builderFlags { ldFlags: strings.Join(in.LdFlags, " "), libFlags: strings.Join(in.libFlags, " "), tidyFlags: strings.Join(in.TidyFlags, " "), + yasmFlags: strings.Join(in.YasmFlags, " "), toolchain: in.Toolchain, clang: in.Clang, tidy: in.Tidy,