lunixbochs / usercorn

dynamic binary analysis via platform emulation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the keystone and capstone libs now land in deps/lib64 (ld: cannot find -lkeystone)

mpictor opened this issue · comments

commented

Took me a while to realize what was going on. There's a patch at the bottom to fix this.

This is with the unstable branch; with stable, I had this issue as well as risc-v errors.

$ git clone github.com/lunixbochs/usercorn
$ git checkout unstable
$ make deps
...
$ make
mkdir -p .gopath/src/github.com/lunixbochs
ln -s ../../../.. .gopath/src/github.com/lunixbochs/usercorn
go get -u github.com/chzyer/readline github.com/golang/snappy github.com/jroimartin/gocui github.com/keystone-engine/keystone/bindings/go/keystone github.com/lunixbochs/argjoy github.com/lunixbochs/capstr github.com/lunixbochs/fvbommel-util/sortorder github.com/lunixbochs/ghostrace/ghost/memio github.com/lunixbochs/ghostrace/ghost/sys/num github.com/lunixbochs/luaish github.com/lunixbochs/luaish/ast github.com/lunixbochs/luaish-luar github.com/lunixbochs/luaish/parse github.com/lunixbochs/luaish/pm github.com/lunixbochs/readline github.com/lunixbochs/struc github.com/mattn/go-colorable github.com/mattn/go-isatty github.com/mattn/go-runewidth github.com/mgutz/ansi github.com/nsf/termbox-go github.com/pkg/errors github.com/rivo/uniseg github.com/shibukawa/configdir github.com/unicorn-engine/unicorn/bindings/go/unicorn golang.org/x/net/context golang.org/x/sys/unix
  # github.com/keystone-engine/keystone/bindings/go/keystone
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lkeystone
collect2: error: ld returned 1 exit status
make: *** [Makefile:121: get] Error 2
$ ld --version
GNU ld (Gentoo 2.37_p1 p0) 2.37
Copyright (C) 2021 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

$ find . -name 'libkeystone.so*'|xargs ls -lh
lrwxrwxrwx 1 mark mark   16 Jan 17 15:00 ./deps/build/keystone/build/llvm/lib64/libkeystone.so -> libkeystone.so.0
-rwxr-xr-x 1 mark mark 6.9M Jan 17 15:00 ./deps/build/keystone/build/llvm/lib64/libkeystone.so.0
lrwxrwxrwx 1 mark mark   16 Jan 17 15:00 ./deps/lib64/libkeystone.so -> libkeystone.so.0
-rwxr-xr-x 1 mark mark 6.9M Jan 17 15:00 ./deps/lib64/libkeystone.so.0

$ sha1sum ./deps/build/keystone/build/llvm/lib64/libkeystone.so.0 ./deps/lib64/libkeystone.so.0
c8953989c7f8bb4de3b5dc22508ecc17f788b3c0  ./deps/build/keystone/build/llvm/lib64/libkeystone.so.0
c8953989c7f8bb4de3b5dc22508ecc17f788b3c0  ./deps/lib64/libkeystone.so.0

$ file ./deps/lib64/libkeystone.so.0
./deps/lib64/libkeystone.so.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped

Eventually I realized there were two dirs:

$ ls ./deps/lib
libunicorn.a  libunicorn.so  libunicorn.so.1  pkgconfig
$ ls ./deps/lib64
libcapstone.so  libcapstone.so.5  libcapstone.so.5.0.0  libkeystone.so  libkeystone.so.0  pkgconfig

... so unicorn is writing to deps/lib but capstone and keystone now use deps/lib64.

diff --git a/Makefile b/Makefile
index 38acfe6..30a1476 100644
--- a/Makefile
+++ b/Makefile
@@ -94,7 +94,7 @@ deps: deps/lib/libunicorn.1.$(LIBEXT) deps/lib/libcapstone.5.$(LIBEXT) deps/lib/
    ln -s ../../../.. .gopath/src/github.com/lunixbochs/usercorn
 
 export CGO_CFLAGS = -I$(DEST)/include
-export CGO_LDFLAGS = -L$(DEST)/lib
+export CGO_LDFLAGS = -L$(DEST)/lib -L$(DEST)/lib64
 
 GOBUILD := go build
 PATH := '$(DEST)/$(GODIR)/bin:$(PATH)'

Can you send this as a PR against unstable so CI will run?