-
Notifications
You must be signed in to change notification settings - Fork 178
Support for Symbolizing Thread-Local Data in .tbss? #246
Comments
Hello @scottconstable ! |
Hi @yota9 ! So suppose I have a program like this:
Ideally I would like to be able to compile a |
The second approach is easier since you've already have the symbol and reserved space, it's true. After a few changes in discoverFileObjects you will be able to get your symbol by name in your pass and insert target-specific code to each BB to access tls variable and increment it. There is no ready functionality to do it but it doesn't sound like very difficult task.. |
@yota9 your analysis above was perfect. I added just 2 LoC into
Now my pass can see the TLS symbols in the
Here is my pass code: auto &MIB = *BC.MIB;
auto *BasicBlockCounterSymbol = BC.Ctx->lookupSymbol("__basic_blocks");
assert(BasicBlockCounterSymbol && "Could not find symbol");
MCInst IncInst;
MIB.createIncMemory(IncInst, BasicBlockCounterSymbol, BC.Ctx.get());
for (auto &It : BC.getBinaryFunctions()) {
BinaryFunction &Function = It.second;
for (BinaryBasicBlock &BB : Function) {
BB.insertInstruction(BB.begin(), IncInst);
}
} Do you have any suggestions? |
@scottconstable This is what I was talking about, that you will need to create your target-specific code. The createIncMemory doesn't know that this is the TLS symbol. I'm not sure about x86, I assume it is similar to ARM - you need access thread-register, knowing the data structure stored in it you will be able to access data knowing the offset (address) of TLS variable. Since it won't change you can use getAddress() as offset. But the createIncMemory doesn't access thread register & etc, it just increments the value in the memory, which is not right in this case. You will need to create your own smth like createIncTlsMemory to do it. |
Thanks @yota9. I am now able to get the TLS offset in my pass by doing the following:
I then use LLVM's existing MC infrastructure to build instructions with TLS-relative memory operands. I have one more question. Sometimes the |
|
I'm trying to write a pass that inserts some instrumentation code, and which will store statistics in TLS (for example, .tbss). But I cannot figure out how to find
MCSymbol
s for thread-local data. When I write:I see all of the symbols in .data and .bss, but I can't see any data that a given binary exposes in .tbss. I also do not see any members or methods on
BinaryContext
that reference TLS.Is this supported? If not, are there plans to support it? Is there a workaround?
The text was updated successfully, but these errors were encountered: