this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Doing symbol aliases in a programatic way to avoid PIC hassle

+86 -4
+4 -4
src/libSystem/CMakeLists.txt
··· 12 12 endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang") 13 13 14 14 configure_file(config.h.in config.h) 15 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fblocks -std=c++0x") 15 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fblocks -std=c++11") 16 16 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fblocks -D_GNU_SOURCE") 17 17 18 18 #find_path(LIBCXX_INCLUDE_DIR c++/v1/vector) ··· 33 33 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../include/xnu/mach) 34 34 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../include/xnu/bsd) 35 35 36 - ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/directmap.nasm" 37 - COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../../genfuncmap" ARGS "${CMAKE_CURRENT_SOURCE_DIR}/libc/directmap.lst" "${CMAKE_CURRENT_BINARY_DIR}/directmap.nasm") 36 + #ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/directmap.nasm" 37 + # COMMAND "${CMAKE_CURRENT_BINARY_DIR}/../../genfuncmap" ARGS "${CMAKE_CURRENT_SOURCE_DIR}/libc/directmap.lst" "${CMAKE_CURRENT_BINARY_DIR}/directmap.nasm") 38 38 39 39 40 40 set(libc_SRCS ··· 47 47 libc/errno.cpp 48 48 libc/OSAtomic.cpp 49 49 libc/strmode.c 50 - ${CMAKE_CURRENT_BINARY_DIR}/directmap.nasm 51 50 libc/sysctl.cpp 52 51 libc/dir.cpp 53 52 libc/string.cpp ··· 70 69 libc/spawn.cpp 71 70 libc/xlocale.cpp 72 71 libc/malloc_zone.cpp 72 + libc/namemap.cpp 73 73 common/auto.cpp 74 74 common/path.cpp 75 75 )
+3
src/libSystem/libc/directmap.lst src/libSystem/libc/namemap.lst
··· 1 + R"( 2 + 1 3 __error;__errno_location 2 4 3 5 # libstdc++ ··· 50 52 libintl_bind_textdomain_codeset;bind_textdomain_codeset 51 53 libintl_setlocale;setlocale 52 54 55 + )" 53 56
+79
src/libSystem/libc/namemap.cpp
··· 1 + #include <cstring> 2 + #include <map> 3 + #include <string> 4 + #include <sstream> 5 + #include <iostream> 6 + #include "../util/stlutils.h" 7 + 8 + namespace Darling 9 + { 10 + typedef bool (*DlsymHookFunc)(char* symName); 11 + void registerDlsymHook(DlsymHookFunc func); 12 + void deregisterDlsymHook(DlsymHookFunc func); 13 + }; 14 + 15 + static const char* g_directmap = 16 + #include "namemap.lst" 17 + ; 18 + 19 + static std::map<std::string,std::string> g_nameMap; 20 + 21 + static bool NameTranslator(char* symName); 22 + 23 + __attribute__((constructor)) 24 + static void initTranslation() 25 + { 26 + std::istringstream istr(g_directmap); 27 + std::string line; 28 + 29 + while (std::getline(istr, line)) 30 + { 31 + if (line.empty() || line[0] == '#') 32 + continue; 33 + 34 + std::vector<std::string> segs = string_explode(line, ';'); 35 + if (segs.size() < 2) 36 + continue; 37 + 38 + if (segs[0].compare(0, 3, "32!") == 0) 39 + { 40 + #ifdef __x86_64__ 41 + continue; 42 + #else 43 + segs[0] = segs[0].substr(3); 44 + #endif 45 + } 46 + 47 + if (segs[0].compare(0, 3, "64!") == 0) 48 + { 49 + #ifdef __i386__ 50 + continue; 51 + #else 52 + segs[0] = segs[0].substr(3); 53 + #endif 54 + } 55 + 56 + // std::cout << segs[0] << " -> " << segs[1] << std::endl; 57 + g_nameMap[segs[0]] = segs[1]; 58 + } 59 + 60 + Darling::registerDlsymHook(NameTranslator); 61 + } 62 + 63 + __attribute__((destructor)) 64 + static void exitTranslation() 65 + { 66 + Darling::deregisterDlsymHook(NameTranslator); 67 + } 68 + 69 + bool NameTranslator(char* symName) 70 + { 71 + auto it = g_nameMap.find(symName); 72 + if (it != g_nameMap.end()) 73 + { 74 + strcpy(symName, it->second.c_str()); 75 + return true; 76 + } 77 + return false; 78 + } 79 +