Some gcc toolchain are optimizing out the memcpy and this causes dax-errors
to not trigger the SIG_BUS when doing memcpy on an mmap'd buffer. By moving
the buffer to a global variable this bypasses the optimization and allow
the test to work as intended.

Signed-off-by: Dave Jiang <[email protected]>
---
 test/dax-errors.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/test/dax-errors.c b/test/dax-errors.c
index 11d0031..9ea5c91 100644
--- a/test/dax-errors.c
+++ b/test/dax-errors.c
@@ -17,6 +17,8 @@
 
 static sigjmp_buf sj_env;
 static int sig_count;
+/* buf is global in order to avoid gcc memcpy optimization */
+static void *buf;
 
 static void sigbus_hdl(int sig, siginfo_t *siginfo, void *ptr)
 {
@@ -27,7 +29,7 @@ static void sigbus_hdl(int sig, siginfo_t *siginfo, void *ptr)
 
 static int test_dax_read_err(int fd)
 {
-       void *base, *buf;
+       void *base;
        int rc = 0;
 
        if (fd < 0) {

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to