vusec / ridl

RIDL test suite and exploits
https://mdsattacks.com
352 stars 54 forks source link

How to run this tool on OSX #9

Closed bs0man closed 5 years ago

bs0man commented 5 years ago

I'm receiving an error on OSX

cannot execute binary file

prantlf commented 5 years ago

You would need to build this tool for OSX first. I tried to build it by:

cmake -G Xcode .
xcodebuild build -workspace mdstool.xcodeproj/project.xcworkspace -scheme mdstool-cli

but got the following failures:

Ld /Users/prantlf/Sources/github/ridl/Debug/mdstool-cli normal x86_64
    cd /Users/prantlf/Sources.localized/github/ridl
    export MACOSX_DEPLOYMENT_TARGET=10.14
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -L/Users/prantlf/Sources/github/ridl/Debug -F/Users/prantlf/Sources/github/ridl/Debug -filelist /Users/prantlf/Sources/github/ridl/mdstool.build/Debug/mdstool-cli.build/Objects-normal/x86_64/mdstool-cli.LinkFileList -mmacosx-version-min=10.14 -Xlinker -object_path_lto -Xlinker /Users/prantlf/Sources/github/ridl/mdstool.build/Debug/mdstool-cli.build/Objects-normal/x86_64/mdstool-cli_lto.o -Xlinker -no_deduplicate -L/usr/local/opt/e2fsprogs/lib -L/usr/local/opt/libffi/lib -L/usr/local/opt/qt/lib -L/usr/local/opt/icu4c/lib -L/usr/local/opt/ncurses/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/sqlite/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libpcap/lib -L/usr/local/opt/freetype/lib -L/usr/local/opt/freetype/lib -L/usr/local/opt/e2fsprogs/lib -L/usr/local/opt/libffi/lib -L/usr/local/opt/qt/lib -L/usr/local/opt/icu4c/lib -L/usr/local/opt/ncurses/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/sqlite/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/libpcap/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Xlinker -dependency_info -Xlinker /Users/prantlf/Sources/github/ridl/mdstool.build/Debug/mdstool-cli.build/Objects-normal/x86_64/mdstool-cli_dependency_info.dat -o /Users/prantlf/Sources/github/ridl/Debug/mdstool-cli
Undefined symbols for architecture x86_64:
  "_cpuid", referenced from:
      _cpuid_get_vendor_id in cpuid.o
      _cpuid_get_vendor in cpuid.o
      _cpuid_get_brand_string in cpuid.o
      _amd_get_codename in cpuid.o
      _intel_get_codename in cpuid.o
      _query_ridl_info in ridl-1A4AA1CC12B39F7A.o
     (maybe you meant: _cpuid_get_codename, _cpuid_get_brand_string , _cpuid_get_vendor , _cpuid_get_vendor_id , _cpuid_has_feature )
  "_cpuidex", referenced from:
      _amd_has_feature in cpuid.o
      _cpuid_has_feature in cpuid.o
  "_get_memory_size", referenced from:
      _query_sys_info in system-8F9A09A280D49E82.o
  "_get_microcode", referenced from:
      _query_sys_info in system-8F9A09A280D49E82.o
  "_get_os_name", referenced from:
      _query_sys_info in system-8F9A09A280D49E82.o
  "_query_l1tf_info", referenced from:
      _main in main.o
  "_query_meltdown_info", referenced from:
      _main in main.o
  "_query_spectre_info", referenced from:
      _main in main.o
  "_query_ssb_info", referenced from:
      _main in main.o
  "_read_cpu_topology", referenced from:
      _query_ridl_info in ridl-1A4AA1CC12B39F7A.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **

The following build commands failed:
    Ld /Users/prantlf/Sources/github/ridl/Debug/mdstool-cli normal x86_64
(1 failure)
prantlf commented 5 years ago

@StephanvanSchaik, it could be something with cmake and its detection of libraries installed using Homebrew. Although it detected libfreetype, I had to add it to link paths in the Xcode project. Errors, that I posted earlier are from compiling a project with the manually added path to /usr/local/opt/freetype/include/freetype2.

This is the output of cmake from my machine:

$ cmake -G Xcode .

-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- The ASM compiler identification is AppleClang
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Found X11: /usr/X11R6/include
-- Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib
-- Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Checking for module 'freetype2'
--   Found freetype2, version 23.0.17
-- Looking for asprintf
-- Looking for asprintf - found
-- Looking for clock_nanosleep
-- Looking for clock_nanosleep - not found
-- Looking for nanosleep
-- Looking for nanosleep - found
-- Looking for usleep
-- Looking for usleep - found
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/prantlf/Sources/github/ridl
prantlf commented 5 years ago

I fixed the problem with libfreetype by adding the following commands to my .bashrc:

...
LDFLAGS="-L/usr/local/opt/freetype/lib $LDFLAGS"
CPPFLAGS="-I/usr/local/opt/freetype/include $CPPFLAGS"
PKG_CONFIG_PATH="/usr/local/opt/freetype/lib/pkgconfig:$PKG_CONFIG_PATH"
...
export LDFLAGS CPPFLAGS PKG_CONFIG_PATH

