Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link Time Optimization (-flto) triggers static initialization bug in Open3D #4747

Open
3 tasks done
roehling opened this issue Feb 11, 2022 · 0 comments
Open
3 tasks done
Assignees
Labels
build/install Build or installation issue

Comments

@roehling
Copy link
Contributor

Checklist

Steps to reproduce the issue

I first cloned Open3D by:

git clone https://github.com/isl-org/Open3D.git
cd Open3D

Then, I build Open3D (on Debian Sid) with:

mkdir build
cd build
cmake -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON ..
make -j$(nproc)

Error message

Build succeeds without error, but the Open3D GUI will fail to load materials at runtime.

Open3D, Python and System information

- Operating system: Debian unstable ("sid")
- Python version: Python 3.9
- Open3D version: 0.14.1
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: build from source
- Compiler version (if built from source): gcc 11

Additional information

I tracked the bug to a corrupted defaults_mapping::shader_mappings map. The map has static storage and depends on members of FilamentResourceManager, again with stattic storage. This creates a initialization order dependency across translation units, also known as the static initialization order fiasco, and will break Open3D if the static variables from FilamentResourceManager.cpp are not initialized before those in FilamentScene.cpp.

As initialization normally happens in the order the object files are linked, and (thanks to the alphabetic sorting) FilamentResourceManager.cpp comes before FilamentScene.cpp, this bug has not surfaced before. However, LTO seems to mess with the initialization order, thereby exposing the bug.

The static initialization order problem is usually avoided using the Construct On First Use idiom. For now, the bug can be mitigated by disabling/not enabling Link Time Optimization for the Open3D main library. The Python module is not affected and should be built with LTO for performance reasons, actually.

@roehling roehling added the build/install Build or installation issue label Feb 11, 2022
@ssheorey ssheorey self-assigned this Feb 11, 2022
@ssheorey ssheorey assigned errissa and unassigned ssheorey Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build/install Build or installation issue
Projects
None yet
Development

No branches or pull requests

3 participants