1// Copyright 2015 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 15package cc 16 17import ( 18 "strings" 19 20 "android/soong/common" 21) 22 23var ( 24 arm64Cflags = []string{ 25 "-fno-exceptions", // from build/core/combo/select.mk 26 "-Wno-multichar", // from build/core/combo/select.mk 27 "-fno-strict-aliasing", 28 "-fstack-protector-strong", 29 "-ffunction-sections", 30 "-fdata-sections", 31 "-funwind-tables", 32 "-Wa,--noexecstack", 33 "-Werror=format-security", 34 "-D_FORTIFY_SOURCE=2", 35 "-fno-short-enums", 36 "-no-canonical-prefixes", 37 "-fno-canonical-system-headers", 38 39 // Help catch common 32/64-bit errors. 40 "-Werror=pointer-to-int-cast", 41 "-Werror=int-to-pointer-cast", 42 43 "-fno-strict-volatile-bitfields", 44 45 // TARGET_RELEASE_CFLAGS 46 "-DNDEBUG", 47 "-O2 -g", 48 "-Wstrict-aliasing=2", 49 "-fgcse-after-reload", 50 "-frerun-cse-after-loop", 51 "-frename-registers", 52 } 53 54 arm64Ldflags = []string{ 55 "-Wl,-z,noexecstack", 56 "-Wl,-z,relro", 57 "-Wl,-z,now", 58 "-Wl,--build-id=md5", 59 "-Wl,--warn-shared-textrel", 60 "-Wl,--fatal-warnings", 61 "-Wl,-maarch64linux", 62 "-Wl,--hash-style=gnu", 63 "-Wl,--fix-cortex-a53-843419", 64 "-fuse-ld=gold", 65 "-Wl,--icf=safe", 66 "-Wl,--no-undefined-version", 67 68 // Disable transitive dependency library symbol resolving. 69 "-Wl,--allow-shlib-undefined", 70 } 71 72 arm64Cppflags = []string{ 73 "-fvisibility-inlines-hidden", 74 } 75) 76 77const ( 78 arm64GccVersion = "4.9" 79) 80 81func init() { 82 pctx.StaticVariable("arm64GccVersion", arm64GccVersion) 83 84 pctx.SourcePathVariable("arm64GccRoot", 85 "prebuilts/gcc/${HostPrebuiltTag}/aarch64/aarch64-linux-android-${arm64GccVersion}") 86 87 pctx.StaticVariable("arm64GccTriple", "aarch64-linux-android") 88 89 pctx.StaticVariable("arm64Cflags", strings.Join(arm64Cflags, " ")) 90 pctx.StaticVariable("arm64Ldflags", strings.Join(arm64Ldflags, " ")) 91 pctx.StaticVariable("arm64Cppflags", strings.Join(arm64Cppflags, " ")) 92 pctx.StaticVariable("arm64IncludeFlags", strings.Join([]string{ 93 "-isystem ${LibcRoot}/arch-arm64/include", 94 "-isystem ${LibcRoot}/include", 95 "-isystem ${LibcRoot}/kernel/uapi", 96 "-isystem ${LibcRoot}/kernel/uapi/asm-arm64", 97 "-isystem ${LibmRoot}/include", 98 "-isystem ${LibmRoot}/include/arm64", 99 }, " ")) 100 101 pctx.StaticVariable("arm64ClangCflags", strings.Join(clangFilterUnknownCflags(arm64Cflags), " ")) 102 pctx.StaticVariable("arm64ClangLdflags", strings.Join(clangFilterUnknownCflags(arm64Ldflags), " ")) 103 pctx.StaticVariable("arm64ClangCppflags", strings.Join(clangFilterUnknownCflags(arm64Cppflags), " ")) 104} 105 106type toolchainArm64 struct { 107 toolchain64Bit 108} 109 110var toolchainArm64Singleton = &toolchainArm64{} 111 112func (t *toolchainArm64) Name() string { 113 return "arm64" 114} 115 116func (t *toolchainArm64) GccRoot() string { 117 return "${arm64GccRoot}" 118} 119 120func (t *toolchainArm64) GccTriple() string { 121 return "${arm64GccTriple}" 122} 123 124func (t *toolchainArm64) GccVersion() string { 125 return arm64GccVersion 126} 127 128func (t *toolchainArm64) Cflags() string { 129 return "${arm64Cflags}" 130} 131 132func (t *toolchainArm64) Cppflags() string { 133 return "${arm64Cppflags}" 134} 135 136func (t *toolchainArm64) Ldflags() string { 137 return "${arm64Ldflags}" 138} 139 140func (t *toolchainArm64) IncludeFlags() string { 141 return "${arm64IncludeFlags}" 142} 143 144func (t *toolchainArm64) ClangTriple() string { 145 return "${arm64GccTriple}" 146} 147 148func (t *toolchainArm64) ClangCflags() string { 149 return "${arm64ClangCflags}" 150} 151 152func (t *toolchainArm64) ClangCppflags() string { 153 return "${arm64ClangCppflags}" 154} 155 156func (t *toolchainArm64) ClangLdflags() string { 157 return "${arm64Ldflags}" 158} 159 160func arm64ToolchainFactory(arch common.Arch) Toolchain { 161 return toolchainArm64Singleton 162} 163 164func init() { 165 registerDeviceToolchainFactory(common.Arm64, arm64ToolchainFactory) 166} 167