On Wed, Feb 27, 2019 at 1:28 AM Waldek Kozaczuk <[email protected]> wrote:
> Recently I had a chance to explore if we can run Golang pie apps built > with --buildmode=pie options. I have actually added two examples of it - > https://github.com/cloudius-systems/osv-apps/tree/master/golang-pie-example > and > https://github.com/cloudius-systems/osv-apps/tree/master/golang-pie-httpserver > . > > Running Golang pie apps does not require the golang wrapper ( > https://github.com/cloudius-systems/osv/blob/master/modules/golang/go.cc) > which is used to launch apps built as shared libraries which is the > "official way" of running them on OSv. Relatedly Golang pie apps when run > trigger a warning about "a PIE using TLS" (see issue > https://github.com/cloudius-systems/osv/issues/352). Given all that I did > not expect them to run without crashes which also I reported couple of > months ago - > https://github.com/cloudius-systems/osv/issues/352#issuecomment-434692750 > . > > It turns out that original crash from 352 was caused by missing > sys_exit_group syscall fixed later by this commit - > https://github.com/cloudius-systems/osv/commit/a52e73ceec726378pie > shared object tls-modelf642f5621caf5966f96bad9c > <https://github.com/cloudius-systems/osv/commit/a52e73ceec726378f642f5621caf5966f96bad9c>. > So when I built and ran golang-pie-example recently, it would execute > without any problems. Encouraged with it I tried another more complex > example - golang-pie-httpserver - and I was also able to start it and > stress test it with ab. I did not see any issues until I tried to exit with > 'Ctrl-C' which caused a crash as reported by this new issue - > https://github.com/cloudius-systems/osv/issues/1026. > > Couple of questions: > > 1. How do these two apps run almost properly (except for that Ctrl-C > issue) given they are pie's with local-exec TLS which we do not support per > #352? > > > 1. > 2. Do the apps run properly because they actually do NOT use any > thread local variables? Or we simply do not see any bad side effects and > program just "happens' to work fine? I know that Golang language itself > does not have a concept of thread local variables like C++ or Java but > Golang runtime behind the scenes seems to use them given presence of TLS > section. Or maybe TLS section is empty? > > Maybe golang's implementation does not actually use these TLS variables, or is although PIE *can* use local-exec TLS mode, it was intentionally compiled to use any other TLS mode? You can see examples on how a program can choose its variables' TLS model on the whole compilation (-ftlst-model=...) or individual variables in tests/tst-tls.cc. I have no idea if this is the explanation, though. I'm also pretty rusty with all that TLS code, and why the mere existance of that section is a problem. > > 1. The C++ example from #352 executes on OSv but prints wrong value. > What does exactly mean that local-exec TLS is not supported? In what way? > Does code try to read/write data from/to wrong offsets in memory or thread > local variables do not get properly initialized? > > Again, I'm rusty in this, the issue probably has more information than I remember now. I vaguely remember that "local exec" means that the code which *uses* these variables assumes they are in the main per-thread area (%fs), but what we have there are actually OSv's own per-thread variables. > > 1. Is it possible that some patches (for example > > https://github.com/cloudius-systems/osv/commit/e60339de2676b186c1ec957102a5a384506d127e_ > committed to support Golang apps with initial-exec TLS mode helped support > Golang pies as well. > > This is only relevant if somehow the PIE uses initial-exec TLS mode instead of local-exec. Maybe it does? I really have no idea how Go uses TLS... I read some old comment in some random discussion which suggests that Go does something similar to *initial-exec*, but manually, and if this is the case for both the SO and PIE modes, than it should be fine. If it's really fine, I wonder how we can detect it and avoid the warning message. What does that TLS section contain? > -- > You received this message because you are subscribed to the Google Groups > "OSv Development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
