Merge "Revert "Fix -Wl,--exclude-libs for clang runtime libraries"" am: 3bd8c1bb3e

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2130353

Change-Id: Ied8a33fd74af37edc36fcb7eedca9035af00ccf4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Colin Cross 2022-06-17 22:27:39 +00:00 committed by Automerger Merge Worker
commit 87037635da
5 changed files with 16 additions and 165 deletions

View file

@ -95,10 +95,6 @@ type Deps struct {
HeaderLibs []string
RuntimeLibs []string
// UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to
// prevent automatically exporting symbols.
UnexportedStaticLibs []string
// Used for data dependencies adjacent to tests
DataLibs []string
DataBins []string
@ -160,7 +156,6 @@ type PathDeps struct {
GeneratedDeps android.Paths
Flags []string
LdFlags []string
IncludeDirs android.Paths
SystemIncludeDirs android.Paths
ReexportedDirs android.Paths
@ -683,9 +678,6 @@ type libraryDependencyTag struct {
// Whether or not this dependency has to be followed for the apex variants
excludeInApex bool
// If true, don't automatically export symbols from the static library into a shared library.
unexportedSymbols bool
}
// header returns true if the libraryDependencyTag is tagging a header lib dependency.
@ -1929,8 +1921,6 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
}
flags.Local.LdFlags = append(flags.Local.LdFlags, deps.LdFlags...)
c.flags = flags
// We need access to all the flags seen by a source file.
if c.sabi != nil {
@ -2378,13 +2368,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}, depTag, RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs))
}
for _, lib := range deps.UnexportedStaticLibs {
depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency, unexportedSymbols: true}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "link", Variation: "static"},
}, depTag, RewriteSnapshotLib(lib, GetSnapshot(c, &snapshotInfo, actx).StaticLibs))
}
for _, lib := range deps.LateSharedLibs {
if inList(lib, sharedLibNames) {
// This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
@ -2883,10 +2866,6 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
}
}
if libDepTag.unexportedSymbols {
depPaths.LdFlags = append(depPaths.LdFlags,
"-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base())
}
}
if libDepTag.static() && !libDepTag.wholeStatic {

View file

@ -399,7 +399,7 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
if ctx.toolchain().Bionic() {
// libclang_rt.builtins has to be last on the command line
if !Bool(linker.Properties.No_libcrt) && !ctx.header() {
deps.UnexportedStaticLibs = append(deps.UnexportedStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
deps.LateStaticLibs = append(deps.LateStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
}
if inList("libdl", deps.SharedLibs) {
@ -422,7 +422,7 @@ func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
}
} else if ctx.toolchain().Musl() {
if !Bool(linker.Properties.No_libcrt) && !ctx.header() {
deps.UnexportedStaticLibs = append(deps.UnexportedStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
deps.LateStaticLibs = append(deps.LateStaticLibs, config.BuiltinsRuntimeLibrary(ctx.toolchain()))
}
}
@ -530,6 +530,10 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
}
}
if ctx.toolchain().LibclangRuntimeLibraryArch() != "" {
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--exclude-libs="+config.BuiltinsRuntimeLibrary(ctx.toolchain())+".a")
}
CheckBadLinkerFlags(ctx, "ldflags", linker.Properties.Ldflags)
flags.Local.LdFlags = append(flags.Local.LdFlags, proptools.NinjaAndShellEscapeList(linker.Properties.Ldflags)...)

View file

@ -588,6 +588,13 @@ func toDisableUnsignedShiftBaseChange(flags []string) bool {
}
func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a"
if sanitize.Properties.MinimalRuntimeDep {
flags.Local.LdFlags = append(flags.Local.LdFlags,
"-Wl,--exclude-libs,"+minimalRuntimeLib)
}
if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
return flags
}
@ -717,6 +724,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
if enableMinimalRuntime(sanitize) {
flags.Local.CFlags = append(flags.Local.CFlags, strings.Join(minimalRuntimeFlags, " "))
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib)
}
if Bool(sanitize.Properties.Sanitize.Fuzzer) {
@ -1209,7 +1217,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
}
// static executable gets static runtime libs
depTag := libraryDependencyTag{Kind: staticLibraryDependency, unexportedSymbols: true}
depTag := libraryDependencyTag{Kind: staticLibraryDependency}
variations := append(mctx.Target().Variations(),
blueprint.Variation{Mutator: "link", Variation: "static"})
if c.Device() {

View file

@ -201,121 +201,6 @@ func TestAsan(t *testing.T) {
t.Run("device", func(t *testing.T) { check(t, result, "android_arm64_armv8-a") })
}
func TestUbsan(t *testing.T) {
bp := `
cc_binary {
name: "bin_with_ubsan",
host_supported: true,
shared_libs: [
"libshared",
],
static_libs: [
"libstatic",
"libnoubsan",
],
sanitize: {
undefined: true,
}
}
cc_binary {
name: "bin_depends_ubsan",
host_supported: true,
shared_libs: [
"libshared",
],
static_libs: [
"libstatic",
"libubsan",
"libnoubsan",
],
}
cc_binary {
name: "bin_no_ubsan",
host_supported: true,
shared_libs: [
"libshared",
],
static_libs: [
"libstatic",
"libnoubsan",
],
}
cc_library_shared {
name: "libshared",
host_supported: true,
shared_libs: ["libtransitive"],
}
cc_library_shared {
name: "libtransitive",
host_supported: true,
}
cc_library_static {
name: "libubsan",
host_supported: true,
sanitize: {
undefined: true,
}
}
cc_library_static {
name: "libstatic",
host_supported: true,
}
cc_library_static {
name: "libnoubsan",
host_supported: true,
}
`
result := android.GroupFixturePreparers(
prepareForCcTest,
).RunTestWithBp(t, bp)
check := func(t *testing.T, result *android.TestResult, variant string) {
staticVariant := variant + "_static"
minimalRuntime := result.ModuleForTests("libclang_rt.ubsan_minimal", staticVariant)
// The binaries, one with ubsan and one without
binWithUbsan := result.ModuleForTests("bin_with_ubsan", variant)
binDependsUbsan := result.ModuleForTests("bin_depends_ubsan", variant)
binNoUbsan := result.ModuleForTests("bin_no_ubsan", variant)
android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in bin_with_ubsan static libs",
strings.Split(binWithUbsan.Rule("ld").Args["libFlags"], " "),
minimalRuntime.OutputFiles(t, "")[0].String())
android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in bin_depends_ubsan static libs",
strings.Split(binDependsUbsan.Rule("ld").Args["libFlags"], " "),
minimalRuntime.OutputFiles(t, "")[0].String())
android.AssertStringListDoesNotContain(t, "unexpected libclang_rt.ubsan_minimal in bin_no_ubsan static libs",
strings.Split(binNoUbsan.Rule("ld").Args["libFlags"], " "),
minimalRuntime.OutputFiles(t, "")[0].String())
android.AssertStringListContains(t, "missing -Wl,--exclude-libs for minimal runtime in bin_with_ubsan",
strings.Split(binWithUbsan.Rule("ld").Args["ldFlags"], " "),
"-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base())
android.AssertStringListContains(t, "missing -Wl,--exclude-libs for minimal runtime in bin_depends_ubsan static libs",
strings.Split(binDependsUbsan.Rule("ld").Args["ldFlags"], " "),
"-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base())
android.AssertStringListDoesNotContain(t, "unexpected -Wl,--exclude-libs for minimal runtime in bin_no_ubsan static libs",
strings.Split(binNoUbsan.Rule("ld").Args["ldFlags"], " "),
"-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base())
}
t.Run("host", func(t *testing.T) { check(t, result, result.Config.BuildOSTarget.String()) })
t.Run("device", func(t *testing.T) { check(t, result, "android_arm64_armv8-a") })
}
type MemtagNoteType int
const (

View file

@ -73,6 +73,7 @@ func commonDefaultModules() string {
nocrt: true,
system_shared_libs: [],
stl: "none",
srcs: [""],
check_elf_files: false,
sanitize: {
never: true,
@ -83,7 +84,6 @@ func commonDefaultModules() string {
name: "libcompiler_rt-extras",
defaults: ["toolchain_libs_defaults"],
vendor_ramdisk_available: true,
srcs: [""],
}
cc_prebuilt_library_static {
@ -93,13 +93,11 @@ func commonDefaultModules() string {
vendor_available: true,
vendor_ramdisk_available: true,
native_bridge_supported: true,
srcs: [""],
}
cc_prebuilt_library_shared {
name: "libclang_rt.hwasan",
defaults: ["toolchain_libs_defaults"],
srcs: [""],
}
cc_prebuilt_library_static {
@ -110,7 +108,6 @@ func commonDefaultModules() string {
],
vendor_ramdisk_available: true,
native_bridge_supported: true,
srcs: [""],
}
cc_prebuilt_library_static {
@ -119,34 +116,17 @@ func commonDefaultModules() string {
"linux_bionic_supported",
"toolchain_libs_defaults",
],
srcs: [""],
}
// Needed for sanitizer
cc_prebuilt_library_shared {
name: "libclang_rt.ubsan_standalone",
defaults: ["toolchain_libs_defaults"],
srcs: [""],
}
cc_prebuilt_library_static {
name: "libclang_rt.ubsan_minimal",
defaults: ["toolchain_libs_defaults"],
host_supported: true,
target: {
android_arm64: {
srcs: ["libclang_rt.ubsan_minimal.android_arm64.a"],
},
android_arm: {
srcs: ["libclang_rt.ubsan_minimal.android_arm.a"],
},
linux_glibc_x86_64: {
srcs: ["libclang_rt.ubsan_minimal.x86_64.a"],
},
linux_glibc_x86: {
srcs: ["libclang_rt.ubsan_minimal.x86.a"],
},
},
}
cc_library {
@ -566,11 +546,6 @@ var PrepareForTestWithCcDefaultModules = android.GroupFixturePreparers(
"defaults/cc/common/crtend_so.c": nil,
"defaults/cc/common/crtend.c": nil,
"defaults/cc/common/crtbrand.c": nil,
"defaults/cc/common/libclang_rt.ubsan_minimal.android_arm64.a": nil,
"defaults/cc/common/libclang_rt.ubsan_minimal.android_arm.a": nil,
"defaults/cc/common/libclang_rt.ubsan_minimal.x86_64.a": nil,
"defaults/cc/common/libclang_rt.ubsan_minimal.x86.a": nil,
}.AddToFixture(),
// Place the default cc test modules that are common to all platforms in a location that will not