From e742da9d983054f8e11e23eacfd83a7b2a96e370 Mon Sep 17 00:00:00 2001 From: Parth Pratim Chatterjee Date: Tue, 1 Jun 2021 17:59:31 +0530 Subject: [PATCH 1/6] _G_va_list __ap, _IO_getc and _IO_putc fix _G_config.h header file is not included in standard headers of Ubuntu-20.04, which defines _G_va_list. _IO_getc and _IO_putc are not a part of the libc-2.31, leading to missing symbols error. To fix it, extern(s) have been defined in case an executable linked with a libc supporting it is used, or if user provides an implementation for the same. Signed-off-by: Parth Pratim Chatterjee --- model/dce-stdio.cc | 6 +++--- model/dce-stdio.h | 5 +++-- model/libc-dce.cc | 17 ++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/model/dce-stdio.cc b/model/dce-stdio.cc index 076dffcf..6b1ecbe2 100644 --- a/model/dce-stdio.cc +++ b/model/dce-stdio.cc @@ -13,8 +13,8 @@ #include #include #include -#include #include +#include NS_LOG_COMPONENT_DEFINE ("DceStdio"); @@ -726,7 +726,7 @@ int dce___printf_chk (int __flag, __const char *__restrict __format, ...) } int dce___vfprintf_chk (FILE *__restrict __stream, int __flag, - __const char *__restrict __format, _G_va_list __ap) + __const char *__restrict __format, __gnuc_va_list __ap) { NS_LOG_FUNCTION (Current () << UtilsGetNodeId ()); NS_ASSERT (Current () != 0); @@ -761,7 +761,7 @@ int dce___snprintf_chk (char *__restrict __s, size_t __n, int __flag, } int dce___vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, size_t __slen, - __const char *__restrict __format, _G_va_list __ap) + __const char *__restrict __format, __gnuc_va_list __ap) { NS_LOG_FUNCTION (Current () << UtilsGetNodeId ()); NS_ASSERT (Current () != 0); diff --git a/model/dce-stdio.h b/model/dce-stdio.h index 458442b1..2ce28922 100644 --- a/model/dce-stdio.h +++ b/model/dce-stdio.h @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -59,7 +60,7 @@ void dce_perror (const char *s); int dce___printf_chk (int __flag, __const char *__restrict __format, ...); int dce___vfprintf_chk (FILE *__restrict __stream, int __flag, - __const char *__restrict __format, _G_va_list __ap); + __const char *__restrict __format, __gnuc_va_list __ap); int dce___fprintf_chk (FILE *__restrict __stream, int __flag, __const char *__restrict __format, ...); int dce___snprintf_chk (char *__restrict __s, size_t __n, int __flag, @@ -73,7 +74,7 @@ int dce_vasprintf (char **strp, const char *fmt, va_list ap); int dce_vsnprintf (char *s, size_t si, const char *f, va_list ap); int dce___vsnprintf_chk (char *__restrict __s, size_t __n, int __flag, size_t __slen, - __const char *__restrict __format, _G_va_list __ap); + __const char *__restrict __format, __gnuc_va_list __ap); #ifdef __cplusplus diff --git a/model/libc-dce.cc b/model/libc-dce.cc index f130ec57..2c0528b2 100644 --- a/model/libc-dce.cc +++ b/model/libc-dce.cc @@ -108,6 +108,7 @@ #include #include #include +#include extern void __cxa_finalize (void *d); extern int __cxa_atexit (void (*func)(void *), void *arg, void *d); @@ -135,24 +136,26 @@ extern int __sprintf_chk (char *, int, size_t, const char *, ...) __THROW; extern int __snprintf_chk (char *, size_t, int, size_t, const char *, ...) __THROW; extern int __vsprintf_chk (char *, int, size_t, const char *, - _G_va_list) __THROW; + __gnuc_va_list) __THROW; extern int __vsnprintf_chk (char *, size_t, int, size_t, const char *, - _G_va_list) __THROW; + __gnuc_va_list) __THROW; extern int __printf_chk (int, const char *, ...); extern int __fprintf_chk (FILE *, int, const char *, ...); -extern int __vprintf_chk (int, const char *, _G_va_list); -extern int __vfprintf_chk (FILE *, int, const char *, _G_va_list); +extern int __vprintf_chk (int, const char *, __gnuc_va_list); +extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_va_list); extern char * __fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp); extern char * __fgets_chk (char *buf, size_t size, int n, FILE *fp); extern int __asprintf_chk (char **, int, const char *, ...) __THROW; -extern int __vasprintf_chk (char **, int, const char *, _G_va_list) __THROW; +extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW; extern int __dprintf_chk (int, int, const char *, ...); -extern int __vdprintf_chk (int, int, const char *, _G_va_list); +extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list); extern int __obstack_printf_chk (struct obstack *, int, const char *, ...) __THROW; extern int __obstack_vprintf_chk (struct obstack *, int, const char *, - _G_va_list) __THROW; + __gnuc_va_list) __THROW; extern void __stack_chk_fail (void); +extern int _IO_getc(_IO_FILE * __fp); +extern int _IO_putc(int __c, _IO_FILE * __fp); typedef void (*func_t)(...); From 57c8c60fb571e61456ed204e80a9c63fecdf183c Mon Sep 17 00:00:00 2001 From: Parth Pratim Chatterjee Date: Tue, 1 Jun 2021 18:05:34 +0530 Subject: [PATCH 2/6] SIOCGSTAMP fix Signed-off-by: Parth Pratim Chatterjee --- test/test-socket.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test-socket.cc b/test/test-socket.cc index 506fda52..fb8a9a53 100644 --- a/test/test-socket.cc +++ b/test/test-socket.cc @@ -12,6 +12,7 @@ #include #include #include "test-macros.h" +#include #undef OUTPUT #define OUTPUT(s) (std::cout << s << std::endl) From 77cf4945dccf97095f13240fdb5ad910dcf6e0f5 Mon Sep 17 00:00:00 2001 From: Parth Pratim Chatterjee Date: Tue, 1 Jun 2021 18:08:52 +0530 Subject: [PATCH 3/6] Added patch files for disabling glibc security checks and net-next-nuse linker script py 2 to 3 Signed-off-by: Parth Pratim Chatterjee --- .../glibc-2.31-disable-security-checks.patch | 28 +++++++++++++++++++ utils/linker-script-py-to-py3.patch | 10 +++++++ 2 files changed, 38 insertions(+) create mode 100644 utils/glibc-2.31-disable-security-checks.patch create mode 100644 utils/linker-script-py-to-py3.patch diff --git a/utils/glibc-2.31-disable-security-checks.patch b/utils/glibc-2.31-disable-security-checks.patch new file mode 100644 index 00000000..6bef68f6 --- /dev/null +++ b/utils/glibc-2.31-disable-security-checks.patch @@ -0,0 +1,28 @@ +diff --git a/elf/dl-load.c b/elf/dl-load.c +index a6b80f9395..e7dca92238 100644 +--- a/elf/dl-load.c ++++ b/elf/dl-load.c +@@ -1205,9 +1205,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, + /* Make sure we are not dlopen'ing an object that has the + DF_1_NOOPEN flag set, or a PIE object. */ + if ((__glibc_unlikely (l->l_flags_1 & DF_1_NOOPEN) +- && (mode & __RTLD_DLOPEN)) +- || (__glibc_unlikely (l->l_flags_1 & DF_1_PIE) +- && __glibc_unlikely ((mode & __RTLD_OPENEXEC) == 0))) ++ && (mode & __RTLD_DLOPEN))) + { + /* We are not supposed to load this object. Free all resources. */ + _dl_unmap_segments (l); +diff --git a/libio/vtables.c b/libio/vtables.c +index 17f2e8e587..73e6906768 100644 +--- a/libio/vtables.c ++++ b/libio/vtables.c +@@ -69,7 +69,7 @@ _IO_vtable_check (void) + return; + #endif + +- __libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n"); ++ //__libc_fatal ("Fatal error: glibc detected an invalid stdio handle\n"); + } + + /* Some variants of libstdc++ interpose _IO_2_1_stdin_ etc. and diff --git a/utils/linker-script-py-to-py3.patch b/utils/linker-script-py-to-py3.patch new file mode 100644 index 00000000..36a30ded --- /dev/null +++ b/utils/linker-script-py-to-py3.patch @@ -0,0 +1,10 @@ +diff --git a/arch/lib/generate-linker-script.py b/arch/lib/generate-linker-script.py +index db3d7f8dab16..93971ee4871d 100755 +--- a/arch/lib/generate-linker-script.py ++++ b/arch/lib/generate-linker-script.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python ++#!/usr/bin/env python3 + + import re + From 58e0ea1ff0bf1317a8707a0c78b84aae9c5d644f Mon Sep 17 00:00:00 2001 From: Parth Pratim Chatterjee Date: Tue, 1 Jun 2021 18:10:34 +0530 Subject: [PATCH 4/6] Specify the installed directory of modified glibc-2.31 Signed-off-by: Parth Pratim Chatterjee --- wscript | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/wscript b/wscript index 61cc95ec..d1ad0114 100755 --- a/wscript +++ b/wscript @@ -35,6 +35,10 @@ def options(opt): help=('Specify the installed directory of elf-loader'), dest='with_elf_loader', type='string', default=None) + opt.add_option('--with-glibc', + help=('Specify the installed directory of Glibc-2.25'), + dest='with_glibc', type='string', + default=None) opt.add_option('--with-libaspect', help=('Specify the installed directory of libaspect.so'), dest='with_libaspect', type='string', @@ -99,6 +103,8 @@ def configure(conf): conf.load('clang_compilation_database', tooldir=['waf-tools']) conf.load('command', tooldir=['waf-tools']) + conf.env.GLIBC_INSTALL_DIR = conf.options.with_glibc + if Options.options.with_ns3 is not None and os.path.isdir(Options.options.with_ns3): conf.env['NS3_DIR']= os.path.abspath(Options.options.with_ns3) if not 'PKG_CONFIG_PATH' in os.environ: @@ -759,6 +765,20 @@ def build(bld): 'helper/freebsd-stack-helper.h', ] + SYSROOT = bld.env.GLIBC_INSTALL_DIR + extra_cflags_root = [ + '-L'+SYSROOT+'/usr/lib64', + '-I'+SYSROOT+'/include', + '--sysroot='+SYSROOT, + '-Wl,--start-group', + '-Wl,-rpath='+SYSROOT+'/lib64', + '-Wl,--dynamic-linker='+SYSROOT+'/lib64/ld-2.31.so' + ] + wl_end_group = [ + '-Wl,--end-group' + ] + + bld.env.append_value('LINKFLAGS',extra_cflags_root+wl_end_group) module_source = module_source + kernel_source module_headers = module_headers + kernel_headers uselib = ns3waf.modules_uselib(bld, ['core', 'network', 'internet', 'netlink']) @@ -767,7 +787,7 @@ def build(bld): headers=module_headers, use=uselib, includes=kernel_includes, - cxxflags= ['-Wno-deprecated-declarations'], + cxxflags= extra_cflags_root+['-Wno-deprecated-declarations']+wl_end_group, lib=['dl']) # lib=['dl','efence']) @@ -820,7 +840,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc', 'model/libc-global-variables.cc'], target='lib/c-ns3', - cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], + cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, defines=['LIBSETUP=libc_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libc.version'), @@ -829,7 +849,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/pthread-ns3', - cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], + cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, defines=['LIBSETUP=libpthread_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libpthread.version'), @@ -839,7 +859,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/rt-ns3', - cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], + cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, defines=['LIBSETUP=librt_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'librt.version'), @@ -849,7 +869,7 @@ def build(bld): # 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', '-Wno-builtin-declaration-mismatch'], + cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, defines=['LIBSETUP=libm_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libm.version'), @@ -859,7 +879,7 @@ def build(bld): # and forward to the dce_* code bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'], target='lib/dl-ns3', - cxxflags=['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch'], + cxxflags=extra_cflags_root+['-g', '-fno-profile-arcs', '-fno-test-coverage', '-Wno-builtin-declaration-mismatch']+wl_end_group, defines=['LIBSETUP=libdl_setup'], linkflags=['-nostdlib', '-fno-profile-arcs', '-Wl,--version-script=' + os.path.join('model', 'libdl.version'), From 7f4ae0d7520b2b652e494f201c8fb5a50617f445 Mon Sep 17 00:00:00 2001 From: Parth Pratim Chatterjee Date: Thu, 26 Aug 2021 09:47:46 +0530 Subject: [PATCH 5/6] Add glibc path existence checks Check if the custom glibc install directory passed with --with-glibc exists or not. Also, move the checks to the top of def configure(), to avoid any compiler checks in case wrong glibc location is passed. Signed-off-by: Parth Pratim Chatterjee --- wscript | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wscript b/wscript index d1ad0114..31ad653b 100755 --- a/wscript +++ b/wscript @@ -91,6 +91,13 @@ def _check_nonfatal(conf, *args, **kwargs): def configure(conf): + conf.env.GLIBC_INSTALL_DIR = os.path.abspath(conf.options.with_glibc) + + if not os.path.exists(conf.env.GLIBC_INSTALL_DIR): + Logs.error("Custom glibc install directory does not exist ! Please pass a valid directory in --with-glibc argument") + raise SystemExit(1) + return + conf.load('relocation', tooldir=['waf-tools']) conf.load('compiler_c') cc_string = '.'.join(conf.env['CC_VERSION']) @@ -103,7 +110,6 @@ def configure(conf): conf.load('clang_compilation_database', tooldir=['waf-tools']) conf.load('command', tooldir=['waf-tools']) - conf.env.GLIBC_INSTALL_DIR = conf.options.with_glibc if Options.options.with_ns3 is not None and os.path.isdir(Options.options.with_ns3): conf.env['NS3_DIR']= os.path.abspath(Options.options.with_ns3) From 87a3688d22d2824ca0da4c787dbde07ecd9e3abe Mon Sep 17 00:00:00 2001 From: Parth Pratim Chatterjee Date: Sat, 28 Aug 2021 00:43:18 +0530 Subject: [PATCH 6/6] Add -rpath-link to avoid collect2 errors from ld Signed-off-by: Parth Pratim Chatterjee --- wscript | 1 + 1 file changed, 1 insertion(+) diff --git a/wscript b/wscript index 31ad653b..4710389d 100755 --- a/wscript +++ b/wscript @@ -778,6 +778,7 @@ def build(bld): '--sysroot='+SYSROOT, '-Wl,--start-group', '-Wl,-rpath='+SYSROOT+'/lib64', + '-Wl,-rpath-link=/usr/lib/x86_64-linux-gnu', '-Wl,--dynamic-linker='+SYSROOT+'/lib64/ld-2.31.so' ] wl_end_group = [