Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom glibc build support for DCE on Ubuntu 20.04 #117

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions model/dce-stdio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <stdlib.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <libio.h>
#include <string.h>
#include <cstdarg>

NS_LOG_COMPONENT_DEFINE ("DceStdio");

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions model/dce-stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdio_ext.h>
#include <unistd.h>
#include <cstdarg>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions model/libc-dce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
#include <iconv.h>
#include <glob.h>
#include <malloc.h>
#include <cstdarg>

extern void __cxa_finalize (void *d);
extern int __cxa_atexit (void (*func)(void *), void *arg, void *d);
Expand Down Expand Up @@ -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)(...);

Expand Down
1 change: 1 addition & 0 deletions test/test-socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <netinet/ip.h>
#include <unistd.h>
#include "test-macros.h"
#include <linux/sockios.h>

#undef OUTPUT
#define OUTPUT(s) (std::cout << s << std::endl)
Expand Down
28 changes: 28 additions & 0 deletions utils/glibc-2.31-disable-security-checks.patch
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions utils/linker-script-py-to-py3.patch
Original file line number Diff line number Diff line change
@@ -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

39 changes: 33 additions & 6 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -87,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'])
Expand All @@ -99,6 +110,7 @@ def configure(conf):
conf.load('clang_compilation_database', tooldir=['waf-tools'])
conf.load('command', tooldir=['waf-tools'])


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:
Expand Down Expand Up @@ -759,6 +771,21 @@ 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,-rpath-link=/usr/lib/x86_64-linux-gnu',
'-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'])
Expand All @@ -767,7 +794,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'])

Expand Down Expand Up @@ -820,7 +847,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'),
Expand All @@ -829,7 +856,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'),
Expand All @@ -839,7 +866,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'),
Expand All @@ -849,7 +876,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'),
Expand All @@ -859,7 +886,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'),
Expand Down