Skip to content

Commit

Permalink
i#58 MacOS: misc build fixes
Browse files Browse the repository at this point in the history
+ Only pass --hash-style for Linux, not Mac.
+ 32-bit build misc fixes.
+ dr_app_handle_mbr_target() is Linux-only.
+ Support building drwrap on MacOS: support nasm via GLOBAL_REF
  for all symbol references.

SVN-Revision: 2397
  • Loading branch information
derekbruening committed Nov 25, 2013
1 parent 02fdd65 commit 922915f
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
22 changes: 12 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,19 @@ if (UNIX)
set(OPT "${OPT} -fno-omit-frame-pointer")
endif ()

# Generate the .hash section in addition to .gnu.hash for every target, to
# avoid SIGFPE when running our binaries on old systems:
foreach (config ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config_upper)
foreach (var
CMAKE_EXE_LINKER_FLAGS_${config_upper};
CMAKE_MODULE_LINKER_FLAGS_${config_upper};
CMAKE_SHARED_LINKER_FLAGS_${config_upper})
set(${var} "-Wl,--hash-style=both")
if (NOT APPLE)
# Generate the .hash section in addition to .gnu.hash for every target, to
# avoid SIGFPE when running our binaries on old systems:
foreach (config ${CMAKE_BUILD_TYPE} ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config_upper)
foreach (var
CMAKE_EXE_LINKER_FLAGS_${config_upper};
CMAKE_MODULE_LINKER_FLAGS_${config_upper};
CMAKE_SHARED_LINKER_FLAGS_${config_upper})
set(${var} "-Wl,--hash-style=both")
endforeach ()
endforeach ()
endforeach ()
endif ()

# XXX: core-specific: move to core/CMakeLists.txt?
#
Expand Down
4 changes: 2 additions & 2 deletions core/lib/dr_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ DR_APP_API int dr_app_setup_and_start(void);
DR_APP_API bool
dr_app_running_under_dynamorio(void);

#ifdef UNIX
#ifdef LINUX
/**
* DynamoRIO's (experimental) native execution mode supports running
* some modules natively while the others run under DynamoRIO.
Expand All @@ -133,6 +133,6 @@ dr_app_running_under_dynamorio(void);
*/
DR_APP_API void *
dr_app_handle_mbr_target(void *target);
#endif /* UNIX */
#endif /* LINUX */

#endif /* _DR_APP_H_ */
2 changes: 1 addition & 1 deletion core/native_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ is_dr_native_pc(app_pc pc)
{
#ifdef DR_APP_EXPORTS
if (pc == (app_pc) dr_app_running_under_dynamorio
IF_UNIX(|| pc == (app_pc) dr_app_handle_mbr_target))
IF_LINUX(|| pc == (app_pc) dr_app_handle_mbr_target))
return true;
#endif /* DR_APP_EXPORTS */
return false;
Expand Down
14 changes: 9 additions & 5 deletions core/unix/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ static os_privmod_data_t *libdr_opd;
static bool privmod_initialized = false;
static size_t max_client_tls_size = 2 * PAGE_SIZE;

#if defined(INTERNAL) || defined(CLIENT_INTERFACE)
#ifdef LINUX /* XXX i#1285: implement MacOS private loader */
# if defined(INTERNAL) || defined(CLIENT_INTERFACE)
static bool printed_gdb_commands = false;
/* Global so visible in release build gdb */
static char gdb_priv_cmds[4096];
static size_t gdb_priv_cmds_sofar;
# endif
#endif

/* pointing to the I/O data structure in privately loaded libc,
Expand Down Expand Up @@ -170,7 +172,8 @@ os_loader_init_prologue(void)
void
os_loader_init_epilogue(void)
{
#if defined(INTERNAL) || defined(CLIENT_INTERFACE)
#ifdef LINUX /* XXX i#1285: implement MacOS private loader */
# if defined(INTERNAL) || defined(CLIENT_INTERFACE)
/* Print the add-symbol-file commands so they can be copy-pasted into gdb.
* We have to do it in a single syslog so they can be copy pasted.
* For non-internal builds, or for private libs loaded after this point,
Expand All @@ -185,11 +188,12 @@ os_loader_init_epilogue(void)
"set confirm off\n"
"%s", gdb_priv_cmds);
}
#endif /* INTERNAL || CLIENT_INTERFACE */
# endif /* INTERNAL || CLIENT_INTERFACE */
#endif
}

#ifdef LINUX /* XXX i#1285: implement MacOS private loader */
# if defined(INTERNAL) || defined(CLIENT_INTERFACE)
# if defined(INTERNAL) || defined(CLIENT_INTERFACE)
static void
privload_add_gdb_cmd(const char *modpath, app_pc text_addr)
{
Expand All @@ -198,7 +202,7 @@ privload_add_gdb_cmd(const char *modpath, app_pc text_addr)
&gdb_priv_cmds_sofar, "add-symbol-file '%s' %p\n",
modpath, text_addr);
}
# endif
# endif
#endif

