Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit acee27cd authored by Yi Kong's avatar Yi Kong
Browse files

Strip libgcc to only keep fallback symbols

We use libgcc as fallback for symbols not present in libclang_rt
builtins, however we didn't know what exact symbols were being used,
some may not be intended to fallback.

Create libgcc_stripped, which only contains unwind symbols from libgcc.

Bug: 29275768
Test: bionic-unit-tests
Change-Id: I5b349fa6138e51663bf3b67109b880b4356da8e8
parent feef2ef4
Loading
Loading
Loading
Loading
+111 −0
Original line number Diff line number Diff line
@@ -482,6 +482,117 @@ toolchain_library {
    },
}

toolchain_library {
    name: "libgcc_stripped",
    defaults: ["linux_bionic_supported"],
    vendor_available: true,
    recovery_available: true,

    arch: {
        arm: {
            src: "prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a",
            strip: {
                keep_symbols_list: [
                    // unwind-arm.o
                    "_Unwind_Complete",
                    "_Unwind_DeleteException",
                    "_Unwind_GetCFA",
                    "_Unwind_VRS_Get",
                    "_Unwind_VRS_Pop",
                    "_Unwind_VRS_Set",
                    "__aeabi_unwind_cpp_pr0",
                    "__aeabi_unwind_cpp_pr1",
                    "__aeabi_unwind_cpp_pr2",
                    "__gnu_Unwind_Backtrace",
                    "__gnu_Unwind_ForcedUnwind",
                    "__gnu_Unwind_RaiseException",
                    "__gnu_Unwind_Resume",
                    "__gnu_Unwind_Resume_or_Rethrow",

                    // libunwind.o
                    "_Unwind_Backtrace",
                    "_Unwind_ForcedUnwind",
                    "_Unwind_RaiseException",
                    "_Unwind_Resume",
                    "_Unwind_Resume_or_Rethrow",
                    "___Unwind_Backtrace",
                    "___Unwind_ForcedUnwind",
                    "___Unwind_RaiseException",
                    "___Unwind_Resume",
                    "___Unwind_Resume_or_Rethrow",
                    "__gnu_Unwind_Restore_VFP",
                    "__gnu_Unwind_Restore_VFP_D",
                    "__gnu_Unwind_Restore_VFP_D_16_to_31",
                    "__gnu_Unwind_Restore_WMMXC",
                    "__gnu_Unwind_Restore_WMMXD",
                    "__gnu_Unwind_Save_VFP",
                    "__gnu_Unwind_Save_VFP_D",
                    "__gnu_Unwind_Save_VFP_D_16_to_31",
                    "__gnu_Unwind_Save_WMMXC",
                    "__gnu_Unwind_Save_WMMXD",
                    "__restore_core_regs",
                    "restore_core_regs",

                    // pr-support.o
                    "_Unwind_GetDataRelBase",
                    "_Unwind_GetLanguageSpecificData",
                    "_Unwind_GetRegionStart",
                    "_Unwind_GetTextRelBase",
                    "__gnu_unwind_execute",
                    "__gnu_unwind_frame",
                ],
                use_gnu_strip: true,
            },
        },
        arm64: {
            src: "prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/lib/gcc/aarch64-linux-android/4.9.x/libgcc.a",
        },
        x86: {
            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/32/libgcc.a",

        },
        x86_64: {
            src: "prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/lib/gcc/x86_64-linux-android/4.9.x/libgcc.a",
        },
    },
    strip: {
        keep_symbols_list: [
            // unwind-dw2.o
            "_Unwind_Backtrace",
            "_Unwind_DeleteException",
            "_Unwind_FindEnclosingFunction",
            "_Unwind_ForcedUnwind",
            "_Unwind_GetCFA",
            "_Unwind_GetDataRelBase",
            "_Unwind_GetGR",
            "_Unwind_GetIP",
            "_Unwind_GetIPInfo",
            "_Unwind_GetLanguageSpecificData",
            "_Unwind_GetRegionStart",
            "_Unwind_GetTextRelBase",
            "_Unwind_RaiseException",
            "_Unwind_Resume",
            "_Unwind_Resume_or_Rethrow",
            "_Unwind_SetGR",
            "_Unwind_SetIP",
            "__frame_state_for",

            // unwind-dw2-fde-dip.o
            "_Unwind_Find_FDE",
            "__deregister_frame",
            "__deregister_frame_info",
            "__deregister_frame_info_bases",
            "__register_frame",
            "__register_frame_info",
            "__register_frame_info_bases",
            "__register_frame_info_table",
            "__register_frame_info_table_bases",
            "__register_frame_table",
        ],
        use_gnu_strip: true,
    },
}

toolchain_library {
    name: "libwinpthread",
    host_supported: true,
+7 −0
Original line number Diff line number Diff line
@@ -92,6 +92,13 @@ func testApex(t *testing.T, bp string) *android.TestContext {
			recovery_available: true,
		}

		toolchain_library {
			name: "libgcc_stripped",
			src: "",
			vendor_available: true,
			recovery_available: true,
		}

		toolchain_library {
			name: "libclang_rt.builtins-aarch64-android",
			src: "",
+4 −0
Original line number Diff line number Diff line
@@ -255,6 +255,7 @@ type builderFlags struct {
	groupStaticLibs bool

	stripKeepSymbols       bool
	stripKeepSymbolsList   string
	stripKeepMiniDebugInfo bool
	stripAddGnuDebuglink   bool
	stripUseGnuStrip       bool
@@ -835,6 +836,9 @@ func TransformStrip(ctx android.ModuleContext, inputFile android.Path,
	if flags.stripKeepSymbols {
		args += " --keep-symbols"
	}
	if flags.stripKeepSymbolsList != "" {
		args += " -k" + flags.stripKeepSymbolsList
	}
	if flags.stripUseGnuStrip {
		args += " --use-gnu-strip"
	}
+2 −2
Original line number Diff line number Diff line
@@ -1833,13 +1833,13 @@ func TestStaticLibDepExport(t *testing.T) {
	// Check the shared version of lib2.
	variant := "android_arm64_armv8-a_core_shared"
	module := ctx.ModuleForTests("lib2", variant).Module().(*Module)
	checkStaticLibs(t, []string{"lib1", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module)
	checkStaticLibs(t, []string{"lib1", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)

	// Check the static version of lib2.
	variant = "android_arm64_armv8-a_core_static"
	module = ctx.ModuleForTests("lib2", variant).Module().(*Module)
	// libc++_static is linked additionally.
	checkStaticLibs(t, []string{"lib1", "libc++_static", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc"}, module)
	checkStaticLibs(t, []string{"lib1", "libc++_static", "libclang_rt.builtins-aarch64-android", "libatomic", "libgcc_stripped"}, module)
}

var compilerFlagsTestCases = []struct {
+4 −4
Original line number Diff line number Diff line
@@ -228,10 +228,10 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
		// libclang_rt.builtins, libgcc and libatomic have to be last on the command line
		if !Bool(linker.Properties.No_libcrt) {
			deps.LateStaticLibs = append(deps.LateStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
		}

			deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic")
		if !Bool(linker.Properties.No_libgcc) {
			deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc_stripped")
		} else if !Bool(linker.Properties.No_libgcc) {
			deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic")
			deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc")
		}

Loading