View Issue Details

IDProjectCategoryView StatusLast Update
0003040Slicer4Core: Building (CMake, Superbuild)public2017-06-07 23:27
Reporterpieper Assigned Tojcfr  
PriorityurgentSeverityblockReproducibilityalways
Status closedResolutionfixed 
Product Version 
Target VersionSlicer 4.3.0Fixed in VersionSlicer 4.3.0 
Summary0003040: Building DCMTK in shared mode prevents crash at startup
Description

On a recent mac build (r21851) with up to date xcode 4.6 and 10.8.2 slicer crashed on startup in the initialization of dcmtk. The stack trace is in the Additional Information below.

I changed the DCMTK built to be shared and slicer works fine.

Since we have had a lot of problems on various platforms when using a static DCMTK in multiple shared libraries (CLIs, Modules, etc) I suggest we switch to shared DCMTK.

There will no doubt need to be some changes to the packaging and perhaps the app launcher, but that is probably worth it at this point.

Steps To Reproduce

This is the change to make slicer work correctly in a local build.

0000233 Slicer (master *%=)$ git diff
diff --git a/SuperBuild/External_DCMTK.cmake b/SuperBuild/External_DCMTK.cmake
index 1a5bd78..3b6e273 100644
--- a/SuperBuild/External_DCMTK.cmake
+++ b/SuperBuild/External_DCMTK.cmake
@@ -47,7 +47,7 @@ if(NOT DEFINED DCMTK_DIR)
${CMAKE_OSX_EXTERNAL_PROJECT_ARGS}
${CMAKE_PROJECT_INCLUDE_EXTERNAL_PROJECT_ARG}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}

  • -DBUILD_SHARED_LIBS:BOOL=OFF
  • -DBUILD_SHARED_LIBS:BOOL=ON
    -DDCMTK_WITH_DOXYGEN:BOOL=OFF
    -DDCMTK_WITH_ZLIB:BOOL=OFF # see CTK github issue 0000025
    -DDCMTK_WITH_OPENSSL:BOOL=OFF # see CTK github issue 0000025
Additional Information

