Update:
This doesn’t seem to have anything to do with MKL. Just linking with all the boost libraries is enough to cause this. I was able to repro this with just a few files. I am fairly certain this is because of some issue with linking incorrect libraries. Please let me know. I realize that I don’t need all these libraries for the simple test cases I have written.
My g++ version is 4.4.6
Boost version 1.63


File1:
// cat mklmain.cpp 

#define BOOST_ALL_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>



File2:
// cat mkl1.cpp 


#include <boost/test/unit_test.hpp>
#include "logging-helper.h"

BOOST_FIXTURE_TEST_SUITE(mkltest1, Fixture)

BOOST_AUTO_TEST_CASE(math_test_functions1)
{
                BOOST_LOG_SEV(lg, trace) << "Starting test case for mkl test 1";              
               float dot = 3;
                BOOST_TEST(dot == 3);
                BOOST_LOG_SEV(lg, trace) << "Ending test case for mkl test 1";                
}

BOOST_AUTO_TEST_SUITE_END()


File3:
// cat mkl2.cpp 


#include <boost/test/unit_test.hpp>
#include "logging-helper.h"

BOOST_FIXTURE_TEST_SUITE(mkltest2, Fixture)

BOOST_AUTO_TEST_CASE(math_test_functions2)
{
                BOOST_LOG_SEV(lg, trace) << "Starting test case for mkl test 2";              
               float dot = 3;
                BOOST_TEST(dot == 3);
                BOOST_LOG_SEV(lg, trace) << "Ending test case for mkl test 2";                
}

BOOST_AUTO_TEST_SUITE_END()



File4:
// cat logging-helper.h 
// I realize that not all these headers are necessary. Was trying out different things.

#pragma once
#define BOOST_LOG_DYN_LINK 1
#include <boost/move/utility_core.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/sources/severity_logger.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
using namespace logging::trivial;



class Fixture
{
        public:
                src::severity_logger<severity_level> lg;
                
                Fixture(){       
                
                        logging::core::get()->remove_all_sinks();

                                logging::add_console_log
                        (
                                                std::cout,
                                                keywords::format = "[%TimeStamp%]: %Message%"
                                );
                
                        logging::add_common_attributes();
                }
};



My  compile/link line is this

g++ -I/home/anandrs/Downloads/boost_1_63_0 -L/home/anandrs/Downloads/boost_1_63_0/stage/lib mkl1.cpp mkl2.cpp mklmain.cpp -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_context -lboost_locale -lboost_log -lboost_log_setup -lboost_timer -lboost_type_erasure -lboost_wave -lboost_chrono -lboost_filesystem -lboost_graph -lboost_random  -lboost_thread  -lboost_wserialization  -lboost_atomic  -lboost_container  -lboost_date_time  -lboost_iostreams  -lboost_math_c99  -lboost_math_c99f  -lboost_math_c99l  -lboost_math_tr1  -lboost_math_tr1f  -lboost_math_tr1l -lboost_program_options  -lboost_regex  -lboost_serialization  -lboost_signals  -lboost_system  -lboost_exception  -lboost_test_exec_monitor -o BoostMKL


valgrind ./BoostMKL
==83998== Memcheck, a memory error detector
==83998== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==83998== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==83998== Command: ./BoostMKL
==83998== 
Running 2 test cases...
[2017-02-23 10:11:04.603945]: Starting test case for mkl test 2
[2017-02-23 10:11:04.759958]: Ending test case for mkl test 2
[2017-02-23 10:11:04.824863]: Starting test case for mkl test 1
[2017-02-23 10:11:04.830820]: Ending test case for mkl test 1

*** No errors detected
==83998== Invalid read of size 4
==83998==    at 0x93124B6: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib64/libstdc++.so.6.0.13)
==83998==    by 0x9A4AEBC: __cxa_finalize (in /lib64/libc-2.12.so)
==83998==    by 0x5083745: ??? (in /local/home/anandrs/Downloads/boost_1_63_0/stage/lib/libboost_unit_test_framework.so.1.63.0)
==83998==    by 0x50DBE00: ??? (in /local/home/anandrs/Downloads/boost_1_63_0/stage/lib/libboost_unit_test_framework.so.1.63.0)
==83998==    by 0x9A4AB21: exit (in /lib64/libc-2.12.so)
==83998==    by 0x9A33D63: (below main) (in /lib64/libc-2.12.so)
==83998==  Address 0xa1d4cd0 is 16 bytes inside a block of size 32 free'd
==83998==    at 0x4C26FD6: operator delete(void*) (vg_replace_malloc.c:480)
==83998==    by 0x93124C8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib64/libstdc++.so.6.0.13)
==83998==    by 0x9A4AB21: exit (in /lib64/libc-2.12.so)
==83998==    by 0x9A33D63: (below main) (in /lib64/libc-2.12.so)
==83998== 
==83998== Invalid free() / delete / delete[] / realloc()
==83998==    at 0x4C26FD6: operator delete(void*) (vg_replace_malloc.c:480)
==83998==    by 0x93124C8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib64/libstdc++.so.6.0.13)
==83998==    by 0x9A4AEBC: __cxa_finalize (in /lib64/libc-2.12.so)
==83998==    by 0x5083745: ??? (in /local/home/anandrs/Downloads/boost_1_63_0/stage/lib/libboost_unit_test_framework.so.1.63.0)
==83998==    by 0x50DBE00: ??? (in /local/home/anandrs/Downloads/boost_1_63_0/stage/lib/libboost_unit_test_framework.so.1.63.0)
==83998==    by 0x9A4AB21: exit (in /lib64/libc-2.12.so)
==83998==    by 0x9A33D63: (below main) (in /lib64/libc-2.12.so)
==83998==  Address 0xa1d4cc0 is 0 bytes inside a block of size 32 free'd
==83998==    at 0x4C26FD6: operator delete(void*) (vg_replace_malloc.c:480)
==83998==    by 0x93124C8: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib64/libstdc++.so.6.0.13)
==83998==    by 0x9A4AB21: exit (in /lib64/libc-2.12.so)
==83998==    by 0x9A33D63: (below main) (in /lib64/libc-2.12.so)
==83998== 
==83998== 
==83998== HEAP SUMMARY:
==83998==     in use at exit: 1,552 bytes in 34 blocks
==83998==   total heap usage: 3,704 allocs, 3,698 frees, 221,397 bytes allocated
==83998== 
==83998== LEAK SUMMARY:
==83998==    definitely lost: 1,032 bytes in 28 blocks
==83998==    indirectly lost: 0 bytes in 0 blocks
==83998==      possibly lost: 0 bytes in 0 blocks
==83998==    still reachable: 520 bytes in 6 blocks
==83998==         suppressed: 0 bytes in 0 blocks
==83998== Rerun with --leak-check=full to see details of leaked memory
==83998== 
==83998== For counts of detected and suppressed errors, rerun with: -v
==83998== ERROR SUMMARY: 112 errors from 2 contexts (suppressed: 6 from 6)





Thanks,
Anand


On Tue, Feb 21, 2017 at 2:03 PM, anandram sundar <sundaranandram@gmail.com> wrote:
Hi,
    I recently wrote some tests using the Boost testing framework and everything was working fine until I used the intel MKL with my project. As soon as I started linking these libraries, the tests started failing with a segmentation fault. This happens after the test execution is done and when the cleanup is happening. Looking at what valgrind outputs, it seems like there is some memory being released which is invalid(not sure if it is because of calling free on already freed memory).  This actually happens even if none of the code depends on the MKL. Just adding them to the linked libraries is enough to cause this.

GCC 4.9.3
Boost ver 1.62

==85160== Invalid read of size 4
==85160==    at 0x10916C57: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /lib/libstdc++.so.6.0.20)
==85160==    by 0x1104AEBC: __cxa_finalize (in /lib64/libc-2.12.so)
==85160==    by 0x41981E2: ??? (in /lib/libboost_unit_test_framework.so.1.62.0)
==85160==    by 0x400EC5B: _dl_fini (in /lib64/ld-2.12.so)
==85160==    by 0x1104AB21: exit (in /lib64/libc-2.12.so)
==85160==    by 0x11033D63: (below main) (in /lib64/libc-2.12.so)
==85160==  Address 0x1262fab0 is 16 bytes inside a block of size 30 free'd
==85160==    at 0x4C26FD6: operator delete(void*) (vg_replace_malloc.c:480)
==85160==    by 0x1104AB21: exit (in /lib64/libc-2.12.so)
==85160==    by 0x11033D63: (below main) (in /lib64/libc-2.12.so)


==85160== Invalid free() / delete / delete[] / realloc()
==85160==    at 0x4C26FD6: operator delete(void*) (vg_replace_malloc.c:480)
==85160==    by 0x1104AEBC: __cxa_finalize (in /lib64/libc-2.12.so)
==85160==    by 0x41981E2: ??? (in /lib/libboost_unit_test_framework.so.1.62.0)
==85160==    by 0x400EC5B: _dl_fini (in /lib64/ld-2.12.so)
==85160==    by 0x1104AB21: exit (in /lib64/libc-2.12.so)
==85160==    by 0x11033D63: (below main) (in /lib64/libc-2.12.so)
==85160==  Address 0x1262faa0 is 0 bytes inside a block of size 30 free'd
==85160==    at 0x4C26FD6: operator delete(void*) (vg_replace_malloc.c:480)
==85160==    by 0x1104AB21: exit (in /lib64/libc-2.12.so)
==85160==    by 0x11033D63: (below main) (in /lib64/libc-2.12.so)


I am not sure why this is happening. Are there any known compatibility issues between MKL and Boost testing framework. I was using ACML before this and the tests were working fine with them.


Thanks,
Anand