dyninst.git
6 years agoInitialize thrd in a new FrameNode ctor
Josh Stone [Sat, 14 Dec 2013 02:31:02 +0000 (18:31 -0800)]
Initialize thrd in a new FrameNode ctor

Reported by Coverity as UNINIT_CTOR.

6 years agoInitialize and free PSetFeatures::memset
Josh Stone [Sat, 14 Dec 2013 02:26:20 +0000 (18:26 -0800)]
Initialize and free PSetFeatures::memset

Reported by Coverity as UNINIT_CTOR

6 years agostackwalk: convert some stderr chatter to sw_printf
Josh Stone [Fri, 6 Dec 2013 19:32:46 +0000 (11:32 -0800)]
stackwalk: convert some stderr chatter to sw_printf

6 years agosymtabAPI: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:56:55 +0000 (10:56 -0800)]
symtabAPI: Fix Coverity UNINIT_CTOR errors

6 years agosymlite: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:56:46 +0000 (10:56 -0800)]
symlite: Fix Coverity UNINIT_CTOR errors

6 years agostackwalk: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:56:37 +0000 (10:56 -0800)]
stackwalk: Fix Coverity UNINIT_CTOR errors

6 years agoproccontrol: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:56:24 +0000 (10:56 -0800)]
proccontrol: Fix Coverity UNINIT_CTOR errors

6 years agoparseAPI: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:56:11 +0000 (10:56 -0800)]
parseAPI: Fix Coverity UNINIT_CTOR errors

6 years agoinstructionAPI: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:55:53 +0000 (10:55 -0800)]
instructionAPI: Fix Coverity UNINIT_CTOR errors

6 years agoelf: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:55:40 +0000 (10:55 -0800)]
elf: Fix Coverity UNINIT_CTOR errors

6 years agodataflowAPI: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:55:31 +0000 (10:55 -0800)]
dataflowAPI: Fix Coverity UNINIT_CTOR errors

6 years agocommon: Fix Coverity UNINIT_CTOR errors
Josh Stone [Fri, 6 Dec 2013 18:54:58 +0000 (10:54 -0800)]
common: Fix Coverity UNINIT_CTOR errors

6 years agoUse 'delete' for objects created with 'new'
Josh Stone [Wed, 4 Dec 2013 00:58:45 +0000 (16:58 -0800)]
Use 'delete' for objects created with 'new'

These two instances were incorrectly using free().

Reported by clang-analyzer as Memory Error : Bad deallocator.

6 years agoFix accidental switch fallthrough
Josh Stone [Fri, 22 Nov 2013 20:13:59 +0000 (12:13 -0800)]
Fix accidental switch fallthrough

These were reported by Coverity as MISSING_BREAK, and it seems true -
they should not be falling through to the next case.  Add breaks.

6 years agoAnnotate intentional switch fallthrough
Josh Stone [Fri, 22 Nov 2013 20:11:30 +0000 (12:11 -0800)]
Annotate intentional switch fallthrough

These were reported by Coverity as MISSING_BREAK, but they're
intentionally falling through to the next case.  Coverity will infer
this intent if there's a comment in the last line instead of a break.

6 years agoReimplement Linux P_copy with fstream
Josh Stone [Fri, 22 Nov 2013 19:18:11 +0000 (11:18 -0800)]
Reimplement Linux P_copy with fstream

Coverity reported RESOURCE_LEAK for the fds on error paths, and I see it
also doesn't check write() return value.  It's much easier to just let
fstream do the buffer management and IO.

Note: P_copy doesn't appear to actually be used anywhere, and the former
destination mode 0 was also suspicious.  Maybe it should be removed.

6 years agoReimplement getLinuxMaps in real C++
Josh Stone [Fri, 22 Nov 2013 02:44:37 +0000 (18:44 -0800)]
Reimplement getLinuxMaps in real C++

Coverity reported a few OVERFLOW weaknesses in the previous buffer-happy
code.  The whole function is much simpler using fstream to read maps.

6 years agoemitElf: Fix possible sign-extension errors
Josh Stone [Fri, 22 Nov 2013 00:56:36 +0000 (16:56 -0800)]
emitElf: Fix possible sign-extension errors

When you have an expression type "<uint64_t> = <uint16_t> * <uint16_t>",
it sadly takes a detour into signed values.  The operands will be
promoted to int, then multiplied, then sign-extended to finally fill
uint64_t.  If the multiplication result is greater than 0x7fffffff,
overflowing int, then the top 32 bits of the uint64_t will all be 1s.
(That's if the compiler doesn't blow up the int overflow as undefined.)

The easiest solution is to forcefully promote the operands to the target
size and sign before multiplying.

