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 | |
| 56 | // Embed the linker into host bionic binaries. This is needed to support host bionic, |
| 57 | // as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be |
| 58 | // either an absolute path, or relative from CWD. To work around this, we extract |
| 59 | // the load sections from the runtime linker ELF binary and embed them into each host |
| 60 | // bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static |
| 61 | // binary, and then we use a special entry point to fix up the arguments passed by |
| 62 | // the kernel before jumping to the embedded linker. |
| 63 | linuxBionicCrtBeginSharedBinary = append(android.CopyOf(bionicCrtBeginSharedBinary), |
| 64 | "host_bionic_linker_script") |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 65 | ) |
| 66 | |
Colin Cross | 4fa894d | 2022-09-30 15:44:45 -0700 | [diff] [blame] | 67 | const ( |
| 68 | x86_64GccVersion = "4.9" |
| 69 | ) |
| 70 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 71 | func init() { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c4d11bc | 2022-10-14 21:20:27 +0000 | [diff] [blame] | 72 | exportedVars.ExportStringListStaticVariable("LinuxBionicCflags", linuxBionicCflags) |
| 73 | exportedVars.ExportStringListStaticVariable("LinuxBionicLdflags", linuxBionicLdflags) |
Matías Hernández | d0500f1 | 2023-10-20 13:07:14 +0000 | [diff] [blame^] | 74 | exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLdflags) |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 75 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 76 | // 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] | 77 | exportedVars.ExportStringStaticVariable("LinuxBionicGccVersion", x86_64GccVersion) |
| 78 | exportedVars.ExportSourcePathVariable("LinuxBionicGccRoot", |
Colin Cross | 4fa894d | 2022-09-30 15:44:45 -0700 | [diff] [blame] | 79 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}") |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | type toolchainLinuxBionic struct { |
| 83 | toolchain64Bit |
Colin Cross | e3fee34 | 2021-06-21 17:28:25 -0700 | [diff] [blame] | 84 | toolchainBionic |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | func (t *toolchainLinuxBionic) Name() string { |
| 88 | return "x86_64" |
| 89 | } |
| 90 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 91 | func (t *toolchainLinuxBionic) IncludeFlags() string { |
Martin Stjernholm | 41ab251 | 2020-04-08 01:06:07 +0100 | [diff] [blame] | 92 | return "" |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | func (t *toolchainLinuxBionic) ClangTriple() string { |
| 96 | // TODO: we don't have a triple yet b/31393676 |
| 97 | return "x86_64-linux-android" |
| 98 | } |
| 99 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 100 | func (t *toolchainLinuxBionic) Cflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 101 | return "${config.LinuxBionicCflags}" |
| 102 | } |
| 103 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 104 | func (t *toolchainLinuxBionic) Cppflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 105 | return "" |
| 106 | } |
| 107 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 108 | func (t *toolchainLinuxBionic) Ldflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 109 | return "${config.LinuxBionicLdflags}" |
| 110 | } |
| 111 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 112 | func (t *toolchainLinuxBionic) Lldflags() string { |
Chih-Hung Hsieh | 3101a96 | 2018-04-17 14:16:05 -0700 | [diff] [blame] | 113 | return "${config.LinuxBionicLldflags}" |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 116 | func (t *toolchainLinuxBionic) ToolchainCflags() string { |
Dan Willemsen | 38394b9 | 2017-09-18 22:50:22 -0700 | [diff] [blame] | 117 | return "-m64 -march=x86-64" + |
| 118 | // 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] | 119 | " -U__ANDROID__" |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Colin Cross | 33bac24 | 2021-07-14 17:03:16 -0700 | [diff] [blame] | 122 | func (t *toolchainLinuxBionic) ToolchainLdflags() string { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 123 | return "-m64" |
| 124 | } |
| 125 | |
| 126 | func (t *toolchainLinuxBionic) AvailableLibraries() []string { |
| 127 | return nil |
| 128 | } |
| 129 | |
Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 130 | func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string { |
| 131 | return "x86_64" |
| 132 | } |
| 133 | |
Colin Cross | d1a2813 | 2021-06-21 17:34:47 -0700 | [diff] [blame] | 134 | func (toolchainLinuxBionic) CrtBeginSharedBinary() []string { |
| 135 | return linuxBionicCrtBeginSharedBinary |
| 136 | } |
| 137 | |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 138 | var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} |
| 139 | |
| 140 | func linuxBionicToolchainFactory(arch android.Arch) Toolchain { |
| 141 | return toolchainLinuxBionicSingleton |
| 142 | } |
| 143 | |
| 144 | func init() { |
| 145 | registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) |
| 146 | } |