blob: 976cc25beb9d9368a440d6bbb2a66434b836e38e [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 (
Colin Cross33bac242021-07-14 17:03:16 -070024 linuxBionicCflags = []string{
Dan Willemsen01a405a2016-06-13 17:19:03 -070025 "-Wa,--noexecstack",
26
27 "-fPIC",
Dan Willemsen01a405a2016-06-13 17:19:03 -070028
29 "-U_FORTIFY_SOURCE",
30 "-D_FORTIFY_SOURCE=2",
31 "-fstack-protector-strong",
32
33 // From x86_64_device
34 "-ffunction-sections",
Dan Willemsen01a405a2016-06-13 17:19:03 -070035 "-fno-short-enums",
Dan Willemsen01a405a2016-06-13 17:19:03 -070036 "-funwind-tables",
Dan Willemsen01a405a2016-06-13 17:19:03 -070037
Dan Willemsen01a405a2016-06-13 17:19:03 -070038 // Tell clang where the gcc toolchain is
39 "--gcc-toolchain=${LinuxBionicGccRoot}",
40
Dan Willemsen01a405a2016-06-13 17:19:03 -070041 // This is normally in ClangExtraTargetCflags, but this is considered host
42 "-nostdlibinc",
Colin Cross33bac242021-07-14 17:03:16 -070043 }
Dan Willemsen01a405a2016-06-13 17:19:03 -070044
Colin Cross33bac242021-07-14 17:03:16 -070045 linuxBionicLdflags = []string{
Dan Willemsen01a405a2016-06-13 17:19:03 -070046 "-Wl,-z,noexecstack",
47 "-Wl,-z,relro",
48 "-Wl,-z,now",
49 "-Wl,--build-id=md5",
Dan Willemsen01a405a2016-06-13 17:19:03 -070050 "-Wl,--fatal-warnings",
Dan Willemsen01a405a2016-06-13 17:19:03 -070051 "-Wl,--hash-style=gnu",
52 "-Wl,--no-undefined-version",
53
54 // Use the device gcc toolchain
55 "--gcc-toolchain=${LinuxBionicGccRoot}",
Colin Cross33bac242021-07-14 17:03:16 -070056 }
Colin Crossd1a28132021-06-21 17:34:47 -070057
58 // Embed the linker into host bionic binaries. This is needed to support host bionic,
59 // as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be
60 // either an absolute path, or relative from CWD. To work around this, we extract
61 // the load sections from the runtime linker ELF binary and embed them into each host
62 // bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static
63 // binary, and then we use a special entry point to fix up the arguments passed by
64 // the kernel before jumping to the embedded linker.
65 linuxBionicCrtBeginSharedBinary = append(android.CopyOf(bionicCrtBeginSharedBinary),
66 "host_bionic_linker_script")
Dan Willemsen01a405a2016-06-13 17:19:03 -070067)
68
69func init() {
70 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " "))
71 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " "))
Colin Cross33bac242021-07-14 17:03:16 -070072 pctx.StaticVariable("LinuxBionicLldflags", strings.Join(linuxBionicLdflags, " "))
Dan Willemsen01a405a2016-06-13 17:19:03 -070073
Dan Willemsen01a405a2016-06-13 17:19:03 -070074 // Use the device gcc toolchain for now
75 pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}")
76}
77
78type toolchainLinuxBionic struct {
79 toolchain64Bit
Colin Crosse3fee342021-06-21 17:28:25 -070080 toolchainBionic
Dan Willemsen01a405a2016-06-13 17:19:03 -070081}
82
83func (t *toolchainLinuxBionic) Name() string {
84 return "x86_64"
85}
86
87func (t *toolchainLinuxBionic) GccRoot() string {
88 return "${config.LinuxBionicGccRoot}"
89}
90
91func (t *toolchainLinuxBionic) GccTriple() string {
92 return "x86_64-linux-android"
93}
94
95func (t *toolchainLinuxBionic) GccVersion() string {
96 return "4.9"
97}
98
Dan Willemsen01a405a2016-06-13 17:19:03 -070099func (t *toolchainLinuxBionic) IncludeFlags() string {
Martin Stjernholm41ab2512020-04-08 01:06:07 +0100100 return ""
Dan Willemsen01a405a2016-06-13 17:19:03 -0700101}
102
103func (t *toolchainLinuxBionic) ClangTriple() string {
104 // TODO: we don't have a triple yet b/31393676
105 return "x86_64-linux-android"
106}
107
Colin Cross33bac242021-07-14 17:03:16 -0700108func (t *toolchainLinuxBionic) Cflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700109 return "${config.LinuxBionicCflags}"
110}
111
Colin Cross33bac242021-07-14 17:03:16 -0700112func (t *toolchainLinuxBionic) Cppflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700113 return ""
114}
115
Colin Cross33bac242021-07-14 17:03:16 -0700116func (t *toolchainLinuxBionic) Ldflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700117 return "${config.LinuxBionicLdflags}"
118}
119
Colin Cross33bac242021-07-14 17:03:16 -0700120func (t *toolchainLinuxBionic) Lldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700121 return "${config.LinuxBionicLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700122}
123
Colin Cross33bac242021-07-14 17:03:16 -0700124func (t *toolchainLinuxBionic) ToolchainCflags() string {
Dan Willemsen38394b92017-09-18 22:50:22 -0700125 return "-m64 -march=x86-64" +
126 // TODO: We're not really android, but we don't have a triple yet b/31393676
Alex Lighta08ae842018-10-31 11:18:22 -0700127 " -U__ANDROID__"
Dan Willemsen01a405a2016-06-13 17:19:03 -0700128}
129
Colin Cross33bac242021-07-14 17:03:16 -0700130func (t *toolchainLinuxBionic) ToolchainLdflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700131 return "-m64"
132}
133
134func (t *toolchainLinuxBionic) AvailableLibraries() []string {
135 return nil
136}
137
Dan Willemsen9ff34c02018-10-10 17:58:19 -0700138func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string {
139 return "x86_64"
140}
141
Colin Crossd1a28132021-06-21 17:34:47 -0700142func (toolchainLinuxBionic) CrtBeginSharedBinary() []string {
143 return linuxBionicCrtBeginSharedBinary
144}
145
Dan Willemsen01a405a2016-06-13 17:19:03 -0700146var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{}
147
148func linuxBionicToolchainFactory(arch android.Arch) Toolchain {
149 return toolchainLinuxBionicSingleton
150}
151
152func init() {
153 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory)
154}