Move ELF build-id reader into a separate library.

Bug: 328702178
Change-Id: I188a8d20d22e67e4f0c7e3441e3781fff369c828
This commit is contained in:
Peter Collingbourne 2024-03-14 21:17:21 -07:00
parent 208444ce5d
commit 941ff1dbc7
5 changed files with 35 additions and 7 deletions

View file

@ -5,17 +5,16 @@ package {
blueprint_go_binary { blueprint_go_binary {
name: "symbols_map", name: "symbols_map",
srcs: [ srcs: [
"elf.go",
"r8.go", "r8.go",
"symbols_map.go", "symbols_map.go",
], ],
testSrcs: [ testSrcs: [
"elf_test.go",
"r8_test.go", "r8_test.go",
], ],
deps: [ deps: [
"blueprint-pathtools", "blueprint-pathtools",
"golang-protobuf-encoding-prototext", "golang-protobuf-encoding-prototext",
"soong-elf",
"soong-response", "soong-response",
"symbols_map_proto", "symbols_map_proto",
], ],

View file

@ -22,6 +22,7 @@ import (
"strings" "strings"
"android/soong/cmd/symbols_map/symbols_map_proto" "android/soong/cmd/symbols_map/symbols_map_proto"
"android/soong/elf"
"android/soong/response" "android/soong/response"
"github.com/google/blueprint/pathtools" "github.com/google/blueprint/pathtools"
@ -116,7 +117,7 @@ func main() {
if *elfFile != "" { if *elfFile != "" {
typ = symbols_map_proto.Mapping_ELF typ = symbols_map_proto.Mapping_ELF
location = *elfFile location = *elfFile
identifier, err = elfIdentifier(*elfFile, true) identifier, err = elf.Identifier(*elfFile, true)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "error reading elf identifier: %s\n", err) fmt.Fprintf(os.Stderr, "error reading elf identifier: %s\n", err)
os.Exit(1) os.Exit(1)

28
elf/Android.bp Normal file
View file

@ -0,0 +1,28 @@
// Copyright 2016 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
bootstrap_go_package {
name: "soong-elf",
pkgPath: "android/soong/elf",
srcs: [
"elf.go",
],
testSrcs: [
"elf_test.go",
],
}

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package elf
import ( import (
"debug/elf" "debug/elf"
@ -26,9 +26,9 @@ import (
const gnuBuildID = "GNU\x00" const gnuBuildID = "GNU\x00"
// elfIdentifier extracts the elf build ID from an elf file. If allowMissing is true it returns // Identifier extracts the elf build ID from an elf file. If allowMissing is true it returns
// an empty identifier if the file exists but the build ID note does not. // an empty identifier if the file exists but the build ID note does not.
func elfIdentifier(filename string, allowMissing bool) (string, error) { func Identifier(filename string, allowMissing bool) (string, error) {
f, err := os.Open(filename) f, err := os.Open(filename)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to open %s: %w", filename, err) return "", fmt.Errorf("failed to open %s: %w", filename, err)

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package main package elf
import ( import (
"bytes" "bytes"