// Copyright 2017 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package pprofimport ()var ( errBadELF = errors.New("malformed ELF binary") errNoBuildID = errors.New("no NT_GNU_BUILD_ID found in ELF binary"))// elfBuildID returns the GNU build ID of the named ELF binary,// without introducing a dependency on debug/elf and its dependencies.func elfBuildID( string) (string, error) { := make([]byte, 256) , := os.Open()if != nil {return"", }defer .Close()if , := .ReadAt([:64], 0); != nil {return"", }// ELF file begins with \x7F E L F.if [0] != 0x7F || [1] != 'E' || [2] != 'L' || [3] != 'F' {return"", errBadELF }varbinary.ByteOrderswitch [5] {default:return"", errBadELFcase1: // little-endian = binary.LittleEndiancase2: // big-endian = binary.BigEndian }varintvar , int64switch [4] {default:return"", errBadELFcase1: // 32-bit file header = int64(.Uint32([32:])) = int64(.Uint16([46:]))if != 40 {return"", errBadELF } = int(.Uint16([48:]))case2: // 64-bit file header = int64(.Uint64([40:])) = int64(.Uint16([58:]))if != 64 {return"", errBadELF } = int(.Uint16([60:])) }for := 0; < ; ++ {if , := .ReadAt([:], +int64()*); != nil {return"", }if := .Uint32([4:]); != 7 { // SHT_NOTEcontinue }var , int64if == 40 {// 32-bit section header = int64(.Uint32([16:])) = int64(.Uint32([20:])) } else {// 64-bit section header = int64(.Uint64([24:])) = int64(.Uint64([32:])) } += for < {if , := .ReadAt([:16], ); != nil { // room for header + name GNU\x00return"", } := int(.Uint32([0:])) := int(.Uint32([4:])) := int(.Uint32([8:])) := + int64(12+(+3)&^3) = + int64((+3)&^3)if != 4 || != 3 || [12] != 'G' || [13] != 'N' || [14] != 'U' || [15] != '\x00' { // want name GNU\x00 type 3 (NT_GNU_BUILD_ID)continue }if > len() {return"", errBadELF }if , := .ReadAt([:], ); != nil {return"", }returnfmt.Sprintf("%x", [:]), nil } }return"", errNoBuildID}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.