blob: 093876d5e97809c066cb56b2ee316b2f1e869c5c [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
Dan Willemsen01a405a2016-06-13 17:19:03 -070057 // This is normally in ClangExtraTargetCflags, but this is considered host
58 "-nostdlibinc",
59 })
60
61 linuxBionicLdflags = ClangFilterUnknownCflags([]string{
62 "-Wl,-z,noexecstack",
63 "-Wl,-z,relro",
64 "-Wl,-z,now",
65 "-Wl,--build-id=md5",
66 "-Wl,--warn-shared-textrel",
67 "-Wl,--fatal-warnings",
68 "-Wl,--gc-sections",
69 "-Wl,--hash-style=gnu",
70 "-Wl,--no-undefined-version",
71
72 // Use the device gcc toolchain
73 "--gcc-toolchain=${LinuxBionicGccRoot}",
74 })
75)
76
77func init() {
78 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " "))
79 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " "))
80
81 pctx.StaticVariable("LinuxBionicIncludeFlags", bionicHeaders("x86_64", "x86"))
82
83 // Use the device gcc toolchain for now
84 pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}")
85}
86
87type toolchainLinuxBionic struct {
88 toolchain64Bit
89}
90
91func (t *toolchainLinuxBionic) Name() string {
92 return "x86_64"
93}
94
95func (t *toolchainLinuxBionic) GccRoot() string {
96 return "${config.LinuxBionicGccRoot}"
97}
98
99func (t *toolchainLinuxBionic) GccTriple() string {
100 return "x86_64-linux-android"
101}
102
103func (t *toolchainLinuxBionic) GccVersion() string {
104 return "4.9"
105}
106
107func (t *toolchainLinuxBionic) Cflags() string {
108 return ""
109}
110
111func (t *toolchainLinuxBionic) Cppflags() string {
112 return ""
113}
114
115func (t *toolchainLinuxBionic) Ldflags() string {
116 return ""
117}
118
119func (t *toolchainLinuxBionic) IncludeFlags() string {
120 return "${config.LinuxBionicIncludeFlags}"
121}
122
123func (t *toolchainLinuxBionic) ClangTriple() string {
124 // TODO: we don't have a triple yet b/31393676
125 return "x86_64-linux-android"
126}
127
128func (t *toolchainLinuxBionic) ClangCflags() string {
129 return "${config.LinuxBionicCflags}"
130}
131
132func (t *toolchainLinuxBionic) ClangCppflags() string {
133 return ""
134}
135
136func (t *toolchainLinuxBionic) ClangLdflags() string {
137 return "${config.LinuxBionicLdflags}"
138}
139
140func (t *toolchainLinuxBionic) ToolchainClangCflags() string {
Dan Willemsen38394b92017-09-18 22:50:22 -0700141 return "-m64 -march=x86-64" +
142 // TODO: We're not really android, but we don't have a triple yet b/31393676
143 " -U__ANDROID__ -fno-emulated-tls"
Dan Willemsen01a405a2016-06-13 17:19:03 -0700144}
145
146func (t *toolchainLinuxBionic) ToolchainClangLdflags() string {
147 return "-m64"
148}
149
150func (t *toolchainLinuxBionic) AvailableLibraries() []string {
151 return nil
152}
153
154func (t *toolchainLinuxBionic) Bionic() bool {
155 return true
156}
157
158var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{}
159
160func linuxBionicToolchainFactory(arch android.Arch) Toolchain {
161 return toolchainLinuxBionicSingleton
162}
163
164func init() {
165 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory)
166}