void
Expand Down
3 changes: 2 additions & 1 deletion core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,8 @@ get_num_processors(void)
* which should be lower-level than sysctlbyname(), and replace
* that w/ its straightforward raw syscall underneath later.
*/
int res = sysctlbyname("hw.ncpu", NULL, NULL, &num_cpu, sizeof(num_cpu));
DEBUG_DECLARE(int res = )
sysctlbyname("hw.ncpu", NULL, NULL, &num_cpu, sizeof(num_cpu));
ASSERT(res == 0);
#else
/* We used to use get_nprocs_conf, but that's in libc, so now we just
Expand Down
6 changes: 4 additions & 2 deletions core/unix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,9 @@ thread_set_self_context(void *cxt)
* full machine state", so we need to get the rest of the state,
*/
sigframe_rt_t frame;
#if defined(LINUX) || defined(DEBUG)
sigcontext_t *sc = (sigcontext_t *) cxt;
#endif
app_pc xsp_for_sigreturn;
#ifdef VMX86_SERVER
ASSERT_NOT_IMPLEMENTED(false); /* PR 405694: can't use regular sigreturn! */
Expand Down Expand Up @@ -2152,7 +2154,7 @@ copy_frame_to_stack(dcontext_t *dcontext, int sig, sigframe_rt_t *frame, byte *s
thread_sig_info_t *info = (thread_sig_info_t *) dcontext->signal_field;
bool rtframe = IS_RT_FOR_APP(info, sig);
uint frame_size = get_app_frame_size(info, sig);
#ifndef X64
#if defined(LINUX) && !defined(X64)
bool has_restorer = sig_has_restorer(info, sig);
#endif
byte *check_pc;
Expand Down Expand Up @@ -4677,7 +4679,7 @@ os_forge_exception(app_pc target_pc, dr_exception_type_t type)
* I'm going with #1 for now b/c the common case is simpler.
*/
dcontext_t *dcontext = get_thread_private_dcontext();
#if !defined(X64) || defined(LINUX)
#ifdef LINUX
thread_sig_info_t *info = (thread_sig_info_t *) dcontext->signal_field;
#endif
char frame_plus_xstate[sizeof(sigframe_rt_t) + AVX_FRAME_EXTRA];
Expand Down
6 changes: 5 additions & 1 deletion ext/drwrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ include_directories(${DynamoRIO_DIR})

# we aren't using DR's configure.h so we have to set defines:
if (UNIX)
set(asm_defs ${asm_defs} -DASSEMBLE_WITH_GAS)
if (APPLE)
set(asm_defs ${asm_defs} -DASSEMBLE_WITH_NASM)
else (APPLE)
set(asm_defs ${asm_defs} -DASSEMBLE_WITH_GAS)
endif (APPLE)
else (UNIX)
set(asm_defs ${asm_defs} -DASSEMBLE_WITH_MASM)
endif (UNIX)
Expand Down
11 changes: 5 additions & 6 deletions ext/drwrap/drwrap_asm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ GLOBAL_LABEL(FUNCNAME:)
*/
push REG_XAX
push REG_XDX
CALLC0(replace_native_xfer_stack_adjust)
CALLC0(GLOBAL_REF(replace_native_xfer_stack_adjust))
mov ecx, eax
pop REG_XDX
pop REG_XAX
Expand All @@ -86,11 +86,11 @@ GLOBAL_LABEL(FUNCNAME:)
/* put app retaddr into the slot we made above the 2 pushes */
push REG_XAX
push REG_XDX
CALLC0(replace_native_xfer_app_retaddr)
CALLC0(GLOBAL_REF(replace_native_xfer_app_retaddr))
mov PTRSZ [2 * ARG_SZ + REG_XSP], REG_XAX

/* now get our target */
CALLC0(replace_native_xfer_target)
CALLC0(GLOBAL_REF(replace_native_xfer_target))
mov REG_XCX, REG_XAX
pop REG_XDX
pop REG_XAX
Expand All @@ -113,6 +113,8 @@ GLOBAL_LABEL(FUNCNAME:)
* from this series. We only support pointer-aligned. We do support
* for x64 although it's quite rare to need it there.
*/
DECLARE_GLOBAL(replace_native_ret_imms)
DECLARE_GLOBAL(replace_native_ret_imms_end)
#define FUNCNAME replace_native_rets
DECLARE_FUNC(FUNCNAME)
GLOBAL_LABEL(FUNCNAME:)
Expand Down Expand Up @@ -162,8 +164,5 @@ ADDRTAKEN_LABEL(replace_native_ret_imms_end:)
nop
END_FUNC(FUNCNAME)

DECLARE_GLOBAL(replace_native_ret_imms)
DECLARE_GLOBAL(replace_native_ret_imms_end)


END_FILE
8 changes: 5 additions & 3 deletions make/DynamoRIOConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,11 @@ function (configure_DynamoRIO_common target is_client x64_var defs_var)
set(tgt_cflags "${tgt_cflags} -mpreferred-stack-boundary=2")
endif (NOT tgt_x64)

# Generate the .hash section in addition to .gnu.hash for every target, to
# avoid SIGFPE when running binaries on old systems:
set(tgt_link_flags "${tgt_link_flags} -Wl,--hash-style=both")
if (NOT APPLE)
# Generate the .hash section in addition to .gnu.hash for every target, to
# avoid SIGFPE when running binaries on old systems:
set(tgt_link_flags "${tgt_link_flags} -Wl,--hash-style=both")
endif (NOT APPLE)

# gcc is invoked for the link step so we have to repeat cflags as well
set(tgt_link_flags "${tgt_cflags} ${tgt_link_flags}")
Expand Down

0 comments on commit 922915f

Please sign in to comment.