blob: f80be9915c2f7459d35e55df6d0377bab2d9db46 [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 (
Dan Willemsen01a405a2016-06-13 17:19:03 -070018 "android/soong/android"
19)
20
21var (
Colin Cross33bac242021-07-14 17:03:16 -070022 linuxBionicCflags = []string{
Dan Willemsen01a405a2016-06-13 17:19:03 -070023 "-Wa,--noexecstack",
24
25 "-fPIC",
Dan Willemsen01a405a2016-06-13 17:19:03 -070026
27 "-U_FORTIFY_SOURCE",
28 "-D_FORTIFY_SOURCE=2",
29 "-fstack-protector-strong",
30
31 // From x86_64_device
32 "-ffunction-sections",
Dan Willemsen01a405a2016-06-13 17:19:03 -070033 "-fno-short-enums",
Dan Willemsen01a405a2016-06-13 17:19:03 -070034 "-funwind-tables",
Dan Willemsen01a405a2016-06-13 17:19:03 -070035
Dan Willemsen01a405a2016-06-13 17:19:03 -070036 // Tell clang where the gcc toolchain is
37 "--gcc-toolchain=${LinuxBionicGccRoot}",
38
Dan Willemsen01a405a2016-06-13 17:19:03 -070039 // This is normally in ClangExtraTargetCflags, but this is considered host
40 "-nostdlibinc",
Colin Cross33bac242021-07-14 17:03:16 -070041 }
Dan Willemsen01a405a2016-06-13 17:19:03 -070042
Colin Cross33bac242021-07-14 17:03:16 -070043 linuxBionicLdflags = []string{
Dan Willemsen01a405a2016-06-13 17:19:03 -070044 "-Wl,-z,noexecstack",
45 "-Wl,-z,relro",
46 "-Wl,-z,now",
47 "-Wl,--build-id=md5",
Dan Willemsen01a405a2016-06-13 17:19:03 -070048 "-Wl,--fatal-warnings",
Dan Willemsen01a405a2016-06-13 17:19:03 -070049 "-Wl,--hash-style=gnu",
50 "-Wl,--no-undefined-version",
51
52 // Use the device gcc toolchain
53 "--gcc-toolchain=${LinuxBionicGccRoot}",
Colin Cross33bac242021-07-14 17:03:16 -070054 }
Colin Crossd1a28132021-06-21 17:34:47 -070055
Eric Rahm19524712023-10-20 15:56:27 +000056 linuxBionicLldflags = append(linuxBionicLdflags,
57 "-Wl,--compress-debug-sections=zstd",
58 )
59
Colin Crossd1a28132021-06-21 17:34:47 -070060 // Embed the linker into host bionic binaries. This is needed to support host bionic,
61 // as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be
62 // either an absolute path, or relative from CWD. To work around this, we extract
63 // the load sections from the runtime linker ELF binary and embed them into each host
64 // bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static
65 // binary, and then we use a special entry point to fix up the arguments passed by
66 // the kernel before jumping to the embedded linker.
67 linuxBionicCrtBeginSharedBinary = append(android.CopyOf(bionicCrtBeginSharedBinary),
68 "host_bionic_linker_script")
Dan Willemsen01a405a2016-06-13 17:19:03 -070069)
70
Colin Cross4fa894d2022-09-30 15:44:45 -070071const (
72 x86_64GccVersion = "4.9"
73)
74
Dan Willemsen01a405a2016-06-13 17:19:03 -070075func init() {
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc4d11bc2022-10-14 21:20:27 +000076 exportedVars.ExportStringListStaticVariable("LinuxBionicCflags", linuxBionicCflags)
77 exportedVars.ExportStringListStaticVariable("LinuxBionicLdflags", linuxBionicLdflags)
Eric Rahm19524712023-10-20 15:56:27 +000078 exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLldflags)
Dan Willemsen01a405a2016-06-13 17:19:03 -070079
Dan Willemsen01a405a2016-06-13 17:19:03 -070080 // Use the device gcc toolchain for now
Alex Márquez Pérez Muñíz Díaz Púras Thaureauxc4d11bc2022-10-14 21:20:27 +000081 exportedVars.ExportStringStaticVariable("LinuxBionicGccVersion", x86_64GccVersion)
82 exportedVars.ExportSourcePathVariable("LinuxBionicGccRoot",
Colin Cross4fa894d2022-09-30 15:44:45 -070083 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}")
Dan Willemsen01a405a2016-06-13 17:19:03 -070084}
85
86type toolchainLinuxBionic struct {
87 toolchain64Bit
Colin Crosse3fee342021-06-21 17:28:25 -070088 toolchainBionic
Dan Willemsen01a405a2016-06-13 17:19:03 -070089}
90
91func (t *toolchainLinuxBionic) Name() string {
92 return "x86_64"
93}
94
Dan Willemsen01a405a2016-06-13 17:19:03 -070095func (t *toolchainLinuxBionic) IncludeFlags() string {
Martin Stjernholm41ab2512020-04-08 01:06:07 +010096 return ""
Dan Willemsen01a405a2016-06-13 17:19:03 -070097}
98
99func (t *toolchainLinuxBionic) ClangTriple() string {
100 // TODO: we don't have a triple yet b/31393676
101 return "x86_64-linux-android"
102}
103
Colin Cross33bac242021-07-14 17:03:16 -0700104func (t *toolchainLinuxBionic) Cflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700105 return "${config.LinuxBionicCflags}"
106}
107
Colin Cross33bac242021-07-14 17:03:16 -0700108func (t *toolchainLinuxBionic) Cppflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700109 return ""
110}
111
Colin Cross33bac242021-07-14 17:03:16 -0700112func (t *toolchainLinuxBionic) Ldflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700113 return "${config.LinuxBionicLdflags}"
114}
115
Colin Cross33bac242021-07-14 17:03:16 -0700116func (t *toolchainLinuxBionic) Lldflags() string {
Chih-Hung Hsieh3101a962018-04-17 14:16:05 -0700117 return "${config.LinuxBionicLldflags}"
Chih-Hung Hsieh02b4da52018-04-03 11:33:34 -0700118}
119
Colin Cross33bac242021-07-14 17:03:16 -0700120func (t *toolchainLinuxBionic) ToolchainCflags() string {
Dan Willemsen38394b92017-09-18 22:50:22 -0700121 return "-m64 -march=x86-64" +
122 // TODO: We're not really android, but we don't have a triple yet b/31393676
Alex Lighta08ae842018-10-31 11:18:22 -0700123 " -U__ANDROID__"
Dan Willemsen01a405a2016-06-13 17:19:03 -0700124}
125
Colin Cross33bac242021-07-14 17:03:16 -0700126func (t *toolchainLinuxBionic) ToolchainLdflags() string {
Dan Willemsen01a405a2016-06-13 17:19:03 -0700127 return "-m64"
128}
129
130func (t *toolchainLinuxBionic) AvailableLibraries() []string {
131 return nil
132}
133
Dan Willemsen9ff34c02018-10-10 17:58:19 -0700134func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string {
135 return "x86_64"
136}
137
Colin Crossd1a28132021-06-21 17:34:47 -0700138func (toolchainLinuxBionic) CrtBeginSharedBinary() []string {
139 return linuxBionicCrtBeginSharedBinary
140}
141
Dan Willemsen01a405a2016-06-13 17:19:03 -0700142var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{}
143
144func linuxBionicToolchainFactory(arch android.Arch) Toolchain {
145 return toolchainLinuxBionicSingleton
146}
147
148func init() {
149 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory)
150}