Repository navigation
Moving the rest of Unix libraries to the 'overrider' mechanism when linked into static host. - #45995
Conversation
|
Tagging subscribers to this area: @dotnet/ncl Issue Details
|
|
Tagging subscribers to this area: @vitek-karas, @agocke Issue Details
|
|
As far as I know, runtime/src/libraries/Native/Unix/System.Native/extra_libs.cmake Lines 7 to 10 in 08ad834 |
|
@am11 - What worries me is that the INOTIFY check in extra_libs.cmake is sufficient when we build .so version of the library, but not enough when linking static host. I wonder why we see the failure on FreeBSD at all. |
|
I think because in installer partition, we do not have introspection for |
|
@am11 right, clr and libs partitions check for HAVE_INOTIFY, since that impacts which headers to include. I think including the |
| @@ -0,0 +1,50 @@ | |||
| #!/usr/bin/env python | |||
There was a problem hiding this comment.
We have been discussing removal of python usage from our build system recently. So adding a new python script doesn't sound like a good thing. Since this is Unix only, a shell script would be ideal. Could you please convert this to a shell script? It should be pretty straightforward. I'll be happy to help with that if you want.
There was a problem hiding this comment.
I'd really appreciate help here. It would likely take me days to write the same in shell. :-)
There was a problem hiding this comment.
We have CMAKE_NM available, we can probably live even without cmake script calling shell script and just do the checking inside cmake script itself.
There was a problem hiding this comment.
Sure, let me put together a shell version.
There was a problem hiding this comment.
@am11 our responses have crossed. I don't think we can check that in cmake script, as it is executed at build files generation time and we need to execute it after the actual build.
There was a problem hiding this comment.
Sure, let me put together a shell version.
Thanks! I am not using shell scripts often and this is well beyond my expertise.
TBH, I am not an expert in python either, but it is a much more approachable language, so it was my choice over bash or awk.
There was a problem hiding this comment.
@janvorli, ok, so it is for the post-build target. We can still pass CMAKE_NM as argument which is located with proper mechanism for the current toolchain, rather than assuming it is available in PATH.
runtime/eng/native/configuretools.cmake
Line 43 in faae224
| #else | ||
| void SystemNative_ReadEvents(int32_t sock, NetworkChangeEvent onNetworkChange) | ||
| { | ||
| // NOTSUPPORTEDAPI |
There was a problem hiding this comment.
I don't think "not supported" and "unreachable" should be treated the same. Is this function a dummy simply to help the linker or is this needed? Basically if it is really "unreachable" it shouldn't be able to ever be executed if this function shouldn't ever be execute and we want a hard failure I think FAILFAST is more appropriate. My concern here is how does one debug this failure?
There was a problem hiding this comment.
NOTSUPPORTEDAPI was just a marker for myself to find all these at the end - in case if I get a better idea what should be in the bodies. I forgot to remove these.
These are methods that were previously excluded on some platforms via conditional compilation due to underlying OS not having said functionality. The stubs that I have put instead are primarily to make compiler happy. They are not expected to be called, since previously they were not even there.
In most cases there is a way to fail gracefully with ENOSUP, which I think is the right way to implement these. However a few cases do not provide such option.
For the cases that cannot naturally fail, my preference would be to have a "release assert" to prevent accidental use of unimplemented API. __builtin_unreachable is one way to achieve that which is also cross-platform.
There was a problem hiding this comment.
I could also use abort(). I will switch to that as a more obvious failfast case.
There was a problem hiding this comment.
I could also use abort(). I will switch to that as a more obvious failfast case.
That would be my preference here. Thanks.
There was a problem hiding this comment.
In most cases there is a way to fail gracefully with ENOSUP, which I think is the right way to implement these.
There is a quite a bit of prior art in the libraries PAL where we handle this case by returning errno = ENOTSUP. I do not think we need to bother with making distinction between not supported and unreachable for the libraries PAL.
There was a problem hiding this comment.
Yes, I went through all of these (had to remove // NOTSUPPORTEDAPI marker anyways) and all looks like using errno = ENOTSUP pattern.
The only one that needs a failfast is void SystemNative_ReadEvents(int32_t sock, NetworkChangeEvent onNetworkChange)
| DllImportEntry(BrotliSetDictionaryData) | ||
| DllImportEntry(BrotliDecoderGetErrorCode) | ||
| DllImportEntry(BrotliEncoderTakeOutput) | ||
| DllImportEntry(BrotliEncoderVersion) |
There was a problem hiding this comment.
Why do we need to export these? They do not seem to be used anywhere in the .cs files.
There was a problem hiding this comment.
They are exported and the diffing script found them. I am not sure why we export them.
There was a problem hiding this comment.
They are BROTLI_COMMON_API and that ends up __declspec(dllexport) because we set
add_definitions(-DBROTLI_SHARED_COMPILATION)
It looks intentional. Like for use from other native stuff.
I can try not setting BROTLI_SHARED_COMPILATION.
There was a problem hiding this comment.
We should not be exporting them if we are not using them. It just keeps dead unused code around.
| @@ -14,7 +14,6 @@ set(NATIVECOMPRESSION_SOURCES | |||
| ) | |||
|
|
|||
| if (NOT CLR_CMAKE_TARGET_BROWSER) | |||
There was a problem hiding this comment.
Could you please also delete the unused methods from src\libraries\Native\Windows\System.IO.Compression.Native\System.IO.Compression.Native.def ?
There was a problem hiding this comment.
Looks like there are also actual BROTLI_DEC_API/BROTLI_ENC_API which we are not using.
Ex:
BROTLI_DEC_API BROTLI_BOOL BrotliDecoderHasMoreOutput(...)
BROTLI_ENC_API size_t BrotliEncoderMaxCompressedSize(size_t input_size);
I will assume that in our use patterns we have no need for these and will remove the decorations.
There was a problem hiding this comment.
Or better - replace with some noop like BROTLI_INTERNAL, - so that we could find them easily if needed
There was a problem hiding this comment.
Changing upstream code is not ideal, we have tried so far to keep them (brotli, zlib, libunwind and rapidjson) drop-in for next version update as much as possible. Maybe we can configure fvisibility and friends to achieve the desired result? Or strip those symbols after target is built.
There was a problem hiding this comment.
It is tempting to set exports externally via version-scripts. That is known for causing portability issues in the past, but maybe, since this is a simple leaf dll case, it would work here.
There was a problem hiding this comment.
I made the Unix exports cpecified externally via version-scripts. We will set BROTLI_SHARED_COMPILATION so that all stuff intended to be public is public, as before.
But then what is actually exported will be reduced to what we use by passing explicit list of exports to the linker.
There was a problem hiding this comment.
So, now System.IO.Compression.Native DSO exports exactly the number entries that is used by managed part. That is on all platforms - Windows, Unix, OSX, IOS.
Perhaps that will allow for some bits to be trimmed off.
|
@am11 I've pushed in the change from .py to .sh, but I haven't passed in the nm path as you've suggested yet. I'll look into that tomorrow with another fix I need to do to the script for OSX. |
| #!/usr/bin/env bash | ||
|
|
||
| dllList=$(nm $1 | awk '/^[0-9a-fA-F]+ T \S+/ { if ($3 != "_init" && $3 != "_fini") print $3 }') | ||
| entriesList=$(awk 'match($0, /^\s+DllImportEntry\((\S+)\)/, m) { print m[1]}' $2) |
There was a problem hiding this comment.
This expression only worked for me on macOS but failed on Linux, FreeBSD and illumos. The following variant works on all (on illumos/OpenIndiana, worked with nawk but not with the default; oawk):
entriesList=$(awk -F'DllImportEntry\\(|\\)' '/DllImportEntry/{ print $2 }' $2)alternatively, we can use pure bash to split the strings to get the consistent results.
… is actually used and to match Unix.
| add_definitions(-DTARGET_UNIX) | ||
| endif(CLR_CMAKE_TARGET_UNIX) | ||
|
|
||
| # Ensure that awk is present |
There was a problem hiding this comment.
This is needed to make version-scripts helpers to work in libs partition.
We should consider switching libs to use the configurecompiler.cmake. Not in this PR though.
There was a problem hiding this comment.
runtime/eng/native/configurecompiler.cmake
Lines 636 to 662 in 90c647d
I think these lines belong in
eng/native/configuretools.cmake, which is in use by libraries partition. That will prevent us from re-duplicating the code, which was previously de-duplicated. 🙂
There was a problem hiding this comment.
@am11 right, configuretools.cmake is a better place. Thanks!
|
@janvorli, thanks, I agree that getting rid of python dependency is good, but getting rid of a few awk scripts in favor of pure bash script; as you have done, is actually more advantageous in terms of maintenance. The reason is AWK implementation on each Unix-like platform is different, it could be gawk,mawk,nawk,oawk or something else. Cross platform support of consistent syntax by version has not been a problem with python, which makes it a reliable choice in many toolings. |
|
I think I have addressed all the concerns. If there are no more, may I merge this? |
|
Thanks everyone!!! |
…obile dotnet#45995 added this and it relies on this code in configuretools.cmake to detect which linker is used: https://github.com/dotnet/runtime/blob/4bc323242d43dda85d490c0630c4637ffc092469/eng/native/configuretools.cmake#L66-L86 However passing `-Wl,--version` to the compiler doesn't seem to work when using the clang provided by the Android NDK, it still uses the system linker in /usr/bin/ld. On OSX that one doesn't support the `--version` option so we don't detect LD_GNU which we'd need for providing the correct `-Wl,--version-script` compiler option. It looks like this only passed on the PR because we build Android on Linux there and the system linker _is_ GNU there so the check was successful. Disable the generation of the exports file on mobile platforms since we don't use it there anyway.
…obile (#46222) #45995 added this and it relies on this code in configuretools.cmake to detect which linker is used: https://github.com/dotnet/runtime/blob/4bc323242d43dda85d490c0630c4637ffc092469/eng/native/configuretools.cmake#L66-L86 However passing `-Wl,--version` to the compiler doesn't seem to work when using the clang provided by the Android NDK, it still uses the system linker in /usr/bin/ld. On OSX that one doesn't support the `--version` option so we don't detect LD_GNU which we'd need for providing the correct `-Wl,--version-script` compiler option. It looks like this only passed on the PR because we build Android on Linux there and the system linker _is_ GNU there so the check was successful. Disable the generation of the exports file on mobile platforms since we don't use it there anyway.
Resolves:#43699
entrypoints.cis consistent with the exports from a corresponding .so/.dylibThere were some changes in the libraries themselves. That was mostly motivated by fixing discrepancies between exported APIs depending on available OS features. Since at a library level we have a single dispatch table, we need all the methods to be present, even if containing trivial error-returning implementation.
NOTE: The same API unification was not done for IOS, TVOS, Android. There are significant differences in exported APIs on mobile.
It can be resolved in the same way - by adding a lot of stubs that do nothing and return errors, but it would be unnecessary churn right now, since we do not do superhost on those platforms.