Hide Blender symbols by default on all platforms #76442

Open
opened 2020-05-05 12:22:15 +02:00 by Brecht Van Lommel · 9 comments

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
Author
Owner

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

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

Added subscribers: @brecht, @Sergey

Added subscribers: @brecht, @Sergey
Author
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`).

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?
Author
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.

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?

This issue was referenced by f937c186de

This issue was referenced by f937c186dedeec4ead1ead9c16646c4aaebafd1b
Member

Added subscriber: @xavierh

Added subscriber: @xavierh

This issue was referenced by cfd16c04f8

This issue was referenced by cfd16c04f8316270b67c73775a5885d6bc4dc4e2
Brecht Van Lommel changed title from Build with -fvisibility=hidden on Linux and macOS to Hide Blender symbols by default on all platforms 2022-07-29 18:04:36 +02:00
Philipp Oeser removed the
Interest
Platforms, Builds & Tests
label 2023-02-10 08:58:24 +01:00
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
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
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
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 Info 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
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#76442
No description provided.