(lldb) bt all

  • thread 0000001: tid = 0x2303, 0x0000000100be5224 libCTKDICOMCore.0.1.dylibdcmtk::log4cplus::thread::impl::tls_set_value(key=0x0000000000000000, value=0x0000000000000001) + 20 at tls.h:98, stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x0000000100be5224 libCTKDICOMCore.0.1.dylibdcmtk::log4cplus::thread::impl::tls_set_value(key=0x0000000000000000, value=0x0000000000000001) + 20 at tls.h:98
    frame 0000001: 0x0000000100be4354 libCTKDICOMCore.0.1.dylibdcmtk::log4cplus::internal::alloc_ptd() + 84 at globinit.cc:320 frame 0000002: 0x0000000100c0934d libCTKDICOMCore.0.1.dylibdcmtk::log4cplus::internal::get_ptd(alloc=true) + 77 at internal.h:171
    frame 0000003: 0x000000010fabe012 libITKIODCMTK-4.4.1.dylibthreadSetup + 18 at globinit.cc:396 frame 0000004: 0x000000010fabde32 libITKIODCMTK-4.4.1.dylibdcmtk::log4cplus::initializeLog4cplus() + 50 at globinit.cc:409
    frame 0000005: 0x000000010fabe111 libITKIODCMTK-4.4.1.dylib_static_log4cplus_initializer(this=0x000000010ffeb0d3) + 17 at globinit.cc:497 frame 0000006: 0x000000010fabe0b5 libITKIODCMTK-4.4.1.dylib_static_log4cplus_initializer(this=0x000000010ffeb0d3) + 21 at globinit.cc:498
    frame 0000007: 0x000000010fabeb44 libITKIODCMTK-4.4.1.dylib__cxx_global_var_init4 + 20 frame 0000008: 0x000000010fabeb8d libITKIODCMTK-4.4.1.dylib_GLOBAL__I_a + 29
    frame 0000009: 0x00007fff5fc13378 dyldImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 236 frame 0000010: 0x00007fff5fc13762 dyldImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 46
    frame 0000011: 0x00007fff5fc1006e dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) + 380 frame 0000012: 0x00007fff5fc0ffc4 dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) + 210
    frame 0000013: 0x00007fff5fc0ffc4 dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) + 210 frame 0000014: 0x00007fff5fc0ffc4 dyldImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) + 210
    frame 0000015: 0x00007fff5fc0feba dyldImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 54 frame 0000016: 0x00007fff5fc01fc0 dylddyld::initializeMainExecutable() + 207
    frame 0000017: 0x00007fff5fc05b04 dylddyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 3060 frame 0000018: 0x00007fff5fc01397 dylddyldbootstrap::start(macho_header const*, int, char const*, long, macho_header const, unsigned long*) + 761
    frame 0000019: 0x00007fff5fc0105e dyld`_dyld_start + 54
TagsNo tags attached.

Relationships

has duplicate 0003048 closedjcfr Crash at start 
has duplicate 0002963 closedpieper crash on exit - dcmtk global dictionary 
has duplicate 0002459 closedjcfr DCMTK Destructor issue - Double Free or corruption when exiting Slicer4 

Activities

jcfr

jcfr

2013-04-01 10:59

administrator   ~0008274

Agree.

millerjv

millerjv

2013-04-02 09:42

developer   ~0008287

My Mac Slicer build is showing the same error.

jcfr

jcfr

2013-04-02 09:45

administrator   ~0008288

Interestingly there are no issues on both the old and new factory. Could you check the CMakeCache.txt to check if the correct DCMTK library are found ? With the new DCMTKConfig.cmake they should.

Do you have any extensions built against a different version of DCMTK that are installed ?

millerjv

millerjv

2013-04-02 10:03

developer   ~0008291

I had completely wiped out my build tree and still had this issue.

DCMTK_DIR:PATH=/Users/200005014/Projects/Slicer4-git/Slicer4-build/DCMTK-build

pieper

pieper

2013-04-02 13:42

administrator   ~0008296

Here are the paths for me in the shared build (where things work). These paths are correct. I don't have the non-shared build anymore but I believe I checked and the paths were correct.

0000013 Slicer-superbuild $ grep DCMTK_DIR */CMakeCache.txt
CTK-build/CMakeCache.txt:DCMTK_DIR:PATH=/Users/pieper/slicer4/latest/Slicer-superbuild/DCMTK-build
ITKv4-build/CMakeCache.txt:DCMTK_DIR:PATH=/Users/pieper/slicer4/latest/Slicer-superbuild/DCMTK-build
Slicer-build/CMakeCache.txt:DCMTK_DIR:PATH=/Users/pieper/slicer4/latest/Slicer-superbuild/DCMTK-build
Slicer-build/CMakeCache.txt:DCMTK_DIR_ROOT:PATH=/Users/pieper/slicer4/latest/Slicer-superbuild/DCMTK-install

jcfr

jcfr

2013-04-02 13:54

administrator   ~0008297

Last edited: 2013-04-02 13:55

It is strange to see the variable "DCMTK_DIR_ROOT" in your Slicer cache, this probably mean that you didn't do a clean build.

If it exists, make sure to remove the folder "/Users/pieper/slicer4/latest/Slicer-superbuild/DCMTK-install"

Could you then confirm that a clean build or current trunk using default option gives a Slicer executable failing to start ?

pieper

pieper

2013-04-02 14:04

administrator   ~0008298

Jim already reported that a clean build crashes on startup...

millerjv

millerjv

2013-04-04 05:32

developer   ~0008307

Here are all my DCMTK paths

% grep DCMTK_DIR */CMakeCache.txt
CTK-build/CMakeCache.txt:DCMTK_DIR:PATH=/Users/200005014/Projects/Slicer4-git/Slicer4-build/DCMTK-build
ITKv4-build/CMakeCache.txt:DCMTK_DIR:PATH=/Users/200005014/Projects/Slicer4-git/Slicer4-build/DCMTK-build
Slicer-build/CMakeCache.txt:DCMTK_DIR:PATH=/Users/200005014/Projects/Slicer4-git/Slicer4-build/DCMTK-build

jcfr

jcfr

2013-04-04 12:08

administrator   ~0008314

Last edited: 2013-04-04 12:08

Following the NA-MIC tcon of April 4th, we discussed that Jim will be creating a small program reproducing the issue. Based on his findings, we will be sending an email to DCMTK folks.

DCMTK commit "b2b14d78c" is suspected to introduce the regression:

Update oflog to log4cplus 1.1.0
https://github.com/commontk/DCMTK/commit/b2b14d78cdafcca698b5ef1c0d102386052b9fc3

millerjv

millerjv

2013-04-04 12:46

developer   ~0008315

This is tricky. The following code works without issue.


#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkDCMTKImageIOFactory.h"
#include "itkObjectFactoryBase.h"

int main(int argc, char* argv[])
{
itk::ObjectFactoryBase::RegisterFactory( itk::DCMTKImageIOFactory::New(), itk::ObjectFactoryBase::INSERT_AT_FRONT );

typedef itk::Image<unsigned char,2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;

ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
reader->GetImageIO()->Print(std::cout);

typedef itk::ImageFileWriter<ImageType> WriterType;

WriterType::Pointer writer = WriterType::New();
writer->SetInput(reader->GetOutput());
writer->SetFileName(argv[2]);
writer->Write();
}


I guess I need to get the "default" factories not to load and have the DCMTKImageIO library loaded from the ITK_AUTOLOAD_PATH

millerjv

millerjv

2013-04-10 07:46

developer   ~0008360

I modified my ITK build so that GDCM is not in the default factory list.

Then I modified the DCMTKImageIOFactory to have an itkLoad function.

The following test program then runs without issue. It loads DCMTKImageIO from the ITK_AUTOLOAD_PATH.

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkExceptionObject.h"

int main(int argc, char* argv[])
{
typedef itk::Image<unsigned char,2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;

ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
catch (itk::ExceptionObject &exc)
{
std::cerr << exc;
}
reader->GetImageIO()->Print(std::cout);

typedef itk::ImageFileWriter<ImageType> WriterType;

WriterType::Pointer writer = WriterType::New();
writer->SetInput(reader->GetOutput());
writer->SetFileName(argv[2]);
writer->Write();
}

millerjv

millerjv

2013-04-10 08:04

developer   ~0008361

Last edited: 2013-04-10 08:05

A program using just the DCMTK logger works if only linked against oflog

#include "dcmtk/oflog/oflog.h"

int main(int argc, char* argv[])
{
OFLogger my_log = OFLog::getLogger("dcmtk.apps.sample");

OFLOG_INFO(my_log, "Testing the DCMTK logger");
}

millerjv

millerjv

2013-04-10 08:05

developer   ~0008362

But when linked against oflog and ITK_LIBRARIES, then it crashes

jcfr

jcfr

2013-04-10 08:13

administrator   ~0008363

That is great. Seems you are able to come with a simpler use case :) Do you think, you could come with an example that produce the crash without involving ITK at all ?

By for example, having:

  • one shared library statically linking against oflog (similar to the ITKDCMTKIO library)
  • a main executable linking statically against oflog and dynamically against the shared library.

With that in hand, we would be able to have the argument to discuss with Offis team.

Thanks again,
Jc

pieper

pieper

2013-04-24 05:28

administrator   ~0008470

Where do we stand on this? Right now people need to change DCMTK to shared in order to run their builds at all on mac (maybe linux too). I think we should move to a shared DCMTK to fix the problem rather than trying to convince the Offis people to accept our use case (which they think is not really a valid one if I understand correctly).

millerjv

millerjv

2013-04-24 06:33

developer   ~0008472

I tried writing a test program that used oflog like above AND did a dlopen on a library that used oflog. I thought this would mimic the ITK issue.

Unfortunately, that program works find.

I had to change my Mac built to using a shared DCMTK as I had other work that needed my attention.

pieper

pieper

2013-04-24 13:00

administrator   ~0008481

I did a completely fresh test build in release mode with DCMTK built shared:

Here is the resulting package, which works for me and is able to load dicom data:

https://s3.amazonaws.com/extra.isomics.com/tmp/Slicer-4.2.0-2013-04-24-macosx-amd64.dmg

All the shared libraries appear to be in the normal spots, so I would think this will work on all platforms.

@jcfr - do you have an objection to having this change checked in? It only seems for the better from my point of view.

jcfr

jcfr

2013-04-24 13:05

administrator   ~0008482

Last edited: 2013-04-24 13:06

@steve: The only think I am thinking about are dcmtk apps. I think they won't work without being run using the Slicer launcher. If this is a none issue. It should be good.

On platform like windows and linux, the launcher setting would have to be updated. There are no rpath within the install tree.

No real show stopper.

pieper

pieper

2013-04-24 13:23

administrator   ~0008483

The dcmtk apps (dcmdump, storescp) are used now in subshells from slicer (AFIAIK) so they should inherit the environment and work I would think. If people need to use slicer's compiled versions of them outside slicer, then I guess having to use the launcher is fair, just like running a CLI.

Regarding the launcher though, I don't think a change needs to be made since the dcmtk libraries should show up in lib/Slicer-4.2 along with all the other shared libraries.

Since this is a problem for developers right now, I'm going to check in the change and we can see if there is any fallout.

pieper

pieper

2013-04-24 13:30

administrator   ~0008484

Fixed in this commit:

http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21914

pieper

pieper

2013-04-27 06:42

administrator   ~0008527

Confirmed that dcmtk built in shared mode works correctly on nightly builds for all platforms.

http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21942
http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21944
http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21947
http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21949

Related Changesets

Slicer: 2145-support-for-installing-extension-from-file 0410e935

2013-04-24 17:27:04

pieper

Details Diff
BUG: 0003040 build DCMTK as shared libraries

This avoids issues where dcmtk code is statically linked into more
than one shared library, meaning that some static initialization
and destructor code is being invoked more than once. See the bug
report for details.

http://www.na-mic.org/Bug/view.php?id=3040

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21914 3bd1e089-480b-0410-8dfb-8563597acbee
mod - SuperBuild/External_DCMTK.cmake Diff File

Slicer: 2145-support-for-installing-extension-from-file 800445da

2013-04-26 17:22:32

pieper

Details Diff
COMP: Include DCMTK shared libraries in packages

Now that DCMTK is built as shared rather than static, the
dlls need to be copied into the install tree for packaging.

See also commit 21914 and bug 0003040.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21944 3bd1e089-480b-0410-8dfb-8563597acbee
add - CMake/SlicerBlockInstallDCMTKLibs.cmake Diff File
mod - CMake/SlicerCPack.cmake Diff File

Slicer: 2145-support-for-installing-extension-from-file 9feb3bd2

2013-04-26 18:01:17

jcfr

Details Diff
COMP: Tweak installation of DCMTK libraries for MacOSX packaging

Following commit r21914, DCMTK libraries are build as shared
library. Commit r21944 ensured that they were installed. Since on MacOSX
the fixup process takes care of copying the library associated with
external projects, this commit exclude the systematic installation
of DCMTK libraries and teach the fixup script where these libraries
are located.

See issue 0003040

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21947 3bd1e089-480b-0410-8dfb-8563597acbee
mod - CMake/SlicerCPack.cmake Diff File
mod - CMake/SlicerCPackBundleFixup.cmake.in Diff File

Issue History

Date Modified Username Field Change
2013-04-01 06:50 pieper New Issue
2013-04-01 06:50 pieper Status new => assigned
2013-04-01 06:50 pieper Assigned To => jcfr
2013-04-01 10:59 jcfr Note Added: 0008274
2013-04-01 11:00 jcfr Priority normal => high
2013-04-02 09:42 millerjv Note Added: 0008287
2013-04-02 09:45 jcfr Note Added: 0008288
2013-04-02 10:03 millerjv Note Added: 0008291
2013-04-02 13:42 pieper Note Added: 0008296
2013-04-02 13:54 jcfr Note Added: 0008297
2013-04-02 13:55 jcfr Note Edited: 0008297
2013-04-02 14:04 pieper Note Added: 0008298
2013-04-04 05:32 millerjv Note Added: 0008307
2013-04-04 12:08 jcfr Note Added: 0008314
2013-04-04 12:08 jcfr Status assigned => feedback
2013-04-04 12:08 jcfr Note Edited: 0008314
2013-04-04 12:46 millerjv Note Added: 0008315
2013-04-05 05:31 jcfr Relationship added has duplicate 0003048
2013-04-10 07:46 millerjv Note Added: 0008360
2013-04-10 08:04 millerjv Note Added: 0008361
2013-04-10 08:04 millerjv Note Edited: 0008361
2013-04-10 08:05 millerjv Note Added: 0008362
2013-04-10 08:05 millerjv Note Edited: 0008361
2013-04-10 08:13 jcfr Note Added: 0008363
2013-04-24 05:28 pieper Note Added: 0008470
2013-04-24 06:33 millerjv Note Added: 0008472
2013-04-24 13:00 pieper Note Added: 0008481
2013-04-24 13:01 pieper Priority high => urgent
2013-04-24 13:01 pieper Severity crash => block
2013-04-24 13:05 jcfr Note Added: 0008482
2013-04-24 13:05 jcfr Note Edited: 0008482
2013-04-24 13:06 jcfr Note Edited: 0008482
2013-04-24 13:23 pieper Note Added: 0008483
2013-04-24 13:30 pieper Note Added: 0008484
2013-04-24 13:30 pieper Status feedback => resolved
2013-04-24 13:30 pieper Fixed in Version => Slicer 4.3.0
2013-04-24 13:30 pieper Resolution open => fixed
2013-04-27 06:42 pieper Note Added: 0008527
2013-04-27 06:42 pieper Status resolved => closed
2013-05-09 10:38 pieper Relationship added has duplicate 0002963
2013-05-09 10:40 pieper Relationship added has duplicate 0002459
2017-06-07 23:27 jcfr Changeset attached => Slicer 2145-support-for-installing-extension-from-file 9feb3bd2
2017-06-07 23:27 pieper Changeset attached => Slicer 2145-support-for-installing-extension-from-file 800445da
2017-06-07 23:27 pieper Changeset attached => Slicer 2145-support-for-installing-extension-from-file 0410e935