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