Reported by Coverity as SIGN_EXTENSION.

6 years agostackwalk: Don't leak CallChecker instances
Josh Stone [Fri, 22 Nov 2013 00:28:01 +0000 (16:28 -0800)]
stackwalk: Don't leak CallChecker instances

Both AnalysisStepperImpl and WandererHelper create CallCheckers in their
constructors, so they should delete in their deconstructors.

Reported by Coverity as CTOR_DTOR_LEAK.

6 years agoproccontrol: Flatten up_notify as a member of int_notify
Josh Stone [Thu, 21 Nov 2013 23:53:04 +0000 (15:53 -0800)]
proccontrol: Flatten up_notify as a member of int_notify

In the int_notify ctor, up_notify is newed, but this member is never
deleted.  Since this object never changes, it doesn't need to be a
pointer at all, so make it a direct member.

However, int_notify is a singleton that's never deleted, so the overall
leakiness isn't really changed here.

Reported by Coverity as CTOR_DTOR_LEAK.

6 years agosymlite: Use pread rather than lseek save/restore
Josh Stone [Thu, 21 Nov 2013 23:34:44 +0000 (15:34 -0800)]
symlite: Use pread rather than lseek save/restore

In SymLite::getInterpreterName, it was doing a SEEK_CUR, SEEK_SET,
read(), then SEEK_SET back to the original offset.  This can all be
replaced by using pread() to read from any offset without affecting the
actual file offset.

The former lseeks triggered Coverity CHECKED_RETURN & NEGATIVE_RETURNS.

6 years agocommon: Fix a sizeof error in calloc/realloc
Josh Stone [Thu, 21 Nov 2013 04:37:44 +0000 (20:37 -0800)]
common: Fix a sizeof error in calloc/realloc

An allocation resulting in (anno_list_t*) should not use the pointer
size, but rather sizeof(anno_list_t).  It just happened to be harmless
here because anno_list_t is itself typedef void*, so the same size.

Reported by Coverity as SIZEOF_MISMATCH.

6 years agopatchAPI: Remove 'during' before destroying it
Josh Stone [Thu, 21 Nov 2013 01:01:55 +0000 (17:01 -0800)]
patchAPI: Remove 'during' before destroying it

In PatchParseCallback::remove_edge_cb, if it has pe->points_.during,
then this is both destroyed and removed from PatchFunctions.  However,
PatchCallback::destroy will delete the point if not batching, and
PatchFunction::remove dereferences it, so destroy must come after.

Reported by Coverity as USE_AFTER_FREE.

6 years agoproccontrol: Avoid dereferencing a deleted 'this'
Josh Stone [Thu, 21 Nov 2013 00:55:09 +0000 (16:55 -0800)]
proccontrol: Avoid dereferencing a deleted 'this'

In linux_process::preTerminate, a debug message asking, "Is this irony?"
has its own irony by calling getPid() when 'this' was just deleted.

Reported by Coverity as USE_AFTER_FREE.

6 years agosymlite: Don't use a delete pointer
Josh Stone [Thu, 21 Nov 2013 00:47:44 +0000 (16:47 -0800)]
symlite: Don't use a delete pointer

In SymElfFactory::closeSymbolReader, if 'ser' isn't in open_symelfs,
then it is deleted, so the function should return without using 'ser'
any more.

Reported by Coverity as USE_AFTER_FREE.

6 years agoproccontrol: Fix a copy-paste typo in ppc_process::readInsnForSS
Josh Stone [Thu, 21 Nov 2013 00:18:56 +0000 (16:18 -0800)]
proccontrol: Fix a copy-paste typo in ppc_process::readInsnForSS

After iterating over all of map mm_for_ss, this function will create a
new mem_response for the request.  If that reports isReady() right away,
then the memcpy incorrectly copies from the previous map iterator, which
is now exhausted (==end()).  This appears to be a copy-paste typo of the
memcpy from within the for loop, and this memcpy should use new_resp.

Reported by Coverity as INVALIDATE_ITERATOR.

6 years agoelf: Fix iteration in the destructor
Josh Stone [Thu, 21 Nov 2013 00:10:47 +0000 (16:10 -0800)]
elf: Fix iteration in the destructor

In Elf_X::~Elf_X, the loop over elf_x_by_fd returns after it finds an
erases its element.  The loop over elf_x_by_ptr should do the same.
It's actually an error to continue the for loop with ++iter, because
map::erase() invalidates its iterator.

Reported by Coverity as INVALIDATE_ITERATOR.

