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 15package config 16 17import ( 18 "android/soong/android" 19 "strings" 20) 21 22var ( 23 linuxBionicCflags = []string{ 24 "-Wa,--noexecstack", 25 26 "-fPIC", 27 28 "-fno-omit-frame-pointer", 29 30 "-U_FORTIFY_SOURCE", 31 "-D_FORTIFY_SOURCE=2", 32 "-fstack-protector-strong", 33 34 // From x86_64_device 35 "-ffunction-sections", 36 "-fno-short-enums", 37 "-funwind-tables", 38 39 // Tell clang where the gcc toolchain is 40 "--gcc-toolchain=${LinuxBionicGccRoot}", 41 42 // This is normally in ClangExtraTargetCflags, but this is considered host 43 "-nostdlibinc", 44 } 45 46 linuxBionicLdflags = []string{ 47 "-Wl,-z,noexecstack", 48 "-Wl,-z,relro", 49 "-Wl,-z,now", 50 "-Wl,--build-id=md5", 51 "-Wl,--fatal-warnings", 52 "-Wl,--no-undefined-version", 53 54 // Use the device gcc toolchain 55 "--gcc-toolchain=${LinuxBionicGccRoot}", 56 } 57 58 linuxBionicLldflags = append(linuxBionicLdflags, 59 "-Wl,--compress-debug-sections=zstd", 60 ) 61 62 // Embed the linker into host bionic binaries. This is needed to support host bionic, 63 // as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be 64 // either an absolute path, or relative from CWD. To work around this, we extract 65 // the load sections from the runtime linker ELF binary and embed them into each host 66 // bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static 67 // binary, and then we use a special entry point to fix up the arguments passed by 68 // the kernel before jumping to the embedded linker. 69 linuxBionicCrtBeginSharedBinary = append(android.CopyOf(bionicCrtBeginSharedBinary), 70 "host_bionic_linker_script") 71) 72 73const ( 74 x86_64GccVersion = "4.9" 75) 76 77func init() { 78 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " ")) 79 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " ")) 80 pctx.StaticVariable("LinuxBionicLldflags", strings.Join(linuxBionicLldflags, " ")) 81 82 // Use the device gcc toolchain for now 83 pctx.StaticVariable("LinuxBionicGccVersion", x86_64GccVersion) 84 pctx.SourcePathVariable("LinuxBionicGccRoot", 85 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}") 86} 87 88type toolchainLinuxBionic struct { 89 toolchain64Bit 90 toolchainBionic 91} 92 93func (t *toolchainLinuxBionic) Name() string { 94 return "x86_64" 95} 96 97func (t *toolchainLinuxBionic) IncludeFlags() string { 98 return "" 99} 100 101func (t *toolchainLinuxBionic) ClangTriple() string { 102 // TODO: we don't have a triple yet b/31393676 103 return "x86_64-linux-android" 104} 105 106func (t *toolchainLinuxBionic) Cflags() string { 107 return "${config.LinuxBionicCflags}" 108} 109 110func (t *toolchainLinuxBionic) Cppflags() string { 111 return "" 112} 113 114func (t *toolchainLinuxBionic) Ldflags() string { 115 return "${config.LinuxBionicLdflags}" 116} 117 118func (t *toolchainLinuxBionic) Lldflags() string { 119 return "${config.LinuxBionicLldflags}" 120} 121 122func (t *toolchainLinuxBionic) ToolchainCflags() string { 123 return "-m64 -march=x86-64" + 124 // TODO: We're not really android, but we don't have a triple yet b/31393676 125 " -U__ANDROID__" 126} 127 128func (t *toolchainLinuxBionic) ToolchainLdflags() string { 129 return "-m64" 130} 131 132func (t *toolchainLinuxBionic) AvailableLibraries() []string { 133 return nil 134} 135 136func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string { 137 return "x86_64" 138} 139 140func (toolchainLinuxBionic) CrtBeginSharedBinary() []string { 141 return linuxBionicCrtBeginSharedBinary 142} 143 144var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} 145 146func linuxBionicToolchainFactory(arch android.Arch) Toolchain { 147 return toolchainLinuxBionicSingleton 148} 149 150func init() { 151 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) 152} 153