From 8df4b3dc6bac76087adb4c4e2ff754be73c60e2c Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 12 Apr 2021 13:20:58 -0700 Subject: [PATCH] Use SHT_RELR relocations where possible. Ideally we'll want to move this logic to the toolchain itself, but right now the linker doesn't even know it's targeting Android, let alone which API level. Bug: http://b/147452927 Test: treehugger Change-Id: I6c5c822d0767e789fa0e2c8e5668fddfd90680bb --- cc/linker.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cc/linker.go b/cc/linker.go index 73fc4f0ee..a9930ada0 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -421,9 +421,13 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { if !BoolDefault(linker.Properties.Pack_relocations, true) { flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=none") } else if ctx.Device() { - // The SHT_RELR relocations is only supported by API level >= 28. - // Do not turn this on if older version NDK is used. - if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 28) { + // SHT_RELR relocations are only supported at API level >= 30. + // ANDROID_RELR relocations were supported at API level >= 28. + // Relocation packer was supported at API level >= 23. + // Do the best we can... + if !ctx.useSdk() || CheckSdkVersionAtLeast(ctx, 30) { + flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=android+relr") + } else if CheckSdkVersionAtLeast(ctx, 28) { flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=android+relr", "-Wl,--use-android-relr-tags")