Hide Blender symbols by default on all platforms #76442

Open
opened 3 years ago by brecht · 9 comments
brecht commented 3 years ago
Owner

The purpose of this task is to hide Blender symbols by default on all platforms, where previously it was only done on Windows.

Related reports that are solved by hiding symbols, and there have been various others in the past.

  • #74262 (Cycles render hangs on Linux and AMD Radeon RX 5700 XT)
  • blender/blender-addons#76414 (Blender crashing when trying to use Cupy)
  • #68052 (Segfault when accessing Cycles Render Devices preferences with two OpenCL platforms, AMD Mesa Clover and Intel Gen9 NEO)
  • #99900 (Segfault on Linux when running third party Python library function with multithreading enabled)

One solution would be compiling all external libraries with -fvisibility=hidden, however the simpler solution seems to be to use a symbol map to hide all symbols except a few required ones.

Status:

  • Windows
  • Linux (D14971)
  • macOS
The purpose of this task is to hide Blender symbols by default on all platforms, where previously it was only done on Windows. Related reports that are solved by hiding symbols, and there have been various others in the past. * #74262 (Cycles render hangs on Linux and AMD Radeon RX 5700 XT) * blender/blender-addons#76414 (Blender crashing when trying to use Cupy) * #68052 (Segfault when accessing Cycles Render Devices preferences with two OpenCL platforms, AMD Mesa Clover and Intel Gen9 NEO) * #99900 (Segfault on Linux when running third party Python library function with multithreading enabled) One solution would be compiling all external libraries with `-fvisibility=hidden`, however the simpler solution seems to be to use a symbol map to hide all symbols except a few required ones. Status: - [x] Windows - [x] Linux ([D14971](https://archive.blender.org/developer/D14971)) - [ ] macOS
brecht commented 3 years ago
Poster
Owner

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
brecht commented 3 years ago
Poster
Owner

Added subscribers: @brecht, @Sergey

Added subscribers: @brecht, @Sergey
brecht commented 3 years ago
Poster
Owner

What might also help here is to use RLTD_DEEPBIND when loading libraries, so that those libraries use their own symbols over global symbols from Blender.

This could be done in clew and Python (with sys.setdlopenflags).

What might also help here is to use `RLTD_DEEPBIND` when loading libraries, so that those libraries use their own symbols over global symbols from Blender. This could be done in clew and Python (with `sys.setdlopenflags`).
Sergey commented 3 years ago
Owner

Will this break ctypes usage in Python scripts?

RLTD_DEEPBIND seems fine to just go ahead and do it. Just make sure this is done in upstream, covering the generator templates. Think you have commit access to all wranglers we use.

What is also not clear to me is whether anything special is to be done with Python modules (_ssl.so for example). Are they not pulling symbols to global scope already? Is it controlled with sys.setdlopenflags? Or do we need to compile all dependencies with hidden visibility?

Will this break `ctypes` usage in Python scripts? `RLTD_DEEPBIND` seems fine to just go ahead and do it. Just make sure this is done in upstream, covering the generator templates. Think you have commit access to all wranglers we use. What is also not clear to me is whether anything special is to be done with Python modules (`_ssl.so` for example). Are they not pulling symbols to global scope already? Is it controlled with `sys.setdlopenflags`? Or do we need to compile all dependencies with hidden visibility?
brecht commented 3 years ago
Poster
Owner

If ctypes is being used to access Blender symbols, that will indeed break. However that already would not have worked on Windows, so I guess none of the commonly used add-ons/plugins rely on it?

RTLD_DEEPBIND didn't seem to help in #68052. But probably it's the right thing to do regardless.

From my understanding RTLD_DEEPBIND is about preferring local symbols over globals ones when binding symbols. So for example if a Luxrender add-on Python module uses OpenImageDenoise, it would use its own version rather than Blender's.

sys.setdlopenflags sets the default flags used when loading Python modules. I don't think this matters much for bundled Python modules like ssl, it's for add-ons that ship binary Python modules.

If `ctypes` is being used to access Blender symbols, that will indeed break. However that already would not have worked on Windows, so I guess none of the commonly used add-ons/plugins rely on it? `RTLD_DEEPBIND` didn't seem to help in #68052. But probably it's the right thing to do regardless. From my understanding `RTLD_DEEPBIND` is about preferring local symbols over globals ones when binding symbols. So for example if a Luxrender add-on Python module uses OpenImageDenoise, it would use its own version rather than Blender's. `sys.setdlopenflags` sets the default flags used when loading Python modules. I don't think this matters much for bundled Python modules like ssl, it's for add-ons that ship binary Python modules.
Sergey commented 3 years ago
Owner

Did you use RTLD_DEEPBIND , RTLD_NOW | RTLD_DEEPBIND or RTLD_LAZY | RTLD_DEEPBIND ?

The reason our tweaks might not have helped is because the driver might be doing library load, and then you have collision of symbols in the whatever ICD is loading.

