Merge changes I75b4a761,I779f28c6,If1422372,I26307dd1
* changes: Introduce inject_bssl_hash library property. BoringSSL FIPS build - introduce extraLibFlags and use for STL libs. Allow linker scripts when building objects. Allow .o files as srcs.
This commit is contained in:
@@ -204,6 +204,7 @@ bootstrap_go_package {
|
|||||||
"cc/gen_test.go",
|
"cc/gen_test.go",
|
||||||
"cc/genrule_test.go",
|
"cc/genrule_test.go",
|
||||||
"cc/library_test.go",
|
"cc/library_test.go",
|
||||||
|
"cc/object_test.go",
|
||||||
"cc/prebuilt_test.go",
|
"cc/prebuilt_test.go",
|
||||||
"cc/proto_test.go",
|
"cc/proto_test.go",
|
||||||
"cc/test_data_test.go",
|
"cc/test_data_test.go",
|
||||||
|
@@ -989,6 +989,10 @@ type ModuleOutPath struct {
|
|||||||
|
|
||||||
var _ Path = ModuleOutPath{}
|
var _ Path = ModuleOutPath{}
|
||||||
|
|
||||||
|
func (p ModuleOutPath) objPathWithExt(ctx ModuleContext, subdir, ext string) ModuleObjPath {
|
||||||
|
return PathForModuleObj(ctx, subdir, pathtools.ReplaceExtension(p.path, ext))
|
||||||
|
}
|
||||||
|
|
||||||
func pathForModule(ctx ModuleContext) OutputPath {
|
func pathForModule(ctx ModuleContext) OutputPath {
|
||||||
return PathForOutput(ctx, ".intermediates", ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
|
return PathForOutput(ctx, ".intermediates", ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
|
||||||
}
|
}
|
||||||
|
@@ -65,14 +65,14 @@ var (
|
|||||||
ld = pctx.AndroidStaticRule("ld",
|
ld = pctx.AndroidStaticRule("ld",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "$ldCmd ${crtBegin} @${out}.rsp " +
|
Command: "$ldCmd ${crtBegin} @${out}.rsp " +
|
||||||
"${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
|
"${libFlags} ${crtEnd} -o ${out} ${ldFlags} ${extraLibFlags}",
|
||||||
CommandDeps: []string{"$ldCmd"},
|
CommandDeps: []string{"$ldCmd"},
|
||||||
Rspfile: "${out}.rsp",
|
Rspfile: "${out}.rsp",
|
||||||
RspfileContent: "${in}",
|
RspfileContent: "${in}",
|
||||||
// clang -Wl,--out-implib doesn't update its output file if it hasn't changed.
|
// clang -Wl,--out-implib doesn't update its output file if it hasn't changed.
|
||||||
Restat: true,
|
Restat: true,
|
||||||
},
|
},
|
||||||
"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags")
|
"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags", "extraLibFlags")
|
||||||
|
|
||||||
partialLd = pctx.AndroidStaticRule("partialLd",
|
partialLd = pctx.AndroidStaticRule("partialLd",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
@@ -259,6 +259,7 @@ type builderFlags struct {
|
|||||||
cppFlags string
|
cppFlags string
|
||||||
ldFlags string
|
ldFlags string
|
||||||
libFlags string
|
libFlags string
|
||||||
|
extraLibFlags string
|
||||||
tidyFlags string
|
tidyFlags string
|
||||||
sAbiFlags string
|
sAbiFlags string
|
||||||
yasmFlags string
|
yasmFlags string
|
||||||
@@ -411,6 +412,9 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
|
case ".o":
|
||||||
|
objFiles[i] = srcFile
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var moduleCflags string
|
var moduleCflags string
|
||||||
@@ -630,6 +634,7 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext,
|
|||||||
"ldCmd": ldCmd,
|
"ldCmd": ldCmd,
|
||||||
"crtBegin": crtBegin.String(),
|
"crtBegin": crtBegin.String(),
|
||||||
"libFlags": strings.Join(libFlagsList, " "),
|
"libFlags": strings.Join(libFlagsList, " "),
|
||||||
|
"extraLibFlags": flags.extraLibFlags,
|
||||||
"ldFlags": flags.ldFlags,
|
"ldFlags": flags.ldFlags,
|
||||||
"crtEnd": crtEnd.String(),
|
"crtEnd": crtEnd.String(),
|
||||||
},
|
},
|
||||||
|
12
cc/cc.go
12
cc/cc.go
@@ -153,6 +153,7 @@ type Flags struct {
|
|||||||
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
|
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
|
||||||
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
|
YasmFlags []string // Flags that apply to yasm assembly source files
|
||||||
@@ -182,17 +183,6 @@ type Flags struct {
|
|||||||
Yacc *YaccProperties
|
Yacc *YaccProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjectLinkerProperties struct {
|
|
||||||
// list of modules that should only provide headers for this module.
|
|
||||||
Header_libs []string `android:"arch_variant,variant_prepend"`
|
|
||||||
|
|
||||||
// names of other cc_object modules to link into this module using partial linking
|
|
||||||
Objs []string `android:"arch_variant"`
|
|
||||||
|
|
||||||
// if set, add an extra objcopy --prefix-symbols= step
|
|
||||||
Prefix_symbols *string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Properties used to compile all C or C++ modules
|
// Properties used to compile all C or C++ modules
|
||||||
type BaseProperties struct {
|
type BaseProperties struct {
|
||||||
// Deprecated. true is the default, false is invalid.
|
// Deprecated. true is the default, false is invalid.
|
||||||
|
@@ -2203,7 +2203,7 @@ func TestStaticExecutable(t *testing.T) {
|
|||||||
ctx := testCc(t, `
|
ctx := testCc(t, `
|
||||||
cc_binary {
|
cc_binary {
|
||||||
name: "static_test",
|
name: "static_test",
|
||||||
srcs: ["foo.c"],
|
srcs: ["foo.c", "baz.o"],
|
||||||
static_executable: true,
|
static_executable: true,
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
|
@@ -113,6 +113,9 @@ type LibraryProperties struct {
|
|||||||
|
|
||||||
// Order symbols in .bss section by their sizes. Only useful for shared libraries.
|
// Order symbols in .bss section by their sizes. Only useful for shared libraries.
|
||||||
Sort_bss_symbols_by_size *bool
|
Sort_bss_symbols_by_size *bool
|
||||||
|
|
||||||
|
// Inject boringssl hash into the shared library. This is only intended for use by external/boringssl.
|
||||||
|
Inject_bssl_hash *bool `android:"arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LibraryMutatedProperties struct {
|
type LibraryMutatedProperties struct {
|
||||||
@@ -766,9 +769,21 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
||||||
library.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags)
|
library.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
library.unstrippedOutputFile = outputFile
|
library.unstrippedOutputFile = outputFile
|
||||||
|
|
||||||
|
// TODO(b/137267623): Remove this in favor of a cc_genrule when they support operating on shared libraries.
|
||||||
|
if Bool(library.Properties.Inject_bssl_hash) {
|
||||||
|
hashedOutputfile := outputFile
|
||||||
|
outputFile = android.PathForModuleOut(ctx, "unhashed", fileName)
|
||||||
|
|
||||||
|
rule := android.NewRuleBuilder()
|
||||||
|
rule.Command().
|
||||||
|
BuiltTool(ctx, "bssl_inject_hash").
|
||||||
|
FlagWithInput("-in-object ", outputFile).
|
||||||
|
FlagWithOutput("-o ", hashedOutputfile)
|
||||||
|
rule.Build(pctx, ctx, "injectCryptoHash", "inject crypto hash")
|
||||||
|
}
|
||||||
|
|
||||||
if Bool(library.baseLinker.Properties.Use_version_lib) {
|
if Bool(library.baseLinker.Properties.Use_version_lib) {
|
||||||
if ctx.Host() {
|
if ctx.Host() {
|
||||||
versionedOutputFile := outputFile
|
versionedOutputFile := outputFile
|
||||||
|
@@ -24,23 +24,26 @@ func TestLibraryReuse(t *testing.T) {
|
|||||||
ctx := testCc(t, `
|
ctx := testCc(t, `
|
||||||
cc_library {
|
cc_library {
|
||||||
name: "libfoo",
|
name: "libfoo",
|
||||||
srcs: ["foo.c"],
|
srcs: ["foo.c", "baz.o"],
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
libfooShared := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("ld")
|
libfooShared := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_shared").Rule("ld")
|
||||||
libfooStatic := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_static").Output("libfoo.a")
|
libfooStatic := ctx.ModuleForTests("libfoo", "android_arm_armv7-a-neon_core_static").Output("libfoo.a")
|
||||||
|
|
||||||
if len(libfooShared.Inputs) != 1 {
|
if len(libfooShared.Inputs) != 2 {
|
||||||
t.Fatalf("unexpected inputs to libfoo shared: %#v", libfooShared.Inputs.Strings())
|
t.Fatalf("unexpected inputs to libfoo shared: %#v", libfooShared.Inputs.Strings())
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(libfooStatic.Inputs) != 1 {
|
if len(libfooStatic.Inputs) != 2 {
|
||||||
t.Fatalf("unexpected inputs to libfoo static: %#v", libfooStatic.Inputs.Strings())
|
t.Fatalf("unexpected inputs to libfoo static: %#v", libfooStatic.Inputs.Strings())
|
||||||
}
|
}
|
||||||
|
|
||||||
if libfooShared.Inputs[0] != libfooStatic.Inputs[0] {
|
if libfooShared.Inputs[0] != libfooStatic.Inputs[0] {
|
||||||
t.Errorf("static object not reused for shared library")
|
t.Errorf("static object not reused for shared library")
|
||||||
}
|
}
|
||||||
|
if libfooShared.Inputs[1] != libfooStatic.Inputs[1] {
|
||||||
|
t.Errorf("static object not reused for shared library")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("extra static source", func(t *testing.T) {
|
t.Run("extra static source", func(t *testing.T) {
|
||||||
|
20
cc/object.go
20
cc/object.go
@@ -33,6 +33,20 @@ type objectLinker struct {
|
|||||||
Properties ObjectLinkerProperties
|
Properties ObjectLinkerProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ObjectLinkerProperties struct {
|
||||||
|
// list of modules that should only provide headers for this module.
|
||||||
|
Header_libs []string `android:"arch_variant,variant_prepend"`
|
||||||
|
|
||||||
|
// names of other cc_object modules to link into this module using partial linking
|
||||||
|
Objs []string `android:"arch_variant"`
|
||||||
|
|
||||||
|
// if set, add an extra objcopy --prefix-symbols= step
|
||||||
|
Prefix_symbols *string
|
||||||
|
|
||||||
|
// if set, the path to a linker script to pass to ld -r when combining multiple object files.
|
||||||
|
Linker_script *string `android:"path,arch_variant"`
|
||||||
|
}
|
||||||
|
|
||||||
// cc_object runs the compiler without running the linker. It is rarely
|
// cc_object runs the compiler without running the linker. It is rarely
|
||||||
// necessary, but sometimes used to generate .s files from .c files to use as
|
// necessary, but sometimes used to generate .s files from .c files to use as
|
||||||
// input to a cc_genrule module.
|
// input to a cc_genrule module.
|
||||||
@@ -71,9 +85,13 @@ func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
|||||||
return deps
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*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.LdFlags = append(flags.LdFlags, ctx.toolchain().ToolchainClangLdflags())
|
||||||
|
|
||||||
|
if lds := android.OptionalPathForModuleSrc(ctx, object.Properties.Linker_script); lds.Valid() {
|
||||||
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-T,"+lds.String())
|
||||||
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, lds.Path())
|
||||||
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
cc/object_test.go
Normal file
31
cc/object_test.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// Copyright 2019 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLinkerScript(t *testing.T) {
|
||||||
|
t.Run("script", func(t *testing.T) {
|
||||||
|
testCc(t, `
|
||||||
|
cc_object {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["baz.o"],
|
||||||
|
linker_script: "foo.lds",
|
||||||
|
}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
12
cc/stl.go
12
cc/stl.go
@@ -223,11 +223,11 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
|
|
||||||
if !ctx.toolchain().Bionic() {
|
if !ctx.toolchain().Bionic() {
|
||||||
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
||||||
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs")
|
||||||
if ctx.staticBinary() {
|
if ctx.staticBinary() {
|
||||||
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
|
flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...)
|
||||||
} else {
|
} else {
|
||||||
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
|
flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...)
|
||||||
}
|
}
|
||||||
if ctx.Windows() {
|
if ctx.Windows() {
|
||||||
// Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj
|
// Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj
|
||||||
@@ -262,11 +262,11 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
// None or error.
|
// None or error.
|
||||||
if !ctx.toolchain().Bionic() {
|
if !ctx.toolchain().Bionic() {
|
||||||
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
||||||
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs")
|
||||||
if ctx.staticBinary() {
|
if ctx.staticBinary() {
|
||||||
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
|
flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...)
|
||||||
} else {
|
} else {
|
||||||
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
|
flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@@ -272,7 +272,9 @@ func CreateTestContext(bp string, fs map[string][]byte,
|
|||||||
mockFS := map[string][]byte{
|
mockFS := map[string][]byte{
|
||||||
"Android.bp": []byte(bp),
|
"Android.bp": []byte(bp),
|
||||||
"foo.c": nil,
|
"foo.c": nil,
|
||||||
|
"foo.lds": nil,
|
||||||
"bar.c": nil,
|
"bar.c": nil,
|
||||||
|
"baz.o": nil,
|
||||||
"a.proto": nil,
|
"a.proto": nil,
|
||||||
"b.aidl": nil,
|
"b.aidl": nil,
|
||||||
"sub/c.aidl": nil,
|
"sub/c.aidl": nil,
|
||||||
|
@@ -67,6 +67,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
|||||||
rsFlags: strings.Join(in.rsFlags, " "),
|
rsFlags: strings.Join(in.rsFlags, " "),
|
||||||
ldFlags: strings.Join(in.LdFlags, " "),
|
ldFlags: strings.Join(in.LdFlags, " "),
|
||||||
libFlags: strings.Join(in.libFlags, " "),
|
libFlags: strings.Join(in.libFlags, " "),
|
||||||
|
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, " "),
|
yasmFlags: strings.Join(in.YasmFlags, " "),
|
||||||
|
Reference in New Issue
Block a user