Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Remove dependency of System.Globalization.Native.so on specific ICU version - #7773

Merged
janvorli merged 1 commit into
dotnet:masterfrom
janvorli:remove-icu-version-dependency
Oct 26, 2016
Merged

janvorli merged 1 commit into
dotnet:masterfrom
janvorli:remove-icu-version-dependency

Conversation

@janvorli

@janvorli janvorli commented Oct 24, 2016 •

Copy link
Copy Markdown
Member

This change adds a shim layer between the ICU libraries and the code in
System.Globalization.Native.so that automatically picks a version of the ICU
libraries that is installed on the current machine. This enables usage of
the same System.Globalization.Native.so on various Linux distributions and
their versions. The minimal ICU version supported is the one the System.Globalization.Native.so is built with.

@janvorli

Copy link
Copy Markdown
Member Author

@stephentoub, @ellismg can you take a look please?
cc: @gkhanna79, @Petermarcu

@janvorli

Copy link
Copy Markdown
Member Author

With this change, I was able to use dotnet cli package for Ubuntu 14.04 (replacing only the System.Globalization.Native.so with my version) and run dotnet new on Debian, Ubuntu 14.04, Ubuntu 16.04, OpenSUSE 13.2 and OpenSUSE latest. On Fedora 24 and CentOS 7.1, I was able to run dotnet --version, but dotnet new fails due to Crypto initialization issue.

char libicui18nName[64];

GetVersionedLibFileName("libicuuc.so", majorVer, minorVer, subVer, libicuucName);
GetVersionedLibFileName("libicui18n.so", majorVer, minorVer, subVer, libicui18nName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I realize this can't happen with the values currently chosen, but if the size of libicuucName/libicui18nName were to be decreased and the values of the max major/minor versions were to be increased, it's possible we could find ourselves overflowing these buffers. Consider putting some length checks in place to ensure that never happens with future refactorings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size is safe for these two libraries even with the max int values for each of the versions. The max combined size of the versions is 33 characters (3 dots and 10 digits max for each int).
But I agree that a size check never hurts.

}

return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the worst case, have you looked to see what kind of startup impact this has with lots of dlopen failures?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to swap the order of the loops to start with the version that tries to go with the three components of the version, which fails to find anything on my Ubuntu. The whole initialization took 45ms in that case on my machine. Without this flip of order, it takes 8ms.

@janvorli

Copy link
Copy Markdown
Member Author

I can see from the CI results that I have an issue on FreeBSD due to a need to use HAVE_SET_MAX_VARIABLE define to pick ucol_setMaxVariable or ucol_setVariableTop and there is some issue on ARM where it looks like the symbol versioning is different (maybe it is not adding versions to ICU symbols at all?).
I am looking into it.

return libicuuc != nullptr;
}

// Select libraries using the version override specified by the CLR_ICU_VERSION_OVERRIDE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use "COMPlus" or some variant instead, for symmetry with the other tuning values?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMPlus is used only for CoreCLR options, so I didn't want to cause confusion by using it for CoreFX components options. Besides that, we use CORE_LIBRARIES and CORECLR_SERVER_GC for Unix corerun / coreconsole, PAL_xxx for PAL stuff.
I am open to any name suggestions, the currrent name was just the first idea I got.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a rational explanation. CLR_ICU_VERSION_OVERRIDE sounds good to me.

#include "errors.h"

#ifndef FEATURE_FIXED_ICU_VERSION
// The System.Globalization.Native.so is built in mode that allows it to find the local

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a better comment would be that we want to support versions of ICU where UDAT_STANDALONE_SHORTER_WEEKDAYS was not yet defined?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is half of the truth. The main problem is really the fact that it is not part of the stable APIs, so even if we wanted to support only newer versions of ICU that have that API, we should not do that unless it became part of the stable API.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I agree that the comment is somehow convoluted, I'll try to clean it a bit and integrate both points in it.

@janvorli
janvorli force-pushed the remove-icu-version-dependency branch 3 times, most recently from 55ebb92 to 7f9fe57 Compare October 25, 2016 08:54
@janvorli

Copy link
Copy Markdown
Member Author

@dotnet-bot test this please

@janvorli
janvorli force-pushed the remove-icu-version-dependency branch 2 times, most recently from a4c63d8 to c544ab5 Compare October 25, 2016 09:51
@janvorli

Copy link
Copy Markdown
Member Author

@ellismg, @stephentoub I've reflected your feedback and fixed the ARM and FreeBSD issues, can you please take another look?

@janvorli

Copy link
Copy Markdown
Member Author

@ellismg, @stephentoub I actually wonder if the MaxICUVersion where I start scanning should be lower than the very conservative 99. The more versions we scan before we find one, the longer time it takes. As I've mentioned, the time even with the starting version 99 and the case we need to scan lib names with all three version components, the whole initialization takes about 45 ms on my native Linux box, which is not much. But still, I can see that since 2012, the ICU had about two major version releases a year, so if this trend continues, the current code is ready for the next 20 years of releases, which sounds like an overkill.
So I wonder if we should start scanning lower and keep raising this value in each release of corefx to match the ICU version growth.

@ellismg

ellismg commented Oct 25, 2016

Copy link
Copy Markdown

So I wonder if we should start scanning lower and keep raising this value in each release of corefx to match the ICU version growth.

I would hate for us to have to patch the LTS trains (i.e the major version releases) in order to bump this number, so we should hopefully always have two years of ICU growth baked in, and then just move things along? Would we be comfortable with starting the cap at something like 70?

// only use stable APIs and the UDAT_STANDALONE_SHORTER_WEEKDAYS doesn't belong to those.
// We also want to support ICU versions where the UDAT_STANDALONE_SHORTER_WEEKDAYS was not
// defined yet.
#undef HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to undef HAVE_SET_MAX_VARIABLE here. Is there some way we can just make changes in the configure step to make all the checks on FEATURE_FIXED_ICU_VERSION being set?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep the configure step agnostic of what we are building and just providing information of what is available during the build.
Now this HAVE_SET_MAX_VARIABLE is different from the HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS. If you have ICU that already has the ucol_setMaxVariable at the build time and you'd try to use the old ucol_setVariableTop, the compilation will fail with warning on the ucol_setVariableTop being deprecated.
It is actually interesting what does it really mean for a stable api like this to be deprecated. Based on what they say on the stable APIs, it should still exist in the future versions of the library, so I assume it won't be removed in the future.
I am actually starting to think that I should change the minimum major version number of ICU that we support to be the version of ICU we are building against. That would mean that when we want to build a version of System.Globalization.Native.so that would work on a set of supported distros, we would build it on a distro with the oldest dependencies from all the distros from the set. That's what we actually need to do for glibc as well to make sure we don't reference a newer version of a function from glibc - from time to time, new versions of the same functions are added to glibc while the older ones remain.
If we did it this way, then we would keep the HAVE_SET_MAX_VARIABLE usage as I have it now.
Does it make sense?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense?

I think so. However, if we make these changes, we should be able to remove the hack around HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS as well, correct. When building in this new mode, we assert that the code will run on any version at least as high at the version you compiled on. Since we only use stable stuff, we can use our configure tests. Right?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my question is why HAVE_SET_MAX_VARIABLE and HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS have to be treated differently if we make the changes you describe. UDAT_STANDALONE_SHORTER_WEEKDAYS was not present in ICU 50 (it went stable in ICU 51) and so the configuration test will fail. If we try to take version of System.Globalization.Native.so built on ICU 51 and run it on a platform with ICU 50 or earlier, our loop to find a library to dlopen would fail, because we stop searching at U_ICU_VERSION_MAJOR_NUM right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I have tried to build it with ICU 52 and the U_HIDE_DRAFT_API defined and the UDAT_STANDALONE_SHORTER_WEEKDAYS was not present, so I have assumed it is still not stable in 52. Now I have tried again and it builds fine, so I think I was just daydreaming.
But with this new idea of using the U_ICU_VERSION_MAJOR_NUM as the minimum major version, it seems HAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS should be handled the same way as the other one as you say.
Regarding

If we try to take version of System.Globalization.Native.so built on ICU 51 and run it on a platform with ICU 50 or earlier, our loop to find a library to dlopen would fail, because we stop searching at U_ICU_VERSION_MAJOR_NUM right?

Yes, that would be the case.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be the case.

Okay, I like the plan.

static void* libicui18n = nullptr;

// Version ranges to search for each of the three version components
static const int MinICUVersion = 50;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can assert at build time that this is greater than or equal to U_ICU_VERSION_MAJOR_NUM, as a sanity check?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading your comment above, it sounds like you may just want to change this to U_ICU_VERSION_MAJOR_NUM anyway :-).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, look at my other comment. I would prefer making it equal to U_ICU_VERSION_MAJOR_NUM.

@janvorli

Copy link
Copy Markdown
Member Author

@ellismg I've made the change we have discussed.

//

// Enable calling ICU functions through shims to enable support for
// multiple versions of ICU if the FEATURE_ICU_VERSION_RESILIENT is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I think FEATURE_ICU_VERSION_RESILIENT is now spelled FEATURE_FIXED_ICU_VERSION? There's another reference to this in a comment at the end of the file.

@ellismg

ellismg commented Oct 25, 2016

Copy link
Copy Markdown

One small NIT, but it LGTM otherwise. Thanks for making the changes here, Jan.

…ersion

This change adds a shim layer between the ICU libraries and the code in
System.Globalization.Native.so that automatically picks a version of the ICU
libraries that is installed on the current machine. This enables usage of
the same System.Globalization.Native.so on various Linux distributions and
their versions. The minimal ICU version supported is U_ICU_VERSION_MAJOR_NUM,
the maximum supported is the minimum plus 20.
@janvorli

Copy link
Copy Markdown
Member Author

@ellismg thanks for spotting the old feature name in the comment.

@janvorli
janvorli force-pushed the remove-icu-version-dependency branch from 5440a38 to f8ca90f Compare October 26, 2016 00:10
@janvorli

Copy link
Copy Markdown
Member Author

@dotnet-bot Windows_NT x64 Formatting

@janvorli janvorli changed the title Remove dependency of System.Globalization.Native.so on specific ICU v… Remove dependency of System.Globalization.Native.so on specific ICU version Oct 26, 2016
@janvorli
janvorli merged commit cf0c28f into dotnet:master Oct 26, 2016
@janvorli
janvorli deleted the remove-icu-version-dependency branch October 26, 2016 09:46
tarekgh added a commit to tarekgh/coreclr that referenced this pull request Oct 27, 2016
there was a change done by the PR dotnet#7773 which removed the dependency on ICU version. and there is another PR dotnet#7811 which used more ICU APIs not listed in the shim.
the change here is to add these APIs to the shim
janvorli pushed a commit that referenced this pull request Oct 27, 2016
there was a change done by the PR #7773 which removed the dependency on ICU version. and there is another PR #7811 which used more ICU APIs not listed in the shim.
the change here is to add these APIs to the shim
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants