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