Skip to content

Commit

Permalink
i#58 MacOS: DR library bounds.
Browse files Browse the repository at this point in the history
We don't have a linker script for linker-supplied start and end
bounds, but we do have the _mh_dylib_header variable that points at
the Mach-O header of our library.

SVN-Revision: 2323
  • Loading branch information
derekbruening committed Oct 8, 2013
1 parent 530c996 commit eff51a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/unix/module.h
Expand Up @@ -153,4 +153,11 @@ typedef bool (*unmap_fn_t)(byte *map, size_t size);
typedef bool (*prot_fn_t)(byte *map, size_t size, uint prot/*MEMPROT_*/);


#ifdef MACOS
/* module_macho.c */
byte *
module_dynamorio_lib_base(void);
#endif


#endif /* MODULE_H */
6 changes: 6 additions & 0 deletions core/unix/module_macho.c
Expand Up @@ -41,6 +41,7 @@
#include "../module_shared.h"
#include "os_private.h"
#include "module_private.h"
#include <mach-o/ldsyms.h> /* _mh_dylib_header */

bool
module_file_has_module_header(const char *filename)
Expand Down Expand Up @@ -183,3 +184,8 @@ module_get_text_section(app_pc file_map, size_t file_size)
return 0;
}

byte *
module_dynamorio_lib_base(void)
{
return (byte *) &_mh_dylib_header;
}
9 changes: 8 additions & 1 deletion core/unix/os.c
Expand Up @@ -6394,13 +6394,17 @@ get_dynamo_library_bounds(void)
dynamorio_libname = NULL;
check_start = (app_pc)&get_dynamo_library_bounds;
#else /* !STATIC_LIBRARY */
# ifdef LINUX
/* PR 361594: we get our bounds from linker-provided symbols.
* Note that referencing the value of these symbols will crash:
* always use the address only.
*/
extern int dynamorio_so_start, dynamorio_so_end;
dynamo_dll_start = (app_pc) &dynamorio_so_start;
dynamo_dll_end = (app_pc) ALIGN_FORWARD(&dynamorio_so_end, PAGE_SIZE);
# elif defined(MACOS)
dynamo_dll_start = module_dynamorio_lib_base();
# endif
check_start = dynamo_dll_start;
dynamorio_libname = IF_UNIT_TEST_ELSE(UNIT_TEST_EXE_NAME,DYNAMORIO_LIBRARY_NAME);
#endif /* STATIC_LIBRARY */
Expand All @@ -6410,8 +6414,11 @@ get_dynamo_library_bounds(void)
BUFFER_SIZE_ELEMENTS(dynamorio_library_path));
LOG(GLOBAL, LOG_VMAREAS, 1, PRODUCT_NAME" library path: %s\n",
dynamorio_library_path);
#ifndef STATIC_LIBRARY
#if !defined(STATIC_LIBRARY) && defined(LINUX)
ASSERT(check_start == dynamo_dll_start && check_end == dynamo_dll_end);
#elif defined(MACOS)
ASSERT(check_start == dynamo_dll_start);
dynamo_dll_end = check_end;
#else
dynamo_dll_start = check_start;
dynamo_dll_end = check_end;
Expand Down

0 comments on commit eff51a8

Please sign in to comment.