microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.16k stars 28.53k forks source link

Allow extensions to pass `DYLD_LIBRARY_PATH` to spawned processes on Mac #123997

Closed Ptival closed 3 years ago

Ptival commented 3 years ago

In https://github.com/microsoft/vscode/issues/88306 the ability to pass DYLD_LIBRARY_PATH to spawned processes was fixed on Mac by declaring proper entitlements.

In fixing https://github.com/microsoft/vscode/issues/104525 however, it was decided to explicitly unset this variable when spawning processes, which is a little weird:

https://github.com/microsoft/vscode/blob/82767cc1d7bf8cdea0f2897276d5d15aee91f3d9/src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts#L176-L180

This unfortunately causes problems. In my case, the Haskell Language Server spawns the cabal tool to compile Haskell files, and that tool needs to receive proper values for DYLD_LIBRARY_PATH for compilation to succeed. The removal of that variable explicitly seems a little bit questionable, so could we at least have some sort of option to change this behavior?

alexdima commented 3 years ago

@deepak1556 We are now deleting the environment variable DYLD_LIBRARY_PATH when spawning the extension host due to extension host crashes we have seen where Electron was respecting it. Is there a safe way where we could allow it again? Would it be possible to disable respecting DYLD_LIBRARY_PATH in Electron so we can revert that change?

deepak1556 commented 3 years ago

Is there a safe way where we could allow it again?

We could copy the value of DYLD_LIBRARY_PATH into DYLD_FALLBACK_LIBRARY_PATH before launching the extension host process, not sure if it will cover all the cases. But based on dlopen docs, it is always the end node that gets searched, so should be a safe fallback.

dlopen() searches for a compatible Mach-O file in the directories specified by a set of environment variables and the process's current working directory.  When set, the environ-
     ment variables contain a colon-separated list of directory paths, which can be absolute or relative to the current working directory.

     When path does not contain a slash character (i.e. it is just a leaf name), dlopen() searches the following until it finds a compatible Mach-O file: $LD_LIBRARY_PATH,
     $DYLD_LIBRARY_PATH, current working directory, $DYLD_FALLBACK_LIBRARY_PATH.

Would it be possible to disable respecting DYLD_LIBRARY_PATH in Electron so we can revert that change?

No its a OS thing. The issue is not directly linked to Electron, when we create the extension host as a fork of the renderer process, the renderer helper executable is dynamically linked to a number of system libraries

otool -L Electron\ Framework ``` Electron Framework: @rpath/Electron Framework.framework/Electron Framework (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 164.0.0) /System/Library/Frameworks/LocalAuthentication.framework/Versions/A/LocalAuthentication (compatibility version 1.0.0, current version 827.40.37) /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0) /System/Library/Frameworks/Quartz.framework/Versions/A/Quartz (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 59754.41.1) /System/Library/Frameworks/SecurityInterface.framework/Versions/A/SecurityInterface (compatibility version 1.0.0, current version 55149.40.3) /System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement (compatibility version 1.0.0, current version 2038.40.38) /System/Library/Frameworks/StoreKit.framework/Versions/A/StoreKit (compatibility version 1.0.0, current version 379.0.0) @rpath/Squirrel.framework/Squirrel (compatibility version 0.0.0, current version 0.0.0) @rpath/ReactiveObjC.framework/ReactiveObjC (compatibility version 0.0.0, current version 0.0.0) @rpath/Mantle.framework/Mantle (compatibility version 0.0.0, current version 0.0.0) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 54.0.0) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2022.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.106.0) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1770.106.0) /System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork (compatibility version 1.0.0, current version 1207.0.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1122.4.0) /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1109.40.9) /System/Library/Frameworks/IOSurface.framework/Versions/A/IOSurface (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1463.0.0) /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/Metal.framework/Versions/A/Metal (compatibility version 1.0.0, current version 244.32.6, weak) /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0) /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0) /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1000.0.0) /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0) /System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/IOBluetooth.framework/Versions/A/IOBluetooth (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreMIDI.framework/Versions/A/CoreMIDI (compatibility version 1.0.0, current version 69.0.0) /System/Library/Frameworks/MediaAccessibility.framework/Versions/A/MediaAccessibility (compatibility version 1.0.0, current version 62.0.0) /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/ForceFeedback.framework/Versions/A/ForceFeedback (compatibility version 1.0.0, current version 1.0.2) /System/Library/Frameworks/GameController.framework/Versions/A/GameController (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreLocation.framework/Versions/A/CoreLocation (compatibility version 1.0.0, current version 2420.8.10) /System/Library/Frameworks/CoreWLAN.framework/Versions/A/CoreWLAN (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/ImageCaptureCore.framework/Versions/A/ImageCaptureCore (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/MediaPlayer.framework/Versions/A/MediaPlayer (compatibility version 1.0.0, current version 1.0.0, weak) /System/Library/Frameworks/MetalKit.framework/Versions/A/MetalKit (compatibility version 1.0.0, current version 147.1.0, weak) /System/Library/Frameworks/Vision.framework/Versions/A/Vision (compatibility version 1.0.0, current version 4.0.90, weak) @rpath/libffmpeg.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/lib/libbsm.0.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libpmenergy.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libpmsample.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libsandbox.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0) /System/Library/Frameworks/CoreBluetooth.framework/Versions/A/CoreBluetooth (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage (compatibility version 1.0.1, current version 5.0.0) /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0) ```

https://github.com/microsoft/vscode/issues/104525 is a case where the libraries from DYLD_LIBRARY_PATH where messing with the symbols of the above dependent libraries. We decided to not respect this variable inside vscode to prevent such crashes.

deepak1556 commented 3 years ago

@Ptival does DYLD_FALLBACK_LIBRARY_PATH work for your use case ?