Home | History | Annotate | Download | only in cc
      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 	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 		"-fstack-protector-strong",
     38 		"-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",
     65 		"-Wl,--no-undefined-version",
     66 	}
     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 
    116 const (
    117 	mipsGccVersion = "4.9"
    118 )
    119 
    120 func init() {
    121 	common.RegisterArchFeatures(common.Mips, "mips32r6",
    122 		"rev6")
    123 
    124 	pctx.StaticVariable("mipsGccVersion", mipsGccVersion)
    125 
    126 	pctx.SourcePathVariable("mipsGccRoot",
    127 		"prebuilts/gcc/${HostPrebuiltTag}/mips/mips64el-linux-android-${mipsGccVersion}")
    128 
    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 
    160 type toolchainMips struct {
    161 	toolchain32Bit
    162 	cflags, clangCflags                   string
    163 	toolchainCflags, toolchainClangCflags string
    164 }
    165 
    166 func (t *toolchainMips) Name() string {
    167 	return "mips"
    168 }
    169 
    170 func (t *toolchainMips) GccRoot() string {
    171 	return "${mipsGccRoot}"
    172 }
    173 
    174 func (t *toolchainMips) GccTriple() string {
    175 	return "${mipsGccTriple}"
    176 }
    177 
    178 func (t *toolchainMips) GccVersion() string {
    179 	return mipsGccVersion
    180 }
    181 
    182 func (t *toolchainMips) ToolchainLdflags() string {
    183 	return "${mipsToolchainLdflags}"
    184 }
    185 
    186 func (t *toolchainMips) ToolchainCflags() string {
    187 	return t.toolchainCflags
    188 }
    189 
    190 func (t *toolchainMips) Cflags() string {
    191 	return t.cflags
    192 }
    193 
    194 func (t *toolchainMips) Cppflags() string {
    195 	return "${mipsCppflags}"
    196 }
    197 
    198 func (t *toolchainMips) Ldflags() string {
    199 	return "${mipsLdflags}"
    200 }
    201 
    202 func (t *toolchainMips) IncludeFlags() string {
    203 	return "${mipsIncludeFlags}"
    204 }
    205 
    206 func (t *toolchainMips) ClangTriple() string {
    207 	return "${mipsClangTriple}"
    208 }
    209 
    210 func (t *toolchainMips) ToolchainClangCflags() string {
    211 	return t.toolchainClangCflags
    212 }
    213 
    214 func (t *toolchainMips) ClangAsflags() string {
    215 	return "-fPIC"
    216 }
    217 
    218 func (t *toolchainMips) ClangCflags() string {
    219 	return t.clangCflags
    220 }
    221 
    222 func (t *toolchainMips) ClangCppflags() string {
    223 	return "${mipsClangCppflags}"
    224 }
    225 
    226 func (t *toolchainMips) ClangLdflags() string {
    227 	return "${mipsClangLdflags}"
    228 }
    229 
    230 func mipsToolchainFactory(arch common.Arch) Toolchain {
    231 	return &toolchainMips{
    232 		cflags:               "${mipsCflags}",
    233 		clangCflags:          "${mipsClangCflags}",
    234 		toolchainCflags:      "${mips" + arch.ArchVariant + "VariantCflags}",
    235 		toolchainClangCflags: "${mips" + arch.ArchVariant + "VariantClangCflags}",
    236 	}
    237 }
    238 
    239 func init() {
    240 	registerDeviceToolchainFactory(common.Mips, mipsToolchainFactory)
    241 }
    242