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 mipsCflags = []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 // TARGET_RELEASE_CFLAGS 45 "-DNDEBUG", 46 "-g", 47 "-Wstrict-aliasing=2", 48 "-fgcse-after-reload", 49 "-frerun-cse-after-loop", 50 "-frename-registers", 51 } 52 53 mipsClangCflags = append(mipsCflags, []string{ 54 "-fPIC", 55 "-fintegrated-as", 56 }...) 57 58 mipsCppflags = []string{ 59 "-fvisibility-inlines-hidden", 60 } 61 62 mipsLdflags = []string{ 63 "-Wl,-z,noexecstack", 64 "-Wl,-z,relro", 65 "-Wl,-z,now", 66 "-Wl,--build-id=md5", 67 "-Wl,--warn-shared-textrel", 68 "-Wl,--fatal-warnings", 69 "-Wl,--allow-shlib-undefined", 70 "-Wl,--no-undefined-version", 71 } 72 73 mipsToolchainLdflags = []string{ 74 "-Wl,-melf32ltsmip", 75 } 76 77 mipsArchVariantCflags = map[string][]string{ 78 "mips32-fp": []string{ 79 "-mips32", 80 "-mfp32", 81 "-modd-spreg", 82 "-mno-synci", 83 }, 84 "mips32r2-fp": []string{ 85 "-mips32r2", 86 "-mfp32", 87 "-modd-spreg", 88 "-msynci", 89 }, 90 "mips32r2-fp-xburst": []string{ 91 "-mips32r2", 92 "-mfp32", 93 "-modd-spreg", 94 "-mno-fused-madd", 95 "-mno-synci", 96 }, 97 "mips32r2dsp-fp": []string{ 98 "-mips32r2", 99 "-mfp32", 100 "-modd-spreg", 101 "-mdsp", 102 "-msynci", 103 }, 104 "mips32r2dspr2-fp": []string{ 105 "-mips32r2", 106 "-mfp32", 107 "-modd-spreg", 108 "-mdspr2", 109 "-msynci", 110 }, 111 "mips32r6": []string{ 112 "-mips32r6", 113 "-mfp64", 114 "-mno-odd-spreg", 115 "-msynci", 116 }, 117 } 118 ) 119 120 const ( 121 mipsGccVersion = "4.9" 122 ) 123 124 func init() { 125 android.RegisterArchVariants(android.Mips, 126 "mips32_fp", 127 "mips32r2_fp", 128 "mips32r2_fp_xburst", 129 "mips32r2dsp_fp", 130 "mips32r2dspr2_fp", 131 "mips32r6") 132 android.RegisterArchFeatures(android.Mips, 133 "dspr2", 134 "rev6", 135 "msa") 136 android.RegisterArchVariantFeatures(android.Mips, "mips32r2dspr2_fp", 137 "dspr2") 138 android.RegisterArchVariantFeatures(android.Mips, "mips32r6", 139 "rev6") 140 141 pctx.StaticVariable("mipsGccVersion", mipsGccVersion) 142 143 pctx.SourcePathVariable("MipsGccRoot", 144 "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mipsGccVersion}") 145 146 pctx.StaticVariable("MipsToolchainLdflags", strings.Join(mipsToolchainLdflags, " ")) 147 pctx.StaticVariable("MipsCflags", strings.Join(mipsCflags, " ")) 148 pctx.StaticVariable("MipsLdflags", strings.Join(mipsLdflags, " ")) 149 pctx.StaticVariable("MipsCppflags", strings.Join(mipsCppflags, " ")) 150 pctx.StaticVariable("MipsIncludeFlags", bionicHeaders("mips", "mips")) 151 152 // Clang cflags 153 pctx.StaticVariable("MipsClangCflags", strings.Join(ClangFilterUnknownCflags(mipsClangCflags), " ")) 154 pctx.StaticVariable("MipsClangLdflags", strings.Join(ClangFilterUnknownCflags(mipsLdflags), " ")) 155 pctx.StaticVariable("MipsClangCppflags", strings.Join(ClangFilterUnknownCflags(mipsCppflags), " ")) 156 157 // Extended cflags 158 159 // Architecture variant cflags 160 for variant, cflags := range mipsArchVariantCflags { 161 pctx.StaticVariable("Mips"+variant+"VariantCflags", strings.Join(cflags, " ")) 162 pctx.StaticVariable("Mips"+variant+"VariantClangCflags", 163 strings.Join(ClangFilterUnknownCflags(cflags), " ")) 164 } 165 } 166 167 type toolchainMips struct { 168 toolchain32Bit 169 cflags, clangCflags string 170 toolchainCflags, toolchainClangCflags string 171 } 172 173 func (t *toolchainMips) Name() string { 174 return "mips" 175 } 176 177 func (t *toolchainMips) GccRoot() string { 178 return "${config.MipsGccRoot}" 179 } 180 181 func (t *toolchainMips) GccTriple() string { 182 return "mips64el-linux-android" 183 } 184 185 func (t *toolchainMips) GccVersion() string { 186 return mipsGccVersion 187 } 188 189 func (t *toolchainMips) ToolchainLdflags() string { 190 return "${config.MipsToolchainLdflags}" 191 } 192 193 func (t *toolchainMips) ToolchainCflags() string { 194 return t.toolchainCflags 195 } 196 197 func (t *toolchainMips) Cflags() string { 198 return t.cflags 199 } 200 201 func (t *toolchainMips) Cppflags() string { 202 return "${config.MipsCppflags}" 203 } 204 205 func (t *toolchainMips) Ldflags() string { 206 return "${config.MipsLdflags}" 207 } 208 209 func (t *toolchainMips) IncludeFlags() string { 210 return "${config.MipsIncludeFlags}" 211 } 212 213 func (t *toolchainMips) ClangTriple() string { 214 return "mipsel-linux-android" 215 } 216 217 func (t *toolchainMips) ToolchainClangLdflags() string { 218 return "${config.MipsToolchainLdflags}" 219 } 220 221 func (t *toolchainMips) ToolchainClangCflags() string { 222 return t.toolchainClangCflags 223 } 224 225 func (t *toolchainMips) ClangAsflags() string { 226 return "-fPIC -fno-integrated-as" 227 } 228 229 func (t *toolchainMips) ClangCflags() string { 230 return t.clangCflags 231 } 232 233 func (t *toolchainMips) ClangCppflags() string { 234 return "${config.MipsClangCppflags}" 235 } 236 237 func (t *toolchainMips) ClangLdflags() string { 238 return "${config.MipsClangLdflags}" 239 } 240 241 func (toolchainMips) SanitizerRuntimeLibraryArch() string { 242 return "mips" 243 } 244 245 func mipsToolchainFactory(arch android.Arch) Toolchain { 246 return &toolchainMips{ 247 cflags: "${config.MipsCflags}", 248 clangCflags: "${config.MipsClangCflags}", 249 toolchainCflags: "${config.Mips" + arch.ArchVariant + "VariantCflags}", 250 toolchainClangCflags: "${config.Mips" + arch.ArchVariant + "VariantClangCflags}", 251 } 252 } 253 254 func init() { 255 registerToolchainFactory(android.Android, android.Mips, mipsToolchainFactory) 256 } 257