gaasedelen / lighthouse

A Coverage Explorer for Reverse Engineers
MIT License
2.23k stars 308 forks source link

CodeCoverage doesn't seem to compile under MacOS Catalina #92

Closed DrWhax closed 3 years ago

DrWhax commented 3 years ago

I've been trying to compile the CodeCoverage file under MacOS catalina, but i've run into some errors.

Of which for now, I've not not overcome, otherwise I would have sent a patch.

gebruiker@GebruiksMacBook pin % make
mkdir -p obj-intel64
/Applications/Xcode.app/Contents/Developer/usr/bin/make objects
make[1]: Nothing to be done for `objects'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make libs
make[1]: Nothing to be done for `libs'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make dlls
make[1]: Nothing to be done for `dlls'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make apps
make[1]: Nothing to be done for `apps'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make tools
/usr/bin/g++ -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fno-rtti -Wtypedef-redefinition -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_MAC -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_UNIX03=0   -I/Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/source/include/pin -I/Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/source/include/pin/gen -isystem /Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/stlport/include -isystem /Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/libstdc++/include -isystem /Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/crt/include -isystem /Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/crt/include/arch-x86_64 -isystem /Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/crt/include/kernel/uapi -isystem /Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/crt/include/kernel/uapi/asm-x86 -I/Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/components/include -I/Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/extras/xed-intel64/include/xed -I/Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/source/tools/Utils -I/Users/gebruiker/Downloads/pin-3.17-98314-g0c048d619-clang-mac/source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing  -std=c++11 -Wno-format -Wno-aligned-new  -c -oobj-intel64/CodeCoverage.o CodeCoverage.cpp
error: unknown warning option '-Wno-aligned-new' [-Werror,-Wunknown-warning-option]
make[1]: *** [obj-intel64/CodeCoverage.o] Error 1
make: *** [all] Error 2

It seems -Wno-aligned-new isn't a flag supported by clang/llvm.

So I tried with gcc-10 from brew:

gebruiker@GebruiksMacBook pin % /usr/local/bin/gcc-10 -v
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc-10
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/10.2.0/libexec/gcc/x86_64-apple-darwin19/10.2.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/10.2.0 --libdir=/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 10.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk SED=/usr/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (Homebrew GCC 10.2.0)
gebruiker@GebruiksMacBook pin % make clean
rm -rf obj-intel64/ *.out* *.log* *.xml *.makefile.copy *.core core.*
gebruiker@GebruiksMacBook pin % make
mkdir -p obj-intel64
/Applications/Xcode.app/Contents/Developer/usr/bin/make objects
make[1]: Nothing to be done for `objects'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make libs
make[1]: Nothing to be done for `libs'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make dlls
make[1]: Nothing to be done for `dlls'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make apps
make[1]: Nothing to be done for `apps'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make tools
/usr/local/bin/gcc-10 -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fno-rtti -Wtypedef-redefinition -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_MAC -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_UNIX03=0   -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin/gen -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/stlport/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/libstdc++/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/arch-x86_64 -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/kernel/uapi -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/kernel/uapi/asm-x86 -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/components/include -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/xed-intel64/include/xed -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/tools/Utils -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing  -std=c++11 -Wno-format -Wno-aligned-new  -c -o obj-intel64/CodeCoverage.o CodeCoverage.cpp
gcc-10: error: unrecognized command-line option '-Wtypedef-redefinition'
make[1]: *** [obj-intel64/CodeCoverage.o] Error 1
make: *** [all] Error 2

Seems I cannot get it to build under any circumstance.

This happens under both Pin 3.13 and 3.17.

Any advice would be much appreciated as this tool looks very awesome! :)

DrWhax commented 3 years ago

I got a fix with llvm-g++!

gebruiker@GebruiksMacBook pin % llvm-g++ -v
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

In Makefile I have this:

  TOOL_CXXFLAGS += -std=c++11 -Wno-format -Wno-error

Which results in:

