From d8f849c4cfe74e6215f99476d5cb6b0e84a0be7f Mon Sep 17 00:00:00 2001 From: Yifan Yang Date: Mon, 13 Mar 2023 13:06:28 -0400 Subject: [PATCH] [build,zsim,virt] zsim now builds and runs on ubuntu 22.04 1. sconstruct is python3 compatible 2. skip arch_prctl syscall 3. copy signum.h from 18.04 to the repo (since it is no longer offered in the newer version of glibc) --- SConstruct | 10 ++++---- misc/ffControl.py | 10 ++++---- misc/gitver.py | 2 +- misc/lint_includes.py | 14 +++++------ misc/list_syscalls.py | 2 +- src/signum.h | 58 +++++++++++++++++++++++++++++++++++++++++++ src/virt/virt.cpp | 17 +++++++++++++ src/zsim.cpp | 2 +- 8 files changed, 95 insertions(+), 20 deletions(-) create mode 100644 src/signum.h diff --git a/SConstruct b/SConstruct index 45f36e81..1aec4ff4 100644 --- a/SConstruct +++ b/SConstruct @@ -8,7 +8,7 @@ def buildSim(cppFlags, dir, type, pgo=None): ''' Build the simulator with a specific base buid dir and config type''' buildDir = joinpath(dir, type) - print "Building " + type + " zsim at " + buildDir + print("Building " + type + " zsim at " + buildDir) env = Environment(ENV = os.environ, tools = ['default', 'textfile']) env["CPPFLAGS"] = cppFlags @@ -37,7 +37,7 @@ def buildSim(cppFlags, dir, type, pgo=None): if "PINPATH" in os.environ: PINPATH = os.environ["PINPATH"] else: - print "ERROR: You need to define the $PINPATH environment variable with Pin's path" + print("ERROR: You need to define the $PINPATH environment variable with Pin's path") sys.exit(1) ROOT = Dir('.').abspath @@ -46,7 +46,7 @@ def buildSim(cppFlags, dir, type, pgo=None): # NOTE (dsm 10 Jan 2013): Tested with Pin 2.10 thru 2.12 as well # NOTE: Original Pin flags included -fno-strict-aliasing, but zsim does not do type punning # NOTE (dsm 16 Apr 2015): Update flags code to support Pin 2.14 while retaining backwards compatibility - env["CPPFLAGS"] += " -g -std=c++0x -Wall -Wno-unknown-pragmas -Wno-deprecated -Wno-unused-function -fomit-frame-pointer -fno-stack-protector" + env["CPPFLAGS"] += " -g -std=c++0x -Wall -Wno-unknown-pragmas -Wno-deprecated -Wno-unused-function -Wno-catch-value -fomit-frame-pointer -fno-stack-protector" env["CPPFLAGS"] += " -MMD -DBIGARRAY_MULTIPLIER=1 -DUSING_XED -DTARGET_IA32E -DHOST_IA32E -fPIC -DTARGET_LINUX" # NOTE (yyf 17 Sep 2020): Enforce to use older ABI when compiled with gcc-5 or newer. env["CPPFLAGS"] += " -fabi-version=2 -D_GLIBCXX_USE_CXX11_ABI=0" @@ -204,11 +204,11 @@ pgoPhase = GetOption('pgoPhase') # when you move the files. Check the repo for a version that tries this. if GetOption('pgoBuild'): for type in buildTypes: - print "Building PGO binary" + print("Building PGO binary") root = Dir('.').abspath testsDir = joinpath(root, "tests") trainCfgs = [f for f in os.listdir(testsDir) if f.startswith("pgo")] - print "Using training configs", trainCfgs + print("Using training configs", trainCfgs) baseDir = joinpath(baseBuildDir, "pgo-" + type) genCmd = "scons -j16 --pgoPhase=generate-" + type diff --git a/misc/ffControl.py b/misc/ffControl.py index 65914cda..11aefef4 100755 --- a/misc/ffControl.py +++ b/misc/ffControl.py @@ -38,19 +38,19 @@ try: line = sys.stdin.readline() except: - print "stdin done, exiting" + print("stdin done, exiting") break if line.startswith("[H] Global segment shmid = "): targetShmid = int(line.split("=")[1].lstrip().rstrip()) - print "Target shmid is", targetShmid + print("Target shmid is", targetShmid) if line.find(opts.lineMatch) >= 0: if targetShmid >= 0: - print "Match, calling fftoggle" + print("Match, calling fftoggle") matches += 1 subprocess.call([os.path.join(opts.fftogglePath, "fftoggle"), str(targetShmid), str(opts.procIdx)]) else: - print "Match but shmid is not valid, not sending signal (are you sure you specified procIdx correctly? it's not the PID)" -print "Done, %d matches" % matches + print("Match but shmid is not valid, not sending signal (are you sure you specified procIdx correctly? it's not the PID)") +print("Done, %d matches" % matches) diff --git a/misc/gitver.py b/misc/gitver.py index 6068b7e5..a54df18b 100644 --- a/misc/gitver.py +++ b/misc/gitver.py @@ -11,4 +11,4 @@ def cmd(c): return os.popen(c).read().strip() .replace(" deletions(-)", "-").replace(" deletion(-)", "-") \ .replace(",", "") diff = "clean" if len(dfstat) == 0 else shstat + " " + dfhash -print ":".join([branch, revnum, rshort, diff]) +print(":".join([branch, revnum, rshort, diff])) diff --git a/misc/lint_includes.py b/misc/lint_includes.py index ad18009d..d3367ee9 100755 --- a/misc/lint_includes.py +++ b/misc/lint_includes.py @@ -53,7 +53,7 @@ def prefix(l): f.close() bName = os.path.basename(src).split(".")[0] - print bName + print(bName) lines = [l for l in txt.split("\n")] @@ -70,18 +70,18 @@ def prefix(l): includeBlocks.append((blockStart, i)) blockStart = -1 - print src, len(includeBlocks), "blocks" + print(src, len(includeBlocks), "blocks") newIncludes = [(s , e, sortIncludes(lines[s:e], bName)) for (s, e) in includeBlocks] for (s , e, ii) in newIncludes: # Print? if ii == lines[s:e]: - print "Block in lines %d-%d matches" % (s, e-1) + print("Block in lines %d-%d matches" % (s, e-1)) continue for i in range(s, e): - print "%3d: %s%s | %s" % (i, lines[i], " "*(40 - len(lines[i][:39])), ii[i-s] if i-s < len(ii) else "") - print "" - + print("%3d: %s%s | %s" % (i, lines[i], " "*(40 - len(lines[i][:39])), ii[i-s] if i-s < len(ii) else "")) + print("") + prevIdx = 0 newLines = [] for (s , e, ii) in newIncludes: @@ -95,4 +95,4 @@ def prefix(l): f.write(outTxt) f.close() -print "Done!" +print("Done!") diff --git a/misc/list_syscalls.py b/misc/list_syscalls.py index dab0524f..cab5169a 100755 --- a/misc/list_syscalls.py +++ b/misc/list_syscalls.py @@ -6,4 +6,4 @@ sysList = [(int(numStr), name) for (name, numStr) in re.findall("#define __NR_(.*?) (\d+)", syscallDefs)] denseList = ["INVALID"]*(max([num for (num, name) in sysList]) + 1) for (num, name) in sysList: denseList[num] = name -print '"' + '",\n"'.join(denseList) + '"' +print('"' + '",\n"'.join(denseList) + '"') diff --git a/src/signum.h b/src/signum.h new file mode 100644 index 00000000..0f70ce50 --- /dev/null +++ b/src/signum.h @@ -0,0 +1,58 @@ +/* Signal number definitions. Linux version. + Copyright (C) 1995-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 + +#ifndef _SIGNAL_H +#error "Never include directly; use instead." +#endif + +#include + +/* Adjustments and additions to the signal number constants for + most Linux systems. */ + +#define SIGSTKFLT 16 /* Stack fault (obsolete). */ +#define SIGPWR 30 /* Power failure imminent. */ + +#undef SIGBUS +#define SIGBUS 7 +#undef SIGUSR1 +#define SIGUSR1 10 +#undef SIGUSR2 +#define SIGUSR2 12 +#undef SIGCHLD +#define SIGCHLD 17 +#undef SIGCONT +#define SIGCONT 18 +#undef SIGSTOP +#define SIGSTOP 19 +#undef SIGTSTP +#define SIGTSTP 20 +#undef SIGURG +#define SIGURG 23 +#undef SIGPOLL +#define SIGPOLL 29 +#undef SIGSYS +#define SIGSYS 31 + +#undef __SIGRTMAX +#define __SIGRTMAX 64 + +#endif /* included. */ diff --git a/src/virt/virt.cpp b/src/virt/virt.cpp index b62fb21d..6783f26a 100644 --- a/src/virt/virt.cpp +++ b/src/virt/virt.cpp @@ -74,6 +74,23 @@ void VirtInit() { // Dispatch methods void VirtSyscallEnter(THREADID tid, CONTEXT *ctxt, SYSCALL_STANDARD std, const char* patchRoot, bool isNopThread) { uint32_t syscall = PIN_GetSyscallNumber(ctxt, std); + + // glibc version 2.28+, if built with GCC's -fcf-protection, will have + // init_cpu_features() (which runs early on during the execution of any + // process) attempt to call the nonexisting ARCH_CET_STATUS (0x3001) + // subfunction of arch_prctl. See: + // https://sourceware.org/git/?p=glibc.git;a=commit;h=394df3815e8ceec750fd06583eee4896174ce808 + // This became the default in Ubuntu 19.10+. See: + // https://wiki.ubuntu.com/ToolChain/CompilerFlags#A-fcf-protection + // Pin v2.14 crashes when it sees this unexpected arch_prctl subfunction. + // Avoid the crash by just pretending to execute the syscall instruction + // while skipping over it. + if (syscall == SYS_arch_prctl && PIN_GetContextReg(ctxt, REG_RDI) == 0x3001) { + PIN_SetContextReg(ctxt, REG_INST_PTR, PIN_GetContextReg(ctxt, REG_INST_PTR) + 2); + PIN_SetContextReg(ctxt, REG_RAX, -1UL); + return; + } + if (syscall >= MAX_SYSCALLS) { warn("syscall %d out of range", syscall); postPatchFunctions[tid] = NullPostPatch; diff --git a/src/zsim.cpp b/src/zsim.cpp index 6ed58076..8f673b8e 100644 --- a/src/zsim.cpp +++ b/src/zsim.cpp @@ -29,7 +29,7 @@ #include "zsim.h" #include #define _SIGNAL_H -#include +#include #undef _SIGNAL_H #include #include