我开发了一个TensorFlow定制操作的小型库 . 这些操作在C中编程并使用Eigen .

当我使用 -march=native 编译器选项编译自定义ops模块时,会发生奇怪的事情 . 生成的模块将始终以libsystem_malloc.dylib中源自free()的"pointer being freed was not allocated"错误中止 . 如果我在没有 -march=native 编译器选项的情况下编译,那么就没有崩溃;也就是说,用这个Bazel命令编译:

bazel build -c opt --copt=-march=native --config=cuda //tensorflow/core/user_ops:custom_ops.so

..生成崩溃模块,但这很好:

bazel build -c opt --config=cuda //tensorflow/core/user_ops:custom_ops.so

lldb 中运行测试脚本并进行反汇编,我看到完全相同的程序集,模数为ASLR .

那么,用 -march=native 编译导致"pointer being freed was not allocated"错误的原因可能是什么?

我的编译器是Apple LLVM版本8.0.0(clang-800.0.42.1),我正在运行macOS'Sierra'10.12.4(16E195) .

UPDATE 地址消毒剂报告:

==4445==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x62a000234220 in thread T29
    #0 0x1000d9db9 in wrap_free (libclang_rt.asan_osx_dynamic.dylib+0x4adb9)
...

0x62a000234220 is located 32 bytes inside of 24032-byte region [0x62a000234200,0x62a000239fe0)
allocated by thread T29 here:
    #0 0x1000d9bf0 in wrap_malloc (libclang_rt.asan_osx_dynamic.dylib+0x4abf0)
    #1 0x12f4dec62 in Eigen::BDCSVD<Eigen::Matrix<double, -1, -1, 1, -1, -1> >::allocate(long, long, unsigned int) (custom_ops.so+0x26fc62)
    #2 0x12f4d20a1 in Eigen::BDCSVD<Eigen::Matrix<double, -1, -1, 1, -1, -1> >::compute(Eigen::Matrix<double, -1, -1, 1, -1, -1> const&, unsigned int) (custom_ops.so+0x2630a1)
    #3 0x12f6822d6 in Eigen::BDCSVD<Eigen::Matrix<double, -1, -1, 1, -1, -1> >::BDCSVD(Eigen::Matrix<double, -1, -1, 1, -1, -1> const&, unsigned int) (custom_ops.so+0x4132d6)
...