gebruiker@GebruiksMacBook pin % make
mkdir -p obj-intel64
/Applications/Xcode.app/Contents/Developer/usr/bin/make objects
make[1]: Nothing to be done for `objects'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make libs
make[1]: Nothing to be done for `libs'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make dlls
make[1]: Nothing to be done for `dlls'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make apps
make[1]: Nothing to be done for `apps'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make tools
/usr/bin/g++ -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fno-rtti -Wtypedef-redefinition -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_MAC -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_UNIX03=0   -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin/gen -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/stlport/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/libstdc++/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/arch-x86_64 -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/kernel/uapi -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/kernel/uapi/asm-x86 -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/components/include -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/xed-intel64/include/xed -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/tools/Utils -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing  -std=c++11 -Wno-format -Wno-error  -c -o obj-intel64/CodeCoverage.o CodeCoverage.cpp
CodeCoverage.cpp:1:17: warning: using directive refers to implicitly-defined namespace 'std'
using namespace std;
                ^
1 warning generated.
/usr/bin/g++ -Wall -Werror -Wno-unknown-pragmas -D__PIN__=1 -DPIN_CRT=1 -fno-stack-protector -fno-exceptions -funwind-tables -fno-rtti -Wtypedef-redefinition -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_MAC -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_UNIX03=0   -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin/gen -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/stlport/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/libstdc++/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/arch-x86_64 -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/kernel/uapi -isystem /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/crt/include/kernel/uapi/asm-x86 -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/components/include -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/xed-intel64/include/xed -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/tools/Utils -I/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/tools/InstLib -O3 -fomit-frame-pointer -fno-strict-aliasing  -std=c++11 -Wno-format -Wno-error  -c -o obj-intel64/ImageManager.o ImageManager.cpp
ImageManager.cpp:1:17: warning: using directive refers to implicitly-defined namespace 'std'
using namespace std;
                ^
1 warning generated.
/usr/bin/g++ -shared /Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/intel64/runtime/pincrt/crtbeginS.o -w -Wl,-exported_symbols_list,/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/source/include/pin/pintool.exp     -o obj-intel64/CodeCoverage.dylib obj-intel64/CodeCoverage.o obj-intel64/ImageManager.o  -L/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/intel64/runtime/pincrt -L/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/intel64/lib -L/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/intel64/lib-ext -L/Users/gebruiker/Downloads/pin-3.13-98189-g60a6ef199-clang-mac/extras/xed-intel64/lib -lpin -lxed -lpin3dwarf -nostdlib -lstlport-dynamic -lm-dynamic -lc-dynamic -lunwind-dynamic
gebruiker@GebruiksMacBook pin % ls -alrt obj-intel64
total 3056
drwxr-xr-x  12 gebruiker  staff      384 Dec 18 15:03 ..
-rw-r--r--   1 gebruiker  staff    37336 Dec 18 15:03 CodeCoverage.o
-rw-r--r--   1 gebruiker  staff    10764 Dec 18 15:03 ImageManager.o
-rwxr-xr-x   1 gebruiker  staff  1509632 Dec 18 15:03 CodeCoverage.dylib
drwxr-xr-x   5 gebruiker  staff      160 Dec 18 15:03 .
gaasedelen commented 3 years ago

Hey! Thanks for looking into this.

For whatever reason, the pintool has been relatively high maintenance. I feel like the build for it breaks at least once a year. Sometimes it is changes to pin's tool building process, otherwise it is platform specific compiler issues.

I actually think the pintool / build file needs to be updated for Windows too, since they changed how the CRT gets compiled in on the latest versions of pin (3.15+?) 🙄. Sigh...

I'll leave this issue open for now as reference for others, and try to circle back and correct some of the outstanding pin build issues in the coming months. Otherwise if you would like to submit a PR, please make it to the dev branch.

Thanks again :-)

DrWhax commented 3 years ago

No problem!

Got even further, seems "using namespace std;" is no longer needed and with that, -Wno-error is also no longer needed and compiles without any errors using llvm out of the box.

On Linux, I also compiled without "using namespace std;". This compile also could do without: "-Wno-aligned-new".

Still have to test on Windows 10, but I assume this could fix some of the issues right now on builds that aren't Windows. Yay!

Will circle back once I tested it out on Win10.

gaasedelen commented 3 years ago

Resolved by PR #94, thanks!