[Mac:Xcode] Mysterious pointer-alignment requirement #97693

Closed
opened 2022-04-29 00:07:02 +02:00 by Loren Osborn · 7 comments

System Information
Operating system: macOS-12.3.1-x86_64-i386-64bit 64 Bits
Graphics card: AMD Radeon Pro 5500M OpenGL Engine ATI Technologies Inc. 4.1 ATI-4.8.15

Blender Version
Broken: version: 3.2.0 Alpha, branch: origin/master, commit date: 2022-04-28 04:03, hash: 198a763944
Worked: (newest version of Blender that worked as expected)

Short description of error
This issue was detected by Xcode's "Undefined Behavior Sanitizer"
For some reason Xcode is complaining that pointers to blender::deg::Node objects and it's 4 derived classes must be 16 byte aligned (on a system with 8 byte pointers). Keep in mind, it seems it is requiring the pointers to be aligned... not the objects they are pointing to. It also seems to only affect these 4 classes.

I am pretty stumped on this second issue, so I am request additional help

Exact steps for others to reproduce the error

  1. Open blender project in Xcode as per "Build as an Xcode project" tutorial
  2. Edit the "schema" via Product->Schema->Edit Schema..
  3. Under the "Run" side panel, select the "Diagnostic" page
  4. Under "Runtime Sanitization" (first section) check "Undefined Behavior Sanitizer" (last item in section)
  5. Build and run blender
  6. After blender launches, go into the "Issue Navigator" sidebar (5th icon at the top of the left sidebar) and select "Runtime"
  7. You will see two types of alignment issues reported (that I am submitting as separate bugs)
  • (This issue) for some reason I am not yet able to determine yet, the system expects blender::deg::Node* (and its 4 derived classes) to be aligned to 16 byte boundaries.
  • (#97691 / D14798) within the RNA function dispatch mechanism, ParameterList items are being written and read without to memory alignment.

This issues is present at Blender startup without needing to load any .blend file.

I am including a stack dump of the issue log with stack traces. I hope it will help diagnose the issue.

alignment_issue_dump_traces.txt

**System Information** Operating system: macOS-12.3.1-x86_64-i386-64bit 64 Bits Graphics card: AMD Radeon Pro 5500M OpenGL Engine ATI Technologies Inc. 4.1 ATI-4.8.15 **Blender Version** Broken: version: 3.2.0 Alpha, branch: origin/master, commit date: 2022-04-28 04:03, hash: 198a763944 Worked: (newest version of Blender that worked as expected) **Short description of error** This issue was detected by Xcode's "Undefined Behavior Sanitizer" For some reason Xcode is complaining that pointers to `blender::deg::Node` objects and it's 4 derived classes must be 16 byte aligned (on a system with 8 byte pointers). Keep in mind, it seems it is requiring the **pointers** to be aligned... not the objects they are pointing to. It also seems to only affect these 4 classes. I am pretty stumped on this second issue, so I am request additional help **Exact steps for others to reproduce the error** 1. Open blender project in Xcode as per "Build as an Xcode project" tutorial 2. Edit the "schema" via Product->Schema->Edit Schema.. 3. Under the "Run" side panel, select the "Diagnostic" page 4. Under "Runtime Sanitization" (first section) check "Undefined Behavior Sanitizer" (last item in section) 5. Build and run blender 6. After blender launches, go into the "Issue Navigator" sidebar (5th icon at the top of the left sidebar) and select "Runtime" 7. You will see two types of alignment issues reported (that I am submitting as separate bugs) * (This issue) for some reason I am not yet able to determine yet, the system expects `blender::deg::Node*` (and its 4 derived classes) to be aligned to 16 byte boundaries. * (#97691 / [D14798](https://archive.blender.org/developer/D14798)) within the RNA function dispatch mechanism, ParameterList items are being written and read without to memory alignment. This issues is present at Blender startup without needing to load any .blend file. I am including a stack dump of the issue log with stack traces. I hope it will help diagnose the issue. [alignment_issue_dump_traces.txt](https://archive.blender.org/developer/F13036070/alignment_issue_dump_traces.txt)
Author

Added subscriber: @linux_dr

Added subscriber: @linux_dr
Member

Added subscriber: @LazyDodo

Added subscriber: @LazyDodo
Member

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

Changed status from 'Needs Triage' to: 'Archived'
Member

for developer questions please use devtalk.blender.org, i left you some pointers on chat how to improve your questions.

for developer questions please use devtalk.blender.org, i left you some pointers on chat how to improve your questions.

Added subscriber: @brecht

Added subscriber: @brecht

For reference, this is most likely due to the use of MEM_CXX_CLASS_ALLOC_FUNCS in the depsgraph code.

The operator new overloading there does not seem to take into account alignment.

For reference, this is most likely due to the use of `MEM_CXX_CLASS_ALLOC_FUNCS` in the depsgraph code. The `operator new` overloading there does not seem to take into account alignment.
Author

@brecht, I will look into this. I didn’t look for a custom operator new that might not respect memory alignments bigger than maxalign_t. That said, my first attempt to resolve this was adding alignas(sizeof(void*)*2) to all 5 affected classes, which did not resolve the issue.

Because of this, I [perhaps wrongly] presumed that the issue was the alignment of the pointers, rather than the objects pointed to. The pointers are mostly allocated on the stack so would not be affected by operator new; so I wrote a special AlignedRawPointer<> class, based on AlignedStorage<>, and replaced all blender::deg::Node*s (and derived pointers) with this custom pointer type, but haven’t gotten it to compile properly yet.

I will investigate if operator new properly handles 16 byte alignments, and resolve that, before I waste any more time on my AlignedRawPointer<> implementation.

I did a quick search for MEM_CXX_CLASS_ALLOC_FUNCS and did not find much relevant. Thank you for the tip; I will investigate it more thoroughly. Thank you for the suggestion.

If you have any other suggestions, I’d appreciate them.

@brecht, I will look into this. I didn’t look for a custom `operator new` that might not respect memory alignments bigger than `maxalign_t`. That said, my first attempt to resolve this was adding `alignas(sizeof(void*)*2)` to all 5 affected classes, which did not resolve the issue. Because of this, I [perhaps wrongly] presumed that the issue was the alignment of the **pointers**, rather than the objects pointed to. The pointers are mostly allocated on the **stack** so would not be affected by `operator new`; so I wrote a special `AlignedRawPointer<>` class, based on `AlignedStorage<>`, and replaced all `blender::deg::Node*`s (and derived pointers) with this custom pointer type, but haven’t gotten it to compile properly yet. I will investigate if `operator new` properly handles 16 byte alignments, and resolve that, before I waste any more time on my `AlignedRawPointer<>` implementation. I did a quick search for `MEM_CXX_CLASS_ALLOC_FUNCS` and did not find much relevant. Thank you for the tip; I will investigate it more thoroughly. Thank you for the suggestion. If you have any other suggestions, I’d appreciate them.
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
3 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#97693
No description provided.