This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Don't use ARM_VFPREGS_SIZE for old kernels.
ClosedPublic

Authored by m.ostapenko on Nov 23 2015, 5:55 AM.

Details

Summary

Hi,

after recent sanitzer library merge to GCC we have noticed, that for older kernel versions ARM_VFPREGS_SIZE is not defined that leads to such error on arm-none-linux-gnueabi:

libtool: compile:
/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/./gcc/xgcc
-shared-libgcc -B/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/g
cc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/./gcc -nostdinc++
-L/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/
libstdc++-v3/src
-L/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/src/.libs
-L/tmp/1800227_1.tmpdir/
aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-linux-gnueabi/gcc3/arm-none-linux-gnueabi/libstdc++-v3/libsupc++/.libs
-B/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/t
ools/arm-none-linux-gnueabi/bin/
-B/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/lib/
-isystem /tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gc
c-fsf-gccsrc/tools/arm-none-linux-gnueabi/include -isystem
/tmp/1800227_1.tmpdir/aci-gcc-fsf/builds/gcc-fsf-gccsrc/tools/arm-none-linux-gnueabi/sys-include
-D_GNU_SOURCE -D_DEBU
G -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_LIMIT_MACROS -DHAVE_RPC_XDR_H=1 -DHAVE_TIRPC_RPC_XDR_H=0 -I.
-I/tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsr
c/libsanitizer/sanitizer_common -I.. -I
/tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libsanitizer/include
-isystem /tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/
gccsrc/libsanitizer/include/system -Wall -W -Wno-unused-parameter
-Wwrite-strings -pedantic -Wno-long-long -fPIC -fno-builtin
-fno-exceptions -fno-rtti -fomit-frame-pointer -fun
wind-tables -fvisibility=hidden -Wno-variadic-macros
-I../../libstdc++-v3/include
-I../../libstdc++-v3/include/arm-none-linux-gnueabi
-I/tmp/1800227_1.tmpdir/aci-gcc-fsf/sources
/gcc-fsf/gccsrc/libsanitizer/../libstdc++-v3/libsupc++ -std=gnu++11
-DSANITIZER_LIBBACKTRACE -DSANITIZER_CP_DEMANGLE -I
/tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/
libsanitizer/../libbacktrace -I ../libbacktrace -I
/tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libsanitizer/../include
-include /tmp/1800227_1.tmpdir/aci-gcc-fsf/so
urces/gcc-fsf/gccsrc/libsanitizer/libbacktrace/backtrace-rename.h -g
-O2 -D_GNU_SOURCE -MT sanitizer_platform_limits_posix.lo -MD -MP -MF
.deps/sanitizer_platform_limits_posix.T
po -c /tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
 -fPIC -DPIC -o .libs/sanitizer_platform_limits_p
osix.o
/tmp/1800227_1.tmpdir/aci-gcc-fsf/sources/gcc-fsf/gccsrc/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc:326:44:
error: 'ARM_VFPREGS_SIZE' was not declared in t
his scope
   unsigned struct_user_vfpregs_struct_sz = ARM_VFPREGS_SIZE;
                                            ^~~~~~~~~~~~~~~~

make[4]: *** [sanitizer_platform_limits_posix.lo] Error 1

After some investigation, I found out that ptrace_getvfpregs and ptrace_setvfpregs have a guard against such an issue:

   int ptrace_getfpxregs = -1;
   int ptrace_setfpxregs = -1;
 #endif // PTRACE_GETFPXREGS/PTRACE_SETFPXREGS
+#if defined(PTRACE_GETVFPREGS) && defined(PTRACE_SETVFPREGS)
+  int ptrace_getvfpregs = PTRACE_GETVFPREGS;
+  int ptrace_setvfpregs = PTRACE_SETVFPREGS;
+#else
+  int ptrace_getvfpregs = -1;
+  int ptrace_setvfpregs = -1;
+#endif

Perhaps we could do the same thing for ARM_VFPREGS_SIZE?

Diff Detail

Repository
rL LLVM

Event Timeline

m.ostapenko retitled this revision from to [sanitizer] Don't use ARM_VFPREGS_SIZE for old kernels..
m.ostapenko updated this object.
m.ostapenko added reviewers: kcc, samsonov, eugenis, rengolin.
m.ostapenko set the repository for this revision to rL LLVM.

Ugh, just noticed, that PTRACE_SETVFPREGS and PTRACE_GETVFPREGS were introduced in Linux 2.6.30 and ARM_VFPREGS_SIZE only in 3.0. So, struct_user_vfpregs_struct_sz = 0 is not safe for 2.6.30 - 2.6.39. Fix by defining ARM_VFPREGS_SIZE as 32 * 8 /*fpregs*/ + 4 /*fpscr*/ for these kernels.

ygribov added inline comments.Nov 23 2015, 8:02 AM
lib/sanitizer_common/sanitizer_platform_limits_posix.cc
127 ↗(On Diff #40928)

Perhaps also assert equality in #else branch?

emaste added a subscriber: emaste.Nov 23 2015, 8:19 AM

In the eventual commit message please make sure to indicate which kernel you're referring to (i.e., Linux), since this file is used on FreeBSD as well.

m.ostapenko added inline comments.Nov 23 2015, 10:13 AM
lib/sanitizer_common/sanitizer_platform_limits_posix.cc
127 ↗(On Diff #40928)

I can do it, but I'll need to move ARM_VFPREGS_SIZE definition down in source code to be able use ASan internal checks (such as COMPILER_CHECK), perhaps just before its usage. Is it OK?

Addressing Yura's comment.

m.ostapenko marked 2 inline comments as done.Nov 23 2015, 12:03 PM
samsonov edited edge metadata.Nov 24 2015, 11:00 AM

I'll let ARM folks comment, but looks reasonable.

Thanks! Will commit this soon if no objections.

This revision was automatically updated to reflect the committed changes.