In Python I remember having all symbols which are not Py*, _Py*, _py* be hidden. The reason of this was conflict with some of the addon which was loading another .so. Apparently, this mapping file got lost when we've switched to make deps for the release environment. So we either need to restore this mapping file, or use hidden visibility for Python as well. Do you have strong opinion on this topic?

Did you use `RTLD_DEEPBIND` , `RTLD_NOW | RTLD_DEEPBIND` or `RTLD_LAZY | RTLD_DEEPBIND` ? The reason our tweaks might not have helped is because the driver might be doing library load, and then you have collision of symbols in the whatever ICD is loading. In Python I remember having all symbols which are not `Py*`, `_Py*`, `_py*` be hidden. The reason of this was conflict with some of the addon which was loading another .so. Apparently, this mapping file got lost when we've switched to `make deps` for the release environment. So we either need to restore this mapping file, or use hidden visibility for Python as well. Do you have strong opinion on this topic?
Collaborator

This issue was referenced by f937c186de

This issue was referenced by f937c186dedeec4ead1ead9c16646c4aaebafd1b
Collaborator

Added subscriber: @xavierh

Added subscriber: @xavierh
Collaborator

This issue was referenced by cfd16c04f8

This issue was referenced by cfd16c04f8316270b67c73775a5885d6bc4dc4e2
brecht changed title from Build with -fvisibility=hidden on Linux and macOS to Hide Blender symbols by default on all platforms 7 months ago
Sign in to join this conversation.
No Label
Interest/Alembic
Interest/Animation & Rigging
Interest/Asset Browser
Interest/Asset Browser Project Overview
Interest/Audio
Interest/Automated Testing
Interest/Blender Asset Bundle
Interest/Collada
Interest/Compositing
Interest/Core
Interest/Cycles
Interest/Dependency Graph
Interest/Development Management
Interest/Eevee & Viewport
Interest/Freestyle
Interest/Geometry Nodes
Interest/Grease Pencil
Interest/Images & Movies
Interest/Import/Export
Interest/Line Art
Interest/Masking
Interest/Modeling
Interest/Modifiers
Interest/Motion Tracking
Interest/Overrides
Interest/Performance
Interest/Pipeline, Assets & I/O
Interest/Translations
Interest/Undo
Interest/USD
Interest/Video Sequencer
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/Triaging
legacy module/User Interface
legacy module/VFX & Video
legacy project/1.0.0-beta.2
legacy project/Asset Browser (Archived)
legacy project/BF Blender: 2.8
legacy project/BF Blender: After Release
legacy project/BF Blender: Next
legacy project/BF Blender: Regressions
legacy project/BF Blender: Unconfirmed
legacy project/Blender 2.70
legacy project/Code Quest
legacy project/Datablocks and Libraries
legacy project/Eevee
legacy project/Game Animation
legacy project/Game Audio
legacy project/Game Data Conversion
legacy project/Game Engine
legacy project/Game Logic
legacy project/Game Physics
legacy project/Game Python
legacy project/Game Rendering
legacy project/Game UI
legacy project/GPU / Viewport
legacy project/GSoC
legacy project/Infrastructure: Websites
legacy project/LibOverrides - Usability and UX
legacy project/Milestone 1: Basic, Local Asset Browser
legacy project/Nodes
legacy project/Nodes & Physics
legacy project/OpenGL Error
legacy project/Papercut
legacy project/Performance
legacy project/Physics
legacy project/Platforms, Builds, Tests & Devices
legacy project/Pose Library Basics
legacy project/Python API
legacy project/Render & Cycles
legacy project/Render Pipeline
legacy project/Retrospective
legacy project/Sculpt, Paint & Texture
legacy project/Text Editor
legacy project/Tracker Curfew
legacy project/Triaging
legacy project/User Interface
legacy project/UV Editing
legacy project/VFX & Video
legacy project/Virtual Reality
legacy project/Wintab High Frequency
Meta/Good First Issue
Meta/Papercut
migration/requires-manual-verification
Module › Animation & Rigging
Module › Core
Module › Development Management
Module › Eevee & Viewport
Module › Grease Pencil
Module › Modeling
Module › Nodes & Physics
Module › Pipeline, Assets & IO
Module › Platforms, Builds, Tests & Devices
Module › Python API
Module › Render & Cycles
Module › Sculpt, Paint & Texture
Module › Triaging
Module › User Interface
Module › VFX & Video
Platform/FreeBSD
Platform/Linux
Platform/macOS
Platform/Windows
Priority › High
Priority › Low
Priority › Normal
Priority › Unbreak Now!
Status › Archived
Status › Confirmed
Status › Duplicate
Status › Needs Information from Developers
Status › Needs Information from User
Status › Needs Triage
Status › Resolved
Type › Bug
Type › Design
Type › Known Issue
Type › Patch
Type › Report
Type › To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#76442
Loading…
There is no content yet.