Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 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 cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 20 | "android/soong/android" |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 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", |
Dan Willemsen | 7a0f848 | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 37 | "-fstack-protector-strong", |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 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 | |
Dan Willemsen | c785ff3 | 2016-05-09 13:34:35 -0700 | [diff] [blame] | 53 | mipsClangCflags = append(mipsCflags, []string{ |
| 54 | "-fPIC", |
Pirama Arumuga Nainar | 58e2dcd | 2016-06-29 17:09:30 -0700 | [diff] [blame] | 55 | "-fno-integrated-as", |
Dan Willemsen | c785ff3 | 2016-05-09 13:34:35 -0700 | [diff] [blame] | 56 | }...) |
| 57 | |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 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", |
Dan Willemsen | c7e4597 | 2015-12-09 13:05:28 -0800 | [diff] [blame] | 70 | "-Wl,--no-undefined-version", |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 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", |
Dan Willemsen | c785ff3 | 2016-05-09 13:34:35 -0700 | [diff] [blame] | 88 | "-msynci", |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 89 | }, |
| 90 | "mips32r2-fp-xburst": []string{ |
| 91 | "-mips32r2", |
| 92 | "-mfp32", |
| 93 | "-modd-spreg", |
| 94 | "-mno-fused-madd", |
| 95 | "-Wa,-mmxu", |
| 96 | "-mno-synci", |
| 97 | }, |
| 98 | "mips32r2dsp-fp": []string{ |
| 99 | "-mips32r2", |
| 100 | "-mfp32", |
| 101 | "-modd-spreg", |
| 102 | "-mdsp", |
| 103 | "-msynci", |
| 104 | }, |
| 105 | "mips32r2dspr2-fp": []string{ |
| 106 | "-mips32r2", |
| 107 | "-mfp32", |
| 108 | "-modd-spreg", |
| 109 | "-mdspr2", |
| 110 | "-msynci", |
| 111 | }, |
| 112 | "mips32r6": []string{ |
| 113 | "-mips32r6", |
| 114 | "-mfp64", |
| 115 | "-mno-odd-spreg", |
| 116 | "-msynci", |
| 117 | }, |
| 118 | } |
| 119 | ) |
| 120 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 121 | const ( |
| 122 | mipsGccVersion = "4.9" |
| 123 | ) |
| 124 | |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 125 | func init() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 126 | android.RegisterArchFeatures(android.Mips, "mips32r6", |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 127 | "rev6") |
| 128 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 129 | pctx.StaticVariable("mipsGccVersion", mipsGccVersion) |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 130 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 131 | pctx.SourcePathVariable("mipsGccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 132 | "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mipsGccVersion}") |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 133 | |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 134 | pctx.StaticVariable("mipsToolchainLdflags", strings.Join(mipsToolchainLdflags, " ")) |
| 135 | pctx.StaticVariable("mipsCflags", strings.Join(mipsCflags, " ")) |
| 136 | pctx.StaticVariable("mipsLdflags", strings.Join(mipsLdflags, " ")) |
| 137 | pctx.StaticVariable("mipsCppflags", strings.Join(mipsCppflags, " ")) |
Colin Cross | f59b69c | 2016-07-21 11:14:12 -0700 | [diff] [blame] | 138 | pctx.StaticVariable("mipsIncludeFlags", bionicHeaders("mips", "mips")) |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 139 | |
| 140 | // Clang cflags |
Dan Willemsen | c785ff3 | 2016-05-09 13:34:35 -0700 | [diff] [blame] | 141 | pctx.StaticVariable("mipsClangCflags", strings.Join(clangFilterUnknownCflags(mipsClangCflags), " ")) |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 142 | pctx.StaticVariable("mipsClangLdflags", strings.Join(clangFilterUnknownCflags(mipsLdflags), " ")) |
| 143 | pctx.StaticVariable("mipsClangCppflags", strings.Join(clangFilterUnknownCflags(mipsCppflags), " ")) |
| 144 | |
| 145 | // Extended cflags |
| 146 | |
| 147 | // Architecture variant cflags |
| 148 | for variant, cflags := range mipsArchVariantCflags { |
| 149 | pctx.StaticVariable("mips"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 150 | pctx.StaticVariable("mips"+variant+"VariantClangCflags", |
| 151 | strings.Join(clangFilterUnknownCflags(cflags), " ")) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | type toolchainMips struct { |
| 156 | toolchain32Bit |
| 157 | cflags, clangCflags string |
| 158 | toolchainCflags, toolchainClangCflags string |
| 159 | } |
| 160 | |
| 161 | func (t *toolchainMips) Name() string { |
| 162 | return "mips" |
| 163 | } |
| 164 | |
| 165 | func (t *toolchainMips) GccRoot() string { |
| 166 | return "${mipsGccRoot}" |
| 167 | } |
| 168 | |
| 169 | func (t *toolchainMips) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame^] | 170 | return "mips64el-linux-android" |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | func (t *toolchainMips) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 174 | return mipsGccVersion |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | func (t *toolchainMips) ToolchainLdflags() string { |
| 178 | return "${mipsToolchainLdflags}" |
| 179 | } |
| 180 | |
| 181 | func (t *toolchainMips) ToolchainCflags() string { |
| 182 | return t.toolchainCflags |
| 183 | } |
| 184 | |
| 185 | func (t *toolchainMips) Cflags() string { |
| 186 | return t.cflags |
| 187 | } |
| 188 | |
| 189 | func (t *toolchainMips) Cppflags() string { |
| 190 | return "${mipsCppflags}" |
| 191 | } |
| 192 | |
| 193 | func (t *toolchainMips) Ldflags() string { |
| 194 | return "${mipsLdflags}" |
| 195 | } |
| 196 | |
| 197 | func (t *toolchainMips) IncludeFlags() string { |
| 198 | return "${mipsIncludeFlags}" |
| 199 | } |
| 200 | |
| 201 | func (t *toolchainMips) ClangTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame^] | 202 | return "mipsel-linux-android" |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Dan Willemsen | c785ff3 | 2016-05-09 13:34:35 -0700 | [diff] [blame] | 205 | func (t *toolchainMips) ToolchainClangLdflags() string { |
| 206 | return "${mipsToolchainLdflags}" |
| 207 | } |
| 208 | |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 209 | func (t *toolchainMips) ToolchainClangCflags() string { |
| 210 | return t.toolchainClangCflags |
| 211 | } |
| 212 | |
Dan Willemsen | 32968a2 | 2016-01-12 22:25:34 -0800 | [diff] [blame] | 213 | func (t *toolchainMips) ClangAsflags() string { |
Pirama Arumuga Nainar | 58e2dcd | 2016-06-29 17:09:30 -0700 | [diff] [blame] | 214 | return "-fPIC -fno-integrated-as" |
Dan Willemsen | 32968a2 | 2016-01-12 22:25:34 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 217 | func (t *toolchainMips) ClangCflags() string { |
| 218 | return t.clangCflags |
| 219 | } |
| 220 | |
| 221 | func (t *toolchainMips) ClangCppflags() string { |
| 222 | return "${mipsClangCppflags}" |
| 223 | } |
| 224 | |
| 225 | func (t *toolchainMips) ClangLdflags() string { |
| 226 | return "${mipsClangLdflags}" |
| 227 | } |
| 228 | |
Colin Cross | d87145f | 2016-05-19 22:43:46 -0700 | [diff] [blame] | 229 | func (toolchainMips) AddressSanitizerRuntimeLibrary() string { |
| 230 | return "libclang_rt.asan-mips-android.so" |
| 231 | } |
| 232 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 233 | func mipsToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 234 | return &toolchainMips{ |
| 235 | cflags: "${mipsCflags}", |
| 236 | clangCflags: "${mipsClangCflags}", |
| 237 | toolchainCflags: "${mips" + arch.ArchVariant + "VariantCflags}", |
| 238 | toolchainClangCflags: "${mips" + arch.ArchVariant + "VariantClangCflags}", |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 243 | registerToolchainFactory(android.Android, android.Mips, mipsToolchainFactory) |
Colin Cross | 023f1e8 | 2015-11-23 16:15:10 -0800 | [diff] [blame] | 244 | } |