Generate .build-id directory tree after every build.
The .build-id directory tree is as described here: https://fedoraproject.org/wiki/RolandMcGrath/BuildID Tools such as llvm-symbolizer understand this tree and can use it to look up symbols by build ID. This CL adds a post-build step that updates the .build-id directory under symbols after every build if necessary to contain symlinks to the corresponding symbols file. I also considered adding this as a build step after copying the symbol file to the symbols directory. However this would be complicated by the fact that many binaries have the same build-id such as the various copies of libc++ for the different APEXes. As a result it would be difficult to implement a .build-id updater that produces a correct symlink tree while taking into account concurrent updates to the same symlink by different build steps. This situation is resolved in the .build-id directory generator by having the symlink point to the lexically smallest path out of all paths with the same build-id. I measured the performance of the UpdateBuildIdDir function by writing a standalone program that just calls the function and running it over a copy of the symbols directory for a specific target. On my machine the execution time of the program when simulating various scenarios was as follows: Null build [1]: 36.2 ms ± 3.4 ms Initial build [2]: 162.3 ms ± 6.6 ms Single update [3]: 128.0 ms ± 6.1 ms Invalid .build-id dir [4]: 222.6 ms ± 8.6 ms This is with some improvements that have been contributed to the Go standard library [5,6]; without those improvements a null build is 37.9 ms ± 4.4 ms and a single update is 143.9 ms ± 4.5 ms. [1] hyperfine './update-build-id ~/2/test-symbols2/' [2] hyperfine -p 'rm -rf ~/2/test-symbols2/.build-id' './update-build-id ~/2/test-symbols2/' [3] hyperfine -p 'dd if=/dev/urandom of=$HOME/2/test-symbols2/system/bin/init conv=notrunc seek=808 bs=1 count=16' './update-build-id ~/2/test-symbols2/' [4] hyperfine -p 'touch ~/2/test-symbols2/.build-id/corrupt; sleep 0.1; touch ~/2/test-symbols2/system/bin/init' './update-build-id ~/2/test-symbols2/' [5] https://go.dev/cl/570877 [6] https://go.dev/cl/571436 Bug: 328702178 Change-Id: I8fc0ea81bd31ec80d6b912ba477e2e24b6b05f68
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"android/soong/elf"
|
||||
"android/soong/ui/metrics"
|
||||
)
|
||||
|
||||
@@ -342,6 +343,7 @@ func Build(ctx Context, config Config) {
|
||||
installCleanIfNecessary(ctx, config)
|
||||
}
|
||||
runNinjaForBuild(ctx, config)
|
||||
updateBuildIdDir(ctx, config)
|
||||
}
|
||||
|
||||
if what&RunDistActions != 0 {
|
||||
@@ -349,6 +351,16 @@ func Build(ctx Context, config Config) {
|
||||
}
|
||||
}
|
||||
|
||||
func updateBuildIdDir(ctx Context, config Config) {
|
||||
ctx.BeginTrace(metrics.RunShutdownTool, "update_build_id_dir")
|
||||
defer ctx.EndTrace()
|
||||
|
||||
symbolsDir := filepath.Join(config.ProductOut(), "symbols")
|
||||
if err := elf.UpdateBuildIdDir(symbolsDir); err != nil {
|
||||
ctx.Printf("failed to update %s/.build-id: %v", symbolsDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
func evaluateWhatToRun(config Config, verboseln func(v ...interface{})) int {
|
||||
//evaluate what to run
|
||||
what := 0
|
||||
|
||||
Reference in New Issue
Block a user