Add linker_scripts property am: 958c957696
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2073768 Change-Id: I419295585abb0180f7e6555aa0351184745036ea Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -49,3 +49,23 @@ cc_binary {
|
|||||||
expectedUnStrippedFile := "outputbase/execroot/__main__/foo"
|
expectedUnStrippedFile := "outputbase/execroot/__main__/foo"
|
||||||
android.AssertStringEquals(t, "Unstripped output file", expectedUnStrippedFile, unStrippedFilePath.String())
|
android.AssertStringEquals(t, "Unstripped output file", expectedUnStrippedFile, unStrippedFilePath.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBinaryLinkerScripts(t *testing.T) {
|
||||||
|
result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
|
||||||
|
cc_binary {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["foo.cc"],
|
||||||
|
linker_scripts: ["foo.ld", "bar.ld"],
|
||||||
|
}`)
|
||||||
|
|
||||||
|
binFoo := result.ModuleForTests("foo", "android_arm64_armv8-a").Rule("ld")
|
||||||
|
|
||||||
|
android.AssertStringListContains(t, "missing dependency on linker_scripts",
|
||||||
|
binFoo.Implicits.Strings(), "foo.ld")
|
||||||
|
android.AssertStringListContains(t, "missing dependency on linker_scripts",
|
||||||
|
binFoo.Implicits.Strings(), "bar.ld")
|
||||||
|
android.AssertStringDoesContain(t, "missing flag for linker_scripts",
|
||||||
|
libfoo.Args["ldFlags"], "-Wl,--script,foo.ld")
|
||||||
|
android.AssertStringDoesContain(t, "missing flag for linker_scripts",
|
||||||
|
libfoo.Args["ldFlags"], "-Wl,--script,bar.ld")
|
||||||
|
}
|
||||||
|
@@ -87,6 +87,8 @@ func CheckBadLinkerFlags(ctx BaseModuleContext, prop string, flags []string) {
|
|||||||
ctx.PropertyErrorf(prop, "Bad flag: `%s` is not allowed", flag)
|
ctx.PropertyErrorf(prop, "Bad flag: `%s` is not allowed", flag)
|
||||||
} else if strings.HasPrefix(flag, "-Wl,--version-script") {
|
} else if strings.HasPrefix(flag, "-Wl,--version-script") {
|
||||||
ctx.PropertyErrorf(prop, "Bad flag: `%s`, use version_script instead", flag)
|
ctx.PropertyErrorf(prop, "Bad flag: `%s`, use version_script instead", flag)
|
||||||
|
} else if flag == "-T" || strings.HasPrefix(flag, "--script") {
|
||||||
|
ctx.PropertyErrorf(prop, "Bad flag: `%s`, use linker_scripts instead", flag)
|
||||||
} else if flag == "--coverage" {
|
} else if flag == "--coverage" {
|
||||||
ctx.PropertyErrorf(prop, "Bad flag: `%s`, use native_coverage instead", flag)
|
ctx.PropertyErrorf(prop, "Bad flag: `%s`, use native_coverage instead", flag)
|
||||||
} else if strings.Contains(flag, " ") {
|
} else if strings.Contains(flag, " ") {
|
||||||
|
14
cc/linker.go
14
cc/linker.go
@@ -227,6 +227,9 @@ type BaseLinkerProperties struct {
|
|||||||
// local file name to pass to the linker as --dynamic-list
|
// local file name to pass to the linker as --dynamic-list
|
||||||
Dynamic_list *string `android:"path,arch_variant"`
|
Dynamic_list *string `android:"path,arch_variant"`
|
||||||
|
|
||||||
|
// local files to pass to the linker as --script
|
||||||
|
Linker_scripts []string `android:"path,arch_variant"`
|
||||||
|
|
||||||
// list of static libs that should not be used to build this module
|
// list of static libs that should not be used to build this module
|
||||||
Exclude_static_libs []string `android:"arch_variant"`
|
Exclude_static_libs []string `android:"arch_variant"`
|
||||||
|
|
||||||
@@ -602,6 +605,17 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
flags.LdFlagsDeps = append(flags.LdFlagsDeps, dynamicList.Path())
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, dynamicList.Path())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkerScriptPaths := android.PathsForModuleSrc(ctx, linker.Properties.Linker_scripts)
|
||||||
|
if len(linkerScriptPaths) > 0 && (ctx.Darwin() || ctx.Windows()) {
|
||||||
|
ctx.PropertyErrorf("linker_scripts", "Only supported for ELF files")
|
||||||
|
} else {
|
||||||
|
for _, linkerScriptPath := range linkerScriptPaths {
|
||||||
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
||||||
|
"-Wl,--script,"+linkerScriptPath.String())
|
||||||
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, linkerScriptPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags
|
return flags
|
||||||
|
Reference in New Issue
Block a user