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/genrule_test.go",
|
||||
"cc/library_test.go",
|
||||
"cc/object_test.go",
|
||||
"cc/prebuilt_test.go",
|
||||
"cc/proto_test.go",
|
||||
"cc/test_data_test.go",
|
||||
|
@@ -989,6 +989,10 @@ type ModuleOutPath struct {
|
||||
|
||||
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 {
|
||||
return PathForOutput(ctx, ".intermediates", ctx.ModuleDir(), ctx.ModuleName(), ctx.ModuleSubDir())
|
||||
}
|
||||
|
@@ -65,14 +65,14 @@ var (
|
||||
ld = pctx.AndroidStaticRule("ld",
|
||||
blueprint.RuleParams{
|
||||
Command: "$ldCmd ${crtBegin} @${out}.rsp " +
|
||||
"${libFlags} ${crtEnd} -o ${out} ${ldFlags}",
|
||||
"${libFlags} ${crtEnd} -o ${out} ${ldFlags} ${extraLibFlags}",
|
||||
CommandDeps: []string{"$ldCmd"},
|
||||
Rspfile: "${out}.rsp",
|
||||
RspfileContent: "${in}",
|
||||
// clang -Wl,--out-implib doesn't update its output file if it hasn't changed.
|
||||
Restat: true,
|
||||
},
|
||||
"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags")
|
||||
"ldCmd", "crtBegin", "libFlags", "crtEnd", "ldFlags", "extraLibFlags")
|
||||
|
||||
partialLd = pctx.AndroidStaticRule("partialLd",
|
||||
blueprint.RuleParams{
|
||||
@@ -259,6 +259,7 @@ type builderFlags struct {
|
||||
cppFlags string
|
||||
ldFlags string
|
||||
libFlags string
|
||||
extraLibFlags string
|
||||
tidyFlags string
|
||||
sAbiFlags string
|
||||
yasmFlags string
|
||||
@@ -411,6 +412,9 @@ func TransformSourceToObj(ctx android.ModuleContext, subdir string, srcFiles and
|
||||
},
|
||||
})
|
||||
continue
|
||||
case ".o":
|
||||
objFiles[i] = srcFile
|
||||
continue
|
||||
}
|
||||
|
||||
var moduleCflags string
|
||||
@@ -627,11 +631,12 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext,
|
||||
Inputs: objFiles,
|
||||
Implicits: deps,
|
||||
Args: map[string]string{
|
||||
"ldCmd": ldCmd,
|
||||
"crtBegin": crtBegin.String(),
|
||||
"libFlags": strings.Join(libFlagsList, " "),
|
||||
"ldFlags": flags.ldFlags,
|
||||
"crtEnd": crtEnd.String(),
|
||||
"ldCmd": ldCmd,
|
||||
"crtBegin": crtBegin.String(),
|
||||
"libFlags": strings.Join(libFlagsList, " "),
|
||||
"extraLibFlags": flags.extraLibFlags,
|
||||
"ldFlags": flags.ldFlags,
|
||||
"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
|
||||
LdFlags []string // Flags that apply to linker command lines
|
||||
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
|
||||
SAbiFlags []string // Flags that apply to header-abi-dumper
|
||||
YasmFlags []string // Flags that apply to yasm assembly source files
|
||||
@@ -182,17 +183,6 @@ type Flags struct {
|
||||
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
|
||||
type BaseProperties struct {
|
||||
// Deprecated. true is the default, false is invalid.
|
||||
|
@@ -2203,7 +2203,7 @@ func TestStaticExecutable(t *testing.T) {
|
||||
ctx := testCc(t, `
|
||||
cc_binary {
|
||||
name: "static_test",
|
||||
srcs: ["foo.c"],
|
||||
srcs: ["foo.c", "baz.o"],
|
||||
static_executable: true,
|
||||
}`)
|
||||
|
||||
|
@@ -113,6 +113,9 @@ type LibraryProperties struct {
|
||||
|
||||
// Order symbols in .bss section by their sizes. Only useful for shared libraries.
|
||||
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 {
|
||||
@@ -766,9 +769,21 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
||||
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
|
||||
library.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags)
|
||||
}
|
||||
|
||||
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 ctx.Host() {
|
||||
versionedOutputFile := outputFile
|
||||
|
@@ -24,23 +24,26 @@ func TestLibraryReuse(t *testing.T) {
|
||||
ctx := testCc(t, `
|
||||
cc_library {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.c"],
|
||||
srcs: ["foo.c", "baz.o"],
|
||||
}`)
|
||||
|
||||
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")
|
||||
|
||||
if len(libfooShared.Inputs) != 1 {
|
||||
if len(libfooShared.Inputs) != 2 {
|
||||
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())
|
||||
}
|
||||
|
||||
if libfooShared.Inputs[0] != libfooStatic.Inputs[0] {
|
||||
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) {
|
||||
|
20
cc/object.go
20
cc/object.go
@@ -33,6 +33,20 @@ type objectLinker struct {
|
||||
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
|
||||
// necessary, but sometimes used to generate .s files from .c files to use as
|
||||
// input to a cc_genrule module.
|
||||
@@ -71,9 +85,13 @@ func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) 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())
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
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() {
|
||||
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
||||
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
||||
flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs")
|
||||
if ctx.staticBinary() {
|
||||
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
|
||||
flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...)
|
||||
} else {
|
||||
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
|
||||
flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...)
|
||||
}
|
||||
if ctx.Windows() {
|
||||
// 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.
|
||||
if !ctx.toolchain().Bionic() {
|
||||
flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
|
||||
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
|
||||
flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs")
|
||||
if ctx.staticBinary() {
|
||||
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
|
||||
flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...)
|
||||
} else {
|
||||
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
|
||||
flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...)
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@@ -272,7 +272,9 @@ func CreateTestContext(bp string, fs map[string][]byte,
|
||||
mockFS := map[string][]byte{
|
||||
"Android.bp": []byte(bp),
|
||||
"foo.c": nil,
|
||||
"foo.lds": nil,
|
||||
"bar.c": nil,
|
||||
"baz.o": nil,
|
||||
"a.proto": nil,
|
||||
"b.aidl": nil,
|
||||
"sub/c.aidl": nil,
|
||||
|
@@ -67,6 +67,7 @@ func flagsToBuilderFlags(in Flags) builderFlags {
|
||||
rsFlags: strings.Join(in.rsFlags, " "),
|
||||
ldFlags: strings.Join(in.LdFlags, " "),
|
||||
libFlags: strings.Join(in.libFlags, " "),
|
||||
extraLibFlags: strings.Join(in.extraLibFlags, " "),
|
||||
tidyFlags: strings.Join(in.TidyFlags, " "),
|
||||
sAbiFlags: strings.Join(in.SAbiFlags, " "),
|
||||
yasmFlags: strings.Join(in.YasmFlags, " "),
|
||||
|
Reference in New Issue
Block a user