RFR: 8282475: SafeFetch should not rely on existence of Thread::current [v7]
Florian Weimer
fweimer at openjdk.java.net
Sat Mar 12 07:48:41 UTC 2022
On Fri, 11 Mar 2022 23:40:36 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> I spent some time doing a static implementation of SafeFetch on Linux x64, and its not super trivial. The problem is that we need to know addresses of instructions inside that function. I can set labels in assembly, and I can export them, but so far I have been unable to use them as addresses in C++ code. I will research some more.
There are basically two ways (easy) to do it. Put global symbols like
.globl address_of_label
address_of_label:
into the assembler sources and use
```c++
extern char address_of_label[] __attribute__ ((visibility ("hidden")));
from the C++ side.
Or use a local label, and export the difference to the function start to a local label in a global data symbol from the assembler side:
.globl SafeFetch // Real function name goes here.
SafeFetch:
// …
.Llabel:
// …
.section .rodata
.globl SafeFetch_label_offset
.p2align 3
SafeFetch_label_offset:
.quad .Llabel - SafeFetch
.type SafeFetch_label_offset, @object
.size SafeFetch_label_offset, 8
And use
```c++
extern uintptr_t SafeFetch_label_offset __attribute__ ((__visibility ("hidden")));
and the expression `(uintptr_t) &SafeFetch + SafeFetch_label_offset` to compute the final address. The second approach is friendlier to tools (which may get confused by symbols in the middle of functions).
If you have a PR, please Cc: me on it, I will have a look.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7727
More information about the serviceability-dev
mailing list