blob: bd6cd0e588f194b4f9d740a2b99c0a58d2d12378 [file] [log] [blame]
Dan Willemsen01a405a2016-06-13 17:19:03 -07001// Copyright 2016 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 config
16
17import (
18 "strings"
19
20 "android/soong/android"
21)
22
23var (
24 linuxBionicCflags = ClangFilterUnknownCflags([]string{
25 "-fno-exceptions", // from build/core/combo/select.mk
26 "-Wno-multichar", // from build/core/combo/select.mk
27
28 "-fdiagnostics-color",
29
30 "-Wa,--noexecstack",
31
32 "-fPIC",
33 "-no-canonical-prefixes",
34
35 "-U_FORTIFY_SOURCE",
36 "-D_FORTIFY_SOURCE=2",
37 "-fstack-protector-strong",
38
39 // From x86_64_device
40 "-ffunction-sections",
41 "-finline-functions",
42 "-finline-limit=300",
43 "-fno-short-enums",
44 "-funswitch-loops",
45 "-funwind-tables",
46 "-no-canonical-prefixes",
47 "-fno-canonical-system-headers",
48
49 // HOST_RELEASE_CFLAGS
50 "-O2", // from build/core/combo/select.mk
51 "-g", // from build/core/combo/select.mk
52 "-fno-strict-aliasing", // from build/core/combo/select.mk
53
54 // Tell clang where the gcc toolchain is
55 "--gcc-toolchain=${LinuxBionicGccRoot}",
56
57 // TODO: We're not really android, but we don't have a triple yet b/31393676
58 "-U__ANDROID__",
59 "-fno-emulated-tls",
60
61 // This is normally in ClangExtraTargetCflags, but this is considered host
62 "-nostdlibinc",
63 })
64
65 linuxBionicLdflags = ClangFilterUnknownCflags([]string{
66 "-Wl,-z,noexecstack",
67 "-Wl,-z,relro",
68 "-Wl,-z,now",
69 "-Wl,--build-id=md5",
70 "-Wl,--warn-shared-textrel",
71 "-Wl,--fatal-warnings",
72 "-Wl,--gc-sections",
73 "-Wl,--hash-style=gnu",
74 "-Wl,--no-undefined-version",
75
76 // Use the device gcc toolchain
77 "--gcc-toolchain=${LinuxBionicGccRoot}",
78 })
79)
80
81func init() {
82 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " "))
83 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " "))
84
85 pctx.StaticVariable("LinuxBionicIncludeFlags", bionicHeaders("x86_64", "x86"))
86
87 // Use the device gcc toolchain for now
88 pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}")
89}
90
91type toolchainLinuxBionic struct {
92 toolchain64Bit
93}
94
95func (t *toolchainLinuxBionic) Name() string {
96 return "x86_64"
97}
98
99func (t *toolchainLinuxBionic) GccRoot() string {
100 return "${config.LinuxBionicGccRoot}"
101}
102
103func (t *toolchainLinuxBionic) GccTriple() string {
104 return "x86_64-linux-android"
105}
106
107func (t *toolchainLinuxBionic) GccVersion() string {
108 return "4.9"
109}
110
111func (t *toolchainLinuxBionic) Cflags() string {
112 return ""
113}
114
115func (t *toolchainLinuxBionic) Cppflags() string {
116 return ""
117}
118
119func (t *toolchainLinuxBionic) Ldflags() string {
120 return ""
121}
122
123func (t *toolchainLinuxBionic) IncludeFlags() string {
124 return "${config.LinuxBionicIncludeFlags}"
125}
126
127func (t *toolchainLinuxBionic) ClangTriple() string {
128 // TODO: we don't have a triple yet b/31393676
129 return "x86_64-linux-android"
130}
131
132func (t *toolchainLinuxBionic) ClangCflags() string {
133 return "${config.LinuxBionicCflags}"
134}
135
136func (t *toolchainLinuxBionic) ClangCppflags() string {
137 return ""
138}
139
140func (t *toolchainLinuxBionic) ClangLdflags() string {
141 return "${config.LinuxBionicLdflags}"
142}
143
144func (t *toolchainLinuxBionic) ToolchainClangCflags() string {
145 return "-m64 -march=x86-64"
146}
147
148func (t *toolchainLinuxBionic) ToolchainClangLdflags() string {
149 return "-m64"
150}
151
152func (t *toolchainLinuxBionic) AvailableLibraries() []string {
153 return nil
154}
155
156func (t *toolchainLinuxBionic) Bionic() bool {
157 return true
158}
159
160var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{}
161
162func linuxBionicToolchainFactory(arch android.Arch) Toolchain {
163 return toolchainLinuxBionicSingleton
164}
165
166func init() {
167 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory)
168}