Running cmake generates files including paths including libfreetype now, without having to edit them manually. However, the failure from ld remains.

prantlf commented 5 years ago

Except for Xcode project, I tried to generate traditional Makefile too:

$ cmake .

-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- The ASM compiler identification is AppleClang
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Found X11: /usr/X11R6/include
-- Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib
-- Looking for XOpenDisplay in /usr/X11R6/lib/libX11.dylib;/usr/X11R6/lib/libXext.dylib - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Checking for module 'freetype2'
--   Found freetype2, version 23.0.17
-- Looking for asprintf
-- Looking for asprintf - found
-- Looking for clock_nanosleep
-- Looking for clock_nanosleep - not found
-- Looking for nanosleep
-- Looking for nanosleep - found
-- Looking for usleep
-- Looking for usleep - found
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/prantlf/Sources/github/ridl

Building the project fails with the same error:

$ make

Scanning dependencies of target mdstool
[  2%] Building C object CMakeFiles/mdstool.dir/source/bitmap.c.o
[  5%] Building C object CMakeFiles/mdstool.dir/source/human.c.o
/Users/prantlf/Sources/github/ridl/source/human.c:26:18: warning: field precision
      should have type 'int', but argument has type 'size_t'
      (aka 'unsigned long') [-Wformat]
        asprintf(&s, "%.*f %s", prec, size, binary ? bunits[i] : units[i]);
                      ~~^~      ~~~~
1 warning generated.
[  8%] Building C object CMakeFiles/mdstool.dir/source/system.c.o
[ 11%] Building C object CMakeFiles/mdstool.dir/source/topology.c.o
[ 14%] Building C object CMakeFiles/mdstool.dir/source/x86/cpuid.c.o
[ 17%] Building C object CMakeFiles/mdstool.dir/source/x86/ridl.c.o
[ 20%] Building C object CMakeFiles/mdstool.dir/source/ui/l1tf.c.o
[ 23%] Building C object CMakeFiles/mdstool.dir/source/ui/main.c.o
[ 26%] Building C object CMakeFiles/mdstool.dir/source/ui/meltdown.c.o
[ 29%] Building C object CMakeFiles/mdstool.dir/source/ui/ridl.c.o
[ 32%] Building C object CMakeFiles/mdstool.dir/source/ui/spectre.c.o
[ 35%] Building C object CMakeFiles/mdstool.dir/source/ui/ssb.c.o
[ 38%] Building C object CMakeFiles/mdstool.dir/source/ui/system.c.o
[ 41%] Building C object CMakeFiles/mdstool.dir/source/x11/canvas.c.o
[ 44%] Building C object CMakeFiles/mdstool.dir/source/x11/display.c.o
/Users/prantlf/Sources/github/ridl/source/x11/display.c:26:16: warning: implicit
      declaration of function 'XrmUniqueQuark' is invalid in C99
      [-Wimplicit-function-declaration]
        display.ctx = XUniqueContext();
                      ^
/usr/X11R6/include/X11/Xutil.h:359:44: note: expanded from macro 'XUniqueContext'
#define XUniqueContext()       ((XContext) XrmUniqueQuark())
                                           ^
1 warning generated.
[ 47%] Building C object CMakeFiles/mdstool.dir/source/x11/events.c.o
[ 50%] Building C object CMakeFiles/mdstool.dir/source/x11/font.c.o
[ 52%] Building C object CMakeFiles/mdstool.dir/source/x11/image.c.o
[ 55%] Building C object CMakeFiles/mdstool.dir/source/x11/window.c.o
[ 58%] Linking C executable mdstool
Undefined symbols for architecture x86_64:
  "_cpuid", referenced from:
      _cpuid_get_vendor_id in cpuid.c.o
      _cpuid_get_vendor in cpuid.c.o
      _cpuid_get_brand_string in cpuid.c.o
      _amd_get_codename in cpuid.c.o
      _intel_get_codename in cpuid.c.o
      _query_ridl_info in ridl.c.o
     (maybe you meant: _cpuid_get_brand_string, _cpuid_has_feature , _cpuid_get_codename , _cpuid_get_vendor_id , _cpuid_get_vendor )
  "_cpuidex", referenced from:
      _amd_has_feature in cpuid.c.o
      _cpuid_has_feature in cpuid.c.o
  "_get_memory_size", referenced from:
      _query_sys_info in system.c.o
  "_get_microcode", referenced from:
      _query_sys_info in system.c.o
  "_get_os_name", referenced from:
      _query_sys_info in system.c.o
  "_query_l1tf_info", referenced from:
      _main in main.c.o
  "_query_meltdown_info", referenced from:
      _main in main.c.o
  "_query_spectre_info", referenced from:
      _main in main.c.o
  "_query_ssb_info", referenced from:
      _main in main.c.o
  "_read_cpu_topology", referenced from:
      _query_ridl_info in ridl.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [mdstool] Error 1
make[1]: *** [CMakeFiles/mdstool.dir/all] Error 2
make: *** [all] Error 2
StephanvanSchaik commented 5 years ago

508d549341d785afc59681ed3f219ef72437d637 adds support for Mac OS X.

prantlf commented 5 years ago

It works perfectly. Thanks a lot!