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", |
| 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 | 3b336c2 | 2015-11-23 16:28:31 -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 | // 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 | mips64Cppflags = []string{ |
| 59 | "-fvisibility-inlines-hidden", |
| 60 | } |
| 61 | |
| 62 | mips64Ldflags = []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 | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | mips64ArchVariantCflags = map[string][]string{ |
| 74 | "mips64r2": []string{ |
| 75 | "-mips64r2", |
| 76 | "-msynci", |
| 77 | }, |
| 78 | "mips64r6": []string{ |
| 79 | "-mips64r6", |
| 80 | "-msynci", |
Nikola Veljkovic | 3d6a38d | 2016-08-22 20:03:39 +0200 | [diff] [blame] | 81 | |
| 82 | // revert once clang picks up r278824 |
| 83 | "-mcompact-branches=never", |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 84 | }, |
| 85 | } |
| 86 | ) |
| 87 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 88 | const ( |
| 89 | mips64GccVersion = "4.9" |
| 90 | ) |
| 91 | |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 92 | func init() { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame^] | 93 | android.RegisterArchVariants(android.Mips64, |
| 94 | "mips64r2", |
| 95 | "mips64r6") |
| 96 | android.RegisterArchFeatures(android.Mips64, "rev6") |
| 97 | android.RegisterArchVariantFeatures(android.Mips64, "mips64r6", |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 98 | "rev6") |
| 99 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 100 | pctx.StaticVariable("mips64GccVersion", mips64GccVersion) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 101 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 102 | pctx.SourcePathVariable("Mips64GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 103 | "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mips64GccVersion}") |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 104 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 105 | pctx.StaticVariable("Mips64Cflags", strings.Join(mips64Cflags, " ")) |
| 106 | pctx.StaticVariable("Mips64Ldflags", strings.Join(mips64Ldflags, " ")) |
| 107 | pctx.StaticVariable("Mips64Cppflags", strings.Join(mips64Cppflags, " ")) |
| 108 | pctx.StaticVariable("Mips64IncludeFlags", bionicHeaders("mips64", "mips")) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 109 | |
| 110 | // Clang cflags |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 111 | pctx.StaticVariable("Mips64ClangCflags", strings.Join(ClangFilterUnknownCflags(mips64Cflags), " ")) |
| 112 | pctx.StaticVariable("Mips64ClangLdflags", strings.Join(ClangFilterUnknownCflags(mips64Ldflags), " ")) |
| 113 | pctx.StaticVariable("Mips64ClangCppflags", strings.Join(ClangFilterUnknownCflags(mips64Cppflags), " ")) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 114 | |
| 115 | // Extended cflags |
| 116 | |
| 117 | // Architecture variant cflags |
| 118 | for variant, cflags := range mips64ArchVariantCflags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 119 | pctx.StaticVariable("Mips64"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 120 | pctx.StaticVariable("Mips64"+variant+"VariantClangCflags", |
| 121 | strings.Join(ClangFilterUnknownCflags(cflags), " ")) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | type toolchainMips64 struct { |
| 126 | toolchain64Bit |
| 127 | cflags, clangCflags string |
| 128 | toolchainCflags, toolchainClangCflags string |
| 129 | } |
| 130 | |
| 131 | func (t *toolchainMips64) Name() string { |
| 132 | return "mips64" |
| 133 | } |
| 134 | |
| 135 | func (t *toolchainMips64) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 136 | return "${config.Mips64GccRoot}" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | func (t *toolchainMips64) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 140 | return "mips64el-linux-android" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | func (t *toolchainMips64) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 144 | return mips64GccVersion |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 145 | } |
| 146 | |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 147 | func (t *toolchainMips64) ToolchainCflags() string { |
| 148 | return t.toolchainCflags |
| 149 | } |
| 150 | |
| 151 | func (t *toolchainMips64) Cflags() string { |
| 152 | return t.cflags |
| 153 | } |
| 154 | |
| 155 | func (t *toolchainMips64) Cppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 156 | return "${config.Mips64Cppflags}" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | func (t *toolchainMips64) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 160 | return "${config.Mips64Ldflags}" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | func (t *toolchainMips64) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 164 | return "${config.Mips64IncludeFlags}" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | func (t *toolchainMips64) ClangTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 168 | return t.GccTriple() |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | func (t *toolchainMips64) ToolchainClangCflags() string { |
| 172 | return t.toolchainClangCflags |
| 173 | } |
| 174 | |
| 175 | func (t *toolchainMips64) ClangCflags() string { |
| 176 | return t.clangCflags |
| 177 | } |
| 178 | |
| 179 | func (t *toolchainMips64) ClangCppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 180 | return "${config.Mips64ClangCppflags}" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | func (t *toolchainMips64) ClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 184 | return "${config.Mips64ClangLdflags}" |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 187 | func (toolchainMips64) SanitizerRuntimeLibraryArch() string { |
| 188 | return "mips64" |
Colin Cross | d87145f | 2016-05-19 22:43:46 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 191 | func mips64ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 192 | return &toolchainMips64{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 193 | cflags: "${config.Mips64Cflags}", |
| 194 | clangCflags: "${config.Mips64ClangCflags}", |
| 195 | toolchainCflags: "${config.Mips64" + arch.ArchVariant + "VariantCflags}", |
| 196 | toolchainClangCflags: "${config.Mips64" + arch.ArchVariant + "VariantClangCflags}", |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
| 200 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 201 | registerToolchainFactory(android.Android, android.Mips64, mips64ToolchainFactory) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 202 | } |