6 years agoAssert that dwarf_loclist_from_expr_a returns cnt==1
Josh Stone [Wed, 20 Nov 2013 23:49:33 +0000 (15:49 -0800)]
Assert that dwarf_loclist_from_expr_a returns cnt==1

Coverity reports ARRAY_VS_SINGLETON in DwarfWalker::decodeExpression,
because the address of a singleton, &descs, is passed with cnt to
decodeLocationListForStaticOffsetOrAddress, which treats it as an array.
Without knowledge of cnt, the analyzer thinks this could be source of
memory corruption.

In fact, dwarf_loclist_from_expr_a always sets listlen (cnt) to 1 on
success.  If we assert this, then the analyzer can tell that the
singleton "array" bound is fine.

6 years agodataflowAPI: Correct an assertion test
Josh Stone [Wed, 20 Nov 2013 23:02:05 +0000 (15:02 -0800)]
dataflowAPI: Correct an assertion test

Based on surrounding context, it seems clear that this assert meant to
test equality, not the result of assignment.

Reported by Coverity as ASSERT_SIDE_EFFECT.

6 years agoWe were double-adding field sizes to structs when they came from DWARF. This fixes...
Bill Williams [Fri, 13 Dec 2013 22:27:59 +0000 (16:27 -0600)]
We were double-adding field sizes to structs when they came from DWARF. This fixes that; we still need to add field sizes in cases where users create their own data types.

6 years agoIndirect tail calls shouldn't count as unresolved control flow for instrumentation...
Bill Williams [Fri, 13 Dec 2013 20:33:25 +0000 (14:33 -0600)]
Indirect tail calls shouldn't count as unresolved control flow for instrumentation purposes.

6 years agoAssorted bugfixes: don't die on DW_OP_piece, remove unimplemented stream operators...
Bill Williams [Fri, 13 Dec 2013 17:11:00 +0000 (11:11 -0600)]
Assorted bugfixes: don't die on DW_OP_piece, remove unimplemented stream operators from headers, bug fix for indirect tail calls, treat indirect symbols as functions in our aggregates, and handle DW_FORM_sec_offset.

6 years agoFixes for three bugs: tie CMake version dependency to use of the relevant features...
William Williams [Thu, 12 Dec 2013 17:06:45 +0000 (09:06 -0800)]
Fixes for three bugs: tie CMake version dependency to use of the relevant features, check types for compatibility not pointer equality, and don't apply tail call heuristics to call instructions.

6 years agoMerge branch 'master' into pc_mem_stats
Matthew LeGendre [Wed, 11 Dec 2013 18:50:22 +0000 (10:50 -0800)]
Merge branch 'master' into pc_mem_stats

6 years agoFix installation issues from RT library cmake split
Matthew LeGendre [Wed, 11 Dec 2013 18:49:17 +0000 (10:49 -0800)]
Fix installation issues from RT library cmake split

6 years agoDo include <linux/ptrace.h> for glibc prior to 2.7
Josh Stone [Thu, 28 Nov 2013 01:10:14 +0000 (17:10 -0800)]
Do include <linux/ptrace.h> for glibc prior to 2.7

6 years agoRefactor RT library into separate CMake project so we can change compilers
Matthew LeGendre [Wed, 27 Nov 2013 00:00:35 +0000 (16:00 -0800)]
Refactor RT library into separate CMake project so we can change compilers

6 years agoDefault to libiberty demangler
Matthew LeGendre [Tue, 26 Nov 2013 17:53:13 +0000 (09:53 -0800)]
Default to libiberty demangler

6 years agoEnable built-in gcc demangler rather than libiberty's
Matthew LeGendre [Mon, 25 Nov 2013 21:08:39 +0000 (13:08 -0800)]
Enable built-in gcc demangler rather than libiberty's

6 years agoJust include <sys/ptrace.h>
William Cohen [Mon, 5 Aug 2013 16:24:36 +0000 (12:24 -0400)]
Just include <sys/ptrace.h>

Ref: https://bugzilla.redhat.com/show_bug.cgi?id=991889

6 years agoMerge branch 'clang-warnings'
Josh Stone [Fri, 22 Nov 2013 20:31:09 +0000 (12:31 -0800)]
Merge branch 'clang-warnings'

6 years agoPostponedSyscall fixes
Matthew LeGendre [Wed, 13 Nov 2013 23:38:31 +0000 (15:38 -0800)]
PostponedSyscall fixes

6 years agoBuild downloaded packages in build dir rather than source dir. Prevents conflicts...
Matthew LeGendre [Wed, 20 Nov 2013 17:44:49 +0000 (09:44 -0800)]
Build downloaded packages in build dir rather than source dir.  Prevents conflicts when sharing source tree between platforms.

6 years agoFix an error message Address formatting [-Wstring-plus-int]
Josh Stone [Wed, 20 Nov 2013 01:15:26 +0000 (17:15 -0800)]
Fix an error message Address formatting [-Wstring-plus-int]

6 years agoRemove extra parentheses for plain conditions [-Wparentheses-equality]
Josh Stone [Wed, 20 Nov 2013 01:04:12 +0000 (17:04 -0800)]
Remove extra parentheses for plain conditions [-Wparentheses-equality]

6 years agoAdd extra parentheses for assignment-as-condition [-Wparentheses]
Josh Stone [Wed, 20 Nov 2013 01:02:36 +0000 (17:02 -0800)]
Add extra parentheses for assignment-as-condition  [-Wparentheses]

6 years agoConvince Clang that it's possible for an EdgeTypeEnum to be -1
Josh Stone [Wed, 20 Nov 2013 00:55:16 +0000 (16:55 -0800)]
Convince Clang that it's possible for an EdgeTypeEnum to be -1

[-Wtautological-constant-out-of-range-compare]

6 years agoFix NULLs returned to bools [-Wnull-conversion]
Josh Stone [Wed, 20 Nov 2013 00:44:27 +0000 (16:44 -0800)]
Fix NULLs returned to bools [-Wnull-conversion]

6 years agoExpand SW calltree interface to allow expanding and modifying CallTree. Needed for...
Matthew LeGendre [Wed, 20 Nov 2013 00:39:37 +0000 (16:39 -0800)]
Expand SW calltree interface to allow expanding and modifying CallTree.  Needed for STAT.

6 years agoPPC64 build fix for SymtabAPI
Matthew LeGendre [Wed, 20 Nov 2013 00:39:02 +0000 (16:39 -0800)]
PPC64 build fix for SymtabAPI

6 years agoNew PC PlatFeature interface for querying process memory usage. Implemented on BGQ...
Matthew LeGendre [Wed, 20 Nov 2013 00:38:48 +0000 (16:38 -0800)]
New PC PlatFeature interface for querying process memory usage.  Implemented on BGQ and Linux

6 years agoHide sometimes-unused functions better [-Wunused-function]
Josh Stone [Wed, 20 Nov 2013 00:38:18 +0000 (16:38 -0800)]
Hide sometimes-unused functions better [-Wunused-function]

- Mark ParserDetails.h is_code() static inline, so compilation units
  which don't call it will just ignore it.

- Only define aix_region_hack() if define(os_aix).

6 years agoFix issue where we were using the wrong BGQ compiler for the RT library
Matthew LeGendre [Wed, 20 Nov 2013 00:36:10 +0000 (16:36 -0800)]
Fix issue where we were using the wrong BGQ compiler for the RT library

6 years agoFix BGQ build error in RT library
Matthew LeGendre [Wed, 20 Nov 2013 00:35:42 +0000 (16:35 -0800)]
Fix BGQ build error in RT library

6 years agoRemove unused data members [-Wunused-private-field]
Josh Stone [Wed, 20 Nov 2013 00:33:16 +0000 (16:33 -0800)]
Remove unused data members [-Wunused-private-field]

6 years agoUse (void) to squash unused variables [-Wself-assign]
Josh Stone [Wed, 20 Nov 2013 00:00:57 +0000 (16:00 -0800)]
Use (void) to squash unused variables [-Wself-assign]

Clang complains about the previous code:

  warning: explicitly assigning a variable [...] to itself

6 years agofindProcLWPs: initialize lwp_ppid [-Wsometimes-uninitialized]
Josh Stone [Tue, 19 Nov 2013 23:58:12 +0000 (15:58 -0800)]
findProcLWPs: initialize lwp_ppid [-Wsometimes-uninitialized]

6 years agoSeparate unclear "=-" into "= -"
Josh Stone [Tue, 19 Nov 2013 23:50:59 +0000 (15:50 -0800)]
Separate unclear "=-" into "= -"

These gave clang cause for concern, like:

  warning: use of unary operator that may be intended as
  compound assignment (-=)

I believe they really are just meant to assign negative values.

6 years agoFix string termination [-Wnon-literal-null-conversion]
Josh Stone [Tue, 19 Nov 2013 23:46:44 +0000 (15:46 -0800)]
Fix string termination [-Wnon-literal-null-conversion]

These two lines were setting their pointers to '\0', effectively NULL,
rather than writing the value pointed to.

6 years agoReconcile class/struct declarations [-Wmismatched-tags]
Josh Stone [Tue, 19 Nov 2013 23:41:33 +0000 (15:41 -0800)]
Reconcile class/struct declarations [-Wmismatched-tags]

6 years agoLet Dyninst itself be compiled with Clang on Linux
Josh Stone [Tue, 19 Nov 2013 22:41:42 +0000 (14:41 -0800)]
Let Dyninst itself be compiled with Clang on Linux

With clang-3.3-0.10.rc3.fc19.x86_64 and libstdc++-4.8.2-1.fc19.x86_64,
the fixes required were as follows:

- cmake files looking for CMAKE_COMPILER_IS_GNUCXX need to also
  recognize CMAKE_CXX_COMPILER_ID "Clang".

- The ListHash macro had a pointer->int cast that halted Clang.

- Several templates in rose/*InstructionSemantics.h couldn't be resolved
  implicitly; they're now either made explicit or converted to typename.

- ppc32::cr0.val() is apparently not const enough for Clang as a
  template parameter; changed to ppc32::icr0.

6 years agocommon: Use __GLIBCXX__ for libstdc++ checks
Josh Stone [Tue, 19 Nov 2013 22:26:10 +0000 (14:26 -0800)]
common: Use __GLIBCXX__ for libstdc++ checks

A Dyninst client might choose to compile with Clang and libstdc++.
Clang does set __GNUC__ macros, but only as if it were GCC 4.2.1, which
means checks looking for libstdc++ features were misled.  Those checks
are better served by __GLIBCXX__, which is a unique date stamp for each
GCC release.

6 years agodyninstAPI: Remove syscall instrumentation on detach
Josh Stone [Sat, 9 Nov 2013 01:09:24 +0000 (17:09 -0800)]
dyninstAPI: Remove syscall instrumentation on detach

During PCProcess::bootstrapProcess(), many syscalls are instrumented,
which may involve DyninstAPI_RT breakpoints.  If the mutator later
detaches, then there's no one to catch the instrumentation signal, so
the detached mutatee will crash.

With this patch, PCProcess will remove its syscall instrumentation
points when the mutator detaches.  It's still up to mutators to remove
their own instrumentation when desired.

Reported-by: Zifei Tong <soariez@gmail.com>
Signed-off-by: Josh Stone <jistone@redhat.com>
6 years agoWait for PTRACE_SYSCALL after mid-syscall PTRACE_EVENTs
Josh Stone [Thu, 7 Nov 2013 23:25:06 +0000 (15:25 -0800)]
Wait for PTRACE_SYSCALL after mid-syscall PTRACE_EVENTs

It is found that PTRACE_EVENT_FORK, _CLONE, and _EXEC all trigger in the
middle of the syscall in question.  It is not safe to modify the mutatee
at this point, because the syscall return value may not be written into
registers yet.

For instance, test4_2 does some post-fork instrumentation on the parent,
which triggers an iRPC on x86_64.  To run the iRPC, the process state is
saved, state is overwritten to setup the iRPC, process continues, then
state is restored.  When the syscall return value isn't written until
that continue, then it will be lost and we've saved+restored the wrong
value.  This results in test4_2 reporting "fork result: 56" (SYS_clone),
or it may even get -1 and errno=ENOSYS if syscall auditing is enabled.

The exact symptom is kernel-dependent.  The utrace-patched ptrace on
RHEL6 actually did wait to fire the event until after the fork result
was written, so it had no problem.  RHEL5 and Fedora 19 do show the bad
fork result though.

The solution is to create a new "postponed syscall" state, and resume
the process with PTRACE_SYSCALL to finish up the syscall related to the
PTRACE_EVENT first.  Only then is the event actually processed and
callbacks are delivered as needed.

6 years ago* When rewriting a binary and introducing one-page offsets w.r.t. its old virtual...
Bill Williams [Tue, 8 Oct 2013 20:38:47 +0000 (15:38 -0500)]
* When rewriting a binary and introducing one-page offsets w.r.t. its old virtual addresses, ensure that loadable segments are aligned to a single page, not multiple pages.
* Fixes to get parseThat to build properly against a CMake-installed Dyninst.

6 years agoExperimental: support parsing of indirect tail calls when they appear as a function...
Bill Williams [Thu, 3 Oct 2013 18:50:41 +0000 (13:50 -0500)]
Experimental: support parsing of indirect tail calls when they appear as a function's only instructions and lack stack teardown.

6 years agoNull check, don't blithely assume we have type info.
Bill Williams [Wed, 25 Sep 2013 15:36:49 +0000 (10:36 -0500)]
Null check, don't blithely assume we have type info.

6 years agoFix a bad merge that broke Springboard
Josh Stone [Thu, 7 Nov 2013 20:16:43 +0000 (12:16 -0800)]
Fix a bad merge that broke Springboard

In commit 8a035430164e, I removed the 'size' variable from
SpringboardBuilder::generateSpringboard(), as it was not used.

In commit 31b4cd373cd6, Bill initialized 'size' with a proper
value and used it in the call to registerBranch().

When git merged these, it reconciled the changed initialization on its
own, but also kept out a 'size = 1' that I had removed and Bill hadn't
touched.  That assignment is needed now that the variable is used.

6 years agocommon: Canonicalize '//' out of #include paths
Josh Stone [Tue, 5 Nov 2013 01:13:51 +0000 (17:13 -0800)]
common: Canonicalize '//' out of #include paths

Such paths confuse rpm debugedit; see rhbz304121.

6 years agoMerge branch 'jistone/coverity'
Josh Stone [Mon, 4 Nov 2013 21:51:48 +0000 (13:51 -0800)]
Merge branch 'jistone/coverity'

6 years agoFix infinite loops in x86/x86_64 tc_lock_lock
Josh Stone [Thu, 24 Oct 2013 04:03:08 +0000 (21:03 -0700)]
Fix infinite loops in x86/x86_64 tc_lock_lock

With -fvisibility=hidden, gcc gets too smart and inlines atomic_set into
tc_lock_lock.  The optimizer can't tell that the asm in atomic_set is
changing anything, because its input is a fixed pointer, not the
volatile value it points too.  So the x86_64 lock loop looks like this:

  34:   48 c7 c0 01 00 00 00    mov    $0x1,%rax
  3b:   48 89 d9                mov    %rbx,%rcx
  3e:   f0 48 87 01             lock xchg %rax,(%rcx)
  42:   48 89 c2                mov    %rax,%rdx
  45:   0f 1f 00                nopl   (%rax)
  48:   48 85 d2                test   %rdx,%rdx
  4b:   75 fb                   jne    48 <tc_lock_lock+0x28>

That is, on failure 4b jumps back to 48 forever.  It's also not really
correct to be using a 64-bit xchg, since the memory value is just int.
The 32-bit x86 version gets a similar loop with the xchg lifted out.

This patch greatly simplifies the asm, with its input "+m"(*val) ensuring
that gcc knows we're using the volatile value, and a broad "memory"
constraint so the lock can protect other data too.  That loop is now:

  11:   b9 01 00 00 00          mov    $0x1,%ecx
  16:   66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
  1d:   00 00 00
  20:   89 ca                   mov    %ecx,%edx
  22:   87 13                   xchg   %edx,(%rbx)
  24:   85 d2                   test   %edx,%edx
  26:   75 f8                   jne    20 <tc_lock_lock+0x20>

Signed-off-by: Josh Stone <jistone@redhat.com>
6 years agoReally enable -fvisibility=hidden for GCC builds
Josh Stone [Wed, 23 Oct 2013 22:48:50 +0000 (15:48 -0700)]
Really enable -fvisibility=hidden for GCC builds

The visibility flags were being added after the component directories
were specified, which apparently means those subdirectories don't get
the same flags.  Also, the flags weren't quoted correctly when defined,
and -fvisibility-inlines-hidden is only valid for C++.

Now the flags are defined using cmake/visibility.cmake, mimicking
warnings.cmake, and included in the same place in CMakeLists.txt.

I've found no regressions from this change, and there's a substantial
reduction in the size of the libraries.

Signed-off-by: Josh Stone <jistone@redhat.com>
6 years agoFix DYNINST_index_lock state and ppc64 writeFunctionPtr
Josh Stone [Thu, 17 Oct 2013 23:05:25 +0000 (16:05 -0700)]
Fix DYNINST_index_lock state and ppc64 writeFunctionPtr

There are two fixes in this patch to resolve hangs that we've seen on
ppc64 tests, most notably in test_thread_5.

The first is that DYNINST_index_lock may be left in a locked state from
DYNINSTthreadIndexSLOW when DYNINST_thread_hash_size is 0.  This simply
needs an unlock in that error path.

The second resolves *why* DYNINST_thread_hash_size is 0, even after it
was correctly initialized to 40.  This turned out to be corruption when
the mutator writeFunctionPtr sets DYNINST_pthread_self.  Those symbols
in libdyninstAPI_RT.so happen to be arranged like so:

    0000000000031180 B DYNINST_pthread_self
    0000000000031188 B DYNINST_sysEntry
    0000000000031190 B DYNINST_thread_hash_size

So writeFunctionPtr was sending three longs: the function descriptor
correctly in DYNINST_pthread_self; the toc in DYNINST_sysEntry, a dead
variable; and the guilty 0x0 in DYNINST_thread_hash_size.  The only
thing a function pointer actually needs is the function descriptor.

For comparison, on EL5 and EL6 our build has the symbols like so:

    000000000002c400 B DYNINST_pthread_self
    000000000002c408 B DYNINSTlinkSave
    000000000002c410 B DYNINSTtocSave
    000000000002c418 B DYNINST_sysEntry
    000000000002c420 B DYNINST_thread_hash_tids
    000000000002c428 B DYNINST_thread_hash_size

So that still clobbered data, but DYNINSTlinkSave and DYNINSTtocSave are
both unused variables -- no harm done.

Signed-off-by: Josh Stone <jistone@redhat.com>
6 years agoDon't stop mutatees for SIGINT
Josh Stone [Sat, 8 Jun 2013 01:46:04 +0000 (18:46 -0700)]
Don't stop mutatees for SIGINT

In PCEventHandler::shouldStopForSignal(), SIGINT is not a stopping
signal.  SIGINT's default action is to terminate the process, but it can
also be handled or ignored.  It never stops, to my knowledge.

It's hard for me to know the original author's intent, but the other
match on SIGSTOP does make sense.  SIGTSTP, SIGTTIN, and SIGTTOU are
also stopping signals, FWIW, but those may still be caught or ignored.

6 years agoXMM saves: if we're only looking at XMM0-XMM7 as save candidates, then save individua...
Bill Williams [Thu, 19 Sep 2013 19:11:17 +0000 (14:11 -0500)]
XMM saves: if we're only looking at XMM0-XMM7 as save candidates, then save individual live registers. If something more than that is live, fall back to a full fxsave/fxrestore.

6 years agoExperimental: replace fxsave with saves of XMM 0-7
Andrew Bernat [Tue, 2 Apr 2013 17:54:18 +0000 (12:54 -0500)]
Experimental: replace fxsave with saves of XMM 0-7

6 years agoJump tables: handle gcc 4.8 new form.
Bill Williams [Wed, 18 Sep 2013 20:10:18 +0000 (15:10 -0500)]
Jump tables: handle gcc 4.8 new form.

6 years agoMerge branch 'warnings' into coverity
Josh Stone [Tue, 17 Sep 2013 23:08:43 +0000 (16:08 -0700)]
Merge branch 'warnings' into coverity

6 years agodyninstAPI: unname an unused parameter in AstNode::checkType
Josh Stone [Tue, 10 Sep 2013 22:45:40 +0000 (15:45 -0700)]
dyninstAPI: unname an unused parameter in AstNode::checkType

Fixes this warning:

dyninstAPI/src/ast.C:2261:14: warning: unused parameter ‘func’ [-Wunused-parameter]
 BPatch_type *AstNode::checkType(BPatch_function* func) {
              ^

6 years agodyninstAPI_RT: fix many warnings from gcc 4.8
Josh Stone [Fri, 30 Aug 2013 23:27:37 +0000 (16:27 -0700)]
dyninstAPI_RT: fix many warnings from gcc 4.8

Some unused parameters, some size/sign comparison; nothing major.

6 years agodyninstAPI: remove the unused non-vector replaceHandler
Josh Stone [Fri, 30 Aug 2013 22:32:24 +0000 (15:32 -0700)]
dyninstAPI: remove the unused non-vector replaceHandler

This function has grown unused and obsolete due to changes elsewhere in
this source file.  The vectorized replaceHandler is still in use though.

dyninstAPI/src/parse-x86.C:256:13: warning: ‘bool replaceHandler(func_instance*, func_instance*, int_symbol*, std::string)’ defined but not used [-Wunused-function]
 static bool replaceHandler(func_instance *origHandler, func_instance *newHandler,
             ^

6 years agosymtabAPI: un-name a few unused parameter to avoid warnings
Josh Stone [Fri, 30 Aug 2013 22:24:58 +0000 (15:24 -0700)]
symtabAPI: un-name a few unused parameter to avoid warnings

symtabAPI/src/emitElfStatic-x86.C:88:13: warning: unused parameter ‘errMsg’ [-Wunused-parameter]
 static bool computeCtorDtorAddress(relocationEntry &rel, Offset globalOffset,
             ^
symtabAPI/src/emitElfStatic-x86.C:619:6: warning: unused parameter ‘lmap’ [-Wunused-parameter]
 bool emitElfStatic::createNewCtorRegion(LinkMap &lmap) {
      ^
symtabAPI/src/emitElfStatic-x86.C:651:6: warning: unused parameter ‘lmap’ [-Wunused-parameter]
 bool emitElfStatic::createNewDtorRegion(LinkMap &lmap) {
      ^

6 years agocommon: fix a visibility warning on P_cplus_demangle
Josh Stone [Fri, 30 Aug 2013 22:17:12 +0000 (15:17 -0700)]
common: fix a visibility warning on P_cplus_demangle

The attribute is ignored on function definitions, but COMMON_EXPORT
is already tagged on the declaration in linuxKludges.h anyway.

common/src/linuxKludges.C:183:23: warning: ‘visibility’ attribute ignored on non-class types [-Wattributes]
     bool includeTypes )
                       ^

6 years agoMerge remote-tracking branch 'origin/master' into warnings
Josh Stone [Tue, 17 Sep 2013 22:51:34 +0000 (15:51 -0700)]
Merge remote-tracking branch 'origin/master' into warnings

6 years agoMore gcc 4.8 fixes.
Bill Williams [Mon, 16 Sep 2013 18:29:57 +0000 (13:29 -0500)]
More gcc 4.8 fixes.

* Check whether snippet handles are empty and return NULL when inserting if so.
* BPatch_functions have params in both alpha and parameter order; getParams should return them in parameter order.
* DWARF 4 includes a (base, size) form for address ranges, as well as the (low, high) form that we had previously. Recognize this and handle accordingly.

6 years agoCMake patches: only install libdwarf/libelf if we built, and use local mirror for...
Bill Williams [Fri, 6 Sep 2013 19:19:52 +0000 (14:19 -0500)]
CMake patches: only install libdwarf/libelf if we built, and use local mirror for libdwarf rather than unreliable sgiweb site

6 years agoAdd libdl link dependency to proccontrol.
Bill Williams [Thu, 5 Sep 2013 22:24:04 +0000 (17:24 -0500)]
Add libdl link dependency to proccontrol.

6 years agoImprove retExpr type checking: disallow insertion at exit points of void functions.
Bill Williams [Thu, 5 Sep 2013 22:23:37 +0000 (17:23 -0500)]
Improve retExpr type checking: disallow insertion at exit points of void functions.

6 years agoAdd RelWithDebugInfo configuration.
Bill Williams [Wed, 4 Sep 2013 15:54:44 +0000 (10:54 -0500)]
Add RelWithDebugInfo configuration.

6 years agoBug fixes surrounding trap generation: postcondition of addTrap is that the codegen...
Bill Williams [Wed, 4 Sep 2013 15:54:08 +0000 (10:54 -0500)]
Bug fixes surrounding trap generation: postcondition of addTrap is that the codegen parameter contains the necessary changes to the address space (including none, in the dynamic mode case). Always add that codegen to the list of changes to apply. Respect user-level "useTraps" interface.

6 years agoTrap handling update: always respect the BPatch flag unless built without cap_mutatee...
Bill Williams [Tue, 3 Sep 2013 18:50:21 +0000 (13:50 -0500)]
Trap handling update: always respect the BPatch flag unless built without cap_mutatee_traps.

6 years agoRemove spurious output
Bill Williams [Fri, 23 Aug 2013 18:56:59 +0000 (13:56 -0500)]
Remove spurious output

6 years agoRedid static ctor/dtor handling to be compatible with init_array/fini_array as well...
Bill Williams [Thu, 22 Aug 2013 21:29:21 +0000 (16:29 -0500)]
Redid static ctor/dtor handling to be compatible with init_array/fini_array as well as ctors/dtors.

6 years agoAdd static targets
Bill Williams [Thu, 22 Aug 2013 16:38:25 +0000 (11:38 -0500)]
Add static targets

6 years agoRemove AIX code from RTlib tramp guard init
Bill Williams [Thu, 22 Aug 2013 15:35:11 +0000 (10:35 -0500)]
Remove AIX code from RTlib tramp guard init

6 years agoMerge branch 'symbol_visibility'
Bill Williams [Tue, 20 Aug 2013 16:13:09 +0000 (11:13 -0500)]
Merge branch 'symbol_visibility'

6 years agoAdded optimization flags for Windows release
Bill Williams [Tue, 20 Aug 2013 16:12:09 +0000 (11:12 -0500)]
Added optimization flags for Windows release

6 years agoMerge branch 'master' of ssh://git.dyninst.org/pub/dyninst
Bill Williams [Mon, 19 Aug 2013 15:22:29 +0000 (10:22 -0500)]
Merge branch 'master' of ssh://git.dyninst.org/pub/dyninst

6 years agoMerge
Bill Williams [Mon, 19 Aug 2013 15:17:50 +0000 (10:17 -0500)]
Merge

6 years agoRemove incorrect export declaration
Bill Williams [Fri, 9 Aug 2013 17:59:09 +0000 (12:59 -0500)]
Remove incorrect export declaration