2016-06-14 02:19:03 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-07-15 02:03:16 +02:00
|
|
|
linuxBionicCflags = []string{
|
2016-06-14 02:19:03 +02:00
|
|
|
"-Wa,--noexecstack",
|
|
|
|
|
|
|
|
"-fPIC",
|
|
|
|
|
|
|
|
"-U_FORTIFY_SOURCE",
|
|
|
|
"-D_FORTIFY_SOURCE=2",
|
|
|
|
"-fstack-protector-strong",
|
|
|
|
|
|
|
|
// From x86_64_device
|
|
|
|
"-ffunction-sections",
|
|
|
|
"-fno-short-enums",
|
|
|
|
"-funwind-tables",
|
|
|
|
|
|
|
|
// Tell clang where the gcc toolchain is
|
|
|
|
"--gcc-toolchain=${LinuxBionicGccRoot}",
|
|
|
|
|
|
|
|
// This is normally in ClangExtraTargetCflags, but this is considered host
|
|
|
|
"-nostdlibinc",
|
2021-07-15 02:03:16 +02:00
|
|
|
}
|
2016-06-14 02:19:03 +02:00
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
linuxBionicLdflags = []string{
|
2016-06-14 02:19:03 +02:00
|
|
|
"-Wl,-z,noexecstack",
|
|
|
|
"-Wl,-z,relro",
|
|
|
|
"-Wl,-z,now",
|
|
|
|
"-Wl,--build-id=md5",
|
|
|
|
"-Wl,--fatal-warnings",
|
|
|
|
"-Wl,--hash-style=gnu",
|
|
|
|
"-Wl,--no-undefined-version",
|
|
|
|
|
|
|
|
// Use the device gcc toolchain
|
|
|
|
"--gcc-toolchain=${LinuxBionicGccRoot}",
|
2021-07-15 02:03:16 +02:00
|
|
|
}
|
2021-06-22 02:34:47 +02:00
|
|
|
|
2023-10-20 17:56:27 +02:00
|
|
|
linuxBionicLldflags = append(linuxBionicLdflags,
|
|
|
|
"-Wl,--compress-debug-sections=zstd",
|
|
|
|
)
|
|
|
|
|
2021-06-22 02:34:47 +02:00
|
|
|
// Embed the linker into host bionic binaries. This is needed to support host bionic,
|
|
|
|
// as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be
|
|
|
|
// either an absolute path, or relative from CWD. To work around this, we extract
|
|
|
|
// the load sections from the runtime linker ELF binary and embed them into each host
|
|
|
|
// bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static
|
|
|
|
// binary, and then we use a special entry point to fix up the arguments passed by
|
|
|
|
// the kernel before jumping to the embedded linker.
|
|
|
|
linuxBionicCrtBeginSharedBinary = append(android.CopyOf(bionicCrtBeginSharedBinary),
|
|
|
|
"host_bionic_linker_script")
|
2016-06-14 02:19:03 +02:00
|
|
|
)
|
|
|
|
|
2022-10-01 00:44:45 +02:00
|
|
|
const (
|
|
|
|
x86_64GccVersion = "4.9"
|
|
|
|
)
|
|
|
|
|
2016-06-14 02:19:03 +02:00
|
|
|
func init() {
|
2022-10-14 23:20:27 +02:00
|
|
|
exportedVars.ExportStringListStaticVariable("LinuxBionicCflags", linuxBionicCflags)
|
|
|
|
exportedVars.ExportStringListStaticVariable("LinuxBionicLdflags", linuxBionicLdflags)
|
2023-10-20 17:56:27 +02:00
|
|
|
exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLldflags)
|
2016-06-14 02:19:03 +02:00
|
|
|
|
|
|
|
// Use the device gcc toolchain for now
|
2022-10-14 23:20:27 +02:00
|
|
|
exportedVars.ExportStringStaticVariable("LinuxBionicGccVersion", x86_64GccVersion)
|
|
|
|
exportedVars.ExportSourcePathVariable("LinuxBionicGccRoot",
|
2022-10-01 00:44:45 +02:00
|
|
|
"prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${LinuxBionicGccVersion}")
|
2016-06-14 02:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type toolchainLinuxBionic struct {
|
|
|
|
toolchain64Bit
|
2021-06-22 02:28:25 +02:00
|
|
|
toolchainBionic
|
2016-06-14 02:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxBionic) Name() string {
|
|
|
|
return "x86_64"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxBionic) IncludeFlags() string {
|
2020-04-08 02:06:07 +02:00
|
|
|
return ""
|
2016-06-14 02:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxBionic) ClangTriple() string {
|
|
|
|
// TODO: we don't have a triple yet b/31393676
|
|
|
|
return "x86_64-linux-android"
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainLinuxBionic) Cflags() string {
|
2016-06-14 02:19:03 +02:00
|
|
|
return "${config.LinuxBionicCflags}"
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainLinuxBionic) Cppflags() string {
|
2016-06-14 02:19:03 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainLinuxBionic) Ldflags() string {
|
2016-06-14 02:19:03 +02:00
|
|
|
return "${config.LinuxBionicLdflags}"
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainLinuxBionic) Lldflags() string {
|
2018-04-17 23:16:05 +02:00
|
|
|
return "${config.LinuxBionicLldflags}"
|
2018-04-03 20:33:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainLinuxBionic) ToolchainCflags() string {
|
2017-09-19 07:50:22 +02:00
|
|
|
return "-m64 -march=x86-64" +
|
|
|
|
// TODO: We're not really android, but we don't have a triple yet b/31393676
|
2018-10-31 19:18:22 +01:00
|
|
|
" -U__ANDROID__"
|
2016-06-14 02:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 02:03:16 +02:00
|
|
|
func (t *toolchainLinuxBionic) ToolchainLdflags() string {
|
2016-06-14 02:19:03 +02:00
|
|
|
return "-m64"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *toolchainLinuxBionic) AvailableLibraries() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-10-11 02:58:19 +02:00
|
|
|
func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string {
|
|
|
|
return "x86_64"
|
|
|
|
}
|
|
|
|
|
2021-06-22 02:34:47 +02:00
|
|
|
func (toolchainLinuxBionic) CrtBeginSharedBinary() []string {
|
|
|
|
return linuxBionicCrtBeginSharedBinary
|
|
|
|
}
|
|
|
|
|
2016-06-14 02:19:03 +02:00
|
|
|
var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{}
|
|
|
|
|
|
|
|
func linuxBionicToolchainFactory(arch android.Arch) Toolchain {
|
|
|
|
return toolchainLinuxBionicSingleton
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory)
|
|
|
|
}
|