summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2019-08-23 00:15:08 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2019-08-23 00:15:08 +0000
commit792942de478c00f95ea6d23e7e7a11ddd967cfd4 (patch)
tree4dec0542054838249c61b30645b08a3b48f625bf
parentb020d570038c184a5f1c8523ccf113d742c0fae4 (diff)
parent803e161ac92aaea5edc2d66d9ed7b888267e130c (diff)
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.
-rw-r--r--Android.bp1
-rw-r--r--android/paths.go4
-rw-r--r--cc/builder.go19
-rw-r--r--cc/cc.go12
-rw-r--r--cc/cc_test.go2
-rw-r--r--cc/library.go17
-rw-r--r--cc/library_test.go9
-rw-r--r--cc/object.go20
-rw-r--r--cc/object_test.go31
-rw-r--r--cc/stl.go12
-rw-r--r--cc/testing.go2
-rw-r--r--cc/util.go1
12 files changed, 100 insertions, 30 deletions
diff --git a/Android.bp b/Android.bp
index 4e44a0d58..5c76f5a19 100644
--- a/Android.bp
+++ b/Android.bp
@@ -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",
diff --git a/android/paths.go b/android/paths.go
index 51106170c..0d64a61db 100644
--- a/android/paths.go
+++ b/android/paths.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())
}
diff --git a/cc/builder.go b/cc/builder.go
index 3d897704b..00dc742e8 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -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(),
},
})
}
diff --git a/cc/cc.go b/cc/cc.go
index c853e67d8..0245c6a18 100644
--- a/cc/cc.go
+++ b/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.
diff --git a/cc/cc_test.go b/cc/cc_test.go
index c4799e923..52234a8d4 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -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,
}`)
diff --git a/cc/library.go b/cc/library.go
index 0869727fc..249671240 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -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
diff --git a/cc/library_test.go b/cc/library_test.go
index 859b05aff..2acae35cf 100644
--- a/cc/library_test.go
+++ b/cc/library_test.go
@@ -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) {
diff --git a/cc/object.go b/cc/object.go
index 15272eb54..1a2711d2c 100644
--- a/cc/object.go
+++ b/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
}
diff --git a/cc/object_test.go b/cc/object_test.go
new file mode 100644
index 000000000..6ff8a00c3
--- /dev/null
+++ b/cc/object_test.go
@@ -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",
+ }`)
+ })
+
+}
diff --git a/cc/stl.go b/cc/stl.go
index d7feb6fdf..557829918 100644
--- a/cc/stl.go
+++ b/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:
diff --git a/cc/testing.go b/cc/testing.go
index e69b774fc..5a3993c0e 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -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,
diff --git a/cc/util.go b/cc/util.go
index 0d1b2f049..fb6338ac2 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -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, " "),