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 | |
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", |
| 81 | }, |
| 82 | } |
| 83 | ) |
| 84 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 85 | const ( |
| 86 | mips64GccVersion = "4.9" |
| 87 | ) |
| 88 | |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 89 | func init() { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 90 | android.RegisterArchFeatures(android.Mips64, "mips64r6", |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 91 | "rev6") |
| 92 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 93 | pctx.StaticVariable("mips64GccVersion", mips64GccVersion) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 94 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 95 | pctx.SourcePathVariable("mips64GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 96 | "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mips64GccVersion}") |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 97 | |
| 98 | pctx.StaticVariable("mips64GccTriple", "mips64el-linux-android") |
| 99 | |
| 100 | pctx.StaticVariable("mips64Cflags", strings.Join(mips64Cflags, " ")) |
| 101 | pctx.StaticVariable("mips64Ldflags", strings.Join(mips64Ldflags, " ")) |
| 102 | pctx.StaticVariable("mips64Cppflags", strings.Join(mips64Cppflags, " ")) |
| 103 | pctx.StaticVariable("mips64IncludeFlags", strings.Join([]string{ |
| 104 | "-isystem ${LibcRoot}/arch-mips64/include", |
| 105 | "-isystem ${LibcRoot}/include", |
| 106 | "-isystem ${LibcRoot}/kernel/uapi", |
Dan Willemsen | a2abfd6 | 2016-05-18 14:32:32 -0700 | [diff] [blame] | 107 | "-isystem ${LibcRoot}/kernel/common", |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 108 | "-isystem ${LibcRoot}/kernel/uapi/asm-mips", |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 109 | }, " ")) |
| 110 | |
| 111 | // Clang cflags |
| 112 | pctx.StaticVariable("mips64ClangTriple", "mips64el-linux-android") |
| 113 | pctx.StaticVariable("mips64ClangCflags", strings.Join(clangFilterUnknownCflags(mips64Cflags), " ")) |
| 114 | pctx.StaticVariable("mips64ClangLdflags", strings.Join(clangFilterUnknownCflags(mips64Ldflags), " ")) |
| 115 | pctx.StaticVariable("mips64ClangCppflags", strings.Join(clangFilterUnknownCflags(mips64Cppflags), " ")) |
| 116 | |
| 117 | // Extended cflags |
| 118 | |
| 119 | // Architecture variant cflags |
| 120 | for variant, cflags := range mips64ArchVariantCflags { |
| 121 | pctx.StaticVariable("mips64"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 122 | pctx.StaticVariable("mips64"+variant+"VariantClangCflags", |
| 123 | strings.Join(clangFilterUnknownCflags(cflags), " ")) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | type toolchainMips64 struct { |
| 128 | toolchain64Bit |
| 129 | cflags, clangCflags string |
| 130 | toolchainCflags, toolchainClangCflags string |
| 131 | } |
| 132 | |
| 133 | func (t *toolchainMips64) Name() string { |
| 134 | return "mips64" |
| 135 | } |
| 136 | |
| 137 | func (t *toolchainMips64) GccRoot() string { |
| 138 | return "${mips64GccRoot}" |
| 139 | } |
| 140 | |
| 141 | func (t *toolchainMips64) GccTriple() string { |
| 142 | return "${mips64GccTriple}" |
| 143 | } |
| 144 | |
| 145 | func (t *toolchainMips64) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 146 | return mips64GccVersion |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 149 | func (t *toolchainMips64) ToolchainCflags() string { |
| 150 | return t.toolchainCflags |
| 151 | } |
| 152 | |
| 153 | func (t *toolchainMips64) Cflags() string { |
| 154 | return t.cflags |
| 155 | } |
| 156 | |
| 157 | func (t *toolchainMips64) Cppflags() string { |
| 158 | return "${mips64Cppflags}" |
| 159 | } |
| 160 | |
| 161 | func (t *toolchainMips64) Ldflags() string { |
| 162 | return "${mips64Ldflags}" |
| 163 | } |
| 164 | |
| 165 | func (t *toolchainMips64) IncludeFlags() string { |
| 166 | return "${mips64IncludeFlags}" |
| 167 | } |
| 168 | |
| 169 | func (t *toolchainMips64) ClangTriple() string { |
| 170 | return "${mips64ClangTriple}" |
| 171 | } |
| 172 | |
| 173 | func (t *toolchainMips64) ToolchainClangCflags() string { |
| 174 | return t.toolchainClangCflags |
| 175 | } |
| 176 | |
| 177 | func (t *toolchainMips64) ClangCflags() string { |
| 178 | return t.clangCflags |
| 179 | } |
| 180 | |
| 181 | func (t *toolchainMips64) ClangCppflags() string { |
| 182 | return "${mips64ClangCppflags}" |
| 183 | } |
| 184 | |
| 185 | func (t *toolchainMips64) ClangLdflags() string { |
| 186 | return "${mips64ClangLdflags}" |
| 187 | } |
| 188 | |
Colin Cross | d87145f | 2016-05-19 22:43:46 -0700 | [diff] [blame] | 189 | func (toolchainMips64) AddressSanitizerRuntimeLibrary() string { |
| 190 | return "libclang_rt.asan-mips64-android.so" |
| 191 | } |
| 192 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 193 | func mips64ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 194 | return &toolchainMips64{ |
| 195 | cflags: "${mips64Cflags}", |
| 196 | clangCflags: "${mips64ClangCflags}", |
| 197 | toolchainCflags: "${mips64" + arch.ArchVariant + "VariantCflags}", |
| 198 | toolchainClangCflags: "${mips64" + arch.ArchVariant + "VariantClangCflags}", |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame^] | 203 | registerToolchainFactory(android.Android, android.Mips64, mips64ToolchainFactory) |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 204 | } |