llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.54k stars 11.8k forks source link

WebAssembly: libc++abi and clang disagree and width of guard variables in __cxa_guard_acquire/release #42025

Open sbc100 opened 5 years ago

sbc100 commented 5 years ago
Bugzilla Link 42680
Version unspecified
OS Linux
CC @sunfishcode,@mclow,@sbc100

Extended Description

In ItaniumCXXABI.cpp we set UseARMGuardVarABI=true for WebAssembly, but in cxxabi.h we only set the guard type to 32-bit on arm.

This means that clang allocates 4 butes for the guard but libc++abi will assume it 8 bytes and clobber memory on cxa_guard_acquire/cxa_guard_release.

I suggest we simply stop setting UseARMGuardVarABI unless there was a good reason for doing this?

sbc100 commented 5 years ago

Fix is at https://reviews.llvm.org/D64961

sbc100 commented 5 years ago

Ok, we can update libc++abi instead if you prefer.

BTW, arm's rational doens't look like size:

""" 3.2.3.1 Guard variables To support the potential use of initialization guard variables as semaphores that are the target of ARM SWP and LDREX/STREX synchronizing instructions we define a static initialization guard variable to be a 4-byte aligned, 4- byte word with the following inline access protocol. """

Which doesn't mention size saving being their goal but I guess it probably was.

sunfishcode commented 5 years ago

The other way to fix this is would be to have libcxxabi.a's include/__cxxabi_config.h define _LIBCXXABI_GUARD_ABI_ARM when wasm32 is defined.

I think my original reason for enabling the ARM guard ABI was the same reason that ARM does -- to save memory. The only reason it's 64-bit otherwise was that that's what it was on Itanium; we don't actually need that much space.