blob: d88c9060009a5dca8c7c0774d883e23f153cc4d3 [file] [log] [blame]
Colin Cross023f1e82015-11-23 16:15:10 -08001// 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
15package cc
16
17import (
18 "strings"
19
20 "android/soong/common"
21)
22
23var (
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 Willemsen7a0f8482016-01-12 16:22:40 -080037 "-fstack-protector-strong",
Colin Cross023f1e82015-11-23 16:15:10 -080038 "-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
53 mipsCppflags = []string{
54 "-fvisibility-inlines-hidden",
55 }
56
57 mipsLdflags = []string{
58 "-Wl,-z,noexecstack",
59 "-Wl,-z,relro",
60 "-Wl,-z,now",
61 "-Wl,--build-id=md5",
62 "-Wl,--warn-shared-textrel",
63 "-Wl,--fatal-warnings",
64 "-Wl,--allow-shlib-undefined",
Dan Willemsenc7e45972015-12-09 13:05:28 -080065 "-Wl,--no-undefined-version",
Colin Cross023f1e82015-11-23 16:15:10 -080066 }
67
68 mipsToolchainLdflags = []string{
69 "-Wl,-melf32ltsmip",
70 }
71
72 mipsArchVariantCflags = map[string][]string{
73 "mips32-fp": []string{
74 "-mips32",
75 "-mfp32",
76 "-modd-spreg",
77 "-mno-synci",
78 },
79 "mips32r2-fp": []string{
80 "-mips32r2",
81 "-mfp32",
82 "-modd-spreg",
83 "-mno-synci",
84 },
85 "mips32r2-fp-xburst": []string{
86 "-mips32r2",
87 "-mfp32",
88 "-modd-spreg",
89 "-mno-fused-madd",
90 "-Wa,-mmxu",
91 "-mno-synci",
92 },
93 "mips32r2dsp-fp": []string{
94 "-mips32r2",
95 "-mfp32",
96 "-modd-spreg",
97 "-mdsp",
98 "-msynci",
99 },
100 "mips32r2dspr2-fp": []string{
101 "-mips32r2",
102 "-mfp32",
103 "-modd-spreg",
104 "-mdspr2",
105 "-msynci",
106 },
107 "mips32r6": []string{
108 "-mips32r6",
109 "-mfp64",
110 "-mno-odd-spreg",
111 "-msynci",
112 },
113 }
114)
115
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800116const (
117 mipsGccVersion = "4.9"
118)
119
Colin Cross023f1e82015-11-23 16:15:10 -0800120func init() {
121 common.RegisterArchFeatures(common.Mips, "mips32r6",
122 "rev6")
123
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800124 pctx.StaticVariable("mipsGccVersion", mipsGccVersion)
Colin Cross023f1e82015-11-23 16:15:10 -0800125
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700126 pctx.SourcePathVariable("mipsGccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800127 "prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mipsGccVersion}")
Colin Cross023f1e82015-11-23 16:15:10 -0800128
129 pctx.StaticVariable("mipsGccTriple", "mips64el-linux-android")
130
131 pctx.StaticVariable("mipsToolchainLdflags", strings.Join(mipsToolchainLdflags, " "))
132 pctx.StaticVariable("mipsCflags", strings.Join(mipsCflags, " "))
133 pctx.StaticVariable("mipsLdflags", strings.Join(mipsLdflags, " "))
134 pctx.StaticVariable("mipsCppflags", strings.Join(mipsCppflags, " "))
135 pctx.StaticVariable("mipsIncludeFlags", strings.Join([]string{
136 "-isystem ${LibcRoot}/arch-mips/include",
137 "-isystem ${LibcRoot}/include",
138 "-isystem ${LibcRoot}/kernel/uapi",
139 "-isystem ${LibcRoot}/kernel/uapi/asm-mips",
140 "-isystem ${LibmRoot}/include",
141 "-isystem ${LibmRoot}/include/mips",
142 }, " "))
143
144 // Clang cflags
145 pctx.StaticVariable("mipsClangTriple", "mipsel-linux-android")
146 pctx.StaticVariable("mipsClangCflags", strings.Join(clangFilterUnknownCflags(mipsCflags), " "))
147 pctx.StaticVariable("mipsClangLdflags", strings.Join(clangFilterUnknownCflags(mipsLdflags), " "))
148 pctx.StaticVariable("mipsClangCppflags", strings.Join(clangFilterUnknownCflags(mipsCppflags), " "))
149
150 // Extended cflags
151
152 // Architecture variant cflags
153 for variant, cflags := range mipsArchVariantCflags {
154 pctx.StaticVariable("mips"+variant+"VariantCflags", strings.Join(cflags, " "))
155 pctx.StaticVariable("mips"+variant+"VariantClangCflags",
156 strings.Join(clangFilterUnknownCflags(cflags), " "))
157 }
158}
159
160type toolchainMips struct {
161 toolchain32Bit
162 cflags, clangCflags string
163 toolchainCflags, toolchainClangCflags string
164}
165
166func (t *toolchainMips) Name() string {
167 return "mips"
168}
169
170func (t *toolchainMips) GccRoot() string {
171 return "${mipsGccRoot}"
172}
173
174func (t *toolchainMips) GccTriple() string {
175 return "${mipsGccTriple}"
176}
177
178func (t *toolchainMips) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800179 return mipsGccVersion
Colin Cross023f1e82015-11-23 16:15:10 -0800180}
181
182func (t *toolchainMips) ToolchainLdflags() string {
183 return "${mipsToolchainLdflags}"
184}
185
186func (t *toolchainMips) ToolchainCflags() string {
187 return t.toolchainCflags
188}
189
190func (t *toolchainMips) Cflags() string {
191 return t.cflags
192}
193
194func (t *toolchainMips) Cppflags() string {
195 return "${mipsCppflags}"
196}
197
198func (t *toolchainMips) Ldflags() string {
199 return "${mipsLdflags}"
200}
201
202func (t *toolchainMips) IncludeFlags() string {
203 return "${mipsIncludeFlags}"
204}
205
206func (t *toolchainMips) ClangTriple() string {
207 return "${mipsClangTriple}"
208}
209
210func (t *toolchainMips) ToolchainClangCflags() string {
211 return t.toolchainClangCflags
212}
213
214func (t *toolchainMips) ClangCflags() string {
215 return t.clangCflags
216}
217
218func (t *toolchainMips) ClangCppflags() string {
219 return "${mipsClangCppflags}"
220}
221
222func (t *toolchainMips) ClangLdflags() string {
223 return "${mipsClangLdflags}"
224}
225
226func mipsToolchainFactory(arch common.Arch) Toolchain {
227 return &toolchainMips{
228 cflags: "${mipsCflags}",
229 clangCflags: "${mipsClangCflags}",
230 toolchainCflags: "${mips" + arch.ArchVariant + "VariantCflags}",
231 toolchainClangCflags: "${mips" + arch.ArchVariant + "VariantClangCflags}",
232 }
233}
234
235func init() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800236 registerDeviceToolchainFactory(common.Mips, mipsToolchainFactory)
Colin Cross023f1e82015-11-23 16:15:10 -0800237}