blob: e7133c928be13762fc7b30158d627ce6a09ae37e [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{
Dan Willemsen01a405a2016-06-13 17:19:03 -070025 "-fdiagnostics-color",
26
27 "-Wa,--noexecstack",
28
29 "-fPIC",
Dan Willemsen01a405a2016-06-13 17:19:03 -070030
31 "-U_FORTIFY_SOURCE",
32 "-D_FORTIFY_SOURCE=2",
33 "-fstack-protector-strong",
34
35 // From x86_64_device
36 "-ffunction-sections",
37 "-finline-functions",
38 "-finline-limit=300",
39 "-fno-short-enums",
40 "-funswitch-loops",
41 "-funwind-tables",
Dan Willemsen01a405a2016-06-13 17:19:03 -070042 "-fno-canonical-system-headers",
43
Dan Willemsen01a405a2016-06-13 17:19:03 -070044 // Tell clang where the gcc toolchain is
45 "--gcc-toolchain=${LinuxBionicGccRoot}",
46
Dan Willemsen01a405a2016-06-13 17:19:03 -070047 // This is normally in ClangExtraTargetCflags, but this is considered host
48 "-nostdlibinc",
49 })
50
51 linuxBionicLdflags = ClangFilterUnknownCflags([]string{
52 "-Wl,-z,noexecstack",
53 "-Wl,-z,relro",
54 "-Wl,-z,now",
55 "-Wl,--build-id=md5",
56 "-Wl,--warn-shared-textrel",
57 "-Wl,--fatal-warnings",
Dan Willemsen01a405a2016-06-13 17:19:03 -070058 "-Wl,--hash-style=gnu",
59 "-Wl,--no-undefined-version",
60
61 // Use the device gcc toolchain
62 "--gcc-toolchain=${LinuxBionicGccRoot}",
63 })
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070064
65 linuxBionicLldflags = ClangFilterUnknownLldflags(linuxBionicLdflags)
Dan Willemsen01a405a2016-06-13 17:19:03 -070066)
67
68func init() {
69 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " "))
70 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " "))
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -070071 pctx.StaticVariable("LinuxBionicLldflags", strings.Join(linuxBionicLldflags, " "))
Dan Willemsen01a405a2016-06-13 17:19:03 -070072
Dan Willemsen01a405a2016-06-13 17:19:03 -070073 // Use the device gcc toolchain for now
74 pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}")
75}
76
77type toolchainLinuxBionic struct {
78 toolchain64Bit
Colin Crosse3fee342021-06-21 17:28:25 -070079 toolchainBionic
Dan Willemsen01a405a2016-06-13 17:19:03 -070080}
81
82func (t *toolchainLinuxBionic) Name() string {
83 return "x86_64"
84}
85
86func (t *toolchainLinuxBionic) GccRoot() string {
87 return "${config.LinuxBionicGccRoot}"
88}
89
90func (t *toolchainLinuxBionic) GccTriple() string {
91 return "x86_64-linux-android"
92}
93
94func (t *toolchainLinuxBionic) GccVersion() string {
95 return "4.9"
96}
97
Dan Willemsen01a405a2016-06-13 17:19:03 -070098func (t *toolchainLinuxBionic) IncludeFlags() string {
Martin Stjernholm41ab2512020-04-08 01:06:07 +010099 return ""
Dan Willemsen01a405a2016-06-13 17:19:03 -0700100}
101
102func (t *toolchainLinuxBionic) ClangTriple() string {
103 // TODO: we don't have a triple yet b/31393676
104 return "x86_64-linux-android"
105}
106
107func (t *toolchainLinuxBionic) ClangCflags() string {
108 return "${config.LinuxBionicCflags}"
109}
110
111func (t *toolchainLinuxBionic) ClangCppflags() string {
112 return ""
113}
114
115func (t *toolchainLinuxBionic) ClangLdflags() string {
116 return "${config.LinuxBionicLdflags}"
117}
118
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700119func (t *toolchainLinuxBionic) ClangLldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700120 return "${config.LinuxBionicLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700121}
122
Dan Willemsen01a405a2016-06-13 17:19:03 -0700123func (t *toolchainLinuxBionic) ToolchainClangCflags() string {
Dan Willemsen38394b92017-09-18 22:50:22 -0700124 return "-m64 -march=x86-64" +
125 // TODO: We're not really android, but we don't have a triple yet b/31393676
Alex Lighta08ae842018-10-31 11:18:22 -0700126 " -U__ANDROID__"
Dan Willemsen01a405a2016-06-13 17:19:03 -0700127}
128
129func (t *toolchainLinuxBionic) ToolchainClangLdflags() string {
130 return "-m64"
131}
132
133func (t *toolchainLinuxBionic) AvailableLibraries() []string {
134 return nil
135}
136
Dan Willemsen9ff34c02018-10-10 17:58:19 -0700137func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string {
138 return "x86_64"
139}
140
Dan Willemsen01a405a2016-06-13 17:19:03 -0700141var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{}
142
143func linuxBionicToolchainFactory(arch android.Arch) Toolchain {
144 return toolchainLinuxBionicSingleton
145}
146
147func init() {
148 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory)
149}