This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer_common] Support Solaris < 11.4 in GetStaticTlsBoundary
ClosedPublic

Authored by ro on Feb 17 2022, 7:22 AM.

Details

Summary

This patch, on top of D120048, supports GetTls on Solaris 11.3 and Illumos that lack dlpi_tls_modid. It's the same method originally used in D91605, but integrated into GetStaticTlsBoundary.

Tested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11, and x86_64-pc-linux-gnu.

Diff Detail

Event Timeline

ro created this revision.Feb 17 2022, 7:22 AM
ro requested review of this revision.Feb 17 2022, 7:22 AM
Herald added a subscriber: Restricted Project. · View Herald TranscriptFeb 17 2022, 7:22 AM

D120048 decreases the number of lines and looks good to me. But for this one, there is now more complexity... Can we just let old systems (Solaris<=11.3) use *addr = 0; *size = 0;?

ro added a comment.Feb 17 2022, 11:56 AM

D120048 decreases the number of lines and looks good to me. But for this one, there is now more complexity... Can we just let old systems (Solaris<=11.3) use *addr = 0; *size = 0;?

I don't care much about Solaris 11.3. While I do have patches to make LLVM work, I almost certainly won't submit them. However, even current day Illumos is the same, and just using D120048 will break the build for them due to the use of dlpi_tls_modid. Besides, we still have the matter of distinguishing Solaris and Illumos at build time. The current patch avoids all this.

In D120059#3330493, @ro wrote:

D120048 decreases the number of lines and looks good to me. But for this one, there is now more complexity... Can we just let old systems (Solaris<=11.3) use *addr = 0; *size = 0;?

I don't care much about Solaris 11.3. While I do have patches to make LLVM work, I almost certainly won't submit them. However, even current day Illumos is the same, and just using D120048 will break the build for them due to the use of dlpi_tls_modid. Besides, we still have the matter of distinguishing Solaris and Illumos at build time. The current patch avoids all this.

Oh, thanks. Then perhaps adjust the code to work for Solaris 11.4 and let Illumos/Solaris 11.3 use the *addr = 0; *size = 0; fallback? That will have minimum code...

I hope we can get rid of main_tls_modid = 1; and rt_tlsmodid...

ro added a subscriber: jclulow.Feb 17 2022, 1:14 PM
ro added a comment.Feb 17 2022, 1:22 PM

Oh, thanks. Then perhaps adjust the code to work for Solaris 11.4 and let Illumos/Solaris 11.3 use the *addr = 0; *size = 0; fallback? That will have minimum code...

That would effectively mean using D120048 amended to use some SANITIZER_ILLUMOS to distinguish the two. Currently, we don't have that unfortunately, as discussed in D119695. We'd also need to disable the ld -z relax=transtls workaround in that patch, but haven't a way to distinguish Solaris and Illumos in cmake files either.

I have an idea how to get __illumos__ defined (using uname -o in llvm/CMakeLists.txt) to handle the former, but in the end the Illumos community will have to come up with a solution that works for both Solaris and Illumos.

I hope we can get rid of main_tls_modid = 1; and rt_tlsmodid...

Fully agreed that's ugly, but at least it works for everyone and has been proven so in GCC. I'm certainly not vested in it, though, given that I primarily care about Solaris 11.4 where the common code just works.

MaskRay added a comment.EditedFeb 17 2022, 9:30 PM
In D120059#3330715, @ro wrote:

Oh, thanks. Then perhaps adjust the code to work for Solaris 11.4 and let Illumos/Solaris 11.3 use the *addr = 0; *size = 0; fallback? That will have minimum code...

That would effectively mean using D120048 amended to use some SANITIZER_ILLUMOS to distinguish the two. Currently, we don't have that unfortunately, as discussed in D119695. We'd also need to disable the ld -z relax=transtls workaround in that patch, but haven't a way to distinguish Solaris and Illumos in cmake files either.

I have an idea how to get __illumos__ defined (using uname -o in llvm/CMakeLists.txt) to handle the former, but in the end the Illumos community will have to come up with a solution that works for both Solaris and Illumos.

I hope we can get rid of main_tls_modid = 1; and rt_tlsmodid...

Fully agreed that's ugly, but at least it works for everyone and has been proven so in GCC. I'm certainly not vested in it, though, given that I primarily care about Solaris 11.4 where the common code just works.

