Jiyong Park | 4afa2e2 | 2020-07-13 15:43:45 +0900 | [diff] [blame^] | 1 | // Copyright 2020 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "strings" |
| 20 | ) |
| 21 | |
| 22 | var ( |
| 23 | // This is a host toolchain but flags for device toolchain are required |
| 24 | // as the flags are actually for Bionic-based builds. |
| 25 | linuxCrossCflags = ClangFilterUnknownCflags(append(deviceGlobalCflags, |
| 26 | // clang by default enables PIC when the clang triple is set to *-android. |
| 27 | // See toolchain/llvm-project/clang/lib/Driver/ToolChains/CommonArgs.cpp#920. |
| 28 | // However, for this host target, we don't set "-android" to avoid __ANDROID__ macro |
| 29 | // which stands for "Android device target". Keeping PIC on is required because |
| 30 | // many modules we have (e.g. Bionic) assume PIC. |
| 31 | "-fpic", |
| 32 | )) |
| 33 | |
| 34 | linuxCrossLdflags = ClangFilterUnknownCflags([]string{ |
| 35 | "-Wl,-z,noexecstack", |
| 36 | "-Wl,-z,relro", |
| 37 | "-Wl,-z,now", |
| 38 | "-Wl,--build-id=md5", |
| 39 | "-Wl,--warn-shared-textrel", |
| 40 | "-Wl,--fatal-warnings", |
| 41 | "-Wl,--hash-style=gnu", |
| 42 | "-Wl,--no-undefined-version", |
| 43 | }) |
| 44 | ) |
| 45 | |
| 46 | func init() { |
| 47 | pctx.StaticVariable("LinuxBionicArm64Cflags", strings.Join(linuxCrossCflags, " ")) |
| 48 | pctx.StaticVariable("LinuxBionicArm64Ldflags", strings.Join(linuxCrossLdflags, " ")) |
| 49 | } |
| 50 | |
| 51 | // toolchain config for ARM64 Linux CrossHost. Almost everything is the same as the ARM64 Android |
| 52 | // target. The overridden methods below show the differences. |
| 53 | type toolchainLinuxArm64 struct { |
| 54 | toolchainArm64 |
| 55 | } |
| 56 | |
| 57 | func (toolchainLinuxArm64) ClangTriple() string { |
| 58 | // Note the absence of "-android" suffix. The compiler won't define __ANDROID__ |
| 59 | return "aarch64-linux" |
| 60 | } |
| 61 | |
| 62 | func (toolchainLinuxArm64) ClangCflags() string { |
| 63 | // The inherited flags + extra flags |
| 64 | return "${config.Arm64ClangCflags} ${config.LinuxBionicArm64Cflags}" |
| 65 | } |
| 66 | |
| 67 | func linuxArm64ToolchainFactory(arch android.Arch) Toolchain { |
| 68 | archVariant := "armv8-a" // for host, default to armv8-a |
| 69 | toolchainClangCflags := []string{arm64ClangArchVariantCflagsVar[archVariant]} |
| 70 | |
| 71 | // We don't specify CPU architecture for host. Conservatively assume |
| 72 | // the host CPU needs the fix |
| 73 | extraLdflags := "-Wl,--fix-cortex-a53-843419" |
| 74 | |
| 75 | ret := toolchainLinuxArm64{} |
| 76 | |
| 77 | // add the extra ld and lld flags |
| 78 | ret.toolchainArm64.ldflags = strings.Join([]string{ |
| 79 | "${config.Arm64Ldflags}", |
| 80 | "${config.LinuxBionicArm64Ldflags}", |
| 81 | extraLdflags, |
| 82 | }, " ") |
| 83 | ret.toolchainArm64.lldflags = strings.Join([]string{ |
| 84 | "${config.Arm64Lldflags}", |
| 85 | "${config.LinuxBionicArm64Ldflags}", |
| 86 | extraLdflags, |
| 87 | }, " ") |
| 88 | ret.toolchainArm64.toolchainClangCflags = strings.Join(toolchainClangCflags, " ") |
| 89 | return &ret |
| 90 | } |
| 91 | |
| 92 | func init() { |
| 93 | registerToolchainFactory(android.LinuxBionic, android.Arm64, linuxArm64ToolchainFactory) |
| 94 | } |