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 15 package config 16 17 import ( 18 "strings" 19 20 "android/soong/android" 21 ) 22 23 var ( 24 mips64Cflags = []string{ 25 "-fno-exceptions", // from build/core/combo/select.mk 26 "-Wno-multichar", // from build/core/combo/select.mk 27 "-O2", 28 "-fomit-frame-pointer", 29 "-fno-strict-aliasing", 30 "-funswitch-loops", 31 "-U__unix", 32 "-U__unix__", 33 "-Umips", 34 "-ffunction-sections", 35 "-fdata-sections", 36 "-funwind-tables", 37 "-fstack-protector-strong", 38 "-Wa,--noexecstack", 39 "-Werror=format-security", 40 "-D_FORTIFY_SOURCE=2", 41 "-no-canonical-prefixes", 42 "-fno-canonical-system-headers", 43 44 // Help catch common 32/64-bit errors. 45 "-Werror=pointer-to-int-cast", 46 "-Werror=int-to-pointer-cast", 47 "-Werror=implicit-function-declaration", 48 49 // TARGET_RELEASE_CFLAGS 50 "-DNDEBUG", 51 "-g", 52 "-Wstrict-aliasing=2", 53 "-fgcse-after-reload", 54 "-frerun-cse-after-loop", 55 "-frename-registers", 56 } 57 58 mips64ClangCflags = append(mips64Cflags, []string{ 59 "-fintegrated-as", 60 }...) 61 62 mips64Cppflags = []string{ 63 "-fvisibility-inlines-hidden", 64 } 65 66 mips64Ldflags = []string{ 67 "-Wl,-z,noexecstack", 68 "-Wl,-z,relro", 69 "-Wl,-z,now", 70 "-Wl,--build-id=md5", 71 "-Wl,--warn-shared-textrel", 72 "-Wl,--fatal-warnings", 73 "-Wl,--allow-shlib-undefined", 74 "-Wl,--no-undefined-version", 75 } 76 77 mips64ArchVariantCflags = map[string][]string{ 78 "mips64r2": []string{ 79 "-mips64r2", 80 "-msynci", 81 }, 82 "mips64r6": []string{ 83 "-mips64r6", 84 "-msynci", 85 }, 86 } 87 ) 88 89 const ( 90 mips64GccVersion = "4.9" 91 ) 92 93 func init() { 94 android.RegisterArchVariants(android.Mips64, 95 "mips64r2", 96 "mips64r6") 97 android.RegisterArchFeatures(android.Mips64, 98 "rev6", 99 "msa") 100 android.RegisterArchVariantFeatures(android.Mips64, "mips64r6", 101 "rev6") 102 103 pctx.StaticVariable("mips64GccVersion", mips64GccVersion) 104 105 pctx.SourcePathVariable("Mips64GccRoot", 106 "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mips64GccVersion}") 107 108 pctx.StaticVariable("Mips64Cflags", strings.Join(mips64Cflags, " ")) 109 pctx.StaticVariable("Mips64Ldflags", strings.Join(mips64Ldflags, " ")) 110 pctx.StaticVariable("Mips64Cppflags", strings.Join(mips64Cppflags, " ")) 111 pctx.StaticVariable("Mips64IncludeFlags", bionicHeaders("mips64", "mips")) 112 113 // Clang cflags 114 pctx.StaticVariable("Mips64ClangCflags", strings.Join(ClangFilterUnknownCflags(mips64ClangCflags), " ")) 115 pctx.StaticVariable("Mips64ClangLdflags", strings.Join(ClangFilterUnknownCflags(mips64Ldflags), " ")) 116 pctx.StaticVariable("Mips64ClangCppflags", strings.Join(ClangFilterUnknownCflags(mips64Cppflags), " ")) 117 118 // Extended cflags 119 120 // Architecture variant cflags 121 for variant, cflags := range mips64ArchVariantCflags { 122 pctx.StaticVariable("Mips64"+variant+"VariantCflags", strings.Join(cflags, " ")) 123 pctx.StaticVariable("Mips64"+variant+"VariantClangCflags", 124 strings.Join(ClangFilterUnknownCflags(cflags), " ")) 125 } 126 } 127 128 type toolchainMips64 struct { 129 toolchain64Bit 130 cflags, clangCflags string 131 toolchainCflags, toolchainClangCflags string 132 } 133 134 func (t *toolchainMips64) Name() string { 135 return "mips64" 136 } 137 138 func (t *toolchainMips64) GccRoot() string { 139 return "${config.Mips64GccRoot}" 140 } 141 142 func (t *toolchainMips64) GccTriple() string { 143 return "mips64el-linux-android" 144 } 145 146 func (t *toolchainMips64) GccVersion() string { 147 return mips64GccVersion 148 } 149 150 func (t *toolchainMips64) ToolchainCflags() string { 151 return t.toolchainCflags 152 } 153 154 func (t *toolchainMips64) Cflags() string { 155 return t.cflags 156 } 157 158 func (t *toolchainMips64) Cppflags() string { 159 return "${config.Mips64Cppflags}" 160 } 161 162 func (t *toolchainMips64) Ldflags() string { 163 return "${config.Mips64Ldflags}" 164 } 165 166 func (t *toolchainMips64) IncludeFlags() string { 167 return "${config.Mips64IncludeFlags}" 168 } 169 170 func (t *toolchainMips64) ClangTriple() string { 171 return t.GccTriple() 172 } 173 174 func (t *toolchainMips64) ToolchainClangCflags() string { 175 return t.toolchainClangCflags 176 } 177 178 func (t *toolchainMips64) ClangAsflags() string { 179 return "-fno-integrated-as" 180 } 181 182 func (t *toolchainMips64) ClangCflags() string { 183 return t.clangCflags 184 } 185 186 func (t *toolchainMips64) ClangCppflags() string { 187 return "${config.Mips64ClangCppflags}" 188 } 189 190 func (t *toolchainMips64) ClangLdflags() string { 191 return "${config.Mips64ClangLdflags}" 192 } 193 194 func (toolchainMips64) SanitizerRuntimeLibraryArch() string { 195 return "mips64" 196 } 197 198 func mips64ToolchainFactory(arch android.Arch) Toolchain { 199 return &toolchainMips64{ 200 cflags: "${config.Mips64Cflags}", 201 clangCflags: "${config.Mips64ClangCflags}", 202 toolchainCflags: "${config.Mips64" + arch.ArchVariant + "VariantCflags}", 203 toolchainClangCflags: "${config.Mips64" + arch.ArchVariant + "VariantClangCflags}", 204 } 205 } 206 207 func init() { 208 registerToolchainFactory(android.Android, android.Mips64, mips64ToolchainFactory) 209 } 210