Skip to content
Permalink
Browse files

Improved GCC version detection

  • Loading branch information...
xyproto committed Jun 2, 2017
1 parent f8ad809 commit 1826d881ada08ae54e462cf9771d95d7dbc98d73
Showing with 23 additions and 9 deletions.
  1. +3 −4 README.md
  2. +17 −4 main.go
  3. +3 −1 test.sh
@@ -12,8 +12,7 @@ Installation:

Example usage:

elfinfo /usr/bin/ls

Example output:

$ elfinfo /usr/bin/ls
/usr/bin/ls: stripped=true, compiler=GCC 6.3.1, byteorder=LittleEndian, machine=Advanced Micro Devices x86-64

* Version: 0.4
21 main.go
@@ -9,7 +9,7 @@ import (
"strings"
)

const versionString = "ELFinfo 0.3"
const versionString = "ELFinfo 0.4"

// stripped returns true if symbols can not be retrieved from the given ELF file
func stripped(f *elf.File) bool {
@@ -29,12 +29,18 @@ func gccver(f *elf.File) string {
return ""
}
cVersion := string(b)
if strings.Contains(cVersion, "GCC: (GNU) ") {
versionCatcher := regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)`)
gccVersion := string(versionCatcher.Find(b))
if strings.Contains(cVersion, "GCC: (") {
versionCatcher1 := regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)\ `)
gccVersion := strings.TrimSpace(string(versionCatcher1.Find(b)))
if gccVersion != "" {
return "GCC " + gccVersion
}
versionCatcher2 := regexp.MustCompile(`(\d+\.)(\d+\.)?(\*|\d+)`)
gccVersion = strings.TrimSpace(string(versionCatcher2.Find(b)))
if gccVersion != "" {
return "GCC " + gccVersion
}
return "GCC " + cVersion[5:]
}
return cVersion
}
@@ -55,6 +61,13 @@ func gover(f *elf.File) string {
if strings.HasPrefix(goVersion, "go") {
return "Go " + goVersion[2:]
}
if goVersion == "" {
gosec := f.Section(".gosymtab")
if gosec != nil {
return "Go (unknown version)"
}
return ""
}
return goVersion
}

@@ -1,2 +1,4 @@
#!/bin/sh
for f in /usr/bin/*; do ./elfinfo $f; done | cut -d"," -f2 | grep -a compiler
for f in /usr/bin/*; do
echo compiler=$f; echo "$f: " $(./elfinfo "$f" | cut -d, -f2 || echo "$f")
done | grep -ia " compiler="

0 comments on commit 1826d88

Please sign in to comment.
You can’t perform that action at this time.