diff options
author | Colin Cross <ccross@android.com> | 2018-02-23 22:43:24 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-02-23 22:45:55 -0800 |
commit | c4a18e02914e3f7e0be965fbd8c8d62c0fd58f3a (patch) | |
tree | 4d321fdfd3f5b6eb6eb446925d3216c58b2bdb47 /cmd | |
parent | 64c6d4bf14ef109f08cfb976e3e71a18aee0f009 (diff) | |
download | build_soong-c4a18e02914e3f7e0be965fbd8c8d62c0fd58f3a.tar.gz build_soong-c4a18e02914e3f7e0be965fbd8c8d62c0fd58f3a.tar.bz2 build_soong-c4a18e02914e3f7e0be965fbd8c8d62c0fd58f3a.zip |
Sort macho symbol table entries
macho symbol table entries are not always in order, which breaks
finding the next symbol to find the size of the target symbol.
Test: build_version_test
Change-Id: I41d1c3c3ff9929694e9ec2b034553d6b7ddef937
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/symbol_inject/macho.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/cmd/symbol_inject/macho.go b/cmd/symbol_inject/macho.go index 6a1de99a..4a3ecc74 100644 --- a/cmd/symbol_inject/macho.go +++ b/cmd/symbol_inject/macho.go @@ -18,6 +18,7 @@ import ( "debug/macho" "fmt" "io" + "sort" ) func findMachoSymbol(r io.ReaderAt, symbolName string) (uint64, uint64, error) { @@ -29,14 +30,22 @@ func findMachoSymbol(r io.ReaderAt, symbolName string) (uint64, uint64, error) { // symbols in macho files seem to be prefixed with an underscore symbolName = "_" + symbolName - for i, symbol := range machoFile.Symtab.Syms { + symbols := machoFile.Symtab.Syms + sort.Slice(symbols, func(i, j int) bool { + if symbols[i].Sect != symbols[j].Sect { + return symbols[i].Sect < symbols[j].Sect + } + return symbols[i].Value < symbols[j].Value + }) + + for i, symbol := range symbols { if symbol.Sect == 0 { continue } if symbol.Name == symbolName { var nextSymbol *macho.Symbol - if i+1 < len(machoFile.Symtab.Syms) { - nextSymbol = &machoFile.Symtab.Syms[i+1] + if i+1 < len(symbols) { + nextSymbol = &symbols[i+1] } return calculateMachoSymbolOffset(machoFile, symbol, nextSymbol) } |