This is an archive of the discontinued LLVM Phabricator instance.

[libcxxabi][ARM] Make CXX_end_cleanup compatible with Armv6-M
ClosedPublic

Authored by danielkiss on Nov 4 2021, 4:20 AM.

Details

Summary

On Armv6-M the branch may not able to reach the _Unwind_Resume function because it's relocation(R_ARM_THM_JUMP11) is in -2048, 2047 range only.

Diff Detail

Event Timeline

danielkiss created this revision.Nov 4 2021, 4:20 AM
danielkiss requested review of this revision.Nov 4 2021, 4:20 AM
stuij accepted this revision.Nov 4 2021, 6:07 AM

LGTM

This revision is now accepted and ready to land.Nov 4 2021, 6:07 AM
chill requested changes to this revision.Nov 4 2021, 6:21 AM
chill added inline comments.
libcxxabi/src/cxa_exception.cpp
385–386

I'm not entirely convinced.
Isn't this function supposed to preserve r3 ?
Shouldn't the linker take care if the branch is too far away?
If not the linker, couldn't we use r12/ip for the call ?
e.g.

...
push {r1, r2, r3, lr}
bl   __cxa_end_cleanup_impl
ldr  r3, =_Unwind_Resume
mov  r12, r3
pop  {r1, r2, r3, r4}
mov  lr, r4
bx   r12
...
This revision now requires changes to proceed.Nov 4 2021, 6:21 AM
lenary added a subscriber: lenary.Nov 4 2021, 6:22 AM
lenary added inline comments.
libcxxabi/src/cxa_exception.cpp
385–386

This clobbers r3 - was that your intention (given you pushed and popped it)? r4 is clobbered by the function already, so maybe that would be better if you need to preserve as many registers as possible for unwinding?

lenary added inline comments.Nov 4 2021, 6:29 AM
libcxxabi/src/cxa_exception.cpp
385–386

"Shouldn't the linker take care if the branch is too far away?"

sadly not: R_ARM_THM_JUMP11 (the relocation on this b in armv6m) is not one of the relocations the ABI lets the linker insert a veneer for. Unlike aarch64 where veneers are allowed anywhere, on aarch32 veneers are only allowed to be used with specific relocations.

danielkiss updated this revision to Diff 384736.Nov 4 2021, 6:48 AM
danielkiss marked 3 inline comments as done.Nov 4 2021, 6:52 AM
danielkiss added inline comments.
libcxxabi/src/cxa_exception.cpp
385–386

Right, r4 is just saved to align the stack so it could be reused here.

chill accepted this revision.Nov 4 2021, 7:00 AM

LGTM

This revision is now accepted and ready to land.Nov 4 2021, 7:00 AM
lenary accepted this revision.Nov 4 2021, 7:04 AM

LGTM. Thanks for fixing this!

This revision was automatically updated to reflect the committed changes.
danielkiss marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2021, 8:29 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
thakis added a subscriber: thakis.Nov 5 2021, 8:15 AM

This breaks out build.

[104/58411] SOLINK ./libc++_chrome.cr.so
FAILED: libc++_chrome.cr.so libc++_chrome.cr.so.TOC lib.unstripped/libc++_chrome.cr.so
python3 "../../build/toolchain/gcc_solink_wrapper.py" --readelf="../../third_party/llvm-build/Releas...(too long)
ld.lld: error: relocation R_ARM_ABS32 cannot be used against symbol '_Unwind_Resume'; recompile with -fPIC
>>> defined in obj/buildtools/third_party/libunwind/libunwind/Unwind-EHABI.o
>>> referenced by cxa_exception.cpp
>>>               obj/buildtools/third_party/libc++abi/libc++abi/cxa_exception.o:(.text.__cxa_end_cleanup+0x10)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

