Skip to content

Commit

Permalink
Merge pull request #164 from rphillips/try_native_endian
Browse files Browse the repository at this point in the history
fallback to bigendian to check for golang magic number
  • Loading branch information
openshift-merge-bot[bot] authored Mar 18, 2024
2 parents ac1d6d5 + 7cff376 commit 20aba04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.20-openshift-4.14 AS builder
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.21-openshift-4.16 AS builder

WORKDIR /app

Expand Down
23 changes: 20 additions & 3 deletions internal/golang/goscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ const (
// Select the magic number based on the Go version
func magicNumber(goVersion string) []byte {
bs := make([]byte, 4)
magic := _magicNumber(goVersion)
binary.LittleEndian.PutUint32(bs, magic)
return bs
}

// Select the magic number based on the Go version
func magicNumberBigEndian(goVersion string) []byte {
bs := make([]byte, 4)
magic := _magicNumber(goVersion)
binary.BigEndian.PutUint32(bs, magic)
return bs
}

func _magicNumber(goVersion string) uint32 {
var magic uint32
if strings.Compare(goVersion, "go1.20") >= 0 {
magic = go120magic
Expand All @@ -33,8 +47,7 @@ func magicNumber(goVersion string) []byte {
} else {
magic = go12magic
}
binary.LittleEndian.PutUint32(bs, magic)
return bs
return magic
}

// Open a Go ELF executable and read .gopclntab
Expand Down Expand Up @@ -77,7 +90,11 @@ func ReadTable(fileName string, bi *buildinfo.BuildInfo) (*gosym.Table, error) {
magic := magicNumber(bi.GoVersion)
pclntabIndex := bytes.Index(tableData, magic)
if pclntabIndex < 0 {
return nil, fmt.Errorf("could not find magic number in %s ", fileName)
magic = magicNumberBigEndian(bi.GoVersion)
pclntabIndex = bytes.Index(tableData, magic)
if pclntabIndex < 0 {
return nil, fmt.Errorf("could not find magic number in %s ", fileName)
}
}
tableData = tableData[pclntabIndex:]
addr := exe.Section(".text").Addr
Expand Down

0 comments on commit 20aba04

Please sign in to comment.