Skip to content

Commit

Permalink
[build,zsim,virt] zsim now builds and runs on ubuntu 22.04
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Yifan Yang committed Mar 13, 2023
1 parent 78a52c4 commit d8f849c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 20 deletions.
10 changes: 5 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions misc/ffControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

2 changes: 1 addition & 1 deletion misc/gitver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
14 changes: 7 additions & 7 deletions misc/lint_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

Expand All @@ -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:
Expand All @@ -95,4 +95,4 @@ def prefix(l):
f.write(outTxt)
f.close()

print "Done!"
print("Done!")
2 changes: 1 addition & 1 deletion misc/list_syscalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '"')
58 changes: 58 additions & 0 deletions src/signum.h
Original file line number Diff line number Diff line change
@@ -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
<http://www.gnu.org/licenses/>. */

#ifndef _BITS_SIGNUM_H
#define _BITS_SIGNUM_H 1

#ifndef _SIGNAL_H
#error "Never include <bits/signum.h> directly; use <signal.h> instead."
#endif

#include <bits/signum-generic.h>

/* 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 /* <signal.h> included. */
17 changes: 17 additions & 0 deletions src/virt/virt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/zsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "zsim.h"
#include <algorithm>
#define _SIGNAL_H
#include <bits/signum.h>
#include <signum.h>
#undef _SIGNAL_H
#include <dlfcn.h>
#include <execinfo.h>
Expand Down

0 comments on commit d8f849c

Please sign in to comment.