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) 20 21var ( 22 linuxBionicCflags = []string{ 23 "-Wa,--noexecstack", 24 25 "-fPIC", 26 27 "-U_FORTIFY_SOURCE", 28 "-D_FORTIFY_SOURCE=2", 29 "-fstack-protector-strong", 30 31 // From x86_64_device 32 "-ffunction-sections", 33 "-fno-short-enums", 34 "-funwind-tables", 35 36 // Tell clang where the gcc toolchain is 37 "--gcc-toolchain=${LinuxBionicGccRoot}", 38 39 // This is normally in ClangExtraTargetCflags, but this is considered host 40 "-nostdlibinc", 41 } 42 43 linuxBionicLdflags = []string{ 44 "-Wl,-z,noexecstack", 45 "-Wl,-z,relro", 46 "-Wl,-z,now", 47 "-Wl,--build-id=md5", 48 "-Wl,--fatal-warnings", 49 "-Wl,--hash-style=gnu", 50 "-Wl,--no-undefined-version", 51 52 // Use the device gcc toolchain 53 "--gcc-toolchain=${LinuxBionicGccRoot}", 54 } 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") 65) 66 67const ( 68 x86_64GccVersion = "4.9" 69) 70 71func init() { 72 exportedVars.ExportStringListStaticVariable("LinuxBionicCflags", linuxBionicCflags) 73 exportedVars.ExportStringListStaticVariable("LinuxBionicLdflags", linuxBionicLdflags) 74 exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLdflags) 75 76 // Use the device gcc toolchain for now 77 exportedVars.ExportStringStaticVariable("LinuxBionicGccVersion", x86_64GccVersion) 78 exportedVars.ExportSourcePathVariable("LinuxBionicGccRoot", 79 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}") 80} 81 82type toolchainLinuxBionic struct { 83 toolchain64Bit 84 toolchainBionic 85} 86 87func (t *toolchainLinuxBionic) Name() string { 88 return "x86_64" 89} 90 91func (t *toolchainLinuxBionic) IncludeFlags() string { 92 return "" 93} 94 95func (t *toolchainLinuxBionic) ClangTriple() string { 96 // TODO: we don't have a triple yet b/31393676 97 return "x86_64-linux-android" 98} 99 100func (t *toolchainLinuxBionic) Cflags() string { 101 return "${config.LinuxBionicCflags}" 102} 103 104func (t *toolchainLinuxBionic) Cppflags() string { 105 return "" 106} 107 108func (t *toolchainLinuxBionic) Ldflags() string { 109 return "${config.LinuxBionicLdflags}" 110} 111 112func (t *toolchainLinuxBionic) Lldflags() string { 113 return "${config.LinuxBionicLldflags}" 114} 115 116func (t *toolchainLinuxBionic) ToolchainCflags() string { 117 return "-m64 -march=x86-64" + 118 // TODO: We're not really android, but we don't have a triple yet b/31393676 119 " -U__ANDROID__" 120} 121 122func (t *toolchainLinuxBionic) ToolchainLdflags() string { 123 return "-m64" 124} 125 126func (t *toolchainLinuxBionic) AvailableLibraries() []string { 127 return nil 128} 129 130func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string { 131 return "x86_64" 132} 133 134func (toolchainLinuxBionic) CrtBeginSharedBinary() []string { 135 return linuxBionicCrtBeginSharedBinary 136} 137 138var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} 139 140func linuxBionicToolchainFactory(arch android.Arch) Toolchain { 141 return toolchainLinuxBionicSingleton 142} 143 144func init() { 145 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) 146} 147