From: Ivo Raisr Date: Sun, 26 Feb 2017 21:37:04 +0000 (+0000) Subject: Introduce macro ASSUME_ALIGNED and use it in vki-linux.h. X-Git-Tag: svn/VALGRIND_3_13_0~165 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1a6076bcfb9605198bd2bb3789008979f76d9e5;p=thirdparty%2Fvalgrind.git Introduce macro ASSUME_ALIGNED and use it in vki-linux.h. Reduces the number of compiler warnings on MIPS platforms. Partial fix for BZ#370028. Patch by: Aleksandar Rikalo git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16256 --- diff --git a/NEWS b/NEWS index a156093136..f34dc8f50b 100644 --- a/NEWS +++ b/NEWS @@ -108,6 +108,7 @@ where XXXXXX is the bug number as listed below. 368924 WARNING: unhandled arm64-linux syscall: 84 (sync_file_range) 368925 WARNING: unhandled arm64-linux syscall: 130 (tkill) 368926 WARNING: unhandled arm64-linux syscall: 97 (unshare) +370028 Reduce the number of compiler warnings on MIPS platforms (partial fix) 370635 arm64 missing syscall getcpu 371225 Fix order of timer_{gettime,getoverrun,settime} syscalls on arm64 371412 Rename wrap_sys_shmat to sys_shmat like other wrappers diff --git a/include/pub_tool_basics.h b/include/pub_tool_basics.h index 6ef37c7bf5..4712c117cf 100644 --- a/include/pub_tool_basics.h +++ b/include/pub_tool_basics.h @@ -468,6 +468,17 @@ static inline Bool sr_EQ ( UInt sysno, SysRes sr1, SysRes sr2 ) { } var = { .in = x }; var.out; \ }) +/* Some architectures (eg. mips, arm) do not support unaligned memory access + by hardware, so GCC warns about suspicious situations. This macro could + be used to avoid these warnings but only after careful examination. */ +#define ASSUME_ALIGNED(D, x) \ + ({ \ + union { \ + void *in; \ + D out; \ + } var = {.in = (void *) (x)}; var.out; \ + }) + // Poor man's static assert #define STATIC_ASSERT(x) extern int VG_(VG_(VG_(unused)))[(x) ? 1 : -1] \ __attribute__((unused)) diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index b64b52108a..f70be844bf 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -674,7 +674,8 @@ __KINLINE struct vki_cmsghdr * __vki_cmsg_nxthdr(void *__ctl, __vki_kernel_size_ { struct vki_cmsghdr * __ptr; - __ptr = (struct vki_cmsghdr*)(((unsigned char *) __cmsg) + VKI_CMSG_ALIGN(__cmsg->cmsg_len)); + __ptr = ASSUME_ALIGNED(struct vki_cmsghdr *, + ((unsigned char *) __cmsg) + VKI_CMSG_ALIGN(__cmsg->cmsg_len)); if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size) return (struct vki_cmsghdr *)0;