Bug 2101

Summary: When loading binary not compiled with the correct options, dce crashes
Product: dce Reporter: Matthieu Coudron <mattator>
Component: otherAssignee: Hajime Tazaki <tazaki>
Severity: enhancement CC: mattator, ns-bugs
Priority: P5    
Version: unspecified   
Hardware: PC   
OS: Linux   

Description Matthieu Coudron 2015-04-18 15:20:07 EDT
When running DCE with an improper binary it crashes with the enclosed error.
I realized afterwards my binary was not compiled with the correct options:

$ readelf -h ntimed-client
En-tête ELF:
  Magique:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Classe:                            ELF64
  Données:                          complément à 2, système à octets de poids faible d'abord (little endian)
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  Version ABI:                       0
  Type:                              EXEC (fichier exécutable)

0.7s 0 DceExecUtils:SeekFile(/home/teto/ntimed/ntimed-client,  with cwd=, )
0.7s 0 DceExecUtils:CheckFileExe(): [DEBUG] Checking exe files-0/home/teto/ntimed/ntimed-client
0.7s 0 DceExecUtils:CheckFileExe(): [DEBUG] Stat failed
0.7s 0 DceExecUtils:SearchPath(): [DEBUG] m_basePath= and paths=/
0.7s 0 DceExecUtils:SearchPath(): [DEBUG] Pushing path=/
0.7s 0 DceExecUtils:SeekFile(/home/teto/ntimed/ntimed-client,  with cwd=, )
0.7s 0 DceExecUtils:CheckFileExe(): [DEBUG] Checking exe /home/teto/ntimed/ntimed-client

Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:106
106	../sysdeps/x86_64/strlen.S: Aucun fichier ou dossier de ce type.
(gdb) bt
#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x00007ffff1f25ee5 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x00007ffff7b09738 in ns3::ElfCache::EditBuffer (this=0x7ffff7dd8980 <ns3::CoojaLoader::Peek()::modules>, 
    map=0x7ffff7fd7000 "\177ELF\002\001\001", selfId=10) at ../model/elf-cache.cc:208
#3  0x00007ffff7b09ffc in ns3::ElfCache::EditFile (this=0x7ffff7dd8980 <ns3::CoojaLoader::Peek()::modules>, 
    filename=..., selfId=10) at ../model/elf-cache.cc:259
#4  0x00007ffff7b0b362 in ns3::ElfCache::Add (this=0x7ffff7dd8980 <ns3::CoojaLoader::Peek()::modules>, filename=...)
    at ../model/elf-cache.cc:359
#5  0x00007ffff7b0fa7f in ns3::CoojaLoader::LoadModule (this=0x684f60, filename=..., flag=256)
    at ../model/cooja-loader-factory.cc:221
#6  0x00007ffff7b0f683 in ns3::CoojaLoader::Load (this=0x684f60, filename=..., flag=256)
    at ../model/cooja-loader-factory.cc:172
#7  0x00007ffff7a7c75a in ns3::DceManager::LoadMain (ld=0x684f60, filename=..., proc=0x6850c0, 
    err=@0x7ffff7fbed2c: 0) at ../model/dce-manager.cc:1273
#8  0x00007ffff7a75ae7 in ns3::DceManager::PrepareDoStartProcess (current=0x684a30) at ../model/dce-manager.cc:254
#9  0x00007ffff7a76044 in ns3::DceManager::DoStartProcess (context=0x684a30) at ../model/dce-manager.cc:276
#10 0x00007ffff7afd37c in ns3::TaskManager::Trampoline (context=0x634390) at ../model/task-manager.cc:274
#11 0x00007ffff7af6c71 in ns3::UcontextFiberManager::Trampoline (a0=32767, a1=-139472072, a2=0, a3=6505360)
    at ../model/ucontext-fiber-manager.cc:199
#12 0x00007ffff13b48b0 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
Comment 1 Hajime Tazaki 2015-06-01 01:31:06 EDT
it's indeed unhelpful just crash without any message even though the reason is obvious.

I added messages (like below) when DCE detects such an error.

*** unable to open non-shared object file=/source/ns-3-dce/build/bin_dce/no-pic-bin ***
dlerror() = Unable to load: "/source/ns-3-dce/build/bin_dce/no-pic-bin"
assert failed. cond="false", msg="make it sure that DCE binrary file /source/ns-3-dce/build/bin_dce/no-pic-bin was built with correct options: (CFLAGS=-fPIC, LDFLAGS=-pie -rdynamic)", file=../model/dlm-loader-factory.cc, line=99
terminate called without an active exception

both CoojaLoaderFactory and DlmLoaderFactory should detect this error.

the followings are the changesets of this fix.