Glad to know what you only care about Solaris>=11.4:)
It seems that D84046 is the first compiler-rt commit with llumos in the description. So I think compiler-rt has never officially supported illumnos.
Perhaps we should ask them to fix things before adding workarounds to compiler-rt?
Perhaps we can set up a milestone: they need to at least support __illumos__ and dlpi_tls_modid before adding the port to compiler-rt...

ro added a comment.Feb 18 2022, 1:04 AM

Glad to know what you only care about Solaris>=11.4:)

Sure: I'm keeping support in GCC since the 11.3/11.4 differences are useful in a couple of places and the effort is small. LLVM is different, though, given that Solaris support is only slowly coming.

It seems that D84046 is the first compiler-rt commit with llumos in the description. So I think compiler-rt has never officially supported illumnos.

Seems so: even the clang 13 in their oi-userland repo, which has some local patches, doesn't build compiler-rt.

Perhaps we should ask them to fix things before adding workarounds to compiler-rt?

Seems like a plan: instead of me constantly worrying about breaking the build for them without a sensible way for a workaround, the ball is in their court. I certainly don't intend to cause them problems and will continue to point out potential issues in my patches as far as I'm aware of them.

Perhaps we can set up a milestone: they need to at least support __illumos__ and dlpi_tls_modid before adding the port to compiler-rt...

Even the former would be enough as a first step: in that case, we can use the *addr = 0; *size = 0; fallback (though some sort of isOSIllumos() would be needed in clang to avoid using ld -z relax=transtls which they lack).

As a first step, I've filed Issue #53919 so what needs to be done can be kept in one place rather than spread over several reviews.

ro added a comment.Feb 21 2022, 5:22 AM

@MaskRay: With this patch effectively abandoned and the Illumos situation in their court, are you ok with D120048 going in now as is?

In D120059#3335287, @ro wrote:

@MaskRay: With this patch effectively abandoned and the Illumos situation in their court, are you ok with D120048 going in now as is?

Yes!

ro abandoned this revision.Feb 22 2022, 11:24 AM

Abandoned unless absolutely necessary for Illumos support. As discussed, a way better alternative would be for them to implement dlpi_tls_modid or at least provide a way to distuingish Illumos from Solaris as outlined in Issue #53919.

ro added a comment.May 6 2022, 7:28 AM
In D120059#3338258, @ro wrote:

Abandoned unless absolutely necessary for Illumos support. As discussed, a way better alternative would be for them to implement dlpi_tls_modid or at least provide a way to distuingish Illumos from Solaris as outlined in Issue #53919.

Current compiler-rt was just integrated into GCC trunk, which broke the build on Solaris 11.3 for the lack of dlpi_tls_modid. S11.3 is still supported in GCC (and will remain so for quite some time), so I guess the best option forward is to reactivate this patch? @MaskRay?

Herald added a project: Restricted Project. · View Herald TranscriptMay 6 2022, 7:28 AM
Herald added a subscriber: StephenFan. · View Herald Transcript
ro updated this revision to Diff 446110.Jul 20 2022, 4:45 AM

Minor formatting change.

ro added a comment.Jul 20 2022, 4:48 AM

As mentioned before, I'd like to revive this patch (although there's no Action in Phabricator for this AFAICS): importing upstream sanitizers into GCC libsanitizer broke the Solaris 11.3 build, which is still supported in GCC. As a side effect, it would also unbreak (at least in this regard) compiler-rt on Illumos.

Retested on amd64-pc-solaris2.11, sparcv9-sun-solaris2.11 (Solaris 11.4), and x86_64-pc-linux-gnu; as well as the same targets inside the GCC tree (also for Solaris 11.3 there).

MaskRay accepted this revision.Jul 20 2022, 10:50 AM
MaskRay added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
361

Instead of having two chunks of comments, just have one saying that the #if SANITIZER_SOLARIS branch is for Solaris < 11.4 compatibility?

This revision is now accepted and ready to land.Jul 20 2022, 10:50 AM
ro marked an inline comment as done.Jul 21 2022, 12:12 AM
ro added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
361

That's way clearer indeed.

ro updated this revision to Diff 446370.Jul 21 2022, 12:13 AM
ro marked an inline comment as done.

Merge comments.

This revision was landed with ongoing or failed builds.Jul 21 2022, 12:19 AM
This revision was automatically updated to reflect the committed changes.