mach_override icon indicating copy to clipboard operation
mach_override copied to clipboard

allocateBranchIsland is slow

Open rentzsch opened this issue 12 years ago • 5 comments

See https://github.com/rentzsch/mach_star/pull/38 for an attempt to address this.

Alexander Potapenko has enhancements that's part of llvm's AddressSanitizer, but unfortunately the link he gave me is now broken.

rentzsch avatar Aug 10 '12 18:08 rentzsch

Citing my own letter:

Next, allocateBranchIsland() is very slow on 64 bits -- mainly because of the necessity to scan the memory page by page with vm_allocate(). Some information about that is at http://code.google.com/p/address-sanitizer/issues/detail?id=24, basically our tests made 3M calls to vm_allocate in order to override 26 functions. In order to fix that, we need to: -- search for empty memory in a more efficient way (e.g. look for holes in the process address space) -- map several pages with a single mmap/vm_allocate call, so that further mach_override_ptr() invocations can avoid searching and mapping memory. Because AddressSanitizer adds some limitations on the placement of the mappings, I chose to externalize the branch island allocator to let ASan decide where to place the islands. (see http://llvm.org/viewvc/llvm-project?view=rev&revision=148115) I'm a bit dissatisfied with the resulting code, mainly because of casts between BranchIsland* and void_. To cope with that it's better to pass the islands as void_ everywhere and modify allocateBranchIsland so that it keeps track of additional flags itself (it may still store them in the same location)

The LLVM version of mach_override resides at http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/mach_override/ I'll try to find some time and prepare a patch.

ramosian-glider avatar Aug 17 '12 09:08 ramosian-glider

@ramosian-glider thanks for the link, I'll take a look

rentzsch avatar Aug 18 '12 01:08 rentzsch

The link above is dead, but I assume this one is the same: https://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/?diff_format=l&sortby=log&pathrev=146166

I had to use the linked version to successfully override functions (in my case: CGLFlushDrawable) on 10.8 using 32bit clang, the mach_override in the stable branch didn't work for me. I think it should be merged into this project, at least in the unstable branch, it took me quite a while to find that patch.

Fl0ri4n avatar Jul 19 '13 08:07 Fl0ri4n

@Fl0ri4n unfortunately I'm too busy with other projects to look into this. How does the stable branch not work for you? Crash? Just doesn't override?

rentzsch avatar Jul 20 '13 18:07 rentzsch

It just didn't override. I didn't debug it in more detail because I was overriding a function in a foreign precess using mach_inject. The last working compile using the stable branch was on 10.7 using gcc 4.2 (not LLVM), but I‘ve got neither of them installed at the moment, so I can't test if a 32bit gcc-compile using the stable branch would work on Mountain Lion.

Fl0ri4n avatar Jul 22 '13 11:07 Fl0ri4n