(https://bugs.chromium.org/p/chromium/issues/detail?id=1267270)

Please take a look.

This breaks out build.

[104/58411] SOLINK ./libc++_chrome.cr.so
FAILED: libc++_chrome.cr.so libc++_chrome.cr.so.TOC lib.unstripped/libc++_chrome.cr.so
python3 "../../build/toolchain/gcc_solink_wrapper.py" --readelf="../../third_party/llvm-build/Releas...(too long)
ld.lld: error: relocation R_ARM_ABS32 cannot be used against symbol '_Unwind_Resume'; recompile with -fPIC
>>> defined in obj/buildtools/third_party/libunwind/libunwind/Unwind-EHABI.o
>>> referenced by cxa_exception.cpp
>>>               obj/buildtools/third_party/libc++abi/libc++abi/cxa_exception.o:(.text.__cxa_end_cleanup+0x10)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

(https://bugs.chromium.org/p/chromium/issues/detail?id=1267270)

Please take a look.

Thanks for the report, the above proposed change works for chrome and embedded targets too.
I'll reland the patch end of Monday.

libcxxabi/src/cxa_exception.cpp
385–386

Hi @danielkiss,

same as for @thakis, these changes have broken the armv7 toolchain builder

11.219 [3/3/902] Linking CXX shared library C:\buildbot\as-builder-1\x-armv7l\build\lib\armv7-unknown-linux-gnueabihf\libc++abi.so.1.0
FAILED: C:/buildbot/as-builder-1/x-armv7l/build/lib/armv7-unknown-linux-gnueabihf/libc++abi.so.1.0 
cmd.exe /C "cd . && C:\buildbot\as-builder-1\x-armv7l\build\.\bin\clang++.exe --target=armv7-unknown-linux-gnueabihf -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections --target=armv7-unknown-linux-gnueabihf --sysroot=C:/buildbot/.arm-ubuntu  -O3 -DNDEBUG  -Wl,-z,nodelete -Wl,--color-diagnostics  --target=armv7-unknown-linux-gnueabihf --sysroot=C:/buildbot/.arm-ubuntu -nostdlib++ -shared -Wl,-soname,libc++abi.so.1 -o C:\buildbot\as-builder-1\x-armv7l\build\lib\armv7-unknown-linux-gnueabihf\libc++abi.so.1.0 libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_aux_runtime.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_default_handlers.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_demangle.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_exception_storage.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_guard.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_handlers.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_vector.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_virtual.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_exception.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_stdexcept.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/stdlib_typeinfo.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/abort_message.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/fallback_malloc.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/private_typeinfo.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_exception.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_personality.cpp.o libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_thread_atexit.cpp.o  -Wl,-rpath,$ORIGIN/../lib  C:/buildbot/as-builder-1/x-armv7l/build/lib/clang/14.0.0/lib/armv7-unknown-linux-gnueabihf/libclang_rt.builtins.a  C:/buildbot/as-builder-1/x-armv7l/build/lib/armv7-unknown-linux-gnueabihf/libunwind.a  -lpthread  -lc  C:/buildbot/as-builder-1/x-armv7l/build/lib/clang/14.0.0/lib/armv7-unknown-linux-gnueabihf/libclang_rt.builtins.a  -ldl  -lpthread && cd ."
ld.lld: error: relocation R_ARM_ABS32 cannot be used against symbol '_Unwind_Resume'; recompile with -fPIC
>>> defined in C:/buildbot/as-builder-1/x-armv7l/build/lib/armv7-unknown-linux-gnueabihf/libunwind.a(Unwind-EHABI.cpp.o)
>>> referenced by cxa_exception.cpp
>>>               libcxxabi/src/CMakeFiles/cxxabi_shared.dir/cxa_exception.cpp.o:(.text.__cxa_end_cleanup+0x18)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

https://lab.llvm.org/buildbot/#/builders/60/builds/5303

Hi @danielkiss,
The buildbot's build is broken already for more than one day without attention. Sorry, but I'm going to revert this commit.