get memcpy EXC_BAD_ACCESS only with LTO on multi platform!

Innot Sagg donovinsbbkgbi at gmail.com
Fri Jul 17 15:57:53 UTC 2020


I am not sure is this a ldc2 bug or my code bug.  I don't get it 
without LTO. with LTO I get this error on macOS, linux, 
Android(cross build and termux).


the code around this error:

new_ptr = my_zalloc(new_size);
if (! new_ptr ) {
	errno = -2;
	return errno;
}
new_ptr = 1 ;
if ( m_location ) {
	assert(old_ptr);
         // printf("m_location=%p\n", m_location); // add this 
line will not get error;
         // printf("old_ptr=%p\n", old_ptr); // add this line will 
not get error;
	llvm_memcpy(new_ptr, old_ptr, m_location);
}


I am not able to reduce it since I change any things the error 
will gone. for example if I add any one of the printf there will 
no error.

The linux error:
Program received signal SIGSEGV, Segmentation fault.
__memmove_sse2_unaligned_erms () at 
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:384
384	../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No 
such file or directory.
#0  __memmove_sse2_unaligned_erms () at 
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:384
#1  0x0000000000260f9b in expand (bu=0x7fffffffdc78, 
size=<optimized out>, zero=<optimized out>) at /d/buffer.d:919


the android error:
Program received signal SIGSEGV, Segmentation fault.
0x0000007fbf2bf10c in memcpy () from /system/lib64/libc.so
#0  0x0000007fbf2bf10c in memcpy () from /system/lib64/libc.so
#1  0x00000055555b8ad4 in expand (bu=0x7fffffe208, 
size=<optimized out>, zero=<optimized out>) at 
/data/data/com.termux/files/home/d/buffer.d:919

the maxOS error:
* thread #1, queue = 'com.apple.main-thread', stop reason = 
EXC_BAD_ACCESS (code=1, address=0x7ffeefc00000)
   * frame #0: 0x00007fff67c5c929 
libsystem_platform.dylib`_platform_memmove$VARIANT$Haswell + 41
     frame #1: 0x0000000100001e2d tests.exe`expand + 269



the old_ptr is a 512 byte memory block,  m_location = 512.

LTO with -O0, -O1 -O2, -O3 trigger this error. (-O1 on linux no 
error, some of my debug code only work with -O0)

Add printf before the memcpy, or remove LTO will made the error 
go away.

test with ldc2-1.23.0-beta1 and ldc2-1.22.0, same results.

any suggestion how to deal with this case ?








More information about the digitalmars-d-ldc mailing list