This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizers] Libasan failed to be build with -mthumb and -fno-omit-frame-pointer by GCC
ClosedPublic

Authored by denis13 on Aug 2 2018, 5:14 AM.

Details

Summary

GCC fails to build libasan with -mthumb and -fno-omit-frame-pointer

../../../../libsanitizer/sanitizer_common/sanitizer_linux.cc: In function 'sanitizer::uptr sanitizer::internal_clone(int (*)(void*), void*, int, void*, int*, void*, int*)':
../../../../libsanitizer/sanitizer_common/sanitizer_linux.cc:1540:1: error: r7 cannot be used in asm here
}

Regarding to arm ABI, r7 register is using for syscall number, r0 for return value, and r1 - r6 for syscall arguments, by the way r7 for arm with thumb mode is using as frame pointer and it looks like we have a conflict in this case. As far as I understood, GCC has a special check inside IRA
if (!TEST_HARD_REG_BIT (crtl->asm_clobbers, HARD_FRAME_POINTER_REGNUM)), which does not allow to have frame pointer register as clobber register.

There is no issue with clang, but because sanitizer's runtime come from llvm compiler-rt, this fix, ,probably, should be inside llvm compiler-rt.

link to gcc bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86755

Diff Detail

Event Timeline

denis13 created this revision.Aug 2 2018, 5:14 AM
m.ostapenko accepted this revision.Aug 2 2018, 5:21 AM

Looks good, but let's wait for code owners to accept this as well.

lib/sanitizer_common/sanitizer_linux.cc
1600–1603

Please leave a comment here about why we can't use r7 directly.

This revision is now accepted and ready to land.Aug 2 2018, 5:21 AM
denis13 added inline comments.Aug 2 2018, 5:46 AM
lib/sanitizer_common/sanitizer_linux.cc
1600–1603

The problem is -
GCC does not allow to have frame pointer register as clobber register for inline assembler, when flag -fno-omit-frame-pointer is added.

Since arm with thumb mode is using r7 register as frame pointer and at the same time as syscall number register, we got a conflict when is building with -mthumb and -fno-omit-frame-pointer.

But, by the way, there is no issue with clang.

m.ostapenko added inline comments.Aug 2 2018, 6:11 AM
lib/sanitizer_common/sanitizer_linux.cc
1600–1603

Yeah, I've just meant that it would be nice if you leave this comment in the source code at line 1560.

denis13 updated this revision to Diff 158770.Aug 2 2018, 8:54 AM
denis13 updated this revision to Diff 160372.Aug 13 2018, 9:24 AM
m.ostapenko accepted this revision.Aug 13 2018, 12:15 PM

Looks good. Will commit this tomorrow if nobody objects.

Ok for trunk ?

Oh, sorry, forgot about this :(. Please rebase and upload new version.
BTW, please don't forget to add 'llvm-commits' to subscribers so your patch will be visible in ML.

denis13 updated this revision to Diff 164003.Sep 5 2018, 3:28 AM
denis13 closed this revision.Feb 20 2020, 1:57 PM

Since no users anymore for this patch, closing it :)