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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/common" |
| 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 | "-Wa,--noexecstack", |
| 38 | "-Werror=format-security", |
| 39 | "-D_FORTIFY_SOURCE=2", |
| 40 | "-no-canonical-prefixes", |
| 41 | "-fno-canonical-system-headers", |
| 42 | |
| 43 | // Help catch common 32/64-bit errors. |
| 44 | "-Werror=pointer-to-int-cast", |
| 45 | "-Werror=int-to-pointer-cast", |
| 46 | "-Werror=implicit-function-declaration", |
| 47 | |
| 48 | // TARGET_RELEASE_CFLAGS |
| 49 | "-DNDEBUG", |
| 50 | "-g", |
| 51 | "-Wstrict-aliasing=2", |
| 52 | "-fgcse-after-reload", |
| 53 | "-frerun-cse-after-loop", |
| 54 | "-frename-registers", |
| 55 | } |
| 56 | |
| 57 | mips64Cppflags = []string{ |
| 58 | "-fvisibility-inlines-hidden", |
| 59 | } |
| 60 | |
| 61 | mips64Ldflags = []string{ |
| 62 | "-Wl,-z,noexecstack", |
| 63 | "-Wl,-z,relro", |
| 64 | "-Wl,-z,now", |
| 65 | "-Wl,--build-id=md5", |
| 66 | "-Wl,--warn-shared-textrel", |
| 67 | "-Wl,--fatal-warnings", |
| 68 | "-Wl,--allow-shlib-undefined", |
| 69 | } |
| 70 | |
| 71 | mips64ArchVariantCflags = map[string][]string{ |
| 72 | "mips64r2": []string{ |
| 73 | "-mips64r2", |
| 74 | "-msynci", |
| 75 | }, |
| 76 | "mips64r6": []string{ |
| 77 | "-mips64r6", |
| 78 | "-msynci", |
| 79 | }, |
| 80 | } |
| 81 | ) |
| 82 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 83 | const ( |
| 84 | mips64GccVersion = "4.9" |
| 85 | ) |
| 86 | |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 87 | func init() { |
| 88 | common.RegisterArchFeatures(common.Mips64, "mips64r6", |
| 89 | "rev6") |
| 90 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 91 | pctx.StaticVariable("mips64GccVersion", mips64GccVersion) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 92 | |
| 93 | pctx.StaticVariable("mips64GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 94 | "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mips64GccVersion}") |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 95 | |
| 96 | pctx.StaticVariable("mips64GccTriple", "mips64el-linux-android") |
| 97 | |
| 98 | pctx.StaticVariable("mips64Cflags", strings.Join(mips64Cflags, " ")) |
| 99 | pctx.StaticVariable("mips64Ldflags", strings.Join(mips64Ldflags, " ")) |
| 100 | pctx.StaticVariable("mips64Cppflags", strings.Join(mips64Cppflags, " ")) |
| 101 | pctx.StaticVariable("mips64IncludeFlags", strings.Join([]string{ |
| 102 | "-isystem ${LibcRoot}/arch-mips64/include", |
| 103 | "-isystem ${LibcRoot}/include", |
| 104 | "-isystem ${LibcRoot}/kernel/uapi", |
| 105 | "-isystem ${LibcRoot}/kernel/uapi/asm-mips", |
| 106 | "-isystem ${LibmRoot}/include", |
| 107 | "-isystem ${LibmRoot}/include/mips", |
| 108 | }, " ")) |
| 109 | |
| 110 | // Clang cflags |
| 111 | pctx.StaticVariable("mips64ClangTriple", "mips64el-linux-android") |
| 112 | pctx.StaticVariable("mips64ClangCflags", strings.Join(clangFilterUnknownCflags(mips64Cflags), " ")) |
| 113 | pctx.StaticVariable("mips64ClangLdflags", strings.Join(clangFilterUnknownCflags(mips64Ldflags), " ")) |
| 114 | pctx.StaticVariable("mips64ClangCppflags", strings.Join(clangFilterUnknownCflags(mips64Cppflags), " ")) |
| 115 | |
| 116 | // Extended cflags |
| 117 | |
| 118 | // Architecture variant cflags |
| 119 | for variant, cflags := range mips64ArchVariantCflags { |
| 120 | pctx.StaticVariable("mips64"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 121 | pctx.StaticVariable("mips64"+variant+"VariantClangCflags", |
| 122 | strings.Join(clangFilterUnknownCflags(cflags), " ")) |
| 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 { |
| 137 | return "${mips64GccRoot}" |
| 138 | } |
| 139 | |
| 140 | func (t *toolchainMips64) GccTriple() string { |
| 141 | return "${mips64GccTriple}" |
| 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 | |
| 148 | func (t *toolchainMips64) ToolchainLdflags() string { |
| 149 | return "" |
| 150 | } |
| 151 | |
| 152 | func (t *toolchainMips64) ToolchainCflags() string { |
| 153 | return t.toolchainCflags |
| 154 | } |
| 155 | |
| 156 | func (t *toolchainMips64) Cflags() string { |
| 157 | return t.cflags |
| 158 | } |
| 159 | |
| 160 | func (t *toolchainMips64) Cppflags() string { |
| 161 | return "${mips64Cppflags}" |
| 162 | } |
| 163 | |
| 164 | func (t *toolchainMips64) Ldflags() string { |
| 165 | return "${mips64Ldflags}" |
| 166 | } |
| 167 | |
| 168 | func (t *toolchainMips64) IncludeFlags() string { |
| 169 | return "${mips64IncludeFlags}" |
| 170 | } |
| 171 | |
| 172 | func (t *toolchainMips64) ClangTriple() string { |
| 173 | return "${mips64ClangTriple}" |
| 174 | } |
| 175 | |
| 176 | func (t *toolchainMips64) ToolchainClangCflags() string { |
| 177 | return t.toolchainClangCflags |
| 178 | } |
| 179 | |
| 180 | func (t *toolchainMips64) ClangCflags() string { |
| 181 | return t.clangCflags |
| 182 | } |
| 183 | |
| 184 | func (t *toolchainMips64) ClangCppflags() string { |
| 185 | return "${mips64ClangCppflags}" |
| 186 | } |
| 187 | |
| 188 | func (t *toolchainMips64) ClangLdflags() string { |
| 189 | return "${mips64ClangLdflags}" |
| 190 | } |
| 191 | |
| 192 | func mips64ToolchainFactory(arch common.Arch) Toolchain { |
| 193 | return &toolchainMips64{ |
| 194 | cflags: "${mips64Cflags}", |
| 195 | clangCflags: "${mips64ClangCflags}", |
| 196 | toolchainCflags: "${mips64" + arch.ArchVariant + "VariantCflags}", |
| 197 | toolchainClangCflags: "${mips64" + arch.ArchVariant + "VariantClangCflags}", |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | func init() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 202 | registerDeviceToolchainFactory(common.Mips64, mips64ToolchainFactory) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 203 | } |