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

CMake: Add USE_UBSAN #14001

Merged
merged 3 commits into from
Jan 30, 2021
Merged

CMake: Add USE_UBSAN #14001

merged 3 commits into from
Jan 30, 2021

Conversation

glebm
Copy link
Contributor

@glebm glebm commented Jan 29, 2021

  1. Adds an option to use the undefined behaviour sanitizer.
  2. Cleans up the ASAN configuration.

UBSAN is kept debug-only, similar to ASAN, though there is no real reason to do this as they both work just fine in release modes.

@glebm
Copy link
Contributor Author

glebm commented Jan 29, 2021

Does not link with -DUSE_UBSAN=ON:

/usr/bin/ld: lib/libCommon.a(ShaderTranslation.cpp.o):(.data.rel+0x18):
undefined reference to `typeinfo for glslang::TShader'

@glebm
Copy link
Contributor Author

glebm commented Jan 29, 2021

Figured it out

@glebm
Copy link
Contributor Author

glebm commented Jan 29, 2021

UBSAN found 2 UBs on startup: #14002 #14003

@glebm
Copy link
Contributor Author

glebm commented Jan 29, 2021

Most of the UB found by UBSAN immediately are alignment issues.

While x86(_64) is quite lenient towards these (but not in SIMD!), ARM CPUs do not like them at all (immediate crash in scalar code before ARMv7, crash in vectorized code on any ARM)

@hrydgard
Copy link
Owner

Actually it's not true that it's insta-crash on ARMv7, those generally have no problems with scalar load/store with misalignment. ARMv5 and earlier is another story though.

Still, of course, good to fix these.

@hrydgard hrydgard added this to the v1.11.0 milestone Jan 30, 2021
@hrydgard hrydgard merged commit 2399214 into hrydgard:master Jan 30, 2021
@glebm
Copy link
Contributor Author

glebm commented Jan 30, 2021

Yeah that's what I meant with "before ARMv7". MIPS also crashes (e.g. jz4770).

This is not entirely benign even with CPUs that support unaligned access, because none of them support unaligned SIMD instructions. With -O3, the compiler can auto-vectorize code, which then crashes.

@hrydgard
Copy link
Owner

Oh sorry I misread your post. But ARMv6 also handles scalar misalignment fine.

Modern x86 and ARM64 actually both support misaligned SIMD load/stores, although with limitations. Only in the last few generations have x86 allowed unaligned SIMD memory operands.

@glebm glebm deleted the ubsan branch January 30, 2021 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants