From b97976bc00e53e01b52fe217215ffa457a72589e Mon Sep 17 00:00:00 2001 From: Grant Ayers Date: Tue, 7 Jun 2016 21:46:22 -0700 Subject: [PATCH 1/5] [build] Clear any prior definitions of assert() to make sure the zsim version of assert() doesn't create any macro redefinitions. This error can appear, for example, if any system or startup files are brought in during compilation and happen to include . --- src/log.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/log.h b/src/log.h index 7d1526587..1eecb8af5 100644 --- a/src/log.h +++ b/src/log.h @@ -169,7 +169,12 @@ class PrintExpr { #define trace(type, args...) #endif - +/* assert() is already defined as of POSIX.1-2001 and C89. + * Since we are overriding it here we need to make sure we don't create a macro + * redefinition, despite not having '#include ' in zsim. + * (E.g., some environments might include in their system/startup files.) + */ +#undef assert #ifndef NASSERT #define assert(expr) \ if (unlikely(!(expr))) { \ From a489a99b465706651885c139ce24927a77cc7d3b Mon Sep 17 00:00:00 2001 From: Grant Ayers Date: Tue, 7 Jun 2016 21:50:03 -0700 Subject: [PATCH 2/5] [build] Fix an invalid conversion from bool to PostPatchFn. --- src/virt/time.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virt/time.cpp b/src/virt/time.cpp index 72195a0bf..83ec7c0ff 100644 --- a/src/virt/time.cpp +++ b/src/virt/time.cpp @@ -197,7 +197,7 @@ PostPatchFn PatchNanosleep(PrePatchArgs args) { // Check preconditions // FIXME, shouldn't this use safeCopy?? if (!ts) return NullPostPatch; // kernel will return EFAULT - if (ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec > 999999999) return false; // kernel will return EINVAL + if (ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec > 999999999) return NullPostPatch; // kernel will return EINVAL uint64_t waitNsec = timespecToNs(*ts); if (waitNsec >= offsetNsec) waitNsec -= offsetNsec; From 1f8e8f77a7800de4b5091bb29853c17925f14120 Mon Sep 17 00:00:00 2001 From: Grant Ayers Date: Tue, 7 Jun 2016 21:52:13 -0700 Subject: [PATCH 3/5] [build] Prevent an always-false comparison of MAX_SIZE_T to an unsigned int since the former may be out of range of the latter. --- src/g_heap/dlmalloc.h.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_heap/dlmalloc.h.c b/src/g_heap/dlmalloc.h.c index 12ca34b20..62fe60659 100644 --- a/src/g_heap/dlmalloc.h.c +++ b/src/g_heap/dlmalloc.h.c @@ -4166,7 +4166,7 @@ static void* sys_alloc(mstate m, size_t nb) { /* Unmap and unlink any mmapped segments that don't contain used chunks */ static size_t release_unused_segments(mstate m) { size_t released = 0; - unsigned int nsegs = 0; //dsm: Was signed, and gcc was complaining about signed vs unsigned comparisons + size_t nsegs = 0; msegmentptr pred = &m->seg; msegmentptr sp = pred->next; while (sp != 0) { From 5dd1ba04887e4054402c8f5991cde0ceffdac301 Mon Sep 17 00:00:00 2001 From: Grant Ayers Date: Tue, 7 Jun 2016 21:55:24 -0700 Subject: [PATCH 4/5] [build] MemParam::interleaveType is unsigned and cannot be less than zero. --- src/detailed_mem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detailed_mem.cpp b/src/detailed_mem.cpp index 1cc3b6b58..7570dc78d 100644 --- a/src/detailed_mem.cpp +++ b/src/detailed_mem.cpp @@ -621,7 +621,7 @@ void MemChannelBase::AddressMap(Address addr, uint32_t& row, uint32_t& col, uint } uint32_t chnl = (uint32_t)-1; - if (mParam->interleaveType >= 0 && mParam->interleaveType <= 5) { + if (mParam->interleaveType <= 5) { // for non-power of 2 channels chnl = addr % mParam->channelCount; addr /= mParam->channelCount; From 8525ae230ba7efb1896684bba08e769553887838 Mon Sep 17 00:00:00 2001 From: Grant Ayers Date: Fri, 9 Sep 2016 10:40:08 -0700 Subject: [PATCH 5/5] [build] Fix invalid variable names when LOG_TRACE is set. --- src/virt/cpu.cpp | 2 +- src/virt/time.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/virt/cpu.cpp b/src/virt/cpu.cpp index 954eac279..0af67d69d 100644 --- a/src/virt/cpu.cpp +++ b/src/virt/cpu.cpp @@ -59,7 +59,7 @@ PostPatchFn PatchGetcpu(PrePatchArgs args) { uint32_t cpu = cpuenumCpu(procIdx, getCid(args.tid)); // still valid, may become invalid when we leave() assert(cpu != (uint32_t)-1); return [cpu](PostPatchArgs args) { - trace(TimeVirt, "[%d] Post-patching SYS_getcpu", tid); + trace(TimeVirt, "[%d] Post-patching SYS_getcpu", args.tid); ADDRINT arg0 = PIN_GetSyscallArgument(args.ctxt, args.std, 0); ADDRINT arg1 = PIN_GetSyscallArgument(args.ctxt, args.std, 1); VirtGetcpu(args.tid, cpu, arg0, arg1); diff --git a/src/virt/time.cpp b/src/virt/time.cpp index 83ec7c0ff..35598582a 100644 --- a/src/virt/time.cpp +++ b/src/virt/time.cpp @@ -180,17 +180,17 @@ PostPatchFn PatchNanosleep(PrePatchArgs args) { struct timespec* ts; uint64_t offsetNsec = 0; if (isClock) { - trace(TimeVirt, "[%d] Pre-patching SYS_clock_nanosleep", tid); + trace(TimeVirt, "[%d] Pre-patching SYS_clock_nanosleep", args.tid); int flags = (int) PIN_GetSyscallArgument(ctxt, std, 1); ts = (struct timespec*) PIN_GetSyscallArgument(ctxt, std, 2); if (flags == TIMER_ABSTIME) { - trace(TimeVirt, "[%d] SYS_clock_nanosleep requests TIMER_ABSTIME, offsetting", tid); + trace(TimeVirt, "[%d] SYS_clock_nanosleep requests TIMER_ABSTIME, offsetting", args.tid); uint32_t domain = zinfo->procArray[procIdx]->getClockDomain(); uint64_t simNs = cyclesToNs(zinfo->globPhaseCycles); offsetNsec = simNs + zinfo->clockDomainInfo[domain].realtimeOffsetNs; } } else { - trace(TimeVirt, "[%d] Pre-patching SYS_nanosleep", tid); + trace(TimeVirt, "[%d] Pre-patching SYS_nanosleep", args.tid); ts = (struct timespec*) PIN_GetSyscallArgument(ctxt, std, 0); } @@ -228,9 +228,9 @@ PostPatchFn PatchNanosleep(PrePatchArgs args) { SYSCALL_STANDARD std = args.std; if (isClock) { - trace(TimeVirt, "[%d] Post-patching SYS_clock_nanosleep", tid); + trace(TimeVirt, "[%d] Post-patching SYS_clock_nanosleep", args.tid); } else { - trace(TimeVirt, "[%d] Post-patching SYS_nanosleep", tid); + trace(TimeVirt, "[%d] Post-patching SYS_nanosleep", args.tid); } int res = (int)(-PIN_GetSyscallNumber(ctxt, std));