this repo has no description
1
fork

Configure Feed

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

compiler-rt build, working EH on i386

+118 -24
+6
src/CMakeLists.txt
··· 1 1 project(darling-src) 2 2 3 3 cmake_minimum_required(VERSION 2.4.0) 4 + cmake_policy(SET CMP0005 NEW) 5 + 4 6 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") 5 7 include(mig) 6 8 ··· 25 27 if (CMAKE_INSTALL_LIBDIR STREQUAL "lib32") 26 28 set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -m32") 27 29 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") 30 + # We need to add -mlong-double-128 to support long double properly. 31 + # With GCC, we could use -mlong-double-128, but Clang doesn't support that 28 32 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") 29 33 set(CMAKE_ASM_FLAGS "-m32") 30 34 SET(CMAKE_C_SIZEOF_DATA_PTR 4) ··· 35 39 endif (CMAKE_INSTALL_LIBDIR STREQUAL "lib64") 36 40 37 41 add_definitions(-D__APPLE__ -D__DYNAMIC__) 42 + 38 43 configure_file(darling-config.h.in darling-config.h) 39 44 include_directories("${CMAKE_CURRENT_BINARY_DIR}") 40 45 include_directories("${CMAKE_CURRENT_SOURCE_DIR}") ··· 99 104 add_subdirectory(xar) 100 105 add_subdirectory(libedit) 101 106 #add_subdirectory(launchd/src) 107 + add_subdirectory(external/compiler-rt/lib/builtins) 102 108 103 109 ###################### 104 110 # libc++ & libc++abi #
+12 -9
src/libdyld/MachOObject.cpp
··· 165 165 transitionState(dyld_image_state_bound); 166 166 transitionState(dyld_image_state_dependents_initialized); 167 167 168 - registerEHSection(); 168 + // registerEHSection(); 169 169 170 170 if (isMainModule()) 171 171 fillInProgramVars(); ··· 198 198 if (!MachOMgr::instance()->isDestroying()) 199 199 { 200 200 unloadSegments(); 201 - unregisterEHSection(); 201 + // unregisterEHSection(); 202 202 } 203 203 204 204 for (LoadableObject* dep : m_dependencies) ··· 606 606 if (vars != nullptr) 607 607 { 608 608 vars->mh = &m_header; 609 - *vars->NXArgcPtr = g_argc; 610 - *vars->NXArgvPtr = (const char**) g_argv; 611 - *vars->environPtr = (const char**) environ; 612 - *vars->__prognamePtr = g_argv[0]; 609 + vars->NXArgcPtr = &g_argc; 610 + vars->NXArgvPtr = (const char***) &g_argv; 611 + vars->environPtr = (const char***) &environ; 612 + vars->__prognamePtr = (const char**) &g_argv[0]; 613 613 } 614 614 else 615 615 { ··· 668 668 } 669 669 670 670 // These are libgcc functions 671 - extern "C" void __register_frame(void*); 672 - extern "C" void __deregister_frame(void*); 671 + extern "C" void __register_frame(void*) __attribute__((weak)); 672 + extern "C" void __deregister_frame(void*) __attribute__((weak)); 673 673 674 674 void MachOObject::registerEHSection() 675 675 { 676 + if (!__register_frame) 677 + return; 678 + 676 679 auto eh_frame = m_file->get_eh_frame(); 677 680 if (!eh_frame.first) 678 681 return; ··· 773 776 if (bind->type == BIND_TYPE_POINTER || bind->type == BIND_TYPE_STUB) 774 777 { 775 778 void* addr = nullptr; 776 - 779 + 777 780 if (bind->is_classic && bind->is_local) 778 781 addr = (void*) bind->value; 779 782 else
+4
src/libdyld/dyld_priv.cpp
··· 6 6 #include "LoadableObject.h" 7 7 #include "MachOMgr.h" 8 8 #include "MachOObject.h" 9 + #include "dyld_public.h" 9 10 10 11 static std::map<dyld_image_state_change_handler, dyld_image_states> m_handlers; 11 12 ··· 83 84 throw std::runtime_error(error); 84 85 } 85 86 } 87 + 88 + if (state == dyld_image_state_terminated) 89 + _dyld_free_eh_data(obj); 86 90 } 87 91
+89 -10
src/libdyld/dyld_public.cpp
··· 31 31 #include <sys/mman.h> 32 32 #include "../util/log.h" 33 33 #include "../util/leb.h" 34 + #include "eh/EHSection.h" 35 + #include "NativeObject.h" 34 36 35 37 using namespace Darling; 38 + 39 + struct eh_data 40 + { 41 + void* data; 42 + uintptr_t length; 43 + }; 44 + 45 + static std::map<std::string, eh_data> m_ehData; 36 46 37 47 uint32_t _dyld_image_count(void) 38 48 { ··· 321 331 static int dlCallback(struct dl_phdr_info *info, size_t size, void *data) 322 332 { 323 333 CBData* cbdata = static_cast<CBData*>(data); 334 + const ElfW(Ehdr)* hdr = nullptr; 324 335 bool addrMatch = false; 325 - void* maxAddr = 0; 326 - const eh_frame_hdr* ehdr = 0; 336 + void* maxAddr = nullptr; 337 + void* ehData = nullptr; 338 + uintptr_t length = 0; 327 339 328 340 if (cbdata->info->dwarf_section) // we already have a match 329 341 return 0; ··· 346 358 addrMatch = true; 347 359 if (to > maxAddr) 348 360 maxAddr = to; // TODO: could this be improved? libunwind does the same 361 + 362 + if (!hdr) 363 + hdr = static_cast<ElfW(Ehdr)*>(from); 349 364 } 350 365 else if (phdr->p_type == PT_GNU_EH_FRAME) 351 366 { 367 + const eh_frame_hdr* ehdr; 368 + //const ElfW(Shdr)* shdr; 369 + 352 370 //std::cout << "Found .eh_frame_hdr in " << info->dlpi_name << std::endl; 353 371 ehdr = reinterpret_cast<eh_frame_hdr*>(uintptr_t(info->dlpi_addr) + phdr->p_vaddr); 354 - // cbdata->info->dwarf_section_length = phdr->p_memsz; 372 + 373 + if (ehdr->version != 1) 374 + return 0; 375 + 376 + ehData = reinterpret_cast<void*>(readEncodedPointer(ehdr)); 377 + 378 + //shdr = reinterpret_cast<ElfW(Shdr)*>(uintptr_t(hdr) + uintptr_t(hdr->e_shoff)); 379 + 380 + //for (int j = 0; j < hdr->e_shnum; j++) 381 + //{ 382 + // if (shdr->sh_addr == uintptr_t(ehData) - uintptr_t(info->dlpi_addr)) 383 + // { 384 + // length = shdr->sh_size; 385 + // break; 386 + // } 387 + // shdr++; 388 + //} 355 389 } 356 390 } 357 391 358 - if (addrMatch && ehdr) 392 + if (addrMatch && ehData) 359 393 { 394 + length = uintptr_t(maxAddr) - uintptr_t(ehData); 395 + #ifndef __i386 396 + cbdata->info->dwarf_section = ehData; 397 + cbdata->info->dwarf_section_length = length; 398 + #else 360 399 //std::cout << "*** Match found! " << info->dlpi_name << std::endl; 361 - 362 - // Now we find .eh_frame from .eh_frame_hdr 363 - if (ehdr->version != 1) 364 - return 0; 365 - cbdata->info->dwarf_section = reinterpret_cast<void*>(readEncodedPointer(ehdr)); 366 - cbdata->info->dwarf_section_length = uintptr_t(maxAddr) - uintptr_t(cbdata->info->dwarf_section); 400 + auto it = m_ehData.find(info->dlpi_name); 401 + 402 + cbdata->info->mh = (struct mach_header*) info->dlpi_addr; 403 + 404 + if (it != m_ehData.end()) 405 + { 406 + cbdata->info->dwarf_section = it->second.data; 407 + cbdata->info->dwarf_section_length = it->second.length; 408 + } 409 + else 410 + { 411 + EHSection eh; 412 + eh_data ehd; 413 + 414 + static const std::map<int, int> regSwap = { 415 + std::make_pair<int, int>(4, 5), 416 + std::make_pair<int, int>(5, 4) 417 + }; 418 + 419 + eh.load(ehData, length); 420 + eh.swapRegisterNumbers(regSwap); 421 + eh.store(&ehd.data, &ehd.length); 422 + 423 + m_ehData[info->dlpi_name] = ehd; 424 + 425 + cbdata->info->dwarf_section = ehd.data; 426 + cbdata->info->dwarf_section_length = ehd.length; 427 + } 428 + #endif 367 429 } 368 430 369 431 return 0; 432 + } 433 + 434 + void _dyld_free_eh_data(LoadableObject* obj) 435 + { 436 + #ifdef __i386__ 437 + NativeObject* no = dynamic_cast<NativeObject*>(obj); 438 + 439 + if (!no) 440 + return; 441 + 442 + auto it = m_ehData.find(no->path()); 443 + if (it != m_ehData.end()) 444 + { 445 + EHSection::free(it->second.data); 446 + m_ehData.erase(it); 447 + } 448 + #endif 370 449 } 371 450 372 451 bool _dyld_find_unwind_sections(void* addr, struct dyld_unwind_sections* info)
+3
src/libdyld/dyld_public.h
··· 23 23 #include "MachOMgr.h" 24 24 25 25 namespace Darling { 26 + class LoadableObject; 26 27 class MachOObject; 27 28 } 28 29 ··· 74 75 #ifdef __cplusplus 75 76 } 76 77 #endif 78 + 79 + void _dyld_free_eh_data(Darling::LoadableObject* obj); 77 80 78 81 #endif
+1 -1
src/libdyld/eh/EHSection.cpp
··· 70 70 71 71 if (length == 0xffffffff) 72 72 length = reader.read64(); 73 - else if (!length) 73 + else if (!length || length+m_originalStart > m_originalEnd) 74 74 break; // terminating entry 75 75 76 76 endPos = reader.pos() + length;
+1 -2
src/libgcc/CMakeLists.txt
··· 18 18 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 19 19 20 20 add_library(gcc_s SHARED ${libgcc_sources}) 21 - target_link_libraries(gcc_s unwind) 22 - # TODO: link against libcompiler_rt 21 + target_link_libraries(gcc_s compiler_rt) 23 22 24 23 install(TARGETS gcc_s DESTINATION lib${SUFFIX}/darling)
+2 -2
src/libunwind/CMakeLists.txt
··· 7 7 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") 8 8 set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "") 9 9 10 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc -nostdinc++") 11 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -nostdinc") 10 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc -nostdinc++ -ggdb -O0") 11 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2 -msse3 -w -nostdinc -funwind-tables -ggdb -O0") 12 12 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__DARWIN_UNIX03 -fPIC -w") 13 13 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,--version-script=${DARLING_TOP_DIRECTORY}/darwin.map") 14 14