Improve "unrecognized binary" error messages
Previously it would just print "unrecognized binary" no matter what the underlying error message was. This was partly because it was unable to know the actual file type except by trial and error. This commit uses the magic number instead. It also gives a nicer error for fat Mach-O binaries which are currently unsupported.
Set base address on OSX.
This fixes issue #311. The mapped address of libraries was never considered, nor was the load address of the segments. It also fixes a couple of issues in binutils.go, such as when the tail of the data wasn't handled right when grouping symbols at the same address.
Pass text segment info to GetBase to handle Linux kernel ASLR case. (#299)
When pprof symbolizes kernel addresses in vmlinux binary for a profile
converted using https://github.com/google/perf_data_converter, the
addresses need to be adjusted if kernel ASLR is in effect. So far the
call to GetBase did not pass text segment info to GetBase which
shortcircuited the code to merely return zero adjustment. This change
fixes the call to GetBase to address that.
The added test case is a simulation of what happens with vmlinux, but it
should be pretty close. Including a vmlinux file into the test data does
not appear practical due to the binary size. I verified that the test
failed before the fix and passes after.
Note that the fixed issue is specific to the kernel ASLR as user-mode
ASRL-enabled binaries (i.e. built with -pie / -fpie) have ET_DYN type
which takes a different code path in GetBase which did not have issues
before this fix in practice.
* Make binutils thread safe.
binutils is now used from multiple goroutines when the
web interface is enabled (since http server spins up a new
goroutine for each request). Added appropriate synchronization
to various objects in binutils to provide the appropriate
thread-safety.
In addition, added a bunch of tests:
. Test parsing of nm output.
. Tests for Binutils methods.
. Test llvm-symbolizer interface (using an llvm-symbolizer emulator).
* Fix go vet errors about unkeyed literals.
* copy stderr to figure out test failures
* Make shell script portable.
* Update comments to match new var name.
* Give a name to the embedded Mutex field in addr2Liner.
Prefer nm based function names to addr2line based names.
The names produced by addr2line are often incomplete. Fix this by
falling back to nm to get function names and using the nm-provided
name if it is longer.