blob: ba67c0bb72db8e2f86add5f9e1b41028ab8ae407 [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",
Colin Cross023f1e82015-11-23 16:15:10 -0800140 }, " "))
141
142 // Clang cflags
143 pctx.StaticVariable("mipsClangTriple", "mipsel-linux-android")
144 pctx.StaticVariable("mipsClangCflags", strings.Join(clangFilterUnknownCflags(mipsCflags), " "))
145 pctx.StaticVariable("mipsClangLdflags", strings.Join(clangFilterUnknownCflags(mipsLdflags), " "))
146 pctx.StaticVariable("mipsClangCppflags", strings.Join(clangFilterUnknownCflags(mipsCppflags), " "))
147
148 // Extended cflags
149
150 // Architecture variant cflags
151 for variant, cflags := range mipsArchVariantCflags {
152 pctx.StaticVariable("mips"+variant+"VariantCflags", strings.Join(cflags, " "))
153 pctx.StaticVariable("mips"+variant+"VariantClangCflags",
154 strings.Join(clangFilterUnknownCflags(cflags), " "))
155 }
156}
157
158type toolchainMips struct {
159 toolchain32Bit
160 cflags, clangCflags string
161 toolchainCflags, toolchainClangCflags string
162}
163
164func (t *toolchainMips) Name() string {
165 return "mips"
166}
167
168func (t *toolchainMips) GccRoot() string {
169 return "${mipsGccRoot}"
170}
171
172func (t *toolchainMips) GccTriple() string {
173 return "${mipsGccTriple}"
174}
175
176func (t *toolchainMips) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800177 return mipsGccVersion
Colin Cross023f1e82015-11-23 16:15:10 -0800178}
179
180func (t *toolchainMips) ToolchainLdflags() string {
181 return "${mipsToolchainLdflags}"
182}
183
184func (t *toolchainMips) ToolchainCflags() string {
185 return t.toolchainCflags
186}
187
188func (t *toolchainMips) Cflags() string {
189 return t.cflags
190}
191
192func (t *toolchainMips) Cppflags() string {
193 return "${mipsCppflags}"
194}
195
196func (t *toolchainMips) Ldflags() string {
197 return "${mipsLdflags}"
198}
199
200func (t *toolchainMips) IncludeFlags() string {
201 return "${mipsIncludeFlags}"
202}
203
204func (t *toolchainMips) ClangTriple() string {
205 return "${mipsClangTriple}"
206}
207
208func (t *toolchainMips) ToolchainClangCflags() string {
209 return t.toolchainClangCflags
210}
211
Dan Willemsen32968a22016-01-12 22:25:34 -0800212func (t *toolchainMips) ClangAsflags() string {
213 return "-fPIC"
214}
215
Colin Cross023f1e82015-11-23 16:15:10 -0800216func (t *toolchainMips) ClangCflags() string {
217 return t.clangCflags
218}
219
220func (t *toolchainMips) ClangCppflags() string {
221 return "${mipsClangCppflags}"
222}
223
224func (t *toolchainMips) ClangLdflags() string {
225 return "${mipsClangLdflags}"
226}
227
228func mipsToolchainFactory(arch common.Arch) Toolchain {
229 return &toolchainMips{
230 cflags: "${mipsCflags}",
231 clangCflags: "${mipsClangCflags}",
232 toolchainCflags: "${mips" + arch.ArchVariant + "VariantCflags}",
233 toolchainClangCflags: "${mips" + arch.ArchVariant + "VariantClangCflags}",
234 }
235}
236
237func init() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800238 registerDeviceToolchainFactory(common.Mips, mipsToolchainFactory)
Colin Cross023f1e82015-11-23 16:15:10 -0800239}