add libm.so.6 override to fix static/optimized execution issue.
authorHajime Tazaki <tazaki@nict.go.jp>
Thu, 06 Jun 2013 17:22:47 +0900
changeset 482 8ae3af4c090a
parent 481 4c4c52a1ebe7
child 483 16de75865ab5
add libm.so.6 override to fix static/optimized execution issue. __get_cpu_features() had to be called before libc_setup, but wasn't able to resolve dce___get_cpu_feature at the time. instead, load libm.so in advance.
model/dce-manager.cc
model/elf-cache.cc
model/libc-dce.cc
model/libc-ns3.h
model/libm-ns3.version
utils/dcemakeversion.c
wscript
--- a/model/dce-manager.cc	Wed Jun 05 15:35:12 2013 +0900
+++ b/model/dce-manager.cc	Thu Jun 06 17:22:47 2013 +0900
@@ -1246,6 +1246,22 @@
           librt_setup = (void (*) (const struct Libc *))(symbol);
           librt_setup (libc);
 
+          h = ld->Load ("libm-ns3.so", RTLD_GLOBAL);
+          if (h == 0)
+            {
+              err = ENOMEM;
+              return 0;
+            }
+          symbol = ld->Lookup (h, "libm_setup");
+          if (symbol == 0)
+            {
+              NS_FATAL_ERROR ("This is not our fake libm !");
+            }
+          // construct libm now
+          void (*libm_setup)(const struct Libc *fn);
+          libm_setup = (void (*) (const struct Libc *))(symbol);
+          libm_setup (libc);
+
           // finally, call into 'main'.
           h = ld->Load (filename, RTLD_GLOBAL);
 
--- a/model/elf-cache.cc	Wed Jun 05 15:35:12 2013 +0900
+++ b/model/elf-cache.cc	Thu Jun 06 17:22:47 2013 +0900
@@ -29,6 +29,9 @@
   overriden.from = "librt.so.1";
   overriden.to = "librt-ns3.so";
   m_overriden.push_back (overriden);
+  overriden.from = "libm.so.6";
+  overriden.to = "libm-ns3.so";
+  m_overriden.push_back (overriden);
 }
 
 std::string
--- a/model/libc-dce.cc	Wed Jun 05 15:35:12 2013 +0900
+++ b/model/libc-dce.cc	Thu Jun 06 17:22:47 2013 +0900
@@ -96,6 +96,7 @@
 #include <langinfo.h>
 #include <sys/vfs.h>
 #include <termio.h>
+#include <math.h>
 
 extern void __cxa_finalize (void *d);
 extern int __cxa_atexit (void (*func)(void *), void *arg, void *d);
--- a/model/libc-ns3.h	Wed Jun 05 15:35:12 2013 +0900
+++ b/model/libc-ns3.h	Thu Jun 06 17:22:47 2013 +0900
@@ -579,6 +579,9 @@
 DCE    (__fxstatat)
 NATIVE (__cmsg_nxthdr)
 
+// math.h
+NATIVE (lrintl)
+NATIVE (llrintl)
 
 #undef DCE
 #undef DCET
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/model/libm-ns3.version	Thu Jun 06 17:22:47 2013 +0900
@@ -0,0 +1,4 @@
+NS3 {
+global:
+	libm_setup;
+};
--- a/utils/dcemakeversion.c	Wed Jun 05 15:35:12 2013 +0900
+++ b/utils/dcemakeversion.c	Thu Jun 06 17:22:47 2013 +0900
@@ -200,6 +200,7 @@
   createversion (seek4Lib("libc.so"), argv[++i], "model/libc.version");
   createversion (seek4Lib("libpthread.so"), argv[++i], "model/libpthread.version");
   createversion (seek4Lib("librt.so"), argv[++i], "model/librt.version");
+  createversion (seek4Lib("libm.so"), argv[++i], "model/libm.version");
 
   return 0;
 }
--- a/wscript	Wed Jun 05 15:35:12 2013 +0900
+++ b/wscript	Thu Jun 06 17:22:47 2013 +0900
@@ -589,11 +589,12 @@
     
     bld.program(source='utils/dcemakeversion.c', 
                 name='dcemakeversion',
-                target='dcemakeversion', cflags = [ '-g'], linkflags    = ['-lpthread', '-lrt']) 
+                target='dcemakeversion', cflags = [ '-g'], linkflags    = ['-lpthread', '-lrt', '-lm'])
 
-    bld(source=['dcemakeversion','model/libc-ns3.version' , 'model/libpthread-ns3.version' ,'model/librt-ns3.version'],
-        target=['model/libc.version','model/libpthread.version','model/librt.version'],
-        rule='${SRC[0].abspath()} ${SRC[1].abspath()}  ${SRC[2].abspath()}  ${SRC[3].abspath()} ')
+    bld(source=['dcemakeversion','model/libc-ns3.version' , 'model/libpthread-ns3.version' ,
+                'model/librt-ns3.version', 'model/libm-ns3.version'],
+        target=['model/libc.version','model/libpthread.version','model/librt.version','model/libm.version'],
+        rule='${SRC[0].abspath()} ${SRC[1].abspath()}  ${SRC[2].abspath()}  ${SRC[3].abspath()} ${SRC[4].abspath()}')
 
     bld.add_group('dce_use_version_files')
 
@@ -623,6 +624,15 @@
                          '-Wl,--version-script=' + os.path.join('model', 'librt.version'),
                          '-Wl,-soname=librt.so.1'])
 
+    # The very small libm used to replace the glibc
+    # and forward to the dce_* code
+    bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'],
+              target='lib/m-ns3', cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage'],
+              defines=['LIBSETUP=libm_setup'],
+              linkflags=['-nostdlib', '-lc', '-fno-profile-arcs',
+                         '-Wl,--version-script=' + os.path.join('model', 'libm.version'),
+                         '-Wl,-soname=libm.so.6'])
+
     bld.add_subdirs(['utils'])
 
     # Write the build status file.