2016-07-30 03:48:20 +08:00
|
|
|
// Copyright 2016 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
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
import (
|
|
|
|
"android/soong/android"
|
2018-10-09 06:10:12 +08:00
|
|
|
"android/soong/cc/config"
|
2016-07-30 08:28:03 +08:00
|
|
|
"fmt"
|
2018-12-01 06:00:04 +08:00
|
|
|
"strconv"
|
2016-09-30 05:06:02 +08:00
|
|
|
|
2018-02-16 06:12:26 +08:00
|
|
|
"github.com/google/blueprint"
|
2016-09-30 05:06:02 +08:00
|
|
|
"github.com/google/blueprint/proptools"
|
2016-07-30 08:28:03 +08:00
|
|
|
)
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
// This file contains the basic functionality for linking against static libraries and shared
|
|
|
|
// libraries. Final linking into libraries or executables is handled in library.go, binary.go, etc.
|
|
|
|
|
|
|
|
type BaseLinkerProperties struct {
|
|
|
|
// list of modules whose object files should be linked into this module
|
|
|
|
// in their entirety. For static library modules, all of the .o files from the intermediate
|
|
|
|
// directory of the dependency will be linked into this modules .a file. For a shared library,
|
|
|
|
// the dependency's .a file will be linked into this module using -Wl,--whole-archive.
|
|
|
|
Whole_static_libs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
|
|
|
// list of modules that should be statically linked into this module.
|
|
|
|
Static_libs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
|
|
|
// list of modules that should be dynamically linked into this module.
|
|
|
|
Shared_libs []string `android:"arch_variant"`
|
|
|
|
|
2016-12-14 04:50:57 +08:00
|
|
|
// list of modules that should only provide headers for this module.
|
|
|
|
Header_libs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
// list of module-specific flags that will be used for all link steps
|
|
|
|
Ldflags []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of system libraries that will be dynamically linked to
|
2017-08-19 07:52:25 +08:00
|
|
|
// shared library and executable modules. If unset, generally defaults to libc,
|
|
|
|
// libm, and libdl. Set to [] to prevent linking against the defaults.
|
2018-12-04 07:25:46 +08:00
|
|
|
System_shared_libs []string `android:"arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
// allow the module to contain undefined symbols. By default,
|
|
|
|
// modules cannot contain undefined symbols that are not satisified by their immediate
|
|
|
|
// dependencies. Set this flag to true to remove --no-undefined from the linker flags.
|
|
|
|
// This flag should only be necessary for compiling low-level libraries like libc.
|
2016-12-09 01:45:21 +08:00
|
|
|
Allow_undefined_symbols *bool `android:"arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-10-11 04:43:02 +08:00
|
|
|
// don't link in libclang_rt.builtins-*.a
|
2019-02-16 02:07:18 +08:00
|
|
|
No_libcrt *bool `android:"arch_variant"`
|
2018-10-11 04:43:02 +08:00
|
|
|
|
2018-04-04 02:33:34 +08:00
|
|
|
// Use clang lld instead of gnu ld.
|
2018-04-21 02:52:42 +08:00
|
|
|
Use_clang_lld *bool `android:"arch_variant"`
|
2018-04-04 02:33:34 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
// -l arguments to pass to linker for host-provided shared libraries
|
|
|
|
Host_ldlibs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of shared libraries to re-export include directories from. Entries must be
|
|
|
|
// present in shared_libs.
|
|
|
|
Export_shared_lib_headers []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// list of static libraries to re-export include directories from. Entries must be
|
|
|
|
// present in static_libs.
|
|
|
|
Export_static_lib_headers []string `android:"arch_variant"`
|
|
|
|
|
2016-12-14 04:50:57 +08:00
|
|
|
// list of header libraries to re-export include directories from. Entries must be
|
|
|
|
// present in header_libs.
|
|
|
|
Export_header_lib_headers []string `android:"arch_variant"`
|
|
|
|
|
2016-09-29 08:34:58 +08:00
|
|
|
// list of generated headers to re-export include directories from. Entries must be
|
|
|
|
// present in generated_headers.
|
|
|
|
Export_generated_headers []string `android:"arch_variant"`
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
// don't link in crt_begin and crt_end. This flag should only be necessary for
|
|
|
|
// compiling crt or libc.
|
|
|
|
Nocrt *bool `android:"arch_variant"`
|
2016-12-02 06:45:23 +08:00
|
|
|
|
|
|
|
// group static libraries. This can resolve missing symbols issues with interdependencies
|
|
|
|
// between static libraries, but it is generally better to order them correctly instead.
|
|
|
|
Group_static_libs *bool `android:"arch_variant"`
|
2017-06-16 11:03:55 +08:00
|
|
|
|
2017-12-20 01:17:32 +08:00
|
|
|
// list of modules that should be installed with this module. This is similar to 'required'
|
|
|
|
// but '.vendor' suffix will be appended to the module names if the shared libraries have
|
|
|
|
// vendor variants and this module uses VNDK.
|
|
|
|
Runtime_libs []string `android:"arch_variant"`
|
|
|
|
|
2017-06-16 11:03:55 +08:00
|
|
|
Target struct {
|
|
|
|
Vendor struct {
|
2018-11-07 00:12:13 +08:00
|
|
|
// list of shared libs that only should be used to build the vendor
|
|
|
|
// variant of the C/C++ module.
|
|
|
|
Shared_libs []string
|
|
|
|
|
2017-12-20 01:17:32 +08:00
|
|
|
// list of shared libs that should not be used to build the vendor variant
|
|
|
|
// of the C/C++ module.
|
2017-06-16 11:03:55 +08:00
|
|
|
Exclude_shared_libs []string
|
2017-10-13 08:17:01 +08:00
|
|
|
|
2017-12-20 01:17:32 +08:00
|
|
|
// list of static libs that should not be used to build the vendor variant
|
|
|
|
// of the C/C++ module.
|
2017-10-13 08:17:01 +08:00
|
|
|
Exclude_static_libs []string
|
2017-12-20 01:17:32 +08:00
|
|
|
|
2018-08-09 01:58:34 +08:00
|
|
|
// list of header libs that should not be used to build the vendor variant
|
|
|
|
// of the C/C++ module.
|
|
|
|
Exclude_header_libs []string
|
|
|
|
|
2017-12-20 01:17:32 +08:00
|
|
|
// list of runtime libs that should not be installed along with the vendor
|
|
|
|
// variant of the C/C++ module.
|
|
|
|
Exclude_runtime_libs []string
|
2018-10-25 03:42:09 +08:00
|
|
|
|
|
|
|
// version script for this vendor variant
|
|
|
|
Version_script *string `android:"arch_variant"`
|
2017-06-16 11:03:55 +08:00
|
|
|
}
|
2018-01-31 23:54:12 +08:00
|
|
|
Recovery struct {
|
2018-11-07 00:12:13 +08:00
|
|
|
// list of shared libs that only should be used to build the recovery
|
|
|
|
// variant of the C/C++ module.
|
|
|
|
Shared_libs []string
|
|
|
|
|
2019-08-02 04:45:42 +08:00
|
|
|
// list of static libs that only should be used to build the recovery
|
|
|
|
// variant of the C/C++ module.
|
|
|
|
Static_libs []string
|
|
|
|
|
2018-01-31 23:54:12 +08:00
|
|
|
// list of shared libs that should not be used to build
|
|
|
|
// the recovery variant of the C/C++ module.
|
|
|
|
Exclude_shared_libs []string
|
|
|
|
|
|
|
|
// list of static libs that should not be used to build
|
|
|
|
// the recovery variant of the C/C++ module.
|
|
|
|
Exclude_static_libs []string
|
2018-08-11 00:08:13 +08:00
|
|
|
|
|
|
|
// list of header libs that should not be used to build the recovery variant
|
|
|
|
// of the C/C++ module.
|
|
|
|
Exclude_header_libs []string
|
2018-01-31 23:54:12 +08:00
|
|
|
}
|
2017-06-16 11:03:55 +08:00
|
|
|
}
|
2018-02-16 06:12:26 +08:00
|
|
|
|
|
|
|
// make android::build:GetBuildNumber() available containing the build ID.
|
|
|
|
Use_version_lib *bool `android:"arch_variant"`
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-05-24 09:30:46 +08:00
|
|
|
// Generate compact dynamic relocation table, default true.
|
|
|
|
Pack_relocations *bool `android:"arch_variant"`
|
2018-07-27 05:00:24 +08:00
|
|
|
|
|
|
|
// local file name to pass to the linker as --version_script
|
2019-03-05 14:35:41 +08:00
|
|
|
Version_script *string `android:"path,arch_variant"`
|
2018-05-24 09:30:46 +08:00
|
|
|
}
|
|
|
|
|
2018-07-27 05:00:24 +08:00
|
|
|
func NewBaseLinker(sanitize *sanitize) *baseLinker {
|
|
|
|
return &baseLinker{sanitize: sanitize}
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
// baseLinker provides support for shared_libs, static_libs, and whole_static_libs properties
|
|
|
|
type baseLinker struct {
|
|
|
|
Properties BaseLinkerProperties
|
|
|
|
dynamicProperties struct {
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
RunPaths []string `blueprint:"mutated"`
|
|
|
|
BuildStubs bool `blueprint:"mutated"`
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2018-07-27 05:00:24 +08:00
|
|
|
|
|
|
|
sanitize *sanitize
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (linker *baseLinker) appendLdflags(flags []string) {
|
|
|
|
linker.Properties.Ldflags = append(linker.Properties.Ldflags, flags...)
|
|
|
|
}
|
|
|
|
|
2016-08-02 04:20:05 +08:00
|
|
|
func (linker *baseLinker) linkerInit(ctx BaseModuleContext) {
|
2016-07-30 03:48:20 +08:00
|
|
|
if ctx.toolchain().Is64Bit() {
|
2016-07-30 08:28:03 +08:00
|
|
|
linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "../lib64", "lib64")
|
2016-07-30 03:48:20 +08:00
|
|
|
} else {
|
2016-07-30 08:28:03 +08:00
|
|
|
linker.dynamicProperties.RunPaths = append(linker.dynamicProperties.RunPaths, "../lib", "lib")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 04:20:05 +08:00
|
|
|
func (linker *baseLinker) linkerProps() []interface{} {
|
2018-10-25 03:42:09 +08:00
|
|
|
return []interface{}{&linker.Properties, &linker.dynamicProperties}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2018-07-27 05:00:24 +08:00
|
|
|
func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
|
2016-12-14 04:50:57 +08:00
|
|
|
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
|
2017-12-20 01:17:32 +08:00
|
|
|
deps.RuntimeLibs = append(deps.RuntimeLibs, linker.Properties.Runtime_libs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-12-14 04:50:57 +08:00
|
|
|
deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders, linker.Properties.Export_header_lib_headers...)
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...)
|
|
|
|
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
|
2016-09-29 08:34:58 +08:00
|
|
|
deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-02-16 06:12:26 +08:00
|
|
|
if Bool(linker.Properties.Use_version_lib) {
|
|
|
|
deps.WholeStaticLibs = append(deps.WholeStaticLibs, "libbuildversion")
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:01:44 +08:00
|
|
|
if ctx.useVndk() {
|
2018-11-07 00:12:13 +08:00
|
|
|
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Target.Vendor.Shared_libs...)
|
2017-08-09 23:48:06 +08:00
|
|
|
deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Vendor.Exclude_shared_libs)
|
|
|
|
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Vendor.Exclude_shared_libs)
|
2017-10-13 08:17:01 +08:00
|
|
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, linker.Properties.Target.Vendor.Exclude_static_libs)
|
2018-08-09 01:58:34 +08:00
|
|
|
deps.HeaderLibs = removeListFromList(deps.HeaderLibs, linker.Properties.Target.Vendor.Exclude_header_libs)
|
2017-10-13 08:17:01 +08:00
|
|
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Vendor.Exclude_static_libs)
|
|
|
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Vendor.Exclude_static_libs)
|
2017-12-20 01:17:32 +08:00
|
|
|
deps.RuntimeLibs = removeListFromList(deps.RuntimeLibs, linker.Properties.Target.Vendor.Exclude_runtime_libs)
|
2017-08-09 23:48:06 +08:00
|
|
|
}
|
|
|
|
|
2018-01-31 23:54:12 +08:00
|
|
|
if ctx.inRecovery() {
|
2018-11-07 00:12:13 +08:00
|
|
|
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Target.Recovery.Shared_libs...)
|
2018-01-31 23:54:12 +08:00
|
|
|
deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Recovery.Exclude_shared_libs)
|
|
|
|
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Recovery.Exclude_shared_libs)
|
2019-08-02 04:45:42 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Target.Recovery.Static_libs...)
|
2018-01-31 23:54:12 +08:00
|
|
|
deps.StaticLibs = removeListFromList(deps.StaticLibs, linker.Properties.Target.Recovery.Exclude_static_libs)
|
2018-08-11 00:08:13 +08:00
|
|
|
deps.HeaderLibs = removeListFromList(deps.HeaderLibs, linker.Properties.Target.Recovery.Exclude_header_libs)
|
|
|
|
deps.ReexportHeaderLibHeaders = removeListFromList(deps.ReexportHeaderLibHeaders, linker.Properties.Target.Recovery.Exclude_header_libs)
|
2018-01-31 23:54:12 +08:00
|
|
|
deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, linker.Properties.Target.Recovery.Exclude_static_libs)
|
|
|
|
deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, linker.Properties.Target.Recovery.Exclude_static_libs)
|
|
|
|
}
|
|
|
|
|
2018-10-06 03:46:01 +08:00
|
|
|
if ctx.toolchain().Bionic() {
|
2019-02-13 01:41:18 +08:00
|
|
|
// libclang_rt.builtins, libgcc and libatomic have to be last on the command line
|
2018-10-11 04:43:02 +08:00
|
|
|
if !Bool(linker.Properties.No_libcrt) {
|
2019-02-13 01:41:18 +08:00
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
|
2019-03-30 11:05:14 +08:00
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic")
|
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc_stripped")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-15 21:12:43 +08:00
|
|
|
systemSharedLibs := linker.Properties.System_shared_libs
|
2018-12-04 07:25:46 +08:00
|
|
|
if systemSharedLibs == nil {
|
2019-01-15 21:12:43 +08:00
|
|
|
// Provide a default system_shared_libs if it is unspecified. Note: If an
|
|
|
|
// empty list [] is specified, it implies that the module declines the
|
|
|
|
// default system_shared_libs.
|
2018-12-04 07:25:46 +08:00
|
|
|
systemSharedLibs = []string{"libc", "libm", "libdl"}
|
|
|
|
}
|
2017-06-27 09:13:56 +08:00
|
|
|
|
2018-12-04 07:25:46 +08:00
|
|
|
if inList("libdl", deps.SharedLibs) {
|
|
|
|
// If system_shared_libs has libc but not libdl, make sure shared_libs does not
|
|
|
|
// have libdl to avoid loading libdl before libc.
|
|
|
|
if inList("libc", systemSharedLibs) {
|
|
|
|
if !inList("libdl", systemSharedLibs) {
|
|
|
|
ctx.PropertyErrorf("shared_libs",
|
|
|
|
"libdl must be in system_shared_libs, not shared_libs")
|
2017-06-27 09:13:56 +08:00
|
|
|
}
|
2018-12-04 07:25:46 +08:00
|
|
|
_, deps.SharedLibs = removeFromList("libdl", deps.SharedLibs)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2018-12-04 07:25:46 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2019-04-02 07:30:21 +08:00
|
|
|
if inList("libc_scudo", deps.SharedLibs) {
|
|
|
|
// libc_scudo is an alternate implementation of all
|
|
|
|
// allocation functions (malloc, free), that uses
|
|
|
|
// the scudo allocator instead of the default native
|
|
|
|
// allocator. If this library is in the list, make
|
|
|
|
// sure it's first so it properly overrides the
|
|
|
|
// allocation functions of all other shared libraries.
|
|
|
|
_, deps.SharedLibs = removeFromList("libc_scudo", deps.SharedLibs)
|
|
|
|
deps.SharedLibs = append([]string{"libc_scudo"}, deps.SharedLibs...)
|
|
|
|
}
|
|
|
|
|
2018-12-04 07:25:46 +08:00
|
|
|
// If libc and libdl are both in system_shared_libs make sure libdl comes after libc
|
|
|
|
// to avoid loading libdl before libc.
|
|
|
|
if inList("libdl", systemSharedLibs) && inList("libc", systemSharedLibs) &&
|
|
|
|
indexList("libdl", systemSharedLibs) < indexList("libc", systemSharedLibs) {
|
|
|
|
ctx.PropertyErrorf("system_shared_libs", "libdl must be after libc")
|
Split /system and /vendor modules, allow multi-installation
Nothing changes if BOARD_VNDK_VERSION isn't set.
When the VNDK is enabled (BOARD_VNDK_VERSION in Make), this will split
/system and /vendor modules into two different variant spaces that can't
link to each other. There are a few interfaces between the two variant
spaces:
The `llndk_library` stubs will be available in the /vendor variant, but
won't be installed, so at runtime the /system variant will be used.
Setting `vendor_available: true` will split a module into both variants.
The /system (or "core") variant will compile just like today. The
/vendor ("vendor") variant will compile against everything else in the
vendor space (so LL-NDK instead of libc/liblog/etc). There will be two
copies of these libraries installed onto the final device.
Since the available runtime interfaces for vendor modules may be
reduced, and your dependencies may not expose their private interfaces,
we allow the vendor variants to reduce their compilation set, and export
a different set of headers:
cc_library {
name: "libfoo",
srcs: ["common.cpp", "private_impl.cpp"],
export_include_dirs: ["include"],
target: {
vendor: {
export_include_dirs: ["include_vndk"],
exclude_srcs: ["private_impl.cpp"],
srcs: ["vendor_only.cpp"],
},
},
}
So the "core" variant would compile with both "common.cpp" and
"private_impl.cpp", and export "include".
The "vendor" variant would compile "common.cpp" and "vendor_only.cpp",
and export "include_vndk".
Bug: 36426473
Bug: 36079834
Test: out/soong/build.ninja, out/soong/Android- only changes due to _core addition and
.llndk -> .vendor
Test: attempt to compile with BOARD_VNDK_VERSION:=current
Change-Id: Idef28764043bf6c33dc0d2e7e2026c38867ff769
2017-04-07 03:43:22 +08:00
|
|
|
}
|
2018-12-04 07:25:46 +08:00
|
|
|
|
|
|
|
deps.LateSharedLibs = append(deps.LateSharedLibs, systemSharedLibs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2019-01-18 06:44:05 +08:00
|
|
|
if ctx.Fuchsia() {
|
|
|
|
if ctx.ModuleName() != "libbioniccompat" &&
|
|
|
|
ctx.ModuleName() != "libcompiler_rt-extras" &&
|
|
|
|
ctx.ModuleName() != "libcompiler_rt" {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libbioniccompat")
|
|
|
|
}
|
|
|
|
if ctx.ModuleName() != "libcompiler_rt" && ctx.ModuleName() != "libcompiler_rt-extras" {
|
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-05 03:59:48 +08:00
|
|
|
if ctx.Windows() {
|
2017-02-24 09:52:24 +08:00
|
|
|
deps.LateStaticLibs = append(deps.LateStaticLibs, "libwinpthread")
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:33:34 +08:00
|
|
|
func (linker *baseLinker) useClangLld(ctx ModuleContext) bool {
|
2018-04-25 07:00:01 +08:00
|
|
|
// Clang lld is not ready for for Darwin host executables yet.
|
|
|
|
// See https://lld.llvm.org/AtomLLD.html for status of lld for Mach-O.
|
|
|
|
if ctx.Darwin() {
|
|
|
|
return false
|
|
|
|
}
|
2018-04-04 02:33:34 +08:00
|
|
|
if linker.Properties.Use_clang_lld != nil {
|
|
|
|
return Bool(linker.Properties.Use_clang_lld)
|
|
|
|
}
|
2018-10-22 10:47:01 +08:00
|
|
|
return true
|
2018-04-04 02:33:34 +08:00
|
|
|
}
|
|
|
|
|
2018-12-01 06:00:04 +08:00
|
|
|
// Check whether the SDK version is not older than the specific one
|
|
|
|
func CheckSdkVersionAtLeast(ctx ModuleContext, SdkVersion int) bool {
|
|
|
|
if ctx.sdkVersion() == "current" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
parsedSdkVersion, err := strconv.Atoi(ctx.sdkVersion())
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("sdk_version",
|
|
|
|
"Invalid sdk_version value (must be int or current): %q",
|
|
|
|
ctx.sdkVersion())
|
|
|
|
}
|
|
|
|
if parsedSdkVersion < SdkVersion {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-04-04 02:33:34 +08:00
|
|
|
// ModuleContext extends BaseModuleContext
|
|
|
|
// BaseModuleContext should know if LLD is used?
|
2016-08-02 04:20:05 +08:00
|
|
|
func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2016-07-30 03:48:20 +08:00
|
|
|
toolchain := ctx.toolchain()
|
|
|
|
|
Consolidate ldflags that are used on all devices
Move ldflags that are specified for all devices into
deviceGlobalLdflags, and add them to linker.go:
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--build-id=md5
-Wl,--warn-shared-textrel
-Wl,--fatal-warnings
-Wl,--no-undefined-version
Bug: 68855788
Test: m checkbuild
Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e
2017-11-03 14:09:41 +08:00
|
|
|
hod := "Host"
|
|
|
|
if ctx.Os().Class == android.Device {
|
|
|
|
hod = "Device"
|
|
|
|
}
|
|
|
|
|
2018-10-08 11:54:34 +08:00
|
|
|
if linker.useClangLld(ctx) {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, fmt.Sprintf("${config.%sGlobalLldflags}", hod))
|
2018-10-25 03:42:09 +08:00
|
|
|
if !BoolDefault(linker.Properties.Pack_relocations, true) {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=none")
|
2018-12-01 06:00:04 +08:00
|
|
|
} else if ctx.Device() {
|
|
|
|
// The SHT_RELR relocations is only supported by API level >= 28.
|
|
|
|
// Do not turn this on if older version NDK is used.
|
|
|
|
if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 28) {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags,
|
|
|
|
"-Wl,--pack-dyn-relocs=android+relr",
|
|
|
|
"-Wl,--use-android-relr-tags")
|
2018-12-01 06:00:04 +08:00
|
|
|
}
|
2018-05-24 09:30:46 +08:00
|
|
|
}
|
2018-04-04 02:33:34 +08:00
|
|
|
} else {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod))
|
2018-04-04 02:33:34 +08:00
|
|
|
}
|
2017-11-04 04:31:05 +08:00
|
|
|
if Bool(linker.Properties.Allow_undefined_symbols) {
|
|
|
|
if ctx.Darwin() {
|
|
|
|
// darwin defaults to treating undefined symbols as errors
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-undefined,dynamic_lookup")
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2019-06-08 08:58:59 +08:00
|
|
|
} else if !ctx.Darwin() && !ctx.Windows() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--no-undefined")
|
2017-11-04 04:31:05 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2018-10-08 11:54:34 +08:00
|
|
|
if linker.useClangLld(ctx) {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, toolchain.ClangLldflags())
|
2017-11-04 04:31:05 +08:00
|
|
|
} else {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, toolchain.ClangLdflags())
|
2017-11-04 04:31:05 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2019-01-18 06:44:05 +08:00
|
|
|
if !ctx.toolchain().Bionic() && !ctx.Fuchsia() {
|
2017-11-04 04:31:05 +08:00
|
|
|
CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, linker.Properties.Host_ldlibs...)
|
2017-11-04 04:31:05 +08:00
|
|
|
|
|
|
|
if !ctx.Windows() {
|
|
|
|
// Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of device
|
|
|
|
// builds
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags,
|
2017-11-04 04:31:05 +08:00
|
|
|
"-ldl",
|
|
|
|
"-lpthread",
|
|
|
|
"-lm",
|
|
|
|
)
|
|
|
|
if !ctx.Darwin() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-lrt")
|
2017-09-09 03:45:18 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 06:44:05 +08:00
|
|
|
if ctx.Fuchsia() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-lfdio", "-lzircon")
|
2019-01-18 06:44:05 +08:00
|
|
|
}
|
|
|
|
|
2019-08-07 01:03:25 +08:00
|
|
|
if ctx.toolchain().LibclangRuntimeLibraryArch() != "" {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--exclude-libs="+config.BuiltinsRuntimeLibrary(ctx.toolchain())+".a")
|
2019-08-07 01:03:25 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags)
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, proptools.NinjaAndShellEscapeList(linker.Properties.Ldflags)...)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2019-06-08 08:58:59 +08:00
|
|
|
if ctx.Host() && !ctx.Windows() {
|
2016-07-30 03:48:20 +08:00
|
|
|
rpath_prefix := `\$$ORIGIN/`
|
|
|
|
if ctx.Darwin() {
|
|
|
|
rpath_prefix = "@loader_path/"
|
|
|
|
}
|
|
|
|
|
2017-09-19 13:45:15 +08:00
|
|
|
if !ctx.static() {
|
|
|
|
for _, rpath := range linker.dynamicProperties.RunPaths {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,-rpath,"+rpath_prefix+rpath)
|
2017-09-19 13:45:15 +08:00
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:01:44 +08:00
|
|
|
if ctx.useSdk() && (ctx.Arch().ArchType != android.Mips && ctx.Arch().ArchType != android.Mips64) {
|
2017-08-12 04:23:57 +08:00
|
|
|
// The bionic linker now has support gnu style hashes (which are much faster!), but shipping
|
|
|
|
// to older devices requires the old style hash. Fortunately, we can build with both and
|
|
|
|
// it'll work anywhere.
|
|
|
|
// This is not currently supported on MIPS architectures.
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--hash-style=both")
|
2017-08-12 04:23:57 +08:00
|
|
|
}
|
|
|
|
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, toolchain.ToolchainClangLdflags())
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-12-02 06:45:23 +08:00
|
|
|
if Bool(linker.Properties.Group_static_libs) {
|
|
|
|
flags.GroupStaticLibs = true
|
|
|
|
}
|
|
|
|
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
// Version_script is not needed when linking stubs lib where the version
|
|
|
|
// script is created from the symbol map file.
|
|
|
|
if !linker.dynamicProperties.BuildStubs {
|
|
|
|
versionScript := ctx.ExpandOptionalSource(
|
2018-10-25 03:42:09 +08:00
|
|
|
linker.Properties.Version_script, "version_script")
|
2018-07-27 05:00:24 +08:00
|
|
|
|
2018-10-25 03:42:09 +08:00
|
|
|
if ctx.useVndk() && linker.Properties.Target.Vendor.Version_script != nil {
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
versionScript = ctx.ExpandOptionalSource(
|
2018-10-25 03:42:09 +08:00
|
|
|
linker.Properties.Target.Vendor.Version_script,
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
"target.vendor.version_script")
|
|
|
|
}
|
2018-07-27 05:00:24 +08:00
|
|
|
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
if versionScript.Valid() {
|
|
|
|
if ctx.Darwin() {
|
|
|
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
|
|
|
} else {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
"-Wl,--version-script,"+versionScript.String())
|
|
|
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, versionScript.Path())
|
|
|
|
|
|
|
|
if linker.sanitize.isSanitizerEnabled(cfi) {
|
|
|
|
cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath)
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
Add support for versioned stubs.
A cc_library or cc_library_shared can be configured to have stubs
variants of the lib.
cc_library_shared {
name: "libfoo",
srcs: ["foo.cpp"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
then, stubs variants of libfoo for version 1, 2, and 3 are created
from foo.map.txt. Each version has the symbols from the map file where
each symbol is annotated with the version that the symbol was introduced
via the 'introduced=<ver>' syntax. The versions don't need to be in sync
with the platform versions (e.g., P for 28). The versions are local to
the library.
For another library or executable to use the versioned stubs lib, use
the new 'name#ver' syntax to specify the version:
cc_binary {
name: "test",
....
shared_libs: ["libFoo#2"],
}
Internally, a new mutator 'version' is applied to all cc.Module objects.
By default, a variant named 'impl' is created for the non-stub version.
If the versions property is set, additional variations are created per a
version with the mutable property BuildStubs set as true, which lets the
compiler and the linker to build a stubs lib from the symbol file
instead from the source files.
This feature will be used to enforce stable interfaces among APEXs. When
a lib foo in an APEX is depending on a lib bar in another APEX, then bar
should have stable interface (in C lang) and foo should be depending on
one of the stubs libs of bar. Only libraries in the same APEX as foo can
link against non-stub version of it.
Bug: 112672359
Test: m (cc_test added)
Change-Id: I2488be0b9d7b7b8d7761234dc1c9c0e3add8601c
2018-10-15 21:25:07 +08:00
|
|
|
"-Wl,--version-script,"+cfiExportsMap.String())
|
|
|
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, cfiExportsMap)
|
|
|
|
}
|
2018-07-27 05:00:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
2016-07-30 08:28:03 +08:00
|
|
|
func (linker *baseLinker) link(ctx ModuleContext,
|
2016-09-27 08:33:01 +08:00
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
2016-07-30 08:28:03 +08:00
|
|
|
panic(fmt.Errorf("baseLinker doesn't know how to link"))
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
2018-02-16 06:12:26 +08:00
|
|
|
|
|
|
|
// Injecting version symbols
|
|
|
|
// Some host modules want a version number, but we don't want to rebuild it every time. Optionally add a step
|
|
|
|
// after linking that injects a constant placeholder with the current version number.
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pctx.HostBinToolVariable("symbolInjectCmd", "symbol_inject")
|
|
|
|
}
|
|
|
|
|
|
|
|
var injectVersionSymbol = pctx.AndroidStaticRule("injectVersionSymbol",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "$symbolInjectCmd -i $in -o $out -s soong_build_number " +
|
|
|
|
"-from 'SOONG BUILD NUMBER PLACEHOLDER' -v $buildNumberFromFile",
|
|
|
|
CommandDeps: []string{"$symbolInjectCmd"},
|
|
|
|
},
|
|
|
|
"buildNumberFromFile")
|
|
|
|
|
|
|
|
func (linker *baseLinker) injectVersionSymbol(ctx ModuleContext, in android.Path, out android.WritablePath) {
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: injectVersionSymbol,
|
|
|
|
Description: "inject version symbol",
|
|
|
|
Input: in,
|
|
|
|
Output: out,
|
|
|
|
Args: map[string]string{
|
2019-07-16 23:27:32 +08:00
|
|
|
"buildNumberFromFile": proptools.NinjaEscape(ctx.Config().BuildNumberFromFile()),
|
2018-02-16 06:12:26 +08:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2019-06-25 07:08:48 +08:00
|
|
|
|
|
|
|
// Rule to generate .bss symbol ordering file.
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ = pctx.SourcePathVariable("genSortedBssSymbolsPath", "build/soong/scripts/gen_sorted_bss_symbols.sh")
|
|
|
|
gen_sorted_bss_symbols = pctx.AndroidStaticRule("gen_sorted_bss_symbols",
|
|
|
|
blueprint.RuleParams{
|
|
|
|
Command: "CROSS_COMPILE=$crossCompile $genSortedBssSymbolsPath ${in} ${out}",
|
2019-09-20 01:50:18 +08:00
|
|
|
CommandDeps: []string{"$genSortedBssSymbolsPath", "${crossCompile}nm"},
|
2019-06-25 07:08:48 +08:00
|
|
|
},
|
|
|
|
"crossCompile")
|
|
|
|
)
|
|
|
|
|
|
|
|
func (linker *baseLinker) sortBssSymbolsBySize(ctx ModuleContext, in android.Path, symbolOrderingFile android.ModuleOutPath, flags builderFlags) string {
|
|
|
|
crossCompile := gccCmd(flags.toolchain, "")
|
|
|
|
ctx.Build(pctx, android.BuildParams{
|
|
|
|
Rule: gen_sorted_bss_symbols,
|
|
|
|
Description: "generate bss symbol order " + symbolOrderingFile.Base(),
|
|
|
|
Output: symbolOrderingFile,
|
|
|
|
Input: in,
|
|
|
|
Args: map[string]string{
|
|
|
|
"crossCompile": crossCompile,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return "-Wl,--symbol-ordering-file," + symbolOrderingFile.String()
|
|
|
|
}
|