| 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 ( | 
|  | 18 | "strings" | 
|  | 19 |  | 
|  | 20 | "android/soong/android" | 
|  | 21 | ) | 
|  | 22 |  | 
|  | 23 | var ( | 
|  | 24 | linuxBionicCflags = ClangFilterUnknownCflags([]string{ | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 25 | "-fdiagnostics-color", | 
|  | 26 |  | 
|  | 27 | "-Wa,--noexecstack", | 
|  | 28 |  | 
|  | 29 | "-fPIC", | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 30 |  | 
|  | 31 | "-U_FORTIFY_SOURCE", | 
|  | 32 | "-D_FORTIFY_SOURCE=2", | 
|  | 33 | "-fstack-protector-strong", | 
|  | 34 |  | 
|  | 35 | // From x86_64_device | 
|  | 36 | "-ffunction-sections", | 
|  | 37 | "-finline-functions", | 
|  | 38 | "-finline-limit=300", | 
|  | 39 | "-fno-short-enums", | 
|  | 40 | "-funswitch-loops", | 
|  | 41 | "-funwind-tables", | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 42 | "-fno-canonical-system-headers", | 
|  | 43 |  | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 44 | // Tell clang where the gcc toolchain is | 
|  | 45 | "--gcc-toolchain=${LinuxBionicGccRoot}", | 
|  | 46 |  | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 47 | // This is normally in ClangExtraTargetCflags, but this is considered host | 
|  | 48 | "-nostdlibinc", | 
|  | 49 | }) | 
|  | 50 |  | 
|  | 51 | linuxBionicLdflags = ClangFilterUnknownCflags([]string{ | 
|  | 52 | "-Wl,-z,noexecstack", | 
|  | 53 | "-Wl,-z,relro", | 
|  | 54 | "-Wl,-z,now", | 
|  | 55 | "-Wl,--build-id=md5", | 
|  | 56 | "-Wl,--warn-shared-textrel", | 
|  | 57 | "-Wl,--fatal-warnings", | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 58 | "-Wl,--hash-style=gnu", | 
|  | 59 | "-Wl,--no-undefined-version", | 
|  | 60 |  | 
|  | 61 | // Use the device gcc toolchain | 
|  | 62 | "--gcc-toolchain=${LinuxBionicGccRoot}", | 
|  | 63 | }) | 
| Chih-Hung Hsieh | 3101a96 | 2018-04-17 14:16:05 -0700 | [diff] [blame] | 64 |  | 
|  | 65 | linuxBionicLldflags = ClangFilterUnknownLldflags(linuxBionicLdflags) | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 66 | ) | 
|  | 67 |  | 
|  | 68 | func init() { | 
|  | 69 | pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " ")) | 
|  | 70 | pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " ")) | 
| Chih-Hung Hsieh | 3101a96 | 2018-04-17 14:16:05 -0700 | [diff] [blame] | 71 | pctx.StaticVariable("LinuxBionicLldflags", strings.Join(linuxBionicLldflags, " ")) | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 72 |  | 
| Elliott Hughes | de28deb | 2017-10-12 09:07:53 -0700 | [diff] [blame] | 73 | pctx.StaticVariable("LinuxBionicIncludeFlags", bionicHeaders("x86")) | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 74 |  | 
|  | 75 | // Use the device gcc toolchain for now | 
|  | 76 | pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}") | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | type toolchainLinuxBionic struct { | 
|  | 80 | toolchain64Bit | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | func (t *toolchainLinuxBionic) Name() string { | 
|  | 84 | return "x86_64" | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | func (t *toolchainLinuxBionic) GccRoot() string { | 
|  | 88 | return "${config.LinuxBionicGccRoot}" | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | func (t *toolchainLinuxBionic) GccTriple() string { | 
|  | 92 | return "x86_64-linux-android" | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | func (t *toolchainLinuxBionic) GccVersion() string { | 
|  | 96 | return "4.9" | 
|  | 97 | } | 
|  | 98 |  | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 99 | func (t *toolchainLinuxBionic) IncludeFlags() string { | 
|  | 100 | return "${config.LinuxBionicIncludeFlags}" | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | func (t *toolchainLinuxBionic) ClangTriple() string { | 
|  | 104 | // TODO: we don't have a triple yet b/31393676 | 
|  | 105 | return "x86_64-linux-android" | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | func (t *toolchainLinuxBionic) ClangCflags() string { | 
|  | 109 | return "${config.LinuxBionicCflags}" | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | func (t *toolchainLinuxBionic) ClangCppflags() string { | 
|  | 113 | return "" | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | func (t *toolchainLinuxBionic) ClangLdflags() string { | 
|  | 117 | return "${config.LinuxBionicLdflags}" | 
|  | 118 | } | 
|  | 119 |  | 
| Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 120 | func (t *toolchainLinuxBionic) ClangLldflags() string { | 
| Chih-Hung Hsieh | 3101a96 | 2018-04-17 14:16:05 -0700 | [diff] [blame] | 121 | return "${config.LinuxBionicLldflags}" | 
| Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 122 | } | 
|  | 123 |  | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 124 | func (t *toolchainLinuxBionic) ToolchainClangCflags() string { | 
| Dan Willemsen | 38394b9 | 2017-09-18 22:50:22 -0700 | [diff] [blame] | 125 | return "-m64 -march=x86-64" + | 
|  | 126 | // 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] | 127 | " -U__ANDROID__" | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
|  | 130 | func (t *toolchainLinuxBionic) ToolchainClangLdflags() string { | 
|  | 131 | return "-m64" | 
|  | 132 | } | 
|  | 133 |  | 
|  | 134 | func (t *toolchainLinuxBionic) AvailableLibraries() []string { | 
|  | 135 | return nil | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | func (t *toolchainLinuxBionic) Bionic() bool { | 
|  | 139 | return true | 
|  | 140 | } | 
|  | 141 |  | 
| Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 142 | func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string { | 
|  | 143 | return "x86_64" | 
|  | 144 | } | 
|  | 145 |  | 
| Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 146 | var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} | 
|  | 147 |  | 
|  | 148 | func linuxBionicToolchainFactory(arch android.Arch) Toolchain { | 
|  | 149 | return toolchainLinuxBionicSingleton | 
|  | 150 | } | 
|  | 151 |  | 
|  | 152 | func init() { | 
|  | 153 | registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) | 
|  | 154 | } |