Skip to content

Commit

Permalink
For now you need to generate the libc-ns3.generated.h
Browse files Browse the repository at this point in the history
... manually with teh zsh script at the beginning. Ideally, it should be
run by waf.

Aliases are disabled for now while I confirm clang support for weak
linking.
avr-llvm/clang#9
  • Loading branch information
teto committed Nov 10, 2016
1 parent d7a80a5 commit 5916007
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gen_libcns3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# foulle dans liste de fichiers
# list=(dce-termio.h dce-math.h dce-socket.h dce-fd.h)
out="libc-ns3.generated.h"
out="model/libc-ns3.generated.h"

# sys/dce-socket.h
# read '' var <<'EOF'
Expand Down
3 changes: 2 additions & 1 deletion model/dce-dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ NATIVE (versionsort)
namespace ns3 {
struct Thread;

int , internalClosedir, (DIR *dirp, struct Thread *cur));
// used internally only
int dce_internalClosedir (DIR *dirp, struct Thread *cur);

}

Expand Down
14 changes: 8 additions & 6 deletions model/dce-guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
//#ifndef NATIVE
#define NATIVE(name)
#define NATIVE_EXPLICIT(name, proto)
#define NATIVE_WITH_ALIAS (name)

//#endif

// macros stolen from glibc.
// macros stolen from glibc. does not seem to work with clang
//The weak attribute causes the declaration to be emitted as a weak symbol rather
//than a global. This is primarily useful in defining library functions which can
//be overridden in user code, though it can also be used with non-function declarations
#define weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (# name)))

#define DCE_WITH_ALIAS(name) \
weak_alias (__ ## name, name);
//#define DCE_WITH_ALIAS(name) weak_alias (__ ## name, name);
#define DCE_WITH_ALIAS(name)

#define NATIVE_WITH_ALIAS DCE_WITH_ALIAS

#define DCE_WITH_ALIAS2(name, internal) \
weak_alias (internal, name);
//#define DCE_WITH_ALIAS2(name, internal) weak_alias (internal, name);
#define DCE_WITH_ALIAS2(name, internal)

#define NATIVE_WITH_ALIAS2 DCE_WITH_ALIAS2
2 changes: 0 additions & 2 deletions model/dce-link.h
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
#include <link.h>

NATIVE (int, dl_iterate_phdr)
2 changes: 1 addition & 1 deletion model/dce-stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ NATIVE (__secure_getenv)
NATIVE (atoi)
NATIVE (atol)
NATIVE (atoll)
NATIVET (double, atof)
NATIVE (atof)

NATIVE (qsort)

Expand Down
4 changes: 2 additions & 2 deletions model/dce-unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <stdarg.h>
#include <unistd.h>

#include "../dce-guard.h"

#ifdef __cplusplus
extern "C" {
#endif



DCE(ssize_t , write, (int fd, const void *buf, size_t count));
DCE(ssize_t , writev, (int fd, const struct iovec *iov, int iovcnt));
DCE(ssize_t , read, (int fd, void *buf, size_t count));
Expand Down
7 changes: 6 additions & 1 deletion model/libc-dce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
#include <math.h>
#include <assert.h>
#include <dlfcn.h>
#include <dirent.h>
#include <unistd.h>

#include <locale.h>

Expand Down Expand Up @@ -168,10 +170,13 @@ void libc_dce (struct Libc **libc)
//#define DCE_EXPLICIT(rtype,name,...) (*libc)->name ## _fn = dce_ ## name;

#define NATIVE(name) (*libc)->name ## _fn = &name;
// should be ignored
//#define NATIVE_WITH_ALIAS(name, alias)
//#define DCE_WITH_ALIAS(name, alias)
#define DCE_WITH_ALIAS2(name, alias)
#define NATIVE_WITH_ALIAS2(name, alias)

#include "libc-ns3.h"
#include "libc-ns3.generated.h"

(*libc)->strpbrk_fn = dce_strpbrk;
(*libc)->strstr_fn = dce_strstr;
Expand Down
4 changes: 4 additions & 0 deletions model/libc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ extern "C" {

#undef DCE
#undef NATIVE
#undef DCE_WITH_ALIAS
#undef DCE_WITH_ALIAS2
#undef NATIVE_WITH_ALIAS


// weak_alias (strtol, __strtol_internal);
// weak_alias (wctype_l, __wctype_l);
Expand Down
4 changes: 2 additions & 2 deletions model/libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//on peut utiliser des templates pour recuperer les arguments
#define DCE(rtype, name, args...) rtype (*name ## _fn) args ;
/* native => decltype(name) */
#define NATIVE(name) decltype(&name) name ## _fn ;
#define NATIVE(name) decltype(name) name ## _fn ;

// NATIVE_EXPLICIT
struct Libc
Expand All @@ -25,7 +25,7 @@ struct Libc
/* #define NATIVET(rtype, name) NATIVE (name) */

/* #define DCE_EXPLICIT(name,rtype,...) rtype (*name ## _fn) (__VA_ARGS__); */
#include "libc-ns3.h"
#include "libc-ns3.generated.h"

void (*dce_global_variables_setup_fn)(struct DceGlobalVariables *variables);
char* (*strpbrk_fn)(const char *s, const char *accept);
Expand Down
4 changes: 3 additions & 1 deletion model/sys/dce-ioctl.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#ifndef DCE_IOCTL_H
#define DCE_IOCTL_H

#include "../dce-guard.h"

#ifdef __cplusplus
extern "C" {
#endif

DCE(int, dce_ioctl, (int d, long unsigned int request, ...));
DCE(int, ioctl, (int d, long unsigned int request, ...));

#ifdef __cplusplus
}
Expand Down

0 comments on commit 5916007

Please sign in to comment.