Skip to content

Commit

Permalink
i#2267: Expect floatpc failure on AMD processor
Browse files Browse the repository at this point in the history
Adds CMake detection of the processor vendor.

Relaxes the floatpc_xl8all test to expect failure when running on AMD
for inter-block cases, where DR won't be able to translate as the
processor does not supply the PC if there wasn't an exception.

Issue: #2267
  • Loading branch information
derekbruening committed Nov 10, 2023
1 parent 23ad2c3 commit 7df709e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ if (NOT "${TARGET_ARCH}" STREQUAL "${CMAKE_SYSTEM_PROCESSOR}")
endif ()
endif ()

get_processor_vendor(CPU_VENDOR)
if ("${CPU_VENDOR}" STREQUAL "GenuineIntel")
set(CPU_INTEL ON)
elseif ("${CPU_VENDOR}" STREQUAL "AuthenticAMD")
set(CPU_AMD ON)
endif ()

# Support for running cross-compiled tests under emulation.
if (CMAKE_CROSSCOMPILING AND DEFINED CMAKE_FIND_ROOT_PATH)
find_program(QEMU_BINARY qemu-${CMAKE_SYSTEM_PROCESSOR} DOC "QEMU emulation tool")
Expand Down
7 changes: 7 additions & 0 deletions core/arch/x86/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,13 @@ void
mangle_float_pc(dcontext_t *dcontext, instrlist_t *ilist, instr_t *instr,
instr_t *next_instr, uint *flags INOUT)
{
/* XXX i#2267: AMD processors don't provide the last PC when there was no
* exception. Recent processors seem to zero it out. Should we do the same,
* and not supply it for intra-block cases? For now we do supply it, and
* we try (but fail) for inter-block for -translate_fpu_pc (we expect failure
* in our floatpc_xl8all test template for AMD).
*/

/* If there is a prior non-control float instr, we can inline the pc update.
* Otherwise, we go back to d_r_dispatch. In the latter case we do not support
* building traces across the float pc save: we assume it's rare.
Expand Down
25 changes: 25 additions & 0 deletions make/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,28 @@ function (check_sve_processor_and_compiler_support out)
endif ()
set(${out} ${proc_found_sve} PARENT_SCOPE)
endfunction (check_sve_processor_and_compiler_support)

function (get_processor_vendor out)
set(vendor "<unknown>")
if (APPLE)
find_program(SYSCTL NAMES sysctl PATHS /usr/sbin)
if (SYSCTL)
execute_process(COMMAND ${SYSCTL} -n machdep.cpu.vendor
OUTPUT_VARIABLE vendor OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_VARIABLE err)
if ("${vendor}" STREQUAL "")
execute_process(COMMAND ${SYSCTL} -n machdep.cpu.brand_string
OUTPUT_VARIABLE vendor OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_VARIABLE err)
endif ()
endif ()
elseif (WIN32)
get_filename_component(vendor
"[HKEY_LOCAL_MACHINE\\Hardware\\Description\\System\\CentralProcessor\\0;VendorIdentifier]"
NAME CACHE)
elseif (EXISTS "/proc/cpuinfo")
file(READ "/proc/cpuinfo" contents)
string(REGEX REPLACE ".*vendor_id[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1"
vendor "${contents}")
endif ()
message(STATUS "Processor vendor is ${vendor}")
set(${out} ${vendor} PARENT_SCOPE)
endfunction ()
5 changes: 5 additions & 0 deletions suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,11 @@ function(template2expect outexpect template runops key)
elseif (DEFINED ${key}_runsve)
set(rundefs "${rundefs} -D__ARM_FEATURE_SVE")
endif ()
if (CPU_AMD)
set(rundefs "${rundefs} -DCPU_AMD")
elseif (CPU_INTEL)
set(rundefs "${rundefs} -DCPU_INTEL")
endif ()

if (DEFINED ${key}_test_sample_client)
set(rundefs "${rundefs} -DTEST_SAMPLE_CLIENT")
Expand Down
2 changes: 1 addition & 1 deletion suite/tests/common/floatpc.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2013 Google, Inc. All rights reserved.
* Copyright (c) 2013-2023 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down
4 changes: 2 additions & 2 deletions suite/tests/common/floatpc.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef X64
FXSAVE64 intra is correctly handled
# if defined(translate_fpu_pc) || defined(hotp_only)
# if (defined(translate_fpu_pc) || defined(hotp_only)) && !defined(CPU_AMD)
FXSAVE64 inter is correctly handled
# else
FXSAVE64 inter is **incorrectly** handled
Expand All @@ -14,7 +14,7 @@ FNSTENV inter is **incorrectly** handled
# endif
#endif
FXSAVE intra is correctly handled
#if defined(translate_fpu_pc) || defined(hotp_only)
# if (defined(translate_fpu_pc) || defined(hotp_only)) && !defined(CPU_AMD)
FXSAVE inter is correctly handled
#else
FXSAVE inter is **incorrectly** handled
Expand Down

0 comments on commit 7df709e

Please sign in to comment.