runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Enable static linking of OS dependencies on Linux

Open gkhanna79 opened this issue 10 years ago • 56 comments

gkhanna79 avatar Jun 17 '16 13:06 gkhanna79

:clap:

davidfowl avatar Jun 17 '16 14:06 davidfowl

@gkhanna79 anbd @janvorli I started the implementation on CoreFx which was checked in over the week end. The implementation of the CoreClr is on work in progress on my side as I had some problem with the ICU library that I solved last week. I hope to send the push request in the coming week. After that we will need to add library as incremental. You can refer as well to that issue about the same topic https://github.com/dotnet/coreclr/issues/4436

davzucky avatar Jun 20 '16 05:06 davzucky

Licensing question, findICU.cmake is not part of the basic cmake support to find library, however they are a few available on github which could be quite nice to add in the project. What is the policy to use some of file like ?

  • https://github.com/julp/FindICU.cmake
  • https://github.com/facebook/hhvm/blob/master/CMake/FindICU.cmake

Or could as well start to build our own version. Any comment ?

davzucky avatar Jun 20 '16 13:06 davzucky

CC @jkotas

gkhanna79 avatar Jun 21 '16 14:06 gkhanna79

I have run https://github.com/julp/FindICU.cmake through the approval process. It is ok to use it. Could you please add it in a separate PR that will:

  • Add FindICU.cmake file
  • Add license to THIRD-PARTY-NOTICES

jkotas avatar Jun 21 '16 16:06 jkotas

Darn, @shahid-pk you beat me to a reference but THANK YOU!!!

eyoung100 avatar Oct 08 '16 07:10 eyoung100

I have experimented with using libcoreclr.so built on Ubuntu 14.04 and it seems it works fine on SUSE 14.2 and CentOS 7.1. That build of libcoreclr.so depends on most functions from GLIBC 2.2.5, then there are three 2.3, one 2.3.2, one 2.4, one 2.6, two 2.12 symbols and the newest is memcpy with version 2.15. The GLIBC version 2.2.5 was released on 2002-01-20 and version 2.15 on 2012-03-21. Since this seems like this build of libcoreclr.so depends on a reasonably old GLIBC, it may be possible to use that build as a universal libcoreclr.so for all supported Linux systems. All the libXXXX.so built in the coreclr repo are all the same story and the tools like corerun, coreconsole, ilasm, ildasm too. The System.Globalization.Native.so is a different story though, since it links to libicui18n.so and libicuuc.so. Since these don't seem to be on the back compatibility plan as the GLIBC, I guess we would need to link these statically.

janvorli avatar Oct 10 '16 09:10 janvorli

Similarly for GLIBCXX versions - the newest symbol referenced from that library by any of the coreclr components is from version 3.4.15, which was released on 2011-03-25.

janvorli avatar Oct 10 '16 10:10 janvorli

@janvorli Is GLIBCXX 3.4.15 the lowest common denominator?

gkhanna79 avatar Oct 10 '16 16:10 gkhanna79

@gkhanna79 do you mean lowest common denominators for the currently supported Linux distros?

janvorli avatar Oct 10 '16 16:10 janvorli

@janvorli Sort of. What all set of distros, which we support today, would this work for and how does it map to the set of distros we can support using GLIBC version in question? In principle, we want them to be consistently supported and move in tandem.

gkhanna79 avatar Oct 10 '16 16:10 gkhanna79

@gkhanna79 here is a list of distros and the versions of glibc / glibcxx they ship with. The glibcxx version represents the highest version of a symbol in the glibcxx. I don't have Redhat 7.2 installed and there is no docker container with it to enable me to give it a quick try. But I assume it will be the same or higher than CentOS 7.1.

Distro GLIBC GLIBCXX
CentOS 7.1 2.17 3.4.19
Debian 8.4 2.19 3.4.20
openSUSE 13.2 2.19 3.4.19
openSUSE 42.1 2.19 3.4.21
Red Hat 7.2 ? ?
Fedora 23 2.22 3.4.21
Ubuntu 14.04 2.19 3.4.19
Ubuntu 16.04 2.23 3.4.21
Ubuntu 16.10 2.23 3.4.22

janvorli avatar Oct 11 '16 14:10 janvorli

Possibly related to dotnet/coreclr#7573 ?

obadz avatar Oct 11 '16 22:10 obadz

@janvorli The first think I tried to statically link is the libicu library that are used by System.Globalization.native.so that you pointed, however I keep getting into the wall with this library. I tried a lot of distribribution and keep getting the same error. From the docuemntation it look like you can, however I'm getting an error from the linker about position independent. I recompile libicu with the option -fPIC but still getting the same error.

Would you have more knowledge about that ?

davzucky avatar Oct 13 '16 05:10 davzucky

@davzucky I assume when you said you have compiled the libicu, you have done that for all the three icu libraries we depend on (libicuuc, libicui18n and libicudata), right? Are you sure that our build was picking the ones you have built instead of the ones installed by the package manager? Are you sure you have added -fPIC to all necessary places in their build files? How did you modify the CMakeLists.txt to use the static libraries? And if the library contains some asm code, then it might need to be tweaked to be position independent.

janvorli avatar Oct 13 '16 09:10 janvorli

Thank you @janvorli. Looks like the following the least common denominator (excluding RHEL) for now:

GLIBC: 2.17
GLIBCXX: 3.4.19

@ellismg Do you have access to a RHEL machine that @janvorli can use for his investigation?

gkhanna79 avatar Oct 13 '16 17:10 gkhanna79

@janvorli

  • I assume when you said you have compiled the libicu, you have done that for all the three icu libraries we depend on (libicuuc, libicui18n and libicudata), right? Yes I mean all the three
  • Are you sure that our build was picking the ones you have built instead of the ones installed by the package manager? I installed the lib after I build them. So that replace the one I have from the install and I shoult not have any problem. I checked the command line that the linker was using and it was referencing the right path
  • Are you sure you have added -fPIC to all necessary places in their build files? I expect yes. I will try to buikd it again and test
  • How did you modify the CMakeLists.txt to use the static libraries? I updated the current script to take the + adding extra flag. like I did in corefx before.
  • And if the library contains some asm code, then it might need to be tweaked to be position independent. Thank you for the information I wasn't aware about that. I will check that and let you know.

I will check all your point over the week end and come back to you. Thank you

davzucky avatar Oct 14 '16 05:10 davzucky

I have made an experiment to enable System.Globalization.Native.so to use any version of ICU libraries that is present on the system ("any" means within some limits). I got the idea from the ICU doc where they describe building ICU libraries as OS components where an application compiled against one version of the ICU can still work when the ICU gets upgraded. They have a concept of stable APIs - those APIs that are marked as stable are guaranteed to have the same signature / semantics in the future versions of the libicu. And for the usage of ICU as OS libraries, you can disable the renaming of the APIs. So instead of u_tolower_52 in version 52 of the ICU, you'd get u_tolower. When consumers of the APIs define #define U_DISABLE_RENAMING 1, the header files provide prototypes of the functions without the version number. You can see the details here: http://userguide.icu-project.org/design#TOC-ICU-Binary-Compatibility:-Using-ICU-as-an-Operating-System-Level-Library Fortunately, all the APIs we are using are stable. So, here is what I did:

  1. I have defined U_DISABLE_RENAMING as 1 for the build of System.Globalization.Native.so. That compiles everything referencing the unversioned symbols.
  2. I have added an initialization code that finds the installed libcuuc.so.xx and libcui18n.so.xx libraries, calls dlopen to load them dynamically and then calls dlsym for each API name with added version number that it has found and assigns that to a global variable of a type of a pointer to the API function and named by the API with _ptr added.
  3. Add a header that redefines (using #define) each API name to the name with _ptr added at the end.
  4. Include that header after all the unicode/xxxx headers are included.

This essentially makes the code to use the function pointers extracted dynamically using the dlsym.

I have ran the System.Globalization.Tests and System.Runtime.Tests with this modified System.Globalization.Native.so and all of them have passed.

So it seems like a feasible way, we just need to figure out the minimum version of ICU that we can support. Then we don't need to try to link ICU statically.

cc: @gkhanna79, @Petermarcu, @stephentoub. Do you guys have any concerns?

janvorli avatar Oct 20 '16 21:10 janvorli

I like it. That approach also would make it easy to add fallback implementations if ICU can't be found, e.g. just by pointing the function pointers to a local implementation that provides some ASCII/invariant/etc. implementation.

stephentoub avatar Oct 20 '16 21:10 stephentoub

Though, if we did want to statically link it once we moved to this scheme, how would we do it? Include a shim that calls each relevant function and just assign those shims to the pointers?

stephentoub avatar Oct 20 '16 21:10 stephentoub