Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OMPT-annotations #45

Open
jprotze opened this issue Jul 21, 2017 · 16 comments
Open

OMPT-annotations #45

jprotze opened this issue Jul 21, 2017 · 16 comments

Comments

@jprotze
Copy link
Contributor

jprotze commented Jul 21, 2017

Can we detect in the initialization of the OMPT-tool, whether the application is built with TSan or not?
If that would be possible, we could avoid to register the callbacks and remove the potential overhead. This would be a good step for pushing Archer upstream in the long run.

@dongahn
Copy link
Contributor

dongahn commented Jul 21, 2017

Interesting. One way is to check if the TSan runtime is linked in.

@jprotze
Copy link
Contributor Author

jprotze commented Jul 21, 2017

With clang, the tsan runtime is linked statically. So, I don't know how this might work at runtime.

@simoatze
Copy link
Member

The problem is that we could have a program that only has some parts/sources/modules/libraries built with the instrumentation, and some that are not.
So we could check if the program is running with the TSan runtime for example using dlsym("__tsan_read8") or some other well-known exported function.
We could probably iterate over loaded modules and look for "libclang_rt.tsan...".

With tsan we could even have the Tsan runtime running and zero instrumented files and Tsan would still catch problems using the interceptors, but I guess that's not the case for OpenMP programs so one of the previous solution should work.

@jprotze
Copy link
Contributor Author

jprotze commented Jul 21, 2017

dlsym only works if the application is built with -rdynamic (see the earlier mail to Alex).

@simoatze
Copy link
Member

Even if you are looking for symbols from other libraries? I thought it was just a problem with the OMPT symbols

@dongahn
Copy link
Contributor

dongahn commented Jul 21, 2017

You can use nm or BFD library type (https://en.wikipedia.org/wiki/Binary_File_Descriptor_library) on the executable to check the presence of a well-know symbol. But this would be too heavyweight for this purpose...

A better solution would be for TSan itself leave a mark to program header somewhere for the programming model add-on like ours to check. I think PT_NOTE section seems promising.

https://linux.die.net/man/5/elf

One could prototype this in clang or direct ask Sanitizer folks whether they already have something like this?

@simoatze
Copy link
Member

@dongahn why nm or BFD would be heavyweight? It's just a one time check at the OMPT initialization, it shouldn't add that much overhead. I don't think TSan leave any mark in the program header, but I could ask.

@dongahn
Copy link
Contributor

dongahn commented Jul 21, 2017

True. But I'm just concerned about having to deal with a large executable. Instead if this is encoded in the program header of the main executable, perhaps we can write a code to only get to the small memory segment...

@jprotze
Copy link
Contributor Author

jprotze commented Jul 21, 2017

The TSan annotation interface has a RunningOnValgrind function. I couldn't find documentation on the semantics of the function. But I think, a similar function RunningOnTSan that returns true would be helpful. By implementing this function weak in the tool returning false, it would be easy to decide whether TSan is there or not.

@dongahn
Copy link
Contributor

dongahn commented Jul 21, 2017

@jprotze: yes this would be another good - even a more reliable way to check the presence of TSan.

@simoatze
Copy link
Member

we can create such Annotation if missing and if it works we can try to propose it to the LLVM folks

@jprotze
Copy link
Contributor Author

jprotze commented Feb 18, 2018

I think, I found a side-effect solution for this:

we use a weak implementation of RunningOnValgrind, that changes a static variable in our tool. If TSan is there, the provided RunningOnValgrind function would not change this variable.

@simoatze
Copy link
Member

@jprotze yes that would totally work.
I am currently doing some bug fixing and changing the Instrumentation pass to work with Clang/LLVM 6.0.
We can add it in the next release , if you have time we can work on it together.

@simoatze
Copy link
Member

@jprotze I tried RunningOnValgrind and it does not get called by Tsan.
Take a look to this thread for a possible way to find out if the program is running tsan https://groups.google.com/forum/#!searchin/thread-sanitizer/compiled$20with$20tsan%7Csort:date/thread-sanitizer/xUi2rFUltM0/eW3PdjhYBQAJ

@jprotze
Copy link
Contributor Author

jprotze commented Apr 10, 2018

@simoatze I just pushed my idea of the workflow to the RunningOnValgrind branch.
I think, that the APPLE variants of the annotation functions should somehow detect and avoid endless recursion (by calling the function itself) in the case, that there are no annotation functions in the application.

@simoatze
Copy link
Member

simoatze commented Apr 10, 2018

@jprotze Looks good. Maybe add return 0; at the end of runOnValgrind? Do you get warnings at compile time?
Otherwise looks good, you can do a PR to the branch update_to_60 and then we can merge to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants