blob: 0f0420f76a8defd597bf24c69017c16ad58b4d1e [file] [log] [blame]
Colin Cross6371b382015-11-23 14:53:57 -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
Colin Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Cross6371b382015-11-23 14:53:57 -080016
17import (
18 "strings"
19
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Colin Cross6371b382015-11-23 14:53:57 -080021)
22
23var (
24 x86_64Cflags = []string{
Colin Cross6371b382015-11-23 14:53:57 -080025 // Help catch common 32/64-bit errors.
Colin Cross6371b382015-11-23 14:53:57 -080026 "-Werror=implicit-function-declaration",
Colin Cross6371b382015-11-23 14:53:57 -080027 }
28
29 x86_64Cppflags = []string{}
30
31 x86_64Ldflags = []string{
Colin Cross6371b382015-11-23 14:53:57 -080032 "-Wl,--hash-style=gnu",
33 }
34
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070035 x86_64Lldflags = ClangFilterUnknownLldflags(x86_64Ldflags)
36
Colin Cross6371b382015-11-23 14:53:57 -080037 x86_64ArchVariantCflags = map[string][]string{
38 "": []string{
39 "-march=x86-64",
40 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053041 "broadwell": []string{
42 "-march=broadwell",
43 },
44
Colin Cross6371b382015-11-23 14:53:57 -080045 "haswell": []string{
46 "-march=core-avx2",
47 },
48 "ivybridge": []string{
49 "-march=core-avx-i",
50 },
51 "sandybridge": []string{
Dan Willemsenb77bd792016-02-29 15:26:26 -080052 "-march=corei7",
Colin Cross6371b382015-11-23 14:53:57 -080053 },
54 "silvermont": []string{
55 "-march=slm",
56 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053057 "skylake": []string{
58 "-march=skylake",
59 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -070060 "stoneyridge": []string{
61 "-march=bdver4",
62 },
Colin Cross6371b382015-11-23 14:53:57 -080063 }
64
65 x86_64ArchFeatureCflags = map[string][]string{
66 "ssse3": []string{"-DUSE_SSSE3", "-mssse3"},
67 "sse4": []string{"-msse4"},
68 "sse4_1": []string{"-msse4.1"},
69 "sse4_2": []string{"-msse4.2"},
Dan Willemsen4ce47032016-05-06 17:20:53 -070070 "popcnt": []string{"-mpopcnt"},
Colin Cross6371b382015-11-23 14:53:57 -080071 "avx": []string{"-mavx"},
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +053072 "avx2": []string{"-mavx2"},
73 "avx512": []string{"-mavx512"},
Colin Cross6371b382015-11-23 14:53:57 -080074 "aes_ni": []string{"-maes"},
75 }
76)
77
Dan Willemsen34fc3b12015-12-07 12:30:44 -080078const (
79 x86_64GccVersion = "4.9"
80)
81
Colin Cross6371b382015-11-23 14:53:57 -080082func init() {
Dan Willemsen01a3c252019-01-11 19:02:16 -080083 android.RegisterDefaultArchVariantFeatures(android.Android, android.X86_64,
Dan Willemsenb1957a52016-06-23 23:44:54 -070084 "ssse3",
85 "sse4",
86 "sse4_1",
87 "sse4_2",
88 "popcnt")
Colin Cross6371b382015-11-23 14:53:57 -080089
Dan Willemsen34fc3b12015-12-07 12:30:44 -080090 pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion)
Colin Cross6371b382015-11-23 14:53:57 -080091
Colin Crossb98c8b02016-07-29 13:44:28 -070092 pctx.SourcePathVariable("X86_64GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -080093 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}")
Colin Cross6371b382015-11-23 14:53:57 -080094
Colin Crossb98c8b02016-07-29 13:44:28 -070095 pctx.StaticVariable("X86_64ToolchainCflags", "-m64")
96 pctx.StaticVariable("X86_64ToolchainLdflags", "-m64")
Colin Cross6371b382015-11-23 14:53:57 -080097
Colin Crossb98c8b02016-07-29 13:44:28 -070098 pctx.StaticVariable("X86_64Ldflags", strings.Join(x86_64Ldflags, " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -070099 pctx.StaticVariable("X86_64Lldflags", strings.Join(x86_64Lldflags, " "))
Elliott Hughesde28deb2017-10-12 09:07:53 -0700100 pctx.StaticVariable("X86_64IncludeFlags", bionicHeaders("x86"))
Colin Cross6371b382015-11-23 14:53:57 -0800101
102 // Clang cflags
Colin Crossb98c8b02016-07-29 13:44:28 -0700103 pctx.StaticVariable("X86_64ClangCflags", strings.Join(ClangFilterUnknownCflags(x86_64Cflags), " "))
104 pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " "))
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700105 pctx.StaticVariable("X86_64ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86_64Lldflags), " "))
Colin Crossb98c8b02016-07-29 13:44:28 -0700106 pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " "))
Colin Cross6371b382015-11-23 14:53:57 -0800107
Colin Cross91e90042016-12-02 17:13:24 -0800108 // Yasm flags
109 pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64")
110
Colin Cross6371b382015-11-23 14:53:57 -0800111 // Extended cflags
112
113 // Architecture variant cflags
114 for variant, cflags := range x86_64ArchVariantCflags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700115 pctx.StaticVariable("X86_64"+variant+"VariantClangCflags",
116 strings.Join(ClangFilterUnknownCflags(cflags), " "))
Colin Cross6371b382015-11-23 14:53:57 -0800117 }
118}
119
120type toolchainX86_64 struct {
121 toolchain64Bit
Dan Willemsenbd4abf52018-10-07 21:06:36 -0700122 toolchainClangCflags string
Colin Cross6371b382015-11-23 14:53:57 -0800123}
124
125func (t *toolchainX86_64) Name() string {
126 return "x86_64"
127}
128
129func (t *toolchainX86_64) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700130 return "${config.X86_64GccRoot}"
Colin Cross6371b382015-11-23 14:53:57 -0800131}
132
133func (t *toolchainX86_64) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700134 return "x86_64-linux-android"
Colin Cross6371b382015-11-23 14:53:57 -0800135}
136
137func (t *toolchainX86_64) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800138 return x86_64GccVersion
Colin Cross6371b382015-11-23 14:53:57 -0800139}
140
Colin Cross6371b382015-11-23 14:53:57 -0800141func (t *toolchainX86_64) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700142 return "${config.X86_64IncludeFlags}"
Colin Cross6371b382015-11-23 14:53:57 -0800143}
144
145func (t *toolchainX86_64) ClangTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700146 return t.GccTriple()
Colin Cross6371b382015-11-23 14:53:57 -0800147}
148
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700149func (t *toolchainX86_64) ToolchainClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700150 return "${config.X86_64ToolchainLdflags}"
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700151}
152
Colin Cross6371b382015-11-23 14:53:57 -0800153func (t *toolchainX86_64) ToolchainClangCflags() string {
154 return t.toolchainClangCflags
155}
156
157func (t *toolchainX86_64) ClangCflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700158 return "${config.X86_64ClangCflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800159}
160
161func (t *toolchainX86_64) ClangCppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700162 return "${config.X86_64ClangCppflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800163}
164
165func (t *toolchainX86_64) ClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700166 return "${config.X86_64Ldflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800167}
168
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700169func (t *toolchainX86_64) ClangLldflags() string {
170 return "${config.X86_64Lldflags}"
171}
172
Colin Cross91e90042016-12-02 17:13:24 -0800173func (t *toolchainX86_64) YasmFlags() string {
174 return "${config.X86_64YasmFlags}"
175}
176
Yi Kong924adc42018-08-31 14:27:44 -0700177func (toolchainX86_64) LibclangRuntimeLibraryArch() string {
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700178 return "x86_64"
179}
180
Colin Cross635c3b02016-05-18 15:37:25 -0700181func x86_64ToolchainFactory(arch android.Arch) Toolchain {
Colin Cross6371b382015-11-23 14:53:57 -0800182 toolchainClangCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700183 "${config.X86_64ToolchainCflags}",
184 "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}",
Colin Cross6371b382015-11-23 14:53:57 -0800185 }
186
187 for _, feature := range arch.ArchFeatures {
Colin Cross6371b382015-11-23 14:53:57 -0800188 toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...)
189 }
190
191 return &toolchainX86_64{
Colin Cross6371b382015-11-23 14:53:57 -0800192 toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
193 }
194}
195
196func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700197 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
Colin Cross6371b382015-11-23 14:53:57 -0800198}