This patch attempts to fix test patching-unpatching.cc . The new code flushes the instruction cache after modifying the program at runtime.
Details
- Reviewers
dberris rovka rengolin pelikan - Commits
- rG4ab7a30538f6: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rG4ee228bf7326: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rG93fb15788ae4: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rCRT291568: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rCRT290452: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rCRT290354: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rL291568: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rL290452: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
rL290354: [XRay][AArch64] An attempt to fix test patching-unpatching.cc by flushing the…
Diff Detail
Event Timeline
This broke the build. Did you manage to build this on AArch64? How did you test this?
@rSerge You forgot to add a forward declaration for __clear_cache to make it visible like e.g. trampoline_setup.c does.
I cross-compiled compiler-rt project from x86_64-Windows to AArch64-Linux and then tested on QEmu-AArch64-Linux . I thought that the built-in doesn't need any header file inclusion. Apparently for different host platforms the built-in behaves differently, perhaps that's due to compiler version. I'll look into this.
As discussed here , presence or absence of __clear_cache built-in depends on the compiler options. The built-in is common to gcc and clang, just currently in clang it is implemented via a called function in compiler-rt, but (another version of) gcc may inline it as an intrinsic. As discussed here , earlier there was a bug in gcc that gcc was expecting the parameters to be void*, in contradiction to the documentation which says they are char*, and clang developers implemented this bug too (so that parameters are void*), and I understood that clang developers were then fixing this bug.
However, in compiler-rt, file clear_cache.c the function is still defined as void __clear_cache(void *start, void *end) { ... }, and it seems used in file trampoline_setup.c via a forward declaration also as extern void __clear_cache(void* start, void* end);.
So it seems that the best I can do to let the code compile with different gcc and clang versions is to forward-declare the function as extern void __clear_cache(void* start, void* end); and keep the reinterpret_cast<char*> so that the code accepts both the function and the intrinsic (but this may lead to ambiguity for some compiler version and flags).
Still undefined symbol:
undefined reference to `__clear_cache(void*, void*)'
Reverted in r290453.
Next step, we'll test native first before commit.
Happy holidays!
I have been able to reproduce the problem when cross-compiling from x86_64-Linux to AArch64-Linux. Investigating now...
At a minimum, during x86_64-Linux to AArch64-Linux cross-compilation it didn't compile because of extern "C" missing. And the compiled program runs well on QEmu-AArch64-Linux .
@rengolin , what do you mean by "testing native" ? If that's compiling LLVM on AArch64 machine (i.e. without cross-compilation), then it would be challenging for me to do because on QEmu a LLVM build takes about a week, and the OS in the Arm32/AArch64 machines our team has is not exactly Linux.
Hi,
Looks like this slipped through the cracks, I'll do a native run for you today and let you know how it goes.
Thanks.