Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Using Bolt in dynamic libary, occur Segmentation fault #137

Closed
ccx1225 opened this issue Apr 2, 2021 · 12 comments
Closed

Using Bolt in dynamic libary, occur Segmentation fault #137

ccx1225 opened this issue Apr 2, 2021 · 12 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ccx1225
Copy link

ccx1225 commented Apr 2, 2021

#1、 demo
image

the above is the small case, the hello.c is so, the version of gcc is 7.3
gcc hello.c -o libhello.so -I../include -fPIC -shared

gcc main.c -o main -I../include -L../src -lhello

./main

image

2、 Using llvm bolt instrument binary,

./../../../../build/bin/llvm-bolt ./libhello.so -instrument -instrumentation-file=./hello.fdata -use-old-text -instrumentation-sleep-time=30 -o ./libhello.inst

mv libhello.inst libhello.so
./main

image

the so occur segment fault, can anyone know the reason? is current bolt dont support dynamic instrument ?

@ccx1225
Copy link
Author

ccx1225 commented Apr 2, 2021

but i use in Executable bin, is OK, the dynamic lib is error

@maksfb
Copy link
Contributor

maksfb commented Apr 2, 2021

We currently lack the support for instrumenting shared libraries. At the very minimum we should give an error during the instrumentation time. Thanks for reporting.

@ccx1225
Copy link
Author

ccx1225 commented Apr 3, 2021 via email

@undingen
Copy link
Contributor

undingen commented Jun 7, 2021

I run into the same issue :(.
Could you please describe whats missing: Is it just a case of having to call some initialization functions to the bolt runtime from the shared object or is adding support a larger task?
Unfortunately I'm using a AMD Ryzen cpu so can't use perf to get a profile :/.

@rafaelauler
Copy link
Contributor

It's a bit more complicated. Helper code dealing with instrumentation lives in a static library, a .a file with object files .o. We open this archive and link this .o file with RuntimeDyld (an LLVM just-in-time loader). This is straightforward for non-PIC code.

But position independent code, used in shared libraries, requires a bit more. The linker needs to create indirection tables (GOT and PLT) whenever the code references an exported symbol. This means that if we change our build rules to link the runtime library (containing instrumentation code) as a shared lib (.so), we need to write code to merge it into the input .so correctly. Perhaps it's just a matter of copying input sections of the runtime .so to the input .so. Perhaps it will require merging some sections. I can't tell if there is a good strategy to do this easily.

So if you are relying on AMD Ryzen but you somehow have access to a single Intel machine, what you can do is to just collect the profile on an Intel machine, and use the profile on AMD.

@vleonen
Copy link

vleonen commented Aug 10, 2021

@ccx1225 @undingen Please check if the issue is solved in the recent Bolt version (main branch, after commits from MR#192 were cherry-picked).

@ccx1225
Copy link
Author

ccx1225 commented Aug 24, 2021

@vleonen , thank you. It is OK

@yota9
Copy link
Contributor

yota9 commented Sep 18, 2021

@rafaelauler I think we can close this?

@kmod
Copy link

kmod commented Sep 18, 2021

We're still having an issue with running bolt on a shared object -- it no longer crashes during the build process, but the resulting shared object has different behavior. We haven't had time to track it down, but if it helps we can post the raw files.

@yota9
Copy link
Contributor

yota9 commented Sep 18, 2021

Sure @kmod we can try to figure out what is happening, please give us the example which we can use to reproduce the problem

@undingen
Copy link
Contributor

I work together with @kmod on pyston and took a look at the issue:
It comes down to -instrument setting -jump-tables=move internally which generates invalidate code for our main interpreter loop (very complicated function using computed gotos etc) which we already track in #175. Skipping this functions makes instrumenting on the shared object work - thanks for your team implementing this! will make development much easier for me and my amd cpu.

@rafaelauler
Copy link
Contributor

Sounds good, then I'll close this one and leave 175 open. Thanks folks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants