Skip to content

Commit

Permalink
i#3348 sym conflicts: use "d_r_" prefix on core string routines (#3405)
Browse files Browse the repository at this point in the history
Rename our_*snprintf* to d_r_*snprintf* per the new global variable naming policy.
Rename our_*sscanf to d_r_*sscanf.

Rename DR's internal string routines to use a d_r_ prefix to reduce
name conflicts with static linking.  Because on Windows we still want
to use the standard names (because we import from ntdll), we resort to
macro renames within core/ just like we're doing with snprintf.

Remove includes of string.h in core/ to avoid macros and inlined
functions pulling in libc functions, now that our versions use
different names.

Links string.c and io.c into drdecode.

Issue: #3348
  • Loading branch information
derekbruening authored Mar 1, 2019
1 parent e3446b6 commit c8d5db2
Show file tree
Hide file tree
Showing 73 changed files with 198 additions and 199 deletions.
2 changes: 2 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ add_library(drdecode
arch/${ARCH_NAME_SHARED}/mangle.c
arch/mangle_utils.c
arch/decodelib.c
string.c
io.c
)
set_target_properties(drdecode PROPERTIES
COMPILE_FLAGS "-DNOT_DYNAMORIO_CORE_PROPER -DSTANDALONE_DECODER")
Expand Down
10 changes: 3 additions & 7 deletions core/annotations.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ******************************************************
* Copyright (c) 2014-2017 Google, Inc. All rights reserved.
* Copyright (c) 2014-2019 Google, Inc. All rights reserved.
* ******************************************************/

/*
Expand Down Expand Up @@ -45,10 +45,6 @@
# include "../third_party/valgrind/memcheck.h"
# endif

# ifdef UNIX
# include <string.h>
# endif

/* Macros for identifying an annotation head and extracting the pointer to its name.
*
* IS_ANNOTATION_LABEL_INSTR(instr): Evaluates to true for any `instr`
Expand Down Expand Up @@ -1115,9 +1111,9 @@ annotation_printf(const char *format, ...)
ACCT_OTHER, UNPROTECTED);

/* copy the original format string up to the timestamp token */
our_snprintf(timestamped_format, length_before_token, "%s", format);
d_r_snprintf(timestamped_format, length_before_token, "%s", format);
/* copy the timestamp and the remainder of the original format string */
our_snprintf(timestamped_format + length_before_token,
d_r_snprintf(timestamped_format + length_before_token,
(buffer_length - length_before_token), "%s%s", timestamp_buffer,
timestamp_token_start + LOG_ANNOTATION_TIMESTAMP_TOKEN_LENGTH);
/* use the timestamped format string */
Expand Down
1 change: 0 additions & 1 deletion core/arch/aarch64/disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "instr.h"
#include "decode.h"
#include "disassemble.h"
#include <string.h>

#if defined(INTERNAL) || defined(DEBUG) || defined(CLIENT_INTERFACE)

Expand Down
2 changes: 0 additions & 2 deletions core/arch/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
#include "proc.h"
#include "instrument.h"

#include <string.h> /* for memcpy */

#if defined(DEBUG) || defined(INTERNAL)
# include "disassemble.h"
#endif
Expand Down
1 change: 0 additions & 1 deletion core/arch/arm/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "decode_private.h"
#include "decode_fast.h" /* ensure we export decode_next_pc, decode_sizeof */
#include "instr_create.h"
#include <string.h> /* for memcpy */
#include "disassemble.h"

/* ARM decoder.
Expand Down
1 change: 0 additions & 1 deletion core/arch/arm/disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "decode.h"
#include "decode_private.h"
#include "disassemble.h"
#include <string.h>

#if defined(INTERNAL) || defined(DEBUG) || defined(CLIENT_INTERFACE)

Expand Down
4 changes: 2 additions & 2 deletions core/arch/decodelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ print_to_buffer(char *buf, size_t bufsz, size_t *sofar INOUT, const char *fmt, .
ok = (len > 0 && len < (ssize_t)(bufsz - *sofar));
# ifdef UNIX
/* Linux vsnprintf returns what would have been written, unlike Windows
* or our_vsnprintf
* or d_r_vsnprintf
*/
if (len >= (ssize_t)(bufsz - *sofar))
len = -1;
Expand Down Expand Up @@ -207,7 +207,7 @@ print_file(file_t f, const char *fmt, ...)

# ifdef UNIX
/* Linux vsnprintf returns what would have been written, unlike Windows
* or our_vsnprintf
* or d_r_vsnprintf
*/
if (len >= BUFFER_SIZE_ELEMENTS(buf))
len = BUFFER_SIZE_ELEMENTS(buf); /* don't need NULL term */
Expand Down
1 change: 0 additions & 1 deletion core/arch/disassemble_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "decode_fast.h"
#include "disassemble.h"
#include "../module_shared.h"
#include <string.h>

/* these are only needed for symbolic address lookup: */
#include "../fragment.h" /* for fragment_pclookup */
Expand Down
1 change: 0 additions & 1 deletion core/arch/emit_utils_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include "instrlist.h"
#include "instrument.h" /* for dr_insert_call() */
#include "proc.h"
#include <string.h> /* for memcpy */
#include "decode.h"
#include "decode_fast.h"
#include "x86/decode_private.h"
Expand Down
2 changes: 0 additions & 2 deletions core/arch/instr_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
/* FIXME i#1551: refactor this file and avoid this x86-specific include in base arch/ */
#include "x86/decode_private.h"

#include <string.h> /* for memcpy */

#ifdef DEBUG
# include "disassemble.h"
#endif
Expand Down
1 change: 0 additions & 1 deletion core/arch/instrlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "instr.h"
#include "decode.h"
#include "arch.h"
#include <string.h>

#if defined(DEBUG) && defined(CLIENT_INTERFACE)
/* case 10450: give messages to clients */
Expand Down
1 change: 0 additions & 1 deletion core/arch/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include "decode.h"
#include "decode_fast.h"
#include "disassemble.h"
#include <string.h> /* for memcpy */
#include "instrument.h"
#include "../hotpatch.h"
#ifdef RETURN_AFTER_CALL
Expand Down
4 changes: 1 addition & 3 deletions core/arch/loadtoconst.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2012-2014 Google, Inc. All rights reserved.
* Copyright (c) 2012-2019 Google, Inc. All rights reserved.
* Copyright (c) 2002-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -51,8 +51,6 @@
# include "../emit.h"
# include "../link.h"

# include <string.h> /* for memset */

# include "loadtoconst.h"

# ifdef SIDELINE
Expand Down
2 changes: 0 additions & 2 deletions core/arch/opnd_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
# include "x86/decode_private.h"
#endif

#include <string.h> /* for memcpy */

#if defined(DEBUG) && !defined(STANDALONE_DECODER)
/* case 10450: give messages to clients */
/* we can't undef ASSERT b/c of DYNAMO_OPTION */
Expand Down
2 changes: 0 additions & 2 deletions core/arch/retcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
* Need to provide asm code for win32 (currently #error)
*/

# include <string.h> /* for memcpy */

/* we have two ways of keeping our stack in the xmm registers:
* use one of them as a stack pointer, or have a constant top of
* stack and always shift the registers.
Expand Down
1 change: 0 additions & 1 deletion core/arch/sideline.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
# include <sys/wait.h> /* for wait */
# include <linux/sched.h> /* for clone */
# include <signal.h> /* for SIGCHLD */
# include <string.h> /* for memset */
# include <unistd.h> /* for nice */
# define RUN_SIG
typedef pid_t thread_t;
Expand Down
1 change: 0 additions & 1 deletion core/arch/x86/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "decode.h"
#include "decode_fast.h"
#include "decode_private.h"
#include <string.h> /* for memcpy */

/*
* XXX i#431: consider cpuid features when deciding invalid instrs:
Expand Down
1 change: 0 additions & 1 deletion core/arch/x86/disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "decode.h"
#include "decode_private.h"
#include "disassemble.h"
#include <string.h>

#if defined(INTERNAL) || defined(DEBUG) || defined(CLIENT_INTERFACE)

Expand Down
2 changes: 0 additions & 2 deletions core/arch/x86/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#include "decode_fast.h"
#include "decode_private.h"

#include <string.h> /* memcpy, memset */

#ifdef DEBUG
/* case 10450: give messages to clients */
/* we can't undef ASSERT b/c of DYNAMO_OPTION */
Expand Down
2 changes: 0 additions & 2 deletions core/arch/x86/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
# include <sys/syscall.h>
#endif

#include <string.h> /* for memset */

#ifdef ANNOTATIONS
# include "../annotations.h"
#endif
Expand Down
1 change: 0 additions & 1 deletion core/arch/x86/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
# include "../fragment.h"
# include "disassemble.h"
# include "proc.h"
# include <string.h> /* for memset */

/* IMPORTANT INSTRUCTIONS FOR WRITING OPTIMIZATIONS:
*
Expand Down
1 change: 0 additions & 1 deletion core/arch/x86_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "../dispatch.h"
#include "../monitor.h"
#include "arch.h"
#include <string.h> /* for memcpy */

/* Helper routine for the x86.asm PUSH_DR_MCONTEXT, to fill in the xmm0-5 values
* (or all for linux) (or ymm) only if necessary.
Expand Down
8 changes: 3 additions & 5 deletions core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
# include "ntdll.h"
# endif

# include <string.h>

/* DYNAMORIO_VAR_CONFIGDIR is searched first, and then these: */
# ifdef UNIX
# define GLOBAL_CONFIG_DIR "/etc/dynamorio"
Expand Down Expand Up @@ -104,11 +102,11 @@ display_verbose_message(char *format, ...);
# endif
# undef STDERR
# define STDERR stderr
# undef our_snprintf
# undef d_r_snprintf
# ifdef WINDOWS
# define our_snprintf _snprintf
# define d_r_snprintf _snprintf
# else
# define our_snprintf snprintf
# define d_r_snprintf snprintf
# endif
# undef DECLARE_NEVERPROT_VAR
# define DECLARE_NEVERPROT_VAR(var, val) var = (val)
Expand Down
1 change: 0 additions & 1 deletion core/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include "perscache.h"
#include "native_exec.h"
#include "translate.h"
#include <string.h> /* for strstr */

#ifdef CLIENT_INTERFACE
# include "emit.h"
Expand Down
14 changes: 13 additions & 1 deletion core/drlibc/drlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

#ifdef MACOS
# include <sys/utsname.h> /* for struct utsname */
# include <string.h>
#endif

/***************************************************************************
Expand Down Expand Up @@ -72,6 +71,19 @@ ignore_assert(const char *assert_file_line, const char *expr)
return true;
}

WEAK int
d_r_strcmp(const char *left, const char *right)
{
size_t i;
for (i = 0; left[i] != '\0' || right[i] != '\0'; i++) {
if (left[i] < right[i])
return -1;
if (left[i] > right[i])
return 1;
}
return 0;
}

WEAK file_t main_logfile;
WEAK options_t dynamo_options;

Expand Down
1 change: 0 additions & 1 deletion core/drlibc/drlibc_module_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
#include "module_private.h"
#include "../utils.h"
#include "instrument.h"
#include <string.h>
#include <stddef.h> /* offsetof */
#include <link.h> /* Elf_Symndx */

Expand Down
1 change: 0 additions & 1 deletion core/drlibc/drlibc_module_macho.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <mach-o/fat.h>
#include <sys/syscall.h>
#include <stddef.h> /* offsetof */
#include <string.h> /* strcmp */
#include <dlfcn.h>

/* Like is_elf_so_header(), if size == 0 then safe-reads the header; else
Expand Down
2 changes: 0 additions & 2 deletions core/dynamo.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
# include "annotations.h"
#endif

#include <string.h>

#ifdef WINDOWS
/* for close handle, duplicate handle, free memory and constants associated with them
*/
Expand Down
1 change: 0 additions & 1 deletion core/emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "instr_create.h"
#include "monitor.h"
#include "translate.h"
#include <string.h> /* memcpy */

#ifdef DEBUG
# include "decode_fast.h" /* for decode_next_pc for stress_recreate_pc */
Expand Down
1 change: 0 additions & 1 deletion core/fcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#ifdef HOT_PATCHING_INTERFACE
# include "hotpatch.h"
#endif
#include <string.h> /* for memcpy */
#include <stddef.h> /* for offsetof */
#include <limits.h> /* for UCHAR_MAX */
#include "perscache.h"
Expand Down
1 change: 0 additions & 1 deletion core/fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "fcache.h"
#include "emit.h"
#include "monitor.h"
#include <string.h> /* for memset */
#include "instrument.h"
#include <stddef.h> /* for offsetof */
#include <limits.h> /* UINT_MAX */
Expand Down
Loading

0 comments on commit c8d5db2

Please sign in to comment.