Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alexanderkyte
Copy link
Contributor

On android, the dlopen call will take around 1ms per AOT module we try to load. By not using dlopen with the existence check, we rely on a much slower dlopen check that happens later. I think they support dlopen of non-resolved names.

This might break a few things if we don't use the full path to dlopen. If it does, we should probably add existence checks at the caller, but this will be an optimization that works everywhere.

@jonpryor @grendello

@lewurm
Copy link
Contributor

lewurm commented Dec 15, 2018

looks good. did you test this change on a device?

@alexanderkyte
Copy link
Contributor Author

@lewurm I haven't, I was hoping to see our CI test it on sim. I don't have any of the XA caches on my machine currently.

@luhenry
Copy link
Contributor

luhenry commented Dec 17, 2018

@alexanderkyte CI will not give you any result because of #12094

@alexanderkyte
Copy link
Contributor Author

@lewurm @luhenry
The rerun on CI seems to have results here:
https://jenkins.mono-project.com/job/test-mono-pull-request-amd64-osx-products-sdks-android/8336/

That indicates that this works on android (or passes those tests).

@alexanderkyte
Copy link
Contributor Author

alexanderkyte commented Jan 18, 2019

19:54:00 *** start: corlib-xunit
19:54:00 make[1]: Entering directory '/home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/corlib'
19:54:00 make run-xunit-test-local
19:54:03 make[2]: Entering directory '/home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/corlib'
19:54:03 CSC     [net_4_x-linux] net_4_x_corlib_xunit-test.dll
19:54:31 warning CS1701: Assuming assembly reference 'xunit.core, Version=2.2.0.3300, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' used by 'Xunit.NetCore.Extensions' matches identity 'xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' of 'xunit.core', you may need to supply runtime policy
19:54:31 /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/external/corefx/src/System.Runtime/tests/System/DecimalTests.cs(390,33): warning CS1718: Comparison made to same variable; did you mean to compare something else?
19:54:31 /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/external/corefx/src/System.Runtime/tests/System/DecimalTests.cs(391,34): warning CS1718: Comparison made to same variable; did you mean to compare something else?
19:54:31 warning CS8002: Referenced assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.
19:54:32 ok=:; \
19:54:32 PATH="/home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/runtime/_tmpinst/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" REMOTE_EXECUTOR="/home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/lib/net_4_x/tests/RemoteExecutorConsoleApp.exe" MONO_PATH="./../../class/lib/net_4_x-linux:./../../class/lib/net_4_x-linux/tests:.:./../../../external/xunit-binaries:$MONO_PATH" /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/runtime/mono-wrapper --debug    ./../../../external/xunit-binaries/xunit.console.exe ./../../class/lib/net_4_x/tests/net_4_x_corlib_xunit-test.dll -noappdomain -noshadow -parallel none -nunit TestResult-net_4_x-xunit.xml -notrait category=failing -notrait category=nonmonotests -notrait Benchmark=true -notrait category=outerloop -notrait category=nonlinuxtests || ok=false; \
19:54:32 if [ -n "$MONO_BABYSITTER_NUNIT_XML_LIST_FILE" ]; then echo "/home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/corlib/TestResult-net_4_x-xunit.xml" >> "$MONO_BABYSITTER_NUNIT_XML_LIST_FILE"; fi; \
19:54:32 $ok
19:54:33 xUnit.net Console Runner v2.4.1 (64-bit Desktop .NET 4.7.2, runtime: 4.0.30319.42000)
19:54:35   Discovering: net_4_x_corlib_xunit-test
19:54:53   Discovered:  net_4_x_corlib_xunit-test
19:54:53   Starting:    net_4_x_corlib_xunit-test
19:54:56     System.Reflection.Tests.MemberInfoNetCoreAppTests.HasSameMetadataDefinitionAs__CornerCase_HasElementTypes [SKIP]
19:54:56       Mono issue #10129
19:54:56     System.Reflection.Tests.MemberInfoNetCoreAppTests.HasSameMetadataDefinitionAs_GenericTypeParameters [SKIP]
19:54:56       Mono issue #10127
20:02:22     System.Reflection.Tests.FieldInfoTests.SecurityAttributes [SKIP]
20:02:22       It's CAS-related and not actual in Mono
20:02:22     System.Reflection.Tests.FieldInfoTests.SetValueDirect_GetValueDirectRoundDataTest [SKIP]
20:02:22       Mono issue #10372
20:08:32     System.Tests.MathFTests.Ceiling(value: -0.3183099, expectedResult: 0, allowedVariance: 0) [SKIP]
20:08:32       https://github.com/dotnet/coreclr/issues/10287
20:08:32     System.Tests.MathFTests.Ceiling(value: -0.4342945, expectedResult: 0, allowedVariance: 0) [SKIP]
20:08:32       https://github.com/dotnet/coreclr/issues/10287
20:08:32     System.Tests.MathFTests.Ceiling(value: -0.6366197, expectedResult: 0, allowedVariance: 0) [SKIP]
20:08:32       https://github.com/dotnet/coreclr/issues/10287
20:08:32     System.Tests.MathFTests.Ceiling(value: -0.6931472, expectedResult: 0, allowedVariance: 0) [SKIP]
20:08:32       https://github.com/dotnet/coreclr/issues/10287
20:08:32     System.Tests.MathFTests.Ceiling(value: -0.7071068, expectedResult: 0, allowedVariance: 0) [SKIP]
20:08:32       https://github.com/dotnet/coreclr/issues/10287
20:08:32     System.Tests.MathFTests.Ceiling(value: -0.7853982, expectedResult: 0, allowedVariance: 0) [SKIP]
20:08:32       https://github.com/dotnet/coreclr/issues/10287
20:15:06     System.SpanTests.ReadOnlySpanTests.Equals_Encyclopaedia_ReturnsExpected [SKIP]
20:15:06       Mono issue
20:15:08     System.SpanTests.ReadOnlySpanTests.StartsWith_NullInStrings [SKIP]
20:15:08       Mono issue
20:15:08     System.SpanTests.ReadOnlySpanTests.ToUpper_TurkishI_InvariantCulture [SKIP]
20:15:08       Mono issue
20:15:08     System.SpanTests.ReadOnlySpanTests.ToUpper_TurkishI_TurkishCulture [SKIP]
20:15:08       Mono issue
20:15:08     System.SpanTests.ReadOnlySpanTests.ToUpper_TurkishI_EnglishUSCulture [SKIP]
20:15:08       Mono issue
20:15:17     System.SpanTests.ReadOnlySpanTests.IndexOf_HungarianDoubleCompression_HungarianCulture [SKIP]
20:15:17       Mono issue
20:15:19     System.SpanTests.ReadOnlySpanTests.EndsWith [SKIP]
20:15:19       Mono issue
20:15:20     System.SpanTests.ReadOnlySpanTests.Test_ToUpper_Culture [SKIP]
20:15:20       Mono issue
20:15:21     System.SpanTests.ReadOnlySpanTests.CasingTest [SKIP]
20:15:21       Mono issue
20:15:22     System.SpanTests.ReadOnlySpanTests.IndexOf_TurkishI_TurkishCulture [SKIP]
20:15:22       Mono issue
20:15:22     System.SpanTests.ReadOnlySpanTests.IndexOf_CyrillicE_EnglishUSCulture [SKIP]
20:15:22       Mono issue
20:15:23     System.SpanTests.ReadOnlySpanTests.Equals [SKIP]
20:15:23       Mono issue
20:15:24     System.SpanTests.ReadOnlySpanTests.Test_ToLower_Culture [SKIP]
20:15:24       Mono issue
20:15:24     System.SpanTests.ReadOnlySpanTests.IndexOf_CyrillicE_InvariantCulture [SKIP]
20:15:24       Mono issue
20:15:27     System.SpanTests.ReadOnlySpanTests.IndexOf_TurkishI_EnglishUSCulture [SKIP]
20:15:27       Mono issue
20:15:27     System.SpanTests.ReadOnlySpanTests.StartsWith [SKIP]
20:15:27       Mono issue
20:15:58     System.Tests.TypeTestsExtended.GetTypeByName [SKIP]
20:15:58       Mono issue #11692
20:16:21     System.Reflection.Tests.PointerTests.PointerPropertySetValue [SKIP]
20:16:21       Mono issue
20:16:21     System.Reflection.Tests.PointerTests.PointerFieldGetValue [SKIP]
20:16:21       Mono issue
20:16:21     System.Reflection.Tests.PointerTests.PointerPropertyGetValue [SKIP]
20:16:21       Mono issue
20:16:21     System.Reflection.Tests.PointerTests.PointerMethodDelegateParameter [SKIP]
20:16:21       Mono issue
20:16:21     System.Reflection.Tests.PointerTests.PointerFieldSetValue [SKIP]
20:16:21       Mono issue
20:16:21     System.Reflection.Tests.PointerTests.IntPtrFieldSetValue [SKIP]
20:16:21       Mono issue
20:16:21     System.Reflection.Tests.PointerTests.PointerMethodParameter [SKIP]
20:16:21       Mono issue
20:16:22     System.Reflection.Tests.MemberInfoTests.GenericMethodsInheritTheReflectedTypeOfTheirTemplate [SKIP]
20:16:22       Mono issue #10276
20:16:22     System.Reflection.Tests.MemberInfoTests.InheritedEventAccessors [SKIP]
20:16:22       Mono issue #10277
20:16:31     System.Tests.MathTests.Floor_Double(value: 0, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10288
20:16:31     System.Tests.MathTests.Ceiling_Double(value: -0.318309886183791, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10287
20:16:31     System.Tests.MathTests.Ceiling_Double(value: -0.434294481903252, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10287
20:16:31     System.Tests.MathTests.Ceiling_Double(value: -0.636619772367581, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10287
20:16:31     System.Tests.MathTests.Ceiling_Double(value: -0.693147180559945, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10287
20:16:31     System.Tests.MathTests.Ceiling_Double(value: -0.707106781186548, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10287
20:16:31     System.Tests.MathTests.Ceiling_Double(value: -0.785398163397448, expectedResult: 0, allowedVariance: 0) [SKIP]
20:16:31       https://github.com/dotnet/coreclr/issues/10287
20:16:37     System.Reflection.Tests.TypeTests_HiddenTestingOrder.HideDetectionHappensBeforeBindingFlagChecks [SKIP]
20:16:37       Mono issue #11235
20:16:37     System.Reflection.Tests.TypeTests_HiddenTestingOrder.HideDetectionHappensBeforeStaticInNonFlattenedHierarchyChecks [SKIP]
20:16:37       Mono issue #11235
20:18:04     System.Reflection.Tests.ModuleTests.GetTypes [SKIP]
20:18:04       Mono issue
20:18:05     System.Reflection.Tests.ModuleTests.GetFields [SKIP]
20:18:05       Mono issue
20:18:05     System.Reflection.Tests.ModuleTests.GetField [SKIP]
20:18:05       Mono issue
20:24:00 /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/scripts/ci/babysitter: Sending SIGABRT to `make`
20:24:00 Stacktrace:
20:24:00 
20:24:00   at <unknown> <0xffffffff>
20:24:00   at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal (intptr*,int,bool,int) <0x00007>
20:24:00   at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle,uint,bool,bool) [0x00044] in /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/corlib/System.Threading/WaitHandle.cs:90
20:24:00   at System.Threading.WaitHandle.InternalWaitOne (System.Runtime.InteropServices.SafeHandle,long,bool,bool) [0x00014] in /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/referencesource/mscorlib/system/threading/waithandle.cs:262
20:24:00   at System.Threading.WaitHandle.WaitOne (long,bool) [0x00000] in /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/referencesource/mscorlib/system/threading/waithandle.cs:251
20:24:00   at System.Threading.WaitHandle.WaitOne (int,bool) [0x00019] in /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/referencesource/mscorlib/system/threading/waithandle.cs:218
20:24:00   at System.Threading.WaitHandle.WaitOne () [0x00000] in /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mcs/class/referencesource/mscorlib/system/threading/waithandle.cs:234
20:24:00   at Xunit.ConsoleClient.ConsoleRunner.ExecuteAssembly (object,Xunit.XunitProjectAssembly,bool,bool,System.Nullable`1<bool>,System.Nullable`1<int>,bool,bool,System.Nullable`1<Xunit.AppDomainSupport>,bool,bool,Xunit.XunitFilters,bool) [0x0030a] in <d0a8f9c0a85e45998ced25de766fb22e>:0
20:24:00   at Xunit.ConsoleClient.ConsoleRunner.RunProject (Xunit.XunitProject,bool,System.Nullable`1<bool>,System.Nullable`1<bool>,System.Nullable`1<int>,bool,bool,System.Nullable`1<Xunit.AppDomainSupport>,bool,bool,bool) [0x001e5] in <d0a8f9c0a85e45998ced25de766fb22e>:0
20:24:00   at Xunit.ConsoleClient.ConsoleRunner.EntryPoint (string[]) [0x001cb] in <d0a8f9c0a85e45998ced25de766fb22e>:0
20:24:00   at Xunit.ConsoleClient.Program.Main (string[]) [0x0003b] in <d0a8f9c0a85e45998ced25de766fb22e>:0
20:24:00   at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) [0x0002d] in <d0a8f9c0a85e45998ced25de766fb22e>:0
20:24:00 /proc/self/maps:
20:24:00 aaaae02ec000-aaaae069b000 r-xp 00000000 08:02 40906116                   /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mono/mini/mono-sgen
20:24:00 aaaae06ab000-aaaae06b2000 r--p 003af000 08:02 40906116                   /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mono/mini/mono-sgen
20:24:00 aaaae06b2000-aaaae06b7000 rw-p 003b6000 08:02 40906116                   /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mono/mini/mono-sgen
20:24:00 aaaae06b7000-aaaae0748000 rw-p 00000000 00:00 0 
20:24:00 aaaae255b000-aaaae3da1000 rw-p 00000000 00:00 0                          [heap]
20:24:00 fffe04000000-fffe04022000 rw-p 00000000 00:00 0 
20:24:00 fffe04022000-fffe08000000 ---p 00000000 00:00 0 
20:24:00 fffe0c000000-fffe0c022000 rw-p 00000000 00:00 0 
20:24:00 fffe0c022000-fffe10000000 ---p 00000000 00:00 0 
20:24:00 fffe10000000-fffe10022000 rw-p 00000000 00:00 0 
20:24:00 fffe10022000-fffe14000000 ---p 00000000 00:00 0 
20:24:00 fffe14000000-fffe14022000 rw-p 00000000 00:00 0 
20:24:00 fffe14022000-fffe18000000 ---p 00000000 00:00 0 
20:24:00 fffe18000000-fffe18022000 rw-p 00000000 00:00 0 
20:24:00 fffe18022000-fffe1c000000 ---p 00000000 00:00 0 
20:24:00 fffe1c000000-fffe1c022000 rw-p 00000000 00:00 0 
20:24:00 fffe1c022000-fffe20000000 ---p 00000000 00:00 0 
20:24:00 fffe20000000-fffe20022000 rw-p 00000000 00:00 0 
20:24:00 fffe20022000-fffe24000000 ---p 00000000 00:00 0 
20:24:00 fffe243fd000-fffe28000000 rw-p 00000000 00:00 0 
20:24:00 fffe28000000-fffe28022000 rw-p 00000000 00:00 0 
20:24:00 fffe28022000-fffe2c000000 ---p 00000000 00:00 0 
20:24:00 fffe2c000000-fffe2c022000 rw-p 00000000 00:00 0 
20:24:00 fffe2c022000-fffe30000000 ---p 00000000 00:00 0 
20:24:00 fffe30000000-fffe30022000 rw-p 00000000 00:00 0 
20:24:00 Memory around native instruction pointer (0xffff8faf02cc):
20:24:00 0xffff8faf02bc  03 00 80 d2 21 7c 40 93 48 0c 80 d2 01 00 00 d4  ....!|@.H.......
20:24:00 0xffff8faf02cc  13 00 80 52 a0 a3 40 b9 3d 0c 00 94 bf 7f 00 b9  ...R..@.=.......
20:24:00 0xffff8faf02dc  00 00 80 52 21 00 80 52 82 ff 5f 88 5f 00 00 6b  ...R!..R.._._..k
20:24:00 0xffff8faf02ec  61 00 00 54 81 7f 03 88 83 ff ff 35 a0 00 00 54  a..T.......5...T
20:24:00 
20:24:00 
Native stacktrace:
20:24:00 
20:24:00 	/home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/mono/mini/mono(+0xebb5c) [0xaaaae03d7b5c]
20:24:00 Pkilling 0xffff845bf1b0 from 0xffff8fb56000
20:24:00 Pkilling 0xffff8cacb1b0 from 0xffff8fb56000
20:24:00 Pkilling 0xfffe97d7b1b0 from 0xffff8fb56000
20:24:00 Pkilling 0xffff8621d1b0 from 0xffff8fb56000
20:24:01 /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/scripts/ci/babysitter: Command `make` returned with -6 after SIGABRT
20:24:01 /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/scripts/ci/babysitter: Command `make` timed out with -6
20:24:01 /home/builder/jenkins/workspace/test-mono-pull-request-coop-arm64/scripts/ci/babysitter: Saw timeout in test case None (never allowed). Will halt testing.

The one outstanding failure seen on CI: ^

@akoeplinger akoeplinger merged commit 6e80adb into mono:master Jan 18, 2019
@alexanderkyte
Copy link
Contributor Author

@monojenkins backport 2018-08
@monojenkins backport 2018-10
@monojenkins backport 2018-12

As requested by @jonpryor

monojenkins added a commit that referenced this pull request Jan 21, 2019
)

[2018-12] [runtime] Don\u0027t try (slow) dlopen on android if it doesn\u0027t exist

On android, the dlopen call will take around 1ms per AOT module we try to load. By not using dlopen with the existence check, we rely on a much slower dlopen check that happens later. I think they support dlopen of non-resolved names. 

This might break a few things if we don't use the full path to dlopen. If it does, we should probably add existence checks at the caller, but this will be an optimization that works everywhere.  

@jonpryor @grendello 

Backport of #12074.

/cc @alexanderkyte
@lambdageek
Copy link
Member

Going to need to revert this one. It's been identified as the cause of dotnet/android#3388

lambdageek added a commit to lambdageek/mono that referenced this pull request Aug 21, 2019
The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See mono#12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
monojenkins pushed a commit to monojenkins/mono that referenced this pull request Aug 21, 2019
The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See mono#12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
monojenkins pushed a commit to monojenkins/mono that referenced this pull request Aug 21, 2019
The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See mono#12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
lambdageek added a commit that referenced this pull request Aug 22, 2019
…16387)

The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See #12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
lambdageek pushed a commit that referenced this pull request Aug 22, 2019
…16392)

The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See #12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
lambdageek pushed a commit that referenced this pull request Aug 22, 2019
…16393)

The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See #12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.
ManickaP pushed a commit to ManickaP/runtime that referenced this pull request Jan 20, 2020
…ono/mono#16387)

The intention of calling `g_file_test (file, G_FILE_TEST_EXISTS)` where file is
the name of a shared library we want to open is to speed up probing for
non-existent libraries.

See mono/mono#12074

The problem is that if file is just a simple "libdl.so" then `dlopen (file)`
doesn't just look for it in the current working directory, it will probe some
other paths too.  (For example on desktop linux you'd also look in all the
directories in LD_LIBRARY_PATH).  So the g_file_test() call is not a robust way
to avoid calling dlopen if the filename is relative.

But it actually broke more things: dotnet/android#3388

When probing for "libdl.so" on Android mono_lookup_pinvoke_call will first try
prepending some paths that it knows about and we end up calling
`dlopen ("/system/lib/libdl.so")` which will fail because Bionic has security
restrictions on what code can dlopen something from /system/lib with an
absolute path.  Eventually mono_lookup_pinvoke_call will go back to trying the
bare "libdl.so" which hits `g_file_test` and returns NULL.

The new code only does the file test if we pass it an absolute path, which
gives Bionic's dlopen a chance to deal with relative paths however it needs to.

Commit migrated from mono/mono@e74736a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants