diff options
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/binary.go | 13 | ||||
| -rw-r--r-- | rust/builder.go | 6 | ||||
| -rw-r--r-- | rust/config/Android.bp | 2 | ||||
| -rw-r--r-- | rust/config/allowed_list.go | 2 | ||||
| -rw-r--r-- | rust/config/darwin_host.go (renamed from rust/config/x86_darwin_host.go) | 41 | ||||
| -rw-r--r-- | rust/rust.go | 15 | ||||
| -rw-r--r-- | rust/sanitize.go | 4 |
7 files changed, 69 insertions, 14 deletions
diff --git a/rust/binary.go b/rust/binary.go index 2c3f54835..7c18730c6 100644 --- a/rust/binary.go +++ b/rust/binary.go @@ -31,6 +31,11 @@ type BinaryCompilerProperties struct { Static_executable *bool `android:"arch_variant"` } +type binaryInterface interface { + binary() bool + staticallyLinked() bool +} + type binaryDecorator struct { *baseCompiler stripper Stripper @@ -155,3 +160,11 @@ func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage { } return binary.baseCompiler.stdLinkage(ctx) } + +func (binary *binaryDecorator) binary() bool { + return true +} + +func (binary *binaryDecorator) staticallyLinked() bool { + return Bool(binary.Properties.Static_executable) +} diff --git a/rust/builder.go b/rust/builder.go index 426a569bf..f79cf9b12 100644 --- a/rust/builder.go +++ b/rust/builder.go @@ -95,7 +95,7 @@ func init() { func TransformSrcToBinary(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath) buildOutput { - flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto") + flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin") return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "bin") } @@ -112,13 +112,13 @@ func TransformSrctoDylib(ctx ModuleContext, mainSrc android.Path, deps PathDeps, func TransformSrctoStatic(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath) buildOutput { - flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto") + flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin") return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "staticlib") } func TransformSrctoShared(ctx ModuleContext, mainSrc android.Path, deps PathDeps, flags Flags, outputFile android.WritablePath) buildOutput { - flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto") + flags.GlobalRustFlags = append(flags.GlobalRustFlags, "-C lto=thin") return transformSrctoCrate(ctx, mainSrc, deps, flags, outputFile, "cdylib") } diff --git a/rust/config/Android.bp b/rust/config/Android.bp index 5b121c3aa..7757c79fc 100644 --- a/rust/config/Android.bp +++ b/rust/config/Android.bp @@ -16,7 +16,7 @@ bootstrap_go_package { "lints.go", "toolchain.go", "allowed_list.go", - "x86_darwin_host.go", + "darwin_host.go", "x86_linux_bionic_host.go", "x86_linux_host.go", "x86_device.go", diff --git a/rust/config/allowed_list.go b/rust/config/allowed_list.go index 47ca3a7ec..8182c327a 100644 --- a/rust/config/allowed_list.go +++ b/rust/config/allowed_list.go @@ -18,6 +18,7 @@ var ( "frameworks/native/libs/binder/rust", "frameworks/proto_logging/stats", "packages/modules/DnsResolver", + "packages/modules/Uwb", "packages/modules/Virtualization", "prebuilts/rust", "system/bt", @@ -32,6 +33,7 @@ var ( "system/security", "system/tools/aidl", "tools/security/fuzzing/example_rust_fuzzer", + "tools/security/fuzzing/orphans", "vendor/", } diff --git a/rust/config/x86_darwin_host.go b/rust/config/darwin_host.go index 8ff0dd4be..03bea8274 100644 --- a/rust/config/x86_darwin_host.go +++ b/rust/config/darwin_host.go @@ -25,41 +25,64 @@ var ( DarwinRustLinkFlags = []string{ "-B${cc_config.MacToolPath}", } + darwinArm64Rustflags = []string{} + darwinArm64Linkflags = []string{} darwinX8664Rustflags = []string{} darwinX8664Linkflags = []string{} ) func init() { + registerToolchainFactory(android.Darwin, android.Arm64, darwinArm64ToolchainFactory) registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory) + pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " ")) pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " ")) + + pctx.StaticVariable("DarwinToolchainArm64RustFlags", strings.Join(darwinArm64Rustflags, " ")) + pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " ")) pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " ")) pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " ")) } type toolchainDarwin struct { + toolchain64Bit toolchainRustFlags string toolchainLinkFlags string } +type toolchainDarwinArm64 struct { + toolchainDarwin +} + type toolchainDarwinX8664 struct { - toolchain64Bit toolchainDarwin } +func (toolchainDarwinArm64) Supported() bool { + return true +} + func (toolchainDarwinX8664) Supported() bool { return true } -func (toolchainDarwinX8664) Bionic() bool { +func (toolchainDarwin) Bionic() bool { return false } +func (t *toolchainDarwinArm64) Name() string { + return "arm64" +} + func (t *toolchainDarwinX8664) Name() string { return "x86_64" } +func (t *toolchainDarwinArm64) RustTriple() string { + return "aarch64-apple-darwin" +} + func (t *toolchainDarwinX8664) RustTriple() string { return "x86_64-apple-darwin" } @@ -76,6 +99,15 @@ func (t *toolchainDarwin) ProcMacroSuffix() string { return ".dylib" } +func (t *toolchainDarwinArm64) ToolchainLinkFlags() string { + // Prepend the lld flags from cc_config so we stay in sync with cc + return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainArm64LinkFlags}" +} + +func (t *toolchainDarwinArm64) ToolchainRustFlags() string { + return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainArm64RustFlags}" +} + func (t *toolchainDarwinX8664) ToolchainLinkFlags() string { // Prepend the lld flags from cc_config so we stay in sync with cc return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainX8664LinkFlags}" @@ -85,8 +117,13 @@ func (t *toolchainDarwinX8664) ToolchainRustFlags() string { return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainX8664RustFlags}" } +func darwinArm64ToolchainFactory(arch android.Arch) Toolchain { + return toolchainDarwinArm64Singleton +} + func darwinX8664ToolchainFactory(arch android.Arch) Toolchain { return toolchainDarwinX8664Singleton } +var toolchainDarwinArm64Singleton Toolchain = &toolchainDarwinArm64{} var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{} diff --git a/rust/rust.go b/rust/rust.go index 13169f17e..c465cb609 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -261,10 +261,8 @@ func (mod *Module) Rlib() bool { } func (mod *Module) Binary() bool { - if mod.compiler != nil { - if _, ok := mod.compiler.(*binaryDecorator); ok { - return true - } + if binary, ok := mod.compiler.(binaryInterface); ok { + return binary.binary() } return false } @@ -273,7 +271,7 @@ func (mod *Module) StaticExecutable() bool { if !mod.Binary() { return false } - return Bool(mod.compiler.(*binaryDecorator).Properties.Static_executable) + return mod.StaticallyLinked() } func (mod *Module) Object() bool { @@ -1123,7 +1121,12 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { if cc.IsWholeStaticLib(depTag) { // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail // if the library is not prefixed by "lib". - if libName, ok := libNameFromFilePath(linkObject.Path()); ok { + if mod.Binary() { + // Binaries may sometimes need to link whole static libraries that don't start with 'lib'. + // Since binaries don't need to 'rebundle' these like libraries and only use these for the + // final linkage, pass the args directly to the linker to handle these cases. + depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...) + } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok { depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) } else { ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName()) diff --git a/rust/sanitize.go b/rust/sanitize.go index a4ba4bd33..baa383da6 100644 --- a/rust/sanitize.go +++ b/rust/sanitize.go @@ -311,8 +311,8 @@ func (mod *Module) SetSanitizeDep(b bool) { func (mod *Module) StaticallyLinked() bool { if lib, ok := mod.compiler.(libraryInterface); ok { return lib.rlib() || lib.static() - } else if binary, ok := mod.compiler.(*binaryDecorator); ok { - return Bool(binary.Properties.Static_executable) + } else if binary, ok := mod.compiler.(binaryInterface); ok { + return binary.staticallyLinked() } return false } |