libunwind, -static and -lpthread on ARM

Hello,

I’m trying to cross compile an executable that’s using pthread. Target is armv7-linux-gnueabihf. I’m using the latest raspberry pi os as sysroot. I’ve managed to successfully build llvm, clang + all the runtimes and I’m trying to build a statically linked executable that’s using as less GNU stuff as possible.

clang++ -sysroot=… -stdlib=libc++ --rtlib=compiler-rt -static -resource-dir … -fuse-ld=lld -lc++abi -lunwind test.cpp

The linker error I’m getting is:

ld.lld: error: undefined symbol: _Unwind_ForcedUnwind

referenced by unwind.c:121
unwind.o:(__pthread_unwind) in archive path-to-sysroot/usr/lib/arm-linux-gnueabihf/libpthread.a

Peeking at libunwind’s internals, it seems clear there’s no _Unwind_ForcedUnwind built for ARM (at least not with default options). What options do I have?

  1. Should I add some options when building libunwind so I get _Unwind_ForcedUnwind? I’m not sure this is even possible
  2. Use libgcc?

Thanks,
Andrei

Hello,
I may be wrong here but i was getting something like this in old vers of clang.

Id assume, pthread.a namely unwind.c is using api for unwinding thats incompatible with one provided by clang libs. Prolly assumed gcc model or windows api. Id check source of unwind.c and lookup+use or if absent implement exception api version thats compatible with clang. We will need to ask somebody else which clang lib provides this api. Documentation to clang might have some hints too.

Best regards,
Pawel

sob., 1.05.2021, 03:47 użytkownik Andrei Datcu via llvm-dev <llvm-dev@lists.llvm.org> napisał:

Hello,
I may be wrong here but i was getting something like this in old vers of
clang.

Id assume, pthread.a namely unwind.c is using api for unwinding thats
incompatible with one provided by clang libs. Prolly assumed gcc model or
windows api. Id check source of unwind.c and lookup+use or if absent
implement exception api version thats compatible with clang. We will need
to ask somebody else which clang lib provides this api. Documentation to
clang might have some hints too.

Best regards,
Pawel

sob., 1.05.2021, 03:47 użytkownik Andrei Datcu via llvm-dev <
llvm-dev@lists.llvm.org> napisał:

Hello,

I'm trying to cross compile an executable that's using pthread. Target is
armv7-linux-gnueabihf. I'm using the latest raspberry pi os as sysroot.
I've managed to successfully build llvm, clang + all the runtimes and I'm
trying to build a statically linked executable that's using as less GNU
stuff as possible.

clang++ -sysroot=... -stdlib=libc++ --rtlib=compiler-rt -static
-resource-dir ... -fuse-ld=lld -lc++abi -lunwind test.cpp

You can use --unwindlib=libunwind.

-lc++abi -lunwind are technically not in the right place.
It is ok for ld.lld, though.

The linker error I'm getting is:

ld.lld: error: undefined symbol: _Unwind_ForcedUnwind
>>> referenced by unwind.c:121
>>> unwind.o:(__pthread_unwind) in archive
path-to-sysroot/usr/lib/arm-linux-gnueabihf/libpthread.a

Peeking at libunwind's internals, it seems clear there's no
_Unwind_ForcedUnwind built for ARM (at least not with default options).
What options do I have?

Pending patch adding _Unwind_ForcedUnwind for ARM EHABI
https://reviews.llvm.org/D89570

Missed info from docs its already doable via flags. Updating my knowledge base. Hope it gets implemented soon.

Br,
Pawel

sob., 1.05.2021, 04:23 użytkownik Fangrui Song <maskray@google.com> napisał:

Pending patch adding _Unwind_ForcedUnwind for ARM EHABI
https://reviews.llvm.org/D89570

So until this gets merged, the only remaining option is to use libgcc, correct?

Thanks,
Andrei