Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | var ( |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 22 | linuxBionicCflags = []string{ |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 23 | "-Wa,--noexecstack", |
| 24 | |
| 25 | "-fPIC", |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 26 | |
| 27 | "-U_FORTIFY_SOURCE", |
| 28 | "-D_FORTIFY_SOURCE=2", |
| 29 | "-fstack-protector-strong", |
| 30 | |
| 31 | // From x86_64_device |
| 32 | "-ffunction-sections", |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 33 | "-fno-short-enums", |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 34 | "-funwind-tables", |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 35 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 36 | // Tell clang where the gcc toolchain is |
| 37 | "--gcc-toolchain=${LinuxBionicGccRoot}", |
| 38 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 39 | // This is normally in ClangExtraTargetCflags, but this is considered host |
| 40 | "-nostdlibinc", |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 41 | } |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 42 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 43 | linuxBionicLdflags = []string{ |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 44 | "-Wl,-z,noexecstack", |
| 45 | "-Wl,-z,relro", |
| 46 | "-Wl,-z,now", |
| 47 | "-Wl,--build-id=md5", |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 48 | "-Wl,--fatal-warnings", |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 49 | "-Wl,--hash-style=gnu", |
| 50 | "-Wl,--no-undefined-version", |
| 51 | |
| 52 | // Use the device gcc toolchain |
| 53 | "--gcc-toolchain=${LinuxBionicGccRoot}", |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 54 | } |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 55 | |
Eric Rahm | 1952471 | 2023-10-20 15:56:27 +0000 | [diff] [blame^] | 56 | linuxBionicLldflags = append(linuxBionicLdflags, |
| 57 | "-Wl,--compress-debug-sections=zstd", |
| 58 | ) |
| 59 | |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 60 | // 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 Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 69 | ) |
| 70 | |
Colin Cross | 4fa894d | 2022-09-30 15:44:45 -0700 | [diff] [blame] | 71 | const ( |
| 72 | x86_64GccVersion = "4.9" |
| 73 | ) |
| 74 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 75 | func init() { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c4d11bc | 2022-10-14 21:20:27 +0000 | [diff] [blame] | 76 | exportedVars.ExportStringListStaticVariable("LinuxBionicCflags", linuxBionicCflags) |
| 77 | exportedVars.ExportStringListStaticVariable("LinuxBionicLdflags", linuxBionicLdflags) |
Eric Rahm | 1952471 | 2023-10-20 15:56:27 +0000 | [diff] [blame^] | 78 | exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLldflags) |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 79 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 80 | // Use the device gcc toolchain for now |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c4d11bc | 2022-10-14 21:20:27 +0000 | [diff] [blame] | 81 | exportedVars.ExportStringStaticVariable("LinuxBionicGccVersion", x86_64GccVersion) |
| 82 | exportedVars.ExportSourcePathVariable("LinuxBionicGccRoot", |
Colin Cross | 4fa894d | 2022-09-30 15:44:45 -0700 | [diff] [blame] | 83 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}") |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | type toolchainLinuxBionic struct { |
| 87 | toolchain64Bit |
Colin Cross | e3fee34 | 2021-06-21 17:28:25 -0700 | [diff] [blame] | 88 | toolchainBionic |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | func (t *toolchainLinuxBionic) Name() string { |
| 92 | return "x86_64" |
| 93 | } |
| 94 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 95 | func (t *toolchainLinuxBionic) IncludeFlags() string { |
Martin Stjernholm | 41ab251 | 2020-04-08 01:06:07 +0100 | [diff] [blame] | 96 | return "" |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | func (t *toolchainLinuxBionic) ClangTriple() string { |
| 100 | // TODO: we don't have a triple yet b/31393676 |
| 101 | return "x86_64-linux-android" |
| 102 | } |
| 103 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 104 | func (t *toolchainLinuxBionic) Cflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 105 | return "${config.LinuxBionicCflags}" |
| 106 | } |
| 107 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 108 | func (t *toolchainLinuxBionic) Cppflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 109 | return "" |
| 110 | } |
| 111 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 112 | func (t *toolchainLinuxBionic) Ldflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 113 | return "${config.LinuxBionicLdflags}" |
| 114 | } |
| 115 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 116 | func (t *toolchainLinuxBionic) Lldflags() string { |
Chih-Hung Hsieh | 3101a96 | 2018-04-17 14:16:05 -0700 | [diff] [blame] | 117 | return "${config.LinuxBionicLldflags}" |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 120 | func (t *toolchainLinuxBionic) ToolchainCflags() string { |
Dan Willemsen | 38394b9 | 2017-09-18 22:50:22 -0700 | [diff] [blame] | 121 | return "-m64 -march=x86-64" + |
| 122 | // TODO: We're not really android, but we don't have a triple yet b/31393676 |
Alex Light | a08ae84 | 2018-10-31 11:18:22 -0700 | [diff] [blame] | 123 | " -U__ANDROID__" |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 126 | func (t *toolchainLinuxBionic) ToolchainLdflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 127 | return "-m64" |
| 128 | } |
| 129 | |
| 130 | func (t *toolchainLinuxBionic) AvailableLibraries() []string { |
| 131 | return nil |
| 132 | } |
| 133 | |
Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 134 | func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string { |
| 135 | return "x86_64" |
| 136 | } |
| 137 | |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 138 | func (toolchainLinuxBionic) CrtBeginSharedBinary() []string { |
| 139 | return linuxBionicCrtBeginSharedBinary |
| 140 | } |
| 141 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 142 | var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} |
| 143 | |
| 144 | func linuxBionicToolchainFactory(arch android.Arch) Toolchain { |
| 145 | return toolchainLinuxBionicSingleton |
| 146 | } |
| 147 | |
| 148 | func init() { |
| 149 | registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) |
| 150 | } |