2015-01-31 02:27:36 +01:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
package config
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
import (
|
2015-03-18 20:28:32 +01:00
|
|
|
"fmt"
|
2017-03-13 20:40:30 +01:00
|
|
|
"path/filepath"
|
2015-03-18 20:28:32 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
type toolchainFactory func(arch android.Arch) Toolchain
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
func registerToolchainFactory(os android.OsType, arch android.ArchType, factory toolchainFactory) {
|
|
|
|
if toolchainFactories[os] == nil {
|
|
|
|
toolchainFactories[os] = make(map[android.ArchType]toolchainFactory)
|
|
|
|
}
|
|
|
|
toolchainFactories[os][arch] = factory
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2021-01-26 15:18:53 +01:00
|
|
|
type toolchainContext interface {
|
|
|
|
Os() android.OsType
|
|
|
|
Arch() android.Arch
|
|
|
|
}
|
|
|
|
|
|
|
|
type conversionContext interface {
|
|
|
|
BazelConversionMode() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindToolchainWithContext(ctx toolchainContext) Toolchain {
|
|
|
|
t, err := findToolchain(ctx.Os(), ctx.Arch())
|
|
|
|
if err != nil {
|
|
|
|
if c, ok := ctx.(conversionContext); ok && c.BazelConversionMode() {
|
|
|
|
// TODO(b/179123288): determine conversion for toolchain
|
|
|
|
return &toolchainX86_64{}
|
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func FindToolchain(os android.OsType, arch android.Arch) Toolchain {
|
2021-01-26 15:18:53 +01:00
|
|
|
t, err := findToolchain(os, arch)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func findToolchain(os android.OsType, arch android.Arch) (Toolchain, error) {
|
2016-07-29 22:44:28 +02:00
|
|
|
factory := toolchainFactories[os][arch.ArchType]
|
|
|
|
if factory == nil {
|
2021-01-26 15:18:53 +01:00
|
|
|
return nil, fmt.Errorf("Toolchain not found for %s arch %q", os.String(), arch.String())
|
2016-07-29 22:44:28 +02:00
|
|
|
}
|
2021-01-26 15:18:53 +01:00
|
|
|
return factory(arch), nil
|
2016-07-29 22:44:28 +02:00
|
|
|
}
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
type Toolchain interface {
|
2015-03-19 07:38:50 +01:00
|
|
|
Name() string
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
GccRoot() string
|
|
|
|
GccTriple() string
|
2015-12-07 21:30:44 +01:00
|
|
|
// GccVersion should return a real value, not a ninja reference
|
2015-03-19 07:38:50 +01:00
|
|
|
GccVersion() string
|
2017-03-13 20:40:30 +01:00
|
|
|
ToolPath() string
|
2015-12-07 21:30:44 +01:00
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
IncludeFlags() string
|
|
|
|
|
|
|
|
ClangTriple() string
|
2021-07-15 02:03:16 +02:00
|
|
|
ToolchainCflags() string
|
|
|
|
ToolchainLdflags() string
|
|
|
|
Asflags() string
|
|
|
|
Cflags() string
|
|
|
|
Cppflags() string
|
|
|
|
Ldflags() string
|
|
|
|
Lldflags() string
|
|
|
|
InstructionSetFlags(string) (string, error)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2018-03-16 02:44:57 +01:00
|
|
|
ndkTriple() string
|
|
|
|
|
2016-12-03 02:13:24 +01:00
|
|
|
YasmFlags() string
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
Is64Bit() bool
|
2015-11-25 02:53:15 +01:00
|
|
|
|
|
|
|
ShlibSuffix() string
|
|
|
|
ExecutableSuffix() string
|
2016-03-09 19:30:22 +01:00
|
|
|
|
2018-08-31 23:27:44 +02:00
|
|
|
LibclangRuntimeLibraryArch() string
|
2016-05-25 23:47:21 +02:00
|
|
|
|
|
|
|
AvailableLibraries() []string
|
2016-11-17 10:02:25 +01:00
|
|
|
|
2021-06-22 02:34:47 +02:00
|
|
|
CrtBeginStaticBinary() []string
|
|
|
|
CrtBeginSharedBinary() []string
|
|
|
|
CrtBeginSharedLibrary() []string
|
|
|
|
CrtEndStaticBinary() []string
|
|
|
|
CrtEndSharedBinary() []string
|
|
|
|
CrtEndSharedLibrary() []string
|
|
|
|
|
2021-06-22 02:31:50 +02:00
|
|
|
// DefaultSharedLibraries returns the list of shared libraries that will be added to all
|
|
|
|
// targets unless they explicitly specify system_shared_libs.
|
|
|
|
DefaultSharedLibraries() []string
|
|
|
|
|
2016-11-17 10:02:25 +01:00
|
|
|
Bionic() bool
|
2021-07-24 00:23:07 +02:00
|
|
|
Glibc() bool
|
|
|
|
Musl() bool
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 20:28:32 +01:00
|
|
|
type toolchainBase struct {
|
|
|
|
}
|
|
|
|
|
2018-03-16 02:44:57 +01:00
|
|
|
func (t *toolchainBase) ndkTriple() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func NDKTriple(toolchain Toolchain) string {
|
|
|
|
triple := toolchain.ndkTriple()
|
|
|
|
if triple == "" {
|
|
|
|
// Use the clang triple if there is no explicit NDK triple
|
|
|
|
triple = toolchain.ClangTriple()
|
|
|
|
}
|
|
|
|
return triple
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (toolchainBase) InstructionSetFlags(s string) (string, error) {
|
2015-11-03 23:27:00 +01:00
|
|
|
if s != "" {
|
|
|
|
return "", fmt.Errorf("instruction_set: %s is not a supported instruction set", s)
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (toolchainBase) ToolchainCflags() string {
|
2015-11-24 01:11:30 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (toolchainBase) ToolchainLdflags() string {
|
2016-03-31 02:33:52 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (toolchainBase) ShlibSuffix() string {
|
|
|
|
return ".so"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchainBase) ExecutableSuffix() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (toolchainBase) Asflags() string {
|
2016-01-13 07:25:34 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-12-03 02:13:24 +01:00
|
|
|
func (toolchainBase) YasmFlags() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2018-08-31 23:27:44 +02:00
|
|
|
func (toolchainBase) LibclangRuntimeLibraryArch() string {
|
2016-01-06 23:41:07 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:47:21 +02:00
|
|
|
func (toolchainBase) AvailableLibraries() []string {
|
2021-06-22 02:31:50 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-22 02:34:47 +02:00
|
|
|
func (toolchainBase) CrtBeginStaticBinary() []string { return nil }
|
|
|
|
func (toolchainBase) CrtBeginSharedBinary() []string { return nil }
|
|
|
|
func (toolchainBase) CrtBeginSharedLibrary() []string { return nil }
|
|
|
|
func (toolchainBase) CrtEndStaticBinary() []string { return nil }
|
|
|
|
func (toolchainBase) CrtEndSharedBinary() []string { return nil }
|
|
|
|
func (toolchainBase) CrtEndSharedLibrary() []string { return nil }
|
|
|
|
|
2021-06-22 02:31:50 +02:00
|
|
|
func (toolchainBase) DefaultSharedLibraries() []string {
|
|
|
|
return nil
|
2016-05-25 23:47:21 +02:00
|
|
|
}
|
|
|
|
|
2016-11-17 10:02:25 +01:00
|
|
|
func (toolchainBase) Bionic() bool {
|
2021-06-22 02:28:25 +02:00
|
|
|
return false
|
2016-11-17 10:02:25 +01:00
|
|
|
}
|
|
|
|
|
2021-07-24 00:23:07 +02:00
|
|
|
func (toolchainBase) Glibc() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchainBase) Musl() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-03-13 20:40:30 +01:00
|
|
|
func (t toolchainBase) ToolPath() string {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
type toolchain64Bit struct {
|
2015-03-18 20:28:32 +01:00
|
|
|
toolchainBase
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchain64Bit) Is64Bit() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type toolchain32Bit struct {
|
2015-03-18 20:28:32 +01:00
|
|
|
toolchainBase
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (toolchain32Bit) Is64Bit() bool {
|
|
|
|
return false
|
|
|
|
}
|
2016-07-29 22:44:28 +02:00
|
|
|
|
|
|
|
func variantOrDefault(variants map[string]string, choice string) string {
|
|
|
|
if ret, ok := variants[choice]; ok {
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
return variants[""]
|
|
|
|
}
|
|
|
|
|
|
|
|
func addPrefix(list []string, prefix string) []string {
|
|
|
|
for i := range list {
|
|
|
|
list[i] = prefix + list[i]
|
|
|
|
}
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2018-08-31 23:27:44 +02:00
|
|
|
func LibclangRuntimeLibrary(t Toolchain, library string) string {
|
|
|
|
arch := t.LibclangRuntimeLibraryArch()
|
2016-08-15 23:18:24 +02:00
|
|
|
if arch == "" {
|
|
|
|
return ""
|
|
|
|
}
|
2019-07-15 18:34:09 +02:00
|
|
|
if !t.Bionic() {
|
|
|
|
return "libclang_rt." + library + "-" + arch
|
|
|
|
}
|
2018-08-31 23:27:44 +02:00
|
|
|
return "libclang_rt." + library + "-" + arch + "-android"
|
|
|
|
}
|
|
|
|
|
|
|
|
func BuiltinsRuntimeLibrary(t Toolchain) string {
|
|
|
|
return LibclangRuntimeLibrary(t, "builtins")
|
2017-03-27 20:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func AddressSanitizerRuntimeLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "asan")
|
2016-08-15 23:18:24 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 01:19:13 +02:00
|
|
|
func HWAddressSanitizerRuntimeLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "hwasan")
|
2018-08-03 01:19:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func HWAddressSanitizerStaticLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "hwasan_static")
|
2018-08-03 01:19:13 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 23:18:24 +02:00
|
|
|
func UndefinedBehaviorSanitizerRuntimeLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "ubsan_standalone")
|
2017-03-27 20:00:38 +02:00
|
|
|
}
|
|
|
|
|
2018-02-22 00:49:20 +01:00
|
|
|
func UndefinedBehaviorSanitizerMinimalRuntimeLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "ubsan_minimal")
|
2018-02-22 00:49:20 +01:00
|
|
|
}
|
|
|
|
|
2017-03-27 20:00:38 +02:00
|
|
|
func ThreadSanitizerRuntimeLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "tsan")
|
2016-08-15 23:18:24 +02:00
|
|
|
}
|
2017-03-13 20:40:30 +01:00
|
|
|
|
2018-06-12 23:46:54 +02:00
|
|
|
func ScudoRuntimeLibrary(t Toolchain) string {
|
2018-08-31 23:27:44 +02:00
|
|
|
return LibclangRuntimeLibrary(t, "scudo")
|
2018-06-12 23:46:54 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 17:38:39 +02:00
|
|
|
func ScudoMinimalRuntimeLibrary(t Toolchain) string {
|
|
|
|
return LibclangRuntimeLibrary(t, "scudo_minimal")
|
|
|
|
}
|
|
|
|
|
2019-07-15 18:34:09 +02:00
|
|
|
func LibFuzzerRuntimeLibrary(t Toolchain) string {
|
|
|
|
return LibclangRuntimeLibrary(t, "fuzzer")
|
|
|
|
}
|
|
|
|
|
2017-03-13 20:40:30 +01:00
|
|
|
func ToolPath(t Toolchain) string {
|
|
|
|
if p := t.ToolPath(); p != "" {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
return filepath.Join(t.GccRoot(), t.GccTriple(), "bin")
|
|
|
|
}
|
2018-02-20 22:33:42 +01:00
|
|
|
|
|
|
|
var inList = android.InList
|