From: David van Moolenbroek Date: Wed, 11 Nov 2015 12:43:01 +0000 (+0100) Subject: libmagicrt: integrate into build system X-Git-Url: http://zhaoyanbai.com/repos/%22http:/static/doc/zpipe.c?a=commitdiff_plain;h=b2ed49a5d83e311ee0fa9e5ff613639b1bf77aaf;p=minix.git libmagicrt: integrate into build system The magic runtime library is now built as part of the regular build, if the MKMAGIC=yes flag is passed to the build system. The library has been renamed from "magic" to "magicrt" to resolve a name clash with BSD file(1)'s libmagic. All its level-5 LLVM warnings have been resolved. The final library, "libmagicrt.bcc", is now stored in the destination library directory rather than in the source tree. Change-Id: Iebd4b93a2cafbb59f95d938ad1edb8b4f6e729f6 --- diff --git a/distrib/sets/lists/minix-comp/mi b/distrib/sets/lists/minix-comp/mi index 330f83f3e..13e2b06ff 100644 --- a/distrib/sets/lists/minix-comp/mi +++ b/distrib/sets/lists/minix-comp/mi @@ -1949,6 +1949,7 @@ ./usr/lib/libm_pic.a minix-comp ./usr/lib/libmagic.a minix-comp ./usr/lib/libmagic_pic.a minix-comp +./usr/lib/libmagicrt.bcc minix-comp magic ./usr/lib/libmenu.a minix-comp ./usr/lib/libmenu_pic.a minix-comp ./usr/lib/libminc.a minix-comp diff --git a/lib/Makefile b/lib/Makefile index d6c76c962..2bb912706 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -62,6 +62,10 @@ SUBDIR+= ../minix/lib/libclkconf \ ../minix/lib/libi2cdriver .endif +.if (${MKMAGIC} == "yes") +SUBDIR+= ../minix/lib/libmagicrt +.endif + .endif # defined(__MINIX) # # The SUBDIRs above are included here for completeness but should be built diff --git a/minix/lib/Makefile b/minix/lib/Makefile index f470db834..c0325a2f0 100644 --- a/minix/lib/Makefile +++ b/minix/lib/Makefile @@ -44,5 +44,9 @@ SUBDIR+= libgpio SUBDIR+= libi2cdriver .endif +.if (${MKMAGIC} == "yes") +SUBDIR+= libmagicrt +.endif + .include .include diff --git a/minix/lib/libmagicrt/Makefile b/minix/lib/libmagicrt/Makefile new file mode 100644 index 000000000..0151e54de --- /dev/null +++ b/minix/lib/libmagicrt/Makefile @@ -0,0 +1,79 @@ +# Makefile for libmagicrt +# +# The magic runtime library is the runtime state transfer component for live +# update. It is not a regular library. First of all, it is only built when +# MKMAGIC is enabled, which also implies that we are building bitcode. +# Second, the produced file is a single bitcode object containing basically the +# concatenation of the individual bitcode objects produced from the source +# files. The final bitcode object is used to link against system services +# during the rest of the compilation process. It is installed only because +# this makes it easier to refer to it during the rest of the compilation +# process. However, both the library's generation and its installation cannot +# be done with regular bsd.lib.mk rules, which is why this Makefile is rather +# nonstandard. + +.include + +LIBNAME= libmagicrt.bcc + +SRCS= magic.c magic_analysis.c magic_asr.c magic_ds.c +SRCS+= magic_eval.c magic_eval_lib.c magic_mem.c magic_range.c +SRCS+= magic_selement.c magic_sentry.c magic_splay_tree.c +SRCS+= magic_st.c magic_util.c + +OBJS= ${SRCS:.c=.bc} + +CPPFLAGS+= -D__MINIX -D_MINIX_SYSTEM -D_SYSTEM +CPPFLAGS+= -I${.CURDIR}/include +CPPFLAGS+= -I${NETBSDSRCDIR}/minix/llvm/include # for magic_common.h +CPPFLAGS.magic_ds.c+= -I${NETBSDSRCDIR}/minix/servers # for ds/store.h + +# XXX: there is essential code in assert() statements, so force asserts on.. +CPPFLAGS+= -UNDEBUG + +# All functions and data must be assigned to nonstandard sections. However, +# the magic_st module has different rules from the rest. +SECTIONIFY= -sectionify-no-override \ + -sectionify-data-section-map=^_____magic_instr_.*/magic_instr_data,.*/magic_data \ + -sectionify-function-section-map=.*/magic_functions +SECTIONIFY.magic_st.c= \ + -sectionify-data-section-map=.*/magic_data_st \ + -sectionify-function-section-map=.*/magic_functions_st + +# HACK: keep the "temporary" .bc.o files generated as part of running the +# sectionify pass, so that we can trick clang into taking bitcode objects +# during the linking phase, because its driver refuses to take objects with +# the .bc suffix even when using the gold plugin. This works only because +# we are using sectionify on all objects here, and because bsd.lib.mk uses +# temporary names convenient for us. See also the comment in bsd.lib.mk. +SECTIONIFYMV=cp + +LDFLAGS+=-nostdlib -rdynamic -shared -Wl,--plugin \ + -Wl,${NETBSDSRCDIR}/minix/llvm/bin/LLVMgold.so \ + -Wl,-plugin-opt=-disable-fp-elim -Wl,-plugin-opt=emit-llvm + +realall: ${LIBNAME} + +${LIBNAME}: ${OBJS} + ${_MKTARGET_LINK} + ${LINK.c} -o ${.TARGET} ${OBJS:.bc=.bc.o} + +# The following block is a modified copy of similar blocks in bsd.lib.mk. +_LIB=${DESTDIR}/${LIBDIR}/${LIBNAME} +libinstall:: ${_LIB} +.PRECIOUS: ${_LIB} +.if ${MKUPDATE} == "no" +.if !defined(BUILD) && !make(all) && !make(${LIBNAME}) +${_LIB}! .MADE +.endif +${_LIB}! ${LIBNAME} __archiveinstall +.else +.if !defined(BUILD) && !make(all) && !make(${LIBNAME}) +${_LIB}: .MADE +.endif +${_LIB}: ${LIBNAME} __archiveinstall +.endif + +CLEANFILES+= ${LIBNAME} ${OBJS:.bc=.bc.o} + +.include diff --git a/minix/llvm/include/common/ut/uthash.h b/minix/lib/libmagicrt/include/common/ut/uthash.h similarity index 100% rename from minix/llvm/include/common/ut/uthash.h rename to minix/lib/libmagicrt/include/common/ut/uthash.h diff --git a/minix/llvm/include/common/ut/utlist.h b/minix/lib/libmagicrt/include/common/ut/utlist.h similarity index 100% rename from minix/llvm/include/common/ut/utlist.h rename to minix/lib/libmagicrt/include/common/ut/utlist.h diff --git a/minix/llvm/include/magic.h b/minix/lib/libmagicrt/include/magic.h similarity index 98% rename from minix/llvm/include/magic.h rename to minix/lib/libmagicrt/include/magic.h index b8a8ef2c4..475eb42f1 100644 --- a/minix/llvm/include/magic.h +++ b/minix/lib/libmagicrt/include/magic.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -573,7 +574,7 @@ magic_type_walk_root((E)->sentry->type, 0, \ (unsigned long) ((char*)(E)->address - \ (char*)(E)->sentry->address), magic_selement_name_print_cb, \ - (void*)(E)); \ + (void*)__UNCONST((E))); \ } \ else { \ _magic_printf("???"); \ @@ -937,8 +938,8 @@ EXTERN struct _magic_vars_t *_magic_vars; FUNCTION_BLOCK( /* Magic vars wrappers. */ -PUBLIC void *_magic_vars_addr(); -PUBLIC size_t _magic_vars_size(); +PUBLIC void *_magic_vars_addr(void); +PUBLIC size_t _magic_vars_size(void); /* Magic printf. */ PUBLIC int magic_null_printf(const char* format, ...); @@ -949,7 +950,7 @@ PUBLIC void magic_assert_failed(const char *assertion, const char *file, const char *function, const int line); /* Magic utility functions. */ -PUBLIC unsigned long magic_get_sys_pagesize(); +PUBLIC unsigned long magic_get_sys_pagesize(void); /* Magic lock primitives. */ typedef int (*magic_lock_t)(void*); @@ -1017,49 +1018,49 @@ EXTERN unsigned long magic_sys_pagesize; /* Initialization functions. */ PUBLIC void magic_init(void); -PUBLIC void magic_stack_init(); +PUBLIC void magic_stack_init(void); /* Dfunction functions. */ PUBLIC int magic_check_dfunction(struct _magic_dfunction *ptr, int flags); -PUBLIC int magic_check_dfunctions(); -PUBLIC int magic_check_dfunctions_safe(); +PUBLIC int magic_check_dfunctions(void); +PUBLIC int magic_check_dfunctions_safe(void); PUBLIC void magic_print_dfunction(struct _magic_dfunction *dfunction); -PUBLIC void magic_print_dfunctions(); -PUBLIC void magic_print_dfunctions_safe(); +PUBLIC void magic_print_dfunctions(void); +PUBLIC void magic_print_dfunctions_safe(void); PUBLIC void magic_copy_dfunction(struct _magic_dfunction *dfunction, struct _magic_dfunction *dst_dfunction); /* Dsindex functions. */ PUBLIC void magic_print_dsindex(struct _magic_dsindex *dsindex); -PUBLIC void magic_print_dsindexes(); +PUBLIC void magic_print_dsindexes(void); /* Dsentry functions. */ PUBLIC int magic_check_dsentry(struct _magic_dsentry *ptr, int flags); -PUBLIC int magic_check_dsentries(); -PUBLIC int magic_check_dsentries_safe(); +PUBLIC int magic_check_dsentries(void); +PUBLIC int magic_check_dsentries_safe(void); PUBLIC void magic_print_dsentry(struct _magic_dsentry *dsentry); -PUBLIC void magic_print_dsentries(); -PUBLIC void magic_print_dsentries_safe(); +PUBLIC void magic_print_dsentries(void); +PUBLIC void magic_print_dsentries_safe(void); PUBLIC void magic_copy_dsentry(struct _magic_dsentry *dsentry, struct _magic_dsentry *dst_dsentry); /* Sodesc functions. */ PUBLIC void magic_print_sodesc(struct _magic_sodesc *sodesc); -PUBLIC void magic_print_sodescs(); +PUBLIC void magic_print_sodescs(void); /* Dsodesc functions. */ PUBLIC void magic_print_dsodesc(struct _magic_dsodesc *dsodesc); -PUBLIC void magic_print_dsodescs(); -PUBLIC void magic_print_dsodescs_safe(); +PUBLIC void magic_print_dsodescs(void); +PUBLIC void magic_print_dsodescs_safe(void); /* Section functions. */ -PUBLIC void magic_print_sections(); +PUBLIC void magic_print_sections(void); /* Lookup functions. */ PUBLIC struct _magic_sentry* magic_mempool_sentry_lookup_by_range(void *addr, struct _magic_dsentry *dsentry_buff); -PUBLIC struct _magic_dsindex* magic_dsindex_lookup_by_name(char *parent_name, - char *name); +PUBLIC struct _magic_dsindex* + magic_dsindex_lookup_by_name(const char *parent_name, const char *name); PUBLIC struct _magic_dsentry* magic_dsentry_prev_lookup(struct _magic_dsentry* dsentry); PUBLIC struct _magic_dsentry* @@ -1068,16 +1069,16 @@ PUBLIC struct _magic_function* magic_function_lookup_by_id(_magic_id_t id, struct _magic_dfunction *dfunction_buff); PUBLIC struct _magic_function* magic_function_lookup_by_addr(void *addr, struct _magic_dfunction *dfunction_buff); -PUBLIC struct _magic_function* magic_function_lookup_by_name(char *parent_name, - char *name); -PUBLIC struct _magic_type* magic_type_lookup_by_name(char *name); +PUBLIC struct _magic_function* + magic_function_lookup_by_name(const char *parent_name, const char *name); +PUBLIC struct _magic_type* magic_type_lookup_by_name(const char *name); PUBLIC struct _magic_dsodesc* magic_dsodesc_lookup_by_handle(void *handle); PUBLIC int magic_selement_lookup_by_name(char* name, _magic_selement_t *selement, struct _magic_dsentry *dsentry_buff); /* Magic state function functions. */ PUBLIC void magic_print_function(struct _magic_function *function); -PUBLIC void magic_print_functions(); +PUBLIC void magic_print_functions(void); /* Magic state function lookup hash functions. */ PUBLIC void magic_function_hash_build(void *buff, size_t buff_size); @@ -1090,9 +1091,9 @@ PUBLIC void magic_function_hash_dealloc(void *object, size_t size); /* Magic state type functions. */ PUBLIC void magic_print_type(const struct _magic_type* type); -PUBLIC void magic_print_types(); +PUBLIC void magic_print_types(void); PUBLIC void magic_type_str_set_print_style(const int style); -PUBLIC int magic_type_str_get_print_style(); +PUBLIC int magic_type_str_get_print_style(void); PUBLIC void magic_type_str_print(const struct _magic_type* type); PUBLIC void magic_type_values_print(const struct _magic_type* type); PUBLIC void magic_type_names_print(const struct _magic_type* type); diff --git a/minix/llvm/include/magic_analysis.h b/minix/lib/libmagicrt/include/magic_analysis.h similarity index 99% rename from minix/llvm/include/magic_analysis.h rename to minix/lib/libmagicrt/include/magic_analysis.h index 645a266ab..1e1a43529 100644 --- a/minix/llvm/include/magic_analysis.h +++ b/minix/lib/libmagicrt/include/magic_analysis.h @@ -6,7 +6,7 @@ /* Special convenience types. */ #define MAGIC_TYPE_SPECIAL_INIT(STR) { 0, STR, NULL, 0, STR, 0, 0, 0, 0, 0, 0, \ - 0, MAGIC_TYPE_FUNCTION, MAGIC_TYPE_EXTERNAL, 0 } + 0, MAGIC_TYPE_FUNCTION, MAGIC_TYPE_EXTERNAL, 0, NULL } EXTERN char magic_ne_str[]; EXTERN char magic_enf_str[]; EXTERN char magic_bo_str[]; @@ -296,7 +296,7 @@ typedef struct _magic_sel_stats_s _magic_sel_stats_t; ((V) && !MAGIC_PTR_IS_LIKELY_INT((void*)V)) /* Magic callbacks. */ -typedef int (*magic_cb_sentries_analyze_pre_t)(); +typedef int (*magic_cb_sentries_analyze_pre_t)(void); PUBLIC void magic_setcb_sentries_analyze_pre(magic_cb_sentries_analyze_pre_t cb); /* Magic state entry functions. */ diff --git a/minix/llvm/include/magic_asr.h b/minix/lib/libmagicrt/include/magic_asr.h similarity index 88% rename from minix/llvm/include/magic_asr.h rename to minix/lib/libmagicrt/include/magic_asr.h index 5cecde254..ba088898e 100644 --- a/minix/llvm/include/magic_asr.h +++ b/minix/lib/libmagicrt/include/magic_asr.h @@ -8,4 +8,4 @@ PUBLIC int magic_asr_get_padding_size(int region); PUBLIC void magic_asr_permute_dsentries(struct _magic_dsentry **first_dsentry_ptr); -PUBLIC void magic_asr_init(); +PUBLIC void magic_asr_init(void); diff --git a/minix/llvm/include/magic_def.h b/minix/lib/libmagicrt/include/magic_def.h similarity index 94% rename from minix/llvm/include/magic_def.h rename to minix/lib/libmagicrt/include/magic_def.h index 67276ccd2..15476474d 100644 --- a/minix/llvm/include/magic_def.h +++ b/minix/lib/libmagicrt/include/magic_def.h @@ -55,7 +55,7 @@ #define MAGIC_FUNC PUBLIC USED __attribute__((noinline)) #define MAGIC_FUNC_BODY() __asm__("") #define MAGIC_HOOK PUBLIC USED __attribute__((always_inline)) inline -#define MAGIC_MACRO_FUNC __attribute__((always_inline)) +#define MAGIC_MACRO_FUNC static __attribute__((always_inline)) #define TRUE 1 #define FALSE 0 @@ -74,10 +74,13 @@ #ifdef __MINIX #define _MAGIC_CAS(P, O, N) (*(P) == (O) ? *(P)=(N) : (N)+1) #define MAGIC_CAS(P, O, N) (_MAGIC_CAS(P, O, N) == (N) ? (O) : *(P)) +#define _MAGIC_PCAS(P, O, N) (*(P) == (O) ? *(P)=(N) : (void *)((intptr_t)(N)+1)) +#define MAGIC_PCAS(P, O, N) (_MAGIC_PCAS(P, O, N) == (N) ? (O) : *(P)) #define MAGIC_FAA(P, V) (((*P)+=V)-V) #define MAGIC_FAS(P, V) (((*P)-=V)+V) #else #define MAGIC_CAS(P, O, N) __sync_val_compare_and_swap((P), (O), (N)) +#define MAGIC_PCAS(P, O, N) MAGIC_CAS(P, O, N) #define MAGIC_FAA(P, V) __sync_fetch_and_add(P, V) #define MAGIC_FAS(P, V) __sync_fetch_and_sub(P, V) #endif diff --git a/minix/llvm/include/magic_eval.h b/minix/lib/libmagicrt/include/magic_eval.h similarity index 94% rename from minix/llvm/include/magic_eval.h rename to minix/lib/libmagicrt/include/magic_eval.h index 7dd598ef8..beef4dce1 100644 --- a/minix/llvm/include/magic_eval.h +++ b/minix/lib/libmagicrt/include/magic_eval.h @@ -5,7 +5,7 @@ typedef long (*magic_eval_func_t) (long arg); -PUBLIC void magic_eval_init(); +PUBLIC void magic_eval_init(void); /* Eval frontends. */ PUBLIC int magic_eval_int(char *expr, long *result); diff --git a/minix/llvm/include/magic_eval_lib.h b/minix/lib/libmagicrt/include/magic_eval_lib.h similarity index 98% rename from minix/llvm/include/magic_eval_lib.h rename to minix/lib/libmagicrt/include/magic_eval_lib.h index 8b0bb2505..d2ce30c54 100644 --- a/minix/llvm/include/magic_eval_lib.h +++ b/minix/lib/libmagicrt/include/magic_eval_lib.h @@ -29,7 +29,7 @@ struct vartable { }; /* creates a new variable table (NULL if no memory) */ -struct vartable *create_vartable(); +struct vartable *create_vartable(void); /* frees a variable table */ void free_vartable(struct vartable *vt); diff --git a/minix/lib/libmagicrt/include/magic_extern.h b/minix/lib/libmagicrt/include/magic_extern.h new file mode 100644 index 000000000..a5945fb55 --- /dev/null +++ b/minix/lib/libmagicrt/include/magic_extern.h @@ -0,0 +1,29 @@ +#ifndef _MAGIC_EXTERN_H +#define _MAGIC_EXTERN_H + +/* + * TODO: libsys/sef_llvm.c should include this file, all weak external + * function declarations used in that file should be here, and it should + * probably be moved into include/minix/. + */ + +#include +#include + +void magic_data_init(void); +void _magic_ds_st_init(void); + +void *magic_nested_mmap(void *start, size_t length, int prot, int flags, + int fd, off_t offset); +int magic_nested_munmap(void *start, size_t length); + +int _magic_state_transfer(sef_init_info_t *info); +void _magic_dump_eval_bool(char *expr); +void *_magic_real_alloc_contig(size_t len, int flags, uint32_t *phys); +int _magic_real_free_contig(void *addr, size_t len); +int _magic_real_brk(char *newbrk); +void* _magic_real_mmap(void *buf, size_t len, int prot, int flags, int fd, + off_t offset); +int _magic_real_munmap(void *addr, size_t length); + +#endif /* !_MAGIC_EXTERN_H */ diff --git a/minix/llvm/include/magic_mem.h b/minix/lib/libmagicrt/include/magic_mem.h similarity index 95% rename from minix/llvm/include/magic_mem.h rename to minix/lib/libmagicrt/include/magic_mem.h index e365ac7e8..c84955ca5 100644 --- a/minix/llvm/include/magic_mem.h +++ b/minix/lib/libmagicrt/include/magic_mem.h @@ -3,7 +3,7 @@ #include -#define __MA_ARGS__ struct _magic_type *type, char *name, char *parent_name, +#define __MA_ARGS__ struct _magic_type *type, const char *name, const char *parent_name, #define __MA_VALUES__ type, name, parent_name, #define __MA_VALUES_EXT__ MAGIC_VOID_TYPE, MAGIC_ALLOC_EXT_NAME, MAGIC_ALLOC_EXT_PARENT_NAME, @@ -13,7 +13,7 @@ #define __MD_VALUES_DEFAULT__ /* External callbacks. */ -typedef void *(*magic_mem_heap_alloc_cb_t)(size_t size, char *name, char *parent_name); +typedef void *(*magic_mem_heap_alloc_cb_t)(size_t size, const char *name, const char *parent_name); typedef void (*magic_mem_create_dsentry_cb_t)(struct _magic_dsentry *dsentry); typedef int (*magic_mem_heap_free_cb_t)(struct _magic_dsentry *dsentry); extern magic_mem_heap_alloc_cb_t magic_mem_heap_alloc_cb; @@ -24,13 +24,13 @@ extern magic_mem_heap_free_cb_t magic_mem_heap_free_cb; typedef void (*magic_dsentry_cb_t)(struct _magic_dsentry*); PUBLIC int magic_create_dsentry(struct _magic_dsentry *dsentry, void *data_ptr, struct _magic_type *type, size_t size, int flags, - char *name, char *parent_name); + const char *name, const char *parent_name); PUBLIC struct _magic_obdsentry* magic_create_obdsentry(void *data_ptr, struct _magic_type *type, size_t size, int flags, - const char *name, char *parent_name); + const char *name, const char *parent_name); PUBLIC int magic_update_dsentry_state(struct _magic_dsentry *dsentry, unsigned long mstate); -PUBLIC void magic_free_dead_dsentries(); +PUBLIC void magic_free_dead_dsentries(void); PUBLIC void magic_destroy_dsentry(struct _magic_dsentry *dsentry, struct _magic_dsentry *prev_dsentry); PUBLIC void magic_destroy_dsentry_set_ext_cb(const magic_dsentry_cb_t cb); @@ -38,7 +38,7 @@ PUBLIC int magic_destroy_obdsentry_by_addr(void *data_ptr); PUBLIC int magic_update_dsentry(void* addr, struct _magic_type *type); PUBLIC void magic_stack_dsentries_create( struct _magic_dsentry **prev_last_stack_dsentry, int num_dsentries, - /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, char* function_name, char* name, */ ...); + /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, const char* function_name, const char* name, */ ...); PUBLIC void magic_stack_dsentries_destroy( struct _magic_dsentry **prev_last_stack_dsentry, int num_dsentries, /* struct _magic_dsentry *dsentry, */ ...); @@ -46,7 +46,7 @@ PUBLIC void magic_stack_dsentries_destroy( /* Public dfunction functions. */ PUBLIC int magic_create_dfunction(struct _magic_dfunction *dfunction, void *data_ptr, struct _magic_type *type, int flags, - char *name, char *parent_name); + const char *name, const char *parent_name); PUBLIC void magic_destroy_dfunction(struct _magic_dfunction *dfunction); /* Public sodesc functions. */ @@ -257,7 +257,7 @@ EXTERN int magic_mempool_allow_reuse; /* Pass call site information when logging is activated. */ #if (MAGIC_MEM_USAGE_OUTPUT_CTL == 1) -#define __MDEBUG_ARGS__ char* name +#define __MDEBUG_ARGS__ const char* name #else #define __MDEBUG_ARGS__ #endif @@ -267,14 +267,14 @@ MAGIC_HOOK void magic_mempool_create_end(void* addr, int indirection); /* Specific wrappers for the memory pool destruction. */ MAGIC_HOOK void magic_mempool_destroy_begin(void* addr, int memory_reuse); -MAGIC_HOOK void magic_mempool_destroy_end(); +MAGIC_HOOK void magic_mempool_destroy_end(void); /* Specific wrappers for the memory pool resetting */ MAGIC_HOOK void magic_mempool_reset_begin(void* addr); /* Generic wrappers for the rest of the memory pool management functions. */ MAGIC_HOOK void magic_mempool_mgmt_begin(void* addr); -MAGIC_HOOK void magic_mempool_mgmt_end(); +MAGIC_HOOK void magic_mempool_mgmt_end(void); /* Pool block allocation template function and magic wrapper. */ MAGIC_FUNC void *mempool_block_alloc_template(void* addr, size_t size); diff --git a/minix/llvm/include/magic_range.h b/minix/lib/libmagicrt/include/magic_range.h similarity index 100% rename from minix/llvm/include/magic_range.h rename to minix/lib/libmagicrt/include/magic_range.h diff --git a/minix/llvm/include/magic_real_mem.h b/minix/lib/libmagicrt/include/magic_real_mem.h similarity index 100% rename from minix/llvm/include/magic_real_mem.h rename to minix/lib/libmagicrt/include/magic_real_mem.h diff --git a/minix/llvm/include/magic_selement.h b/minix/lib/libmagicrt/include/magic_selement.h similarity index 100% rename from minix/llvm/include/magic_selement.h rename to minix/lib/libmagicrt/include/magic_selement.h diff --git a/minix/llvm/include/magic_sentry.h b/minix/lib/libmagicrt/include/magic_sentry.h similarity index 93% rename from minix/llvm/include/magic_sentry.h rename to minix/lib/libmagicrt/include/magic_sentry.h index cd504836d..c64115d0f 100644 --- a/minix/llvm/include/magic_sentry.h +++ b/minix/lib/libmagicrt/include/magic_sentry.h @@ -34,7 +34,7 @@ _magic_printf("SENTRY: (id=%5lu, name=%s, parent=%s, address=0x%08x, " \ "flags(RLDCdeTAOSNrwxtpbEZIiP)=" \ "%c%c%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d, type=", \ - (unsigned long) MAGIC_SENTRY_ID(E), (E)->name, \ + (unsigned long)MAGIC_SENTRY_ID(E), (E)->name, \ MAGIC_SENTRY_PARENT(E), (unsigned) (E)->address, \ MAGIC_STATE_REGION_C(E), MAGIC_STATE_LIBSPEC_C(E), \ MAGIC_STATE_FLAG(E,MAGIC_STATE_DIRTY), \ @@ -136,13 +136,15 @@ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_id(_magic_id_t id, struct _magic_dsentry *dsentry_buff); PUBLIC struct _magic_sentry *magic_sentry_lookup_by_addr(void *addr, struct _magic_dsentry *dsentry_buff); -PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name(char *parent_name, - char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff); +PUBLIC struct _magic_sentry * + magic_sentry_lookup_by_name(const char *parent_name, const char *name, + _magic_id_t site_id, struct _magic_dsentry *dsentry_buff); PUBLIC struct _magic_sentry *magic_sentry_lookup_by_range(void *addr, struct _magic_dsentry *dsentry_buff); PUBLIC struct _magic_sentry *magic_sentry_lookup_by_min_off_by_n(void *addr, int flags, long *min_n_ptr, struct _magic_dsentry *dsentry_buff); -PUBLIC struct _magic_sentry *magic_sentry_lookup_by_string(char *string); +PUBLIC struct _magic_sentry * + magic_sentry_lookup_by_string(const char *string); /* Lookup index functions. */ PUBLIC void magic_sentry_rl_build_index(void *buff, size_t buff_size); @@ -160,22 +162,24 @@ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_range_index(void *addr, PUBLIC void magic_sentry_hash_build(void *buff, size_t buff_size); PUBLIC void magic_sentry_hash_destroy(void); PUBLIC size_t magic_sentry_hash_estimate_buff_size(int sentries_num); -PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name_hash(char *parent_name, - char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff); +PUBLIC struct _magic_sentry * + magic_sentry_lookup_by_name_hash(const char *parent_name, + const char *name, _magic_id_t site_id, + struct _magic_dsentry *dsentry_buff); PUBLIC void *magic_sentry_hash_alloc(size_t size); PUBLIC void magic_sentry_hash_dealloc(void *object, size_t size); PUBLIC struct _magic_sentry_list *magic_sentry_list_lookup_by_name_hash( - char *parent_name, char *name, _magic_id_t site_id, + const char *parent_name, const char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff); /* Magic state entry functions. */ PUBLIC int magic_check_sentry(struct _magic_sentry *entry); -PUBLIC int magic_check_sentries(); +PUBLIC int magic_check_sentries(void); PUBLIC void magic_print_sentry(struct _magic_sentry* entry); PUBLIC void magic_print_sentry_abs_name(struct _magic_sentry *sentry); -PUBLIC void magic_print_sentries(); -PUBLIC void magic_print_nonstr_sentries(); -PUBLIC void magic_print_str_sentries(); +PUBLIC void magic_print_sentries(void); +PUBLIC void magic_print_nonstr_sentries(void); +PUBLIC void magic_print_str_sentries(void); PUBLIC long magic_sentry_get_off_by_n(struct _magic_sentry* sentry, void *addr, int flags); diff --git a/minix/llvm/include/magic_splay_tree.h b/minix/lib/libmagicrt/include/magic_splay_tree.h similarity index 100% rename from minix/llvm/include/magic_splay_tree.h rename to minix/lib/libmagicrt/include/magic_splay_tree.h diff --git a/minix/llvm/include/magic_structs.h b/minix/lib/libmagicrt/include/magic_structs.h similarity index 95% rename from minix/llvm/include/magic_structs.h rename to minix/lib/libmagicrt/include/magic_structs.h index ac763e0c0..e461ec2b5 100644 --- a/minix/llvm/include/magic_structs.h +++ b/minix/lib/libmagicrt/include/magic_structs.h @@ -9,27 +9,27 @@ /* Magic state type struct. */ struct _magic_type { _magic_id_t id; - char *name; - char **names; + const char *name; + const char **names; unsigned num_names; - char *type_str; + const char *type_str; unsigned size; unsigned num_child_types; struct _magic_type **contained_types; struct _magic_type **compatible_types; - char **member_names; + const char **member_names; unsigned *member_offsets; void *value_set; unsigned type_id; int flags; unsigned bit_width; - void *ext; + const void *ext; }; /* Magic state entry struct. */ struct _magic_sentry { _magic_id_t id; - char *name; + const char *name; struct _magic_type *type; int flags; void *address; @@ -53,7 +53,7 @@ struct _magic_sentry_hash { /* Magic state function struct. */ struct _magic_function { _magic_id_t id; - char *name; + const char *name; struct _magic_type *type; int flags; void *address; @@ -69,7 +69,7 @@ struct _magic_function_hash { /* Magic dynamic function struct. */ struct _magic_dfunction { unsigned long magic_number; - char *parent_name; + const char *parent_name; struct _magic_function function; struct _magic_dfunction *prev; struct _magic_dfunction *next; @@ -78,8 +78,8 @@ struct _magic_dfunction { /* Magic dynamic state index struct. */ struct _magic_dsindex { struct _magic_type *type; - char *name; - char *parent_name; + const char *name; + const char *parent_name; int flags; }; @@ -95,7 +95,7 @@ struct _magic_dsindex { struct _magic_dsentry { unsigned long magic_number; - char *parent_name; + const char *parent_name; char name_ext_buff[MAGIC_DSENTRY_EXT_NAME_BUFF_SIZE]; struct _magic_sentry sentry; struct _magic_type type; @@ -153,8 +153,8 @@ EXTERN struct _magic_obdsentry _magic_obdsentries[MAGIC_MAX_OBDSENTRIES]; #define MAGIC_MAX_MEMPOOLS 1024 #define MAGIC_MAX_MEMPOOL_NAME_LEN 32 #define MAGIC_MEMPOOL_NAME_PREFIX "_magic_mempool_" -EXTERN char *const MAGIC_MEMPOOL_NAME_UNKNOWN; -EXTERN char *const MAGIC_MEMPOOL_NAME_DETACHED; +EXTERN const char *const MAGIC_MEMPOOL_NAME_UNKNOWN; +EXTERN const char *const MAGIC_MEMPOOL_NAME_DETACHED; struct _magic_mpdesc { int is_alive; diff --git a/minix/llvm/include/st/callback.h b/minix/lib/libmagicrt/include/st/callback.h similarity index 97% rename from minix/llvm/include/st/callback.h rename to minix/lib/libmagicrt/include/st/callback.h index 42cc6fabb..627952f03 100644 --- a/minix/llvm/include/st/callback.h +++ b/minix/lib/libmagicrt/include/st/callback.h @@ -70,6 +70,7 @@ PUBLIC void st_cb_map_child_array_selement_generic(_magic_selement_t *cached_sel PUBLIC void st_cb_map_from_parent_union_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); PUBLIC void st_cb_map_child_union_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); PUBLIC void st_cb_map_from_parent_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); +PUBLIC void st_cb_map_child_nonaggr_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); PUBLIC void st_cb_map_child_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); PUBLIC void st_cb_map_child_primitive_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); PUBLIC void st_cb_map_child_ptr_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping); @@ -89,7 +90,7 @@ PUBLIC void st_cb_map_selement_generic(_magic_selement_t *cached_selement, _magi #define ST_CB_PRINT st_cb_print -#define ST_TYPE_NAME_KEY(TYPE) ((char *) (TYPE)->ext) +#define ST_TYPE_NAME_KEY(TYPE) ((const char *) (TYPE)->ext) #define ST_TYPE_NAME_MATCH(REGISTERED_TYPE_NAME_KEY, KEY) \ (REGISTERED_TYPE_NAME_KEY == KEY) diff --git a/minix/llvm/include/st/cb_template.h b/minix/lib/libmagicrt/include/st/cb_template.h similarity index 100% rename from minix/llvm/include/st/cb_template.h rename to minix/lib/libmagicrt/include/st/cb_template.h diff --git a/minix/llvm/include/st/metadata_transfer.h b/minix/lib/libmagicrt/include/st/metadata_transfer.h similarity index 97% rename from minix/llvm/include/st/metadata_transfer.h rename to minix/lib/libmagicrt/include/st/metadata_transfer.h index 371731d2f..e21e5b6b4 100644 --- a/minix/llvm/include/st/metadata_transfer.h +++ b/minix/lib/libmagicrt/include/st/metadata_transfer.h @@ -18,7 +18,7 @@ PRIVATE int transfer_metadata_type_members(st_init_info_t *info, PRIVATE int transfer_metadata_sentries(st_init_info_t *info, struct _magic_vars_t *cached_magic_vars, struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts, - int *max_buff_sz); + size_t *max_buff_sz); PRIVATE int transfer_metadata_sentry_members(st_init_info_t *info, struct _magic_sentry *sentry); @@ -41,7 +41,7 @@ PRIVATE int allocate_pair_metadata_dsentries_from_raw_copy(st_init_info_t *info, PRIVATE int md_transfer_str(st_init_info_t *info, char **str_pt); #define MD_TRANSFER_STR(INFO, STR_PT) \ do { \ - if (md_transfer_str(INFO, STR_PT)) { \ + if (md_transfer_str(INFO, __UNCONST(STR_PT))) { \ printf("%s, line %d. md_transfer_str(): ERROR transferring.\n", \ __FILE__, __LINE__); \ return EGENERIC; \ diff --git a/minix/llvm/include/st/os_callback.h b/minix/lib/libmagicrt/include/st/os_callback.h similarity index 96% rename from minix/llvm/include/st/os_callback.h rename to minix/lib/libmagicrt/include/st/os_callback.h index 590a22475..231c97184 100644 --- a/minix/llvm/include/st/os_callback.h +++ b/minix/lib/libmagicrt/include/st/os_callback.h @@ -14,7 +14,7 @@ DEFINE_DECL_CALLBACK(int, old_state_table_lookup, (void *state_info_opaque, void DEFINE_DECL_CALLBACK(int, copy_state_region, (void *state_info_opaque, uint32_t address, size_t size, uint32_t dst_address)); DEFINE_DECL_CALLBACK(void *, alloc_contig, (size_t len, int flags, uint32_t *phys)); DEFINE_DECL_CALLBACK(int, free_contig, (void *ptr, size_t length)); -DEFINE_DECL_CALLBACK(char *, debug_header, (void)); +DEFINE_DECL_CALLBACK(const char *, debug_header, (void)); /* Default callback values. */ #define ST_CB_OS_PANIC_EMPTY NULL diff --git a/minix/llvm/include/st/private.h b/minix/lib/libmagicrt/include/st/private.h similarity index 100% rename from minix/llvm/include/st/private.h rename to minix/lib/libmagicrt/include/st/private.h diff --git a/minix/llvm/include/st/special.h b/minix/lib/libmagicrt/include/st/special.h similarity index 71% rename from minix/llvm/include/st/special.h rename to minix/lib/libmagicrt/include/st/special.h index e6c39b497..96d601676 100644 --- a/minix/llvm/include/st/special.h +++ b/minix/lib/libmagicrt/include/st/special.h @@ -2,8 +2,8 @@ #define ST_SPECIAL_H /* Public functions for special types and regions. */ -PUBLIC void st_register_typename_key(char *key); -PUBLIC void st_register_typename_keys(char **keys); +PUBLIC void st_register_typename_key(const char *key); +PUBLIC void st_register_typename_keys(const char **keys); PUBLIC int st_add_special_mmapped_region(void *address, size_t size, const char* name); PUBLIC int st_del_special_mmapped_region_by_addr(void *address); diff --git a/minix/llvm/include/st/state_transfer.h b/minix/lib/libmagicrt/include/st/state_transfer.h similarity index 94% rename from minix/llvm/include/st/state_transfer.h rename to minix/lib/libmagicrt/include/st/state_transfer.h index 4ff023caf..fcb1217d3 100644 --- a/minix/llvm/include/st/state_transfer.h +++ b/minix/lib/libmagicrt/include/st/state_transfer.h @@ -79,8 +79,8 @@ typedef struct { __X(function_hash_buff), __X(function_hash_head) /* Public utility functions. */ -PUBLIC int st_strcmp_wildcard(char *with_wildcard, char *without_wildcard); -PUBLIC void st_cb_print(int level, char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info); +PUBLIC int st_strcmp_wildcard(const char *with_wildcard, const char *without_wildcard); +PUBLIC void st_cb_print(int level, const char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info); PUBLIC void st_map_str_sentries(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr); PUBLIC void st_map_sentries(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr); PUBLIC void st_lookup_sentry_pair(struct _magic_sentry **cached_sentry_ptr, struct _magic_sentry **local_sentry_ptr); @@ -151,7 +151,7 @@ PUBLIC int st_transfer_metadata_types(st_init_info_t *info, PUBLIC int st_transfer_metadata_dsentries(st_init_info_t *info, struct _magic_vars_t *cached_magic_vars, struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts, - int *max_buff_sz, int *dsentries_num); + size_t *max_buff_sz, int *dsentries_num); /* Public functions for state transfer. */ PUBLIC int st_state_transfer(st_init_info_t *info); @@ -174,13 +174,13 @@ PUBLIC void st_print_state_diff(st_init_info_t *info, int raw_diff, int print_ch PUBLIC void st_set_status_by_state_flags(int status_flags, int status_op, int match_state_flags, int skip_state_flags); PUBLIC int st_set_status_by_function_ids(int status_flags, int status_op, unsigned long *ids); PUBLIC int st_set_status_by_sentry_ids(int status_flags, int status_op, unsigned long *ids); -PUBLIC int st_set_status_by_names(int status_flags, int status_op, char **parent_names, char **names, _magic_id_t *dsentry_site_ids); +PUBLIC int st_set_status_by_names(int status_flags, int status_op, const char **parent_names, const char **names, _magic_id_t *dsentry_site_ids); PUBLIC int st_set_status_by_local_addrs(int status_flags, int status_op, void **addrs); PUBLIC void st_set_status_by_sentry(int status_flags, int status_op, void *cached_sentry); PUBLIC void st_set_status_by_function(int status_flags, int status_op, void *cached_function); PUBLIC int st_set_status_by_function_id(int status_flags, int status_op, unsigned long id); PUBLIC int st_set_status_by_sentry_id(int status_flags, int status_op, unsigned long id); -PUBLIC int st_set_status_by_name(int status_flags, int status_op, char *parent_name, char *name, _magic_id_t dsentry_site_id); +PUBLIC int st_set_status_by_name(int status_flags, int status_op, const char *parent_name, const char *name, _magic_id_t dsentry_site_id); PUBLIC int st_set_status_by_local_addr(int status_flags, int status_op, void *addr); PUBLIC int st_pair_by_function_ids(unsigned long *cached_ids, unsigned long *local_ids, int status_flags, int status_op); @@ -332,16 +332,16 @@ PUBLIC int st_state_checking_before_receive_set_enabled(int enabled, int max_cyc #define ST_CHECK_INIT() assert(st_init_done && "st_init() should be called first!") -#define ST_SENTRY_IS_CACHED(E) (MAGIC_SENTRY_ID(E) >= 1 && MAGIC_SENTRY_ID(E) <= st_cached_magic_vars.sentries_num && st_cached_magic_vars.sentries[MAGIC_SENTRY_ID(E)-1].address == (E)->address) +#define ST_SENTRY_IS_CACHED(E) (MAGIC_SENTRY_ID(E) >= 1 && (int)MAGIC_SENTRY_ID(E) <= st_cached_magic_vars.sentries_num && st_cached_magic_vars.sentries[MAGIC_SENTRY_ID(E)-1].address == (E)->address) #define ST_GET_CACHED_COUNTERPART(CE,T,CT,LE) do { \ - int i = (CE)->id - 1; \ - assert(i >= 0 && i < st_counterparts.T##_size); \ - LE = st_counterparts.CT[i].counterpart; \ + int _i = (CE)->id - 1; \ + assert(_i >= 0 && _i < st_counterparts.T##_size); \ + LE = st_counterparts.CT[_i].counterpart; \ } while(0) #define ST_SET_CACHED_COUNTERPART(CE,T,CT,LE) do { \ - int i = (CE)->id - 1; \ - assert(i >= 0 && i < st_counterparts.T##_size); \ - st_counterparts.CT[i].counterpart = LE; \ + int _i = (CE)->id - 1; \ + assert(_i >= 0 && _i < st_counterparts.T##_size); \ + st_counterparts.CT[_i].counterpart = LE; \ } while(0) #define ST_HAS_CACHED_COUNTERPART(CE,CT) (st_counterparts.CT[(CE)->id - 1].counterpart != NULL) diff --git a/minix/llvm/include/st/typedefs.h b/minix/lib/libmagicrt/include/st/typedefs.h similarity index 100% rename from minix/llvm/include/st/typedefs.h rename to minix/lib/libmagicrt/include/st/typedefs.h diff --git a/minix/llvm/static/magic/magic.c b/minix/lib/libmagicrt/magic.c similarity index 99% rename from minix/llvm/static/magic/magic.c rename to minix/lib/libmagicrt/magic.c index 428665619..553b3d427 100644 --- a/minix/llvm/static/magic/magic.c +++ b/minix/lib/libmagicrt/magic.c @@ -195,7 +195,7 @@ PRIVATE THREAD_LOCAL struct _magic_dfunction magic_dfunction_buff; /* Magic default stubs. */ PUBLIC struct _magic_type magic_default_type = { - 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_OPAQUE, 0, 0 + 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_OPAQUE, 0, 0, NULL }; PUBLIC struct _magic_dsentry magic_default_dsentry = { @@ -203,7 +203,7 @@ PUBLIC struct _magic_dsentry magic_default_dsentry = { "", /* parent_name */ { 0 }, /* name_ext_buff */ { 0, "", NULL, MAGIC_STATE_DYNAMIC, NULL, NULL }, /* sentry */ - { 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_ARRAY, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC, 0 }, /* type */ + { 0, "", NULL, 0, "", 0, 0, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_ARRAY, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC, 0, NULL }, /* type */ { NULL }, /* type_array */ #if MAGIC_DSENTRY_ALLOW_PREV NULL, /* prev */ @@ -230,7 +230,7 @@ PUBLIC struct _magic_dfunction magic_default_dfunction = { }; PUBLIC struct _magic_type magic_default_ret_addr_type = { - 0, "", NULL, 0, "", sizeof(void*), 1, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_POINTER, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC|MAGIC_TYPE_INT_CAST|MAGIC_TYPE_STRICT_VALUE_SET, 0 + 0, "", NULL, 0, "", sizeof(void*), 1, NULL, NULL, NULL, NULL, NULL, MAGIC_TYPE_POINTER, MAGIC_TYPE_IS_ROOT|MAGIC_TYPE_DYNAMIC|MAGIC_TYPE_INT_CAST|MAGIC_TYPE_STRICT_VALUE_SET, 0, NULL }; /* Magic code reentrant flag. */ @@ -311,7 +311,7 @@ PUBLIC void magic_reentrant_disable(void) /*===========================================================================* * magic_assert_failed * *===========================================================================*/ -PUBLIC void magic_assert_failed(const char *assertion, const char *file, +PUBLIC void __dead magic_assert_failed(const char *assertion, const char *file, const char *function, const int line) { _magic_printf("Assertion '%s' failed in file %s, function %s(), line %d, pid %d\n", @@ -391,7 +391,7 @@ PRIVATE void magic_types_init() static struct _magic_type _magic_void_array_type_buff; static struct _magic_type *_magic_void_array_type_contained_types[1]; static struct _magic_type _magic_ptrint_type_buff; - static char* _magic_ptrint_type_name = "ptrint"; + static const char* _magic_ptrint_type_name = "ptrint"; static char _magic_ptrint_type_str_buff[8]; static struct _magic_type _magic_ptrint_array_type_buff; static struct _magic_type *_magic_ptrint_array_type_contained_types[1]; @@ -423,7 +423,7 @@ PRIVATE void magic_types_init() /*===========================================================================* * magic_data_init * *===========================================================================*/ -MAGIC_FUNC void magic_data_init() +MAGIC_FUNC void magic_data_init(void) { MAGIC_FUNC_BODY(); } @@ -886,8 +886,8 @@ PUBLIC struct _magic_sentry* magic_mempool_sentry_lookup_by_range(void *addr, st /*===========================================================================* * magic_dsindex_lookup_by_name * *===========================================================================*/ -PUBLIC struct _magic_dsindex* magic_dsindex_lookup_by_name(char *parent_name, - char *name) +PUBLIC struct _magic_dsindex* +magic_dsindex_lookup_by_name(const char *parent_name, const char *name) { int i; struct _magic_dsindex* index = NULL; @@ -967,7 +967,7 @@ PUBLIC struct _magic_function* magic_function_lookup_by_id(_magic_id_t id, /* O(1) ID lookup for functions. */ #if MAGIC_LOOKUP_FUNCTION - if(id <= _magic_functions_num) { + if((int)id <= _magic_functions_num) { return &_magic_functions[id - 1]; } #endif @@ -1047,7 +1047,8 @@ PUBLIC struct _magic_function* magic_function_lookup_by_addr(void *addr, /*===========================================================================* * magic_function_lookup_by_name * *===========================================================================*/ -PUBLIC struct _magic_function* magic_function_lookup_by_name(char *parent_name, char *name) +PUBLIC struct _magic_function* +magic_function_lookup_by_name(const char *parent_name, const char *name) { int i; struct _magic_function* entry = NULL; @@ -1243,9 +1244,10 @@ PUBLIC struct _magic_function *magic_function_lookup_by_addr_hash( /*===========================================================================* * magic_type_lookup_by_name * *===========================================================================*/ -PUBLIC struct _magic_type* magic_type_lookup_by_name(char *name) +PUBLIC struct _magic_type* magic_type_lookup_by_name(const char *name) { - int i, j; + int i; + unsigned int j; struct _magic_type* entry = NULL; /* Scan all the entries and return the one matching the provided name. */ @@ -1575,7 +1577,7 @@ PUBLIC void magic_type_values_print(const struct _magic_type* type) *===========================================================================*/ PUBLIC void magic_type_names_print(const struct _magic_type* type) { - int i; + unsigned int i; for(i=0;inum_names;i++) { _magic_printf("%s%s", (i==0 ? "" : "|"), type->names[i]); @@ -1723,7 +1725,7 @@ PUBLIC int magic_type_compatible(const struct _magic_type* type, const struct _m return FALSE; } if(type->num_names > 1) { - for(i=0; inum_names; i++){ + for(i=0; (unsigned int)inum_names; i++){ if(strcmp(type->names[i], other_type->names[i])) { return FALSE; } @@ -1738,14 +1740,14 @@ PUBLIC int magic_type_compatible(const struct _magic_type* type, const struct _m if(type->type_id == MAGIC_TYPE_STRUCT) { if(flags & MAGIC_TYPE_COMPARE_MEMBER_NAMES) { - for(i=0; inum_child_types; i++){ + for(i=0; (unsigned int)inum_child_types; i++){ if(strcmp(type->member_names[i], other_type->member_names[i])) { return FALSE; } } } if(flags & MAGIC_TYPE_COMPARE_MEMBER_OFFSETS) { - for(i=0; inum_child_types; i++){ + for(i=0; (unsigned int)inum_child_types; i++){ if(type->member_offsets[i] != other_type->member_offsets[i]) { return FALSE; } @@ -2240,7 +2242,7 @@ PUBLIC size_t magic_type_get_size(struct _magic_type *type, int flags) } if(flags & MAGIC_SIZE_TYPE_NAMES) { size += sizeof(type->num_names) + sizeof(type->names) + sizeof(*(type->names))*(type->num_names); - for(i=0;inum_names;i++) { + for(i=0;(unsigned int)inum_names;i++) { size += strlen(type->names[i])+1; } } diff --git a/minix/llvm/static/magic/magic_analysis.c b/minix/lib/libmagicrt/magic_analysis.c similarity index 99% rename from minix/llvm/static/magic/magic_analysis.c rename to minix/lib/libmagicrt/magic_analysis.c index bfb9e440e..ae4ed0565 100644 --- a/minix/llvm/static/magic/magic_analysis.c +++ b/minix/lib/libmagicrt/magic_analysis.c @@ -83,7 +83,7 @@ PUBLIC int magic_sentry_analyze(struct _magic_sentry* sentry, int flags, int selement_num = 0, sel_analyzed_num = 0; void* args_array[7]; args_array[0] = (void*) &flags; - args_array[1] = (void*) &cb; + args_array[1] = (void*) __UNCONST(&cb); args_array[2] = (void*) cb_args; args_array[3] = (void*) sentry; args_array[4] = (void*) sentry_stats; @@ -687,7 +687,8 @@ PUBLIC int magic_selement_analyze_ptr_type_invs(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats) { const struct _magic_type* ptr_type = selement->type; - int i, ret = 0; + unsigned int i; + int ret = 0; int trg_flags; const struct _magic_type *trg_type; _magic_trg_stats_t trg_stats; diff --git a/minix/llvm/static/magic/magic_asr.c b/minix/lib/libmagicrt/magic_asr.c similarity index 100% rename from minix/llvm/static/magic/magic_asr.c rename to minix/lib/libmagicrt/magic_asr.c diff --git a/minix/llvm/static/magic/minix/magic_ds.c b/minix/lib/libmagicrt/magic_ds.c similarity index 93% rename from minix/llvm/static/magic/minix/magic_ds.c rename to minix/lib/libmagicrt/magic_ds.c index 12cfe5b54..a2947c4d5 100644 --- a/minix/llvm/static/magic/minix/magic_ds.c +++ b/minix/lib/libmagicrt/magic_ds.c @@ -9,7 +9,7 @@ #include #include -char* sef_sf_typename_keys[] = { "dsi_u", NULL }; +const char* sef_sf_typename_keys[] = { "dsi_u", NULL }; #define dsi_u_idx 0 /*===========================================================================* @@ -61,7 +61,7 @@ static int sef_cb_sf_transfer_dsi_u(_magic_selement_t *selement, _magic_sel_anal /*===========================================================================* * sef_cb_sf_transfer_typename * *===========================================================================*/ -int sef_cb_sf_transfer_typename(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) { +static int sef_cb_sf_transfer_typename(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) { const char *typename_key = ST_TYPE_NAME_KEY(selement->type); if(ST_TYPE_NAME_MATCH(sef_sf_typename_keys[dsi_u_idx],typename_key)) { diff --git a/minix/llvm/static/magic/magic_eval.c b/minix/lib/libmagicrt/magic_eval.c similarity index 100% rename from minix/llvm/static/magic/magic_eval.c rename to minix/lib/libmagicrt/magic_eval.c diff --git a/minix/llvm/static/magic/magic_eval_lib.c b/minix/lib/libmagicrt/magic_eval_lib.c similarity index 98% rename from minix/llvm/static/magic/magic_eval_lib.c rename to minix/lib/libmagicrt/magic_eval_lib.c index 0ed653830..6af7c9013 100644 --- a/minix/llvm/static/magic/magic_eval_lib.c +++ b/minix/lib/libmagicrt/magic_eval_lib.c @@ -14,7 +14,7 @@ #ifdef __MINIX /* FIXME: due to the current linker command line ordering, parts of lib(min)c - * that are used exclusively by libmagic end up not being instrumented, which + * that are used exclusively by libmagicrt end up not being instrumented, which * then causes problems transferring pointers such as _ctype_tab_ and * _tolower_tab_. As a temporary workaround, we redefine the macros that use * those pointers. This code is currently never triggered so it is not @@ -103,7 +103,7 @@ char scantable[UCHAR_MAX+1]; int scantable_ok = 0; /* table of function names */ -char *functable[] = { +const char *functable[] = { "acos", "asin", "atan", "cos", "cosh", "exp", "ln", "log", "sin", "sinh", "sqr", "sqrt", "tan", "tanh", NULL }; @@ -127,7 +127,7 @@ void eval_set_cb_get_func_result(get_func_result_cb_t cb) { int same_str(const char *a, const char *b); int same_str_len(const char *a, const char *b, int len); -void init_scantable(); +void init_scantable(void); int tokenize(struct memh *mh, char **string, struct tok **listptr); int scan_number(char **stringptr, struct val *valptr); int precedence(struct tok *t); @@ -172,7 +172,7 @@ int evaluate(char *expr, struct val *result, struct vartable *vartable) { /**** TOKENIZATION ***/ -void init_scantable() { +void init_scantable(void) { int i; if (scantable_ok) return; @@ -464,8 +464,8 @@ int tokenize(struct memh *mh, char **string, struct tok **listptr) { tok->funcid = 0; /* look for matching function */ for (i = 0; functable[i]; i++) { - char *fname = functable[i]; - if (same_str_len(name, fname, len) && strlen(fname) == len) { + const char *fname = functable[i]; + if (same_str_len(name, fname, len) && strlen(fname) == (size_t)len) { tok->funcid = i+1; break; } @@ -981,33 +981,14 @@ void prt_tok(struct tok *t) { } } -void prt_stk(struct tok *stk, int depth) { - do { prt_tok(&stk[depth]); } while (depth-- > 0); - printf("\n"); -} - void prt_lst(struct tok *t) { for (; t; t=t->next) prt_tok(t); printf("\n"); } -/* variables dumper */ -void dump_vars(struct vartable *vt) { - struct var *v; - if (!vt) printf("no vars\n"); - else for (v=vt->first; v; v=v->next) { - if (v->val.type == T_INT) - printf("'%s'=%ld ", v->name, v->val.ival); - else - printf("'%s'=%g ", v->name, v->val.rval); - } - printf("\n"); -} #else void prt_tok(struct tok *t) {} -void prt_stk(struct tok *stk, int depth) {} void prt_lst(struct tok *t) {} -void dump_vars(struct vartable *vt) {} #endif diff --git a/minix/llvm/static/magic/magic_mem.c b/minix/lib/libmagicrt/magic_mem.c similarity index 98% rename from minix/llvm/static/magic/magic_mem.c rename to minix/lib/libmagicrt/magic_mem.c index b89198ccd..795c8af1d 100644 --- a/minix/llvm/static/magic/magic_mem.c +++ b/minix/lib/libmagicrt/magic_mem.c @@ -46,8 +46,8 @@ PUBLIC THREAD_LOCAL short magic_mem_wrapper_active = 0; PUBLIC THREAD_LOCAL short magic_mempool_mgmt_active_level = 0; PUBLIC THREAD_LOCAL short magic_mempool_ids[MAGIC_MEMPOOL_MAX_FUNC_RECURSIONS]; -char* const MAGIC_MEMPOOL_NAME_UNKNOWN = "_magic_mempool_unknown#"; -char* const MAGIC_MEMPOOL_NAME_DETACHED = "_magic_mempool_detached#"; +const char* const MAGIC_MEMPOOL_NAME_UNKNOWN = "_magic_mempool_unknown#"; +const char* const MAGIC_MEMPOOL_NAME_DETACHED = "_magic_mempool_detached#"; __attribute__((weak)) int magic_mempool_allow_reset = 1; __attribute__((weak)) int magic_mempool_allow_reuse = 1; @@ -130,7 +130,7 @@ PUBLIC void *(*magic_real_vm_map_cacheblock)(dev_t dev, off_t dev_offset, /*===========================================================================* * magic_mempool_alloc_id * *===========================================================================*/ -MAGIC_MACRO_FUNC short magic_mempool_alloc_id() +MAGIC_MACRO_FUNC short magic_mempool_alloc_id(void) { short i, id = -1; @@ -197,7 +197,7 @@ MAGIC_MACRO_FUNC short magic_mempool_lookup_by_addr(void* addr) /*===========================================================================* * magic_mempool_reset * *===========================================================================*/ -MAGIC_MACRO_FUNC void magic_mempool_reset(char* mempool_name, int reset_name) +MAGIC_MACRO_FUNC void magic_mempool_reset(const char* mempool_name, int reset_name) { struct _magic_dsentry *prev_dsentry, *dsentry, *block_dsentry; struct _magic_sentry* sentry; @@ -207,11 +207,13 @@ MAGIC_MACRO_FUNC void magic_mempool_reset(char* mempool_name, int reset_name) if (sentry->name == mempool_name) { block_dsentry = MAGIC_DSENTRY_NEXT_MEMBLOCK(dsentry); if (block_dsentry != NULL) { - struct _magic_dsentry *tmp_block_dsentry = MAGIC_CAS(&MAGIC_DSENTRY_NEXT_MEMBLOCK(dsentry), block_dsentry, NULL); + struct _magic_dsentry *tmp_block_dsentry = + MAGIC_PCAS(&MAGIC_DSENTRY_NEXT_MEMBLOCK(dsentry), block_dsentry, NULL); assert(tmp_block_dsentry == block_dsentry && "New blocks have been allocated from a reseted mempool!"); } if (reset_name) { - char *tmp_name = MAGIC_CAS(&sentry->name, mempool_name, MAGIC_MEMPOOL_NAME_UNKNOWN); + const char *tmp_name = + MAGIC_PCAS(&sentry->name, mempool_name, MAGIC_MEMPOOL_NAME_UNKNOWN); assert(tmp_name == mempool_name && "The name of the mempool has changed while being reseted!"); } MAGIC_MEM_DEBUG_RESET((char*)dsentry); @@ -294,9 +296,10 @@ MAGIC_HOOK void magic_mempool_reset_begin(void* addr) /*===========================================================================* * magic_mempool_dsentry_set_name * *===========================================================================*/ -MAGIC_MACRO_FUNC void magic_mempool_dsentry_set_name(struct _magic_dsentry* dsentry, char* name) +MAGIC_MACRO_FUNC void magic_mempool_dsentry_set_name(struct _magic_dsentry* dsentry, + const char* name) { - char *old_name, *ret; + const char *old_name, *ret; if ((name == MAGIC_MEMPOOL_NAME_UNKNOWN) || (name == MAGIC_MEMPOOL_NAME_DETACHED)) { do { @@ -318,7 +321,8 @@ MAGIC_MACRO_FUNC void magic_mempool_dsentry_set_name(struct _magic_dsentry* dsen /*===========================================================================* * magic_mempool_dsentry_update * *===========================================================================*/ -MAGIC_MACRO_FUNC void magic_mempool_dsentry_update(struct _magic_dsentry* dsentry, char* name) +MAGIC_MACRO_FUNC void magic_mempool_dsentry_update(struct _magic_dsentry* dsentry, + const char* name) { struct _magic_sentry* sentry = MAGIC_DSENTRY_TO_SENTRY(dsentry); struct _magic_dsentry* next_mempool_dsentry; @@ -414,7 +418,7 @@ PUBLIC void *magic_mempool_block_alloc_template(__MA_ARGS__ void* addr, size_t s *===========================================================================*/ PUBLIC int magic_create_dsentry(struct _magic_dsentry *dsentry, void *data_ptr, struct _magic_type *type, size_t size, int flags, - char *name, char *parent_name) + const char *name, const char *parent_name) { /* This function does not require any dsentry locking. */ struct _magic_sentry *sentry = MAGIC_DSENTRY_TO_SENTRY(dsentry); @@ -540,7 +544,7 @@ PUBLIC int magic_create_dsentry(struct _magic_dsentry *dsentry, *===========================================================================*/ PUBLIC struct _magic_obdsentry* magic_create_obdsentry(void *data_ptr, struct _magic_type *type, size_t size, int flags, - const char *name, char *parent_name) + const char *name, const char *parent_name) { struct _magic_obdsentry *obdsentry = NULL; int i, ret; @@ -992,14 +996,14 @@ PUBLIC void magic_stack_init() *===========================================================================*/ PUBLIC void magic_stack_dsentries_create( struct _magic_dsentry **prev_last_stack_dsentry, int num_dsentries, - /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, char* function_name, char* name, */ ...) + /* struct _magic_dsentry *dsentry, struct _magic_type *type, void* data_ptr, const char* function_name, const char* name, */ ...) { int i; struct _magic_dsentry *dsentry; struct _magic_type *type; void* data_ptr; - char* function_name; - char* name; + const char* function_name; + const char* name; char *min_data_ptr = NULL, *max_data_ptr = NULL; va_list va; @@ -1013,8 +1017,8 @@ PUBLIC void magic_stack_dsentries_create( dsentry = va_arg(va, struct _magic_dsentry *); type = va_arg(va, struct _magic_type *); data_ptr = va_arg(va, void *); - function_name = va_arg(va, char *); - name = va_arg(va, char *); + function_name = va_arg(va, const char *); + name = va_arg(va, const char *); if (i == num_dsentries - 1) { /* Return address. */ int *value_set = (void*) type; @@ -1091,7 +1095,7 @@ PUBLIC void magic_stack_dsentries_destroy( *===========================================================================*/ PUBLIC int magic_create_dfunction(struct _magic_dfunction *dfunction, void *data_ptr, struct _magic_type *type, int flags, - char *name, char *parent_name) + const char *name, const char *parent_name) { struct _magic_function *function = MAGIC_DFUNCTION_TO_FUNCTION(dfunction); @@ -2071,9 +2075,9 @@ PUBLIC void *magic_vm_map_cacheblock(__MA_ARGS__ dev_t dev, off_t dev_offset, alloc_length = length + (length % page_size == 0 ? 0 : page_size-(length % page_size)); data_ptr = vm_map_cacheblock(dev, dev_offset, ino, ino_offset, flags, length); if (data_ptr != MAP_FAILED) { - ptr = mmap(data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - MAGIC_MEM_PRINTF("vm_map_cacheblock: ptr = mmap(start, length, prot, flags, fd, offset) <-> 0x%08x = mmap(0x%08x, %d, 0x%08x, 0x%08x, %d, %d)\n", (unsigned) ptr, data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - assert(ptr == data_ptr-page_size); /* Ensured by VM. */ + ptr = mmap((char *)data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + MAGIC_MEM_PRINTF("vm_map_cacheblock: ptr = mmap(start, length, prot, flags, fd, offset) <-> 0x%08x = mmap(0x%08x, %d, 0x%08x, 0x%08x, %d, %d)\n", (unsigned) ptr, (char *)data_ptr-page_size, page_size, magic_mmap_dsentry_header_prot, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + assert(ptr == (char *)data_ptr-page_size); /* Ensured by VM. */ aligned_ptr = ptr; ptr = ((char*)ptr) + page_size - MAGIC_SIZE_TO_REAL(0); } diff --git a/minix/llvm/static/magic/magic_range.c b/minix/lib/libmagicrt/magic_range.c similarity index 99% rename from minix/llvm/static/magic/magic_range.c rename to minix/lib/libmagicrt/magic_range.c index f65f59aa2..266816f7f 100644 --- a/minix/llvm/static/magic/magic_range.c +++ b/minix/lib/libmagicrt/magic_range.c @@ -224,7 +224,7 @@ PUBLIC void magic_ranges_init(void) { int i,j; void *start_address, *end_address; - void* linker_vars[] = { MAGIC_LINKER_VAR_NAMES }; + const char* linker_vars[] = { MAGIC_LINKER_VAR_NAMES }; /* Init sentry and data range. */ MAGIC_RANGE_INIT(magic_data_range); diff --git a/minix/llvm/static/magic/magic_selement.c b/minix/lib/libmagicrt/magic_selement.c similarity index 99% rename from minix/llvm/static/magic/magic_selement.c rename to minix/lib/libmagicrt/magic_selement.c index 9000e78e6..bbe93784b 100644 --- a/minix/llvm/static/magic/magic_selement.c +++ b/minix/lib/libmagicrt/magic_selement.c @@ -23,7 +23,7 @@ PUBLIC int magic_selement_lookup_by_name(char *name, token_buff[len] = '\0'; if (token_start == name) { struct _magic_sentry *sentry; - char *sentry_parent_name = "", *sentry_name = NULL; + const char *sentry_parent_name = "", *sentry_name = NULL; char *delim = NULL; _magic_id_t dsentry_site_id = MAGIC_DSENTRY_SITE_ID_NULL; if (!(delim = strchr(token_buff, MAGIC_DSENTRY_ABS_NAME_SEP[0]))) { @@ -896,13 +896,13 @@ PUBLIC _magic_selement_t* magic_selement_from_relative_name( case MAGIC_TYPE_STRUCT: case MAGIC_TYPE_UNION: - for(i=0;inum_child_types;i++) { + for(i=0; (unsigned int)inum_child_types;i++) { if(!strcmp(parent_type->member_names[i], name)) { child_num = i; break; } } - if(i == parent_type->num_child_types) { + if((unsigned int)i == parent_type->num_child_types) { return NULL; } break; diff --git a/minix/llvm/static/magic/magic_sentry.c b/minix/lib/libmagicrt/magic_sentry.c similarity index 98% rename from minix/llvm/static/magic/magic_sentry.c rename to minix/lib/libmagicrt/magic_sentry.c index 02d7cd5ee..6a6d318b3 100644 --- a/minix/llvm/static/magic/magic_sentry.c +++ b/minix/lib/libmagicrt/magic_sentry.c @@ -115,7 +115,7 @@ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_id(_magic_id_t id, /* O(1) ID lookup for sentries. */ #if MAGIC_LOOKUP_SENTRY - if (id <= _magic_sentries_num) { + if ((int)id <= _magic_sentries_num) { return &_magic_sentries[id - 1]; } #endif @@ -203,8 +203,9 @@ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_addr(void *addr, /*===========================================================================* * magic_sentry_lookup_by_name * *===========================================================================*/ -PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name(char *parent_name, - char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff) +PUBLIC struct _magic_sentry * + magic_sentry_lookup_by_name(const char *parent_name, const char *name, + _magic_id_t site_id, struct _magic_dsentry *dsentry_buff) { int i; struct _magic_sentry *entry = NULL; @@ -397,7 +398,7 @@ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_min_off_by_n(void *addr, /*===========================================================================* * magic_sentry_lookup_by_string * *===========================================================================*/ -PUBLIC struct _magic_sentry *magic_sentry_lookup_by_string(char *string) +PUBLIC struct _magic_sentry *magic_sentry_lookup_by_string(const char *string) { int i; struct _magic_sentry *entry = NULL; @@ -873,7 +874,7 @@ PUBLIC void magic_sentry_hash_dealloc(UNUSED(void *object), UNUSED(size_t sz)) * magic_sentry_lookup_by_name_hash * *===========================================================================*/ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name_hash( - char *parent_name, char *name, _magic_id_t site_id, + const char *parent_name, const char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff) { /* @@ -897,7 +898,7 @@ PUBLIC struct _magic_sentry *magic_sentry_lookup_by_name_hash( * magic_sentry_list_lookup_by_name_hash * *===========================================================================*/ PUBLIC struct _magic_sentry_list *magic_sentry_list_lookup_by_name_hash( - char *parent_name, char *name, _magic_id_t site_id, + const char *parent_name, const char *name, _magic_id_t site_id, struct _magic_dsentry *dsentry_buff) { /* diff --git a/minix/llvm/static/magic/magic_splay_tree.c b/minix/lib/libmagicrt/magic_splay_tree.c similarity index 100% rename from minix/llvm/static/magic/magic_splay_tree.c rename to minix/lib/libmagicrt/magic_splay_tree.c diff --git a/minix/llvm/static/magic/magic_st.c b/minix/lib/libmagicrt/magic_st.c similarity index 98% rename from minix/llvm/static/magic/magic_st.c rename to minix/lib/libmagicrt/magic_st.c index 8eb1cee41..086136f42 100644 --- a/minix/llvm/static/magic/magic_st.c +++ b/minix/lib/libmagicrt/magic_st.c @@ -21,7 +21,7 @@ EXTERN endpoint_t sef_self_endpoint; #define DO_SKIP_INVARIANTS_VIOLATIONS 0 PRIVATE st_alloc_pages *st_alloc_pages_current = NULL; -PRIVATE int st_alloc_buff_available = 0; +PRIVATE size_t st_alloc_buff_available = 0; PRIVATE char *st_alloc_buff_pt = NULL; PRIVATE char *st_pre_allocated_page_pt = NULL; PRIVATE struct _magic_dsentry *st_dsentry_buff = NULL; @@ -173,17 +173,17 @@ PRIVATE int __st_before_receive_sc_max_violations; /* Typedef registration and lookup */ -int st_strcmp_wildcard(char *with_wildcard, char *without_wildcard) +int st_strcmp_wildcard(const char *with_wildcard, const char *without_wildcard) { /* Note: this implementation only supports basic regexes with a '*' * at the beginning or the end of the string. */ - char *star = strchr(with_wildcard, '*'); + const char *star = strchr(with_wildcard, '*'); if (star) { if (star == with_wildcard) { size_t len = strlen(with_wildcard+1); size_t len_without_wildcard = strlen(without_wildcard); - char *match_without_wildcard = without_wildcard+ + const char *match_without_wildcard = without_wildcard+ len_without_wildcard-len; if (match_without_wildcard < without_wildcard) { return -1; @@ -195,17 +195,17 @@ int st_strcmp_wildcard(char *with_wildcard, char *without_wildcard) return strcmp(with_wildcard, without_wildcard); } -char *st_typename_noxfers[] = { ST_TYPENAME_NO_TRANSFER_NAMES, NULL }; -char *st_typename_ixfers[] = { ST_TYPENAME_IDENTITY_TRANSFER_NAMES, NULL }; -char *st_typename_cixfers[] = { ST_TYPENAME_CIDENTITY_TRANSFER_NAMES, NULL }; -char *st_typename_pxfers[] = { ST_TYPENAME_PTR_TRANSFER_NAMES, NULL }; -char *st_typename_sxfers[] = { ST_TYPENAME_STRUCT_TRANSFER_NAMES, NULL }; -char *st_sentryname_ixfers[] = { ST_SENTRYNAME_IDENTITY_TRANSFER_NAMES, NULL }; -char *st_sentryname_cixfers[] = { ST_SENTRYNAME_CIDENTITY_TRANSFER_NAMES, NULL}; -char *st_sentryname_pxfers[] = { ST_SENTRYNAME_PTR_TRANSFER_NAMES, NULL }; +const char *st_typename_noxfers[] = { ST_TYPENAME_NO_TRANSFER_NAMES, NULL }; +const char *st_typename_ixfers[] = { ST_TYPENAME_IDENTITY_TRANSFER_NAMES, NULL }; +const char *st_typename_cixfers[] = { ST_TYPENAME_CIDENTITY_TRANSFER_NAMES, NULL }; +const char *st_typename_pxfers[] = { ST_TYPENAME_PTR_TRANSFER_NAMES, NULL }; +const char *st_typename_sxfers[] = { ST_TYPENAME_STRUCT_TRANSFER_NAMES, NULL }; +const char *st_sentryname_ixfers[] = { ST_SENTRYNAME_IDENTITY_TRANSFER_NAMES, NULL }; +const char *st_sentryname_cixfers[] = { ST_SENTRYNAME_CIDENTITY_TRANSFER_NAMES, NULL}; +const char *st_sentryname_pxfers[] = { ST_SENTRYNAME_PTR_TRANSFER_NAMES, NULL }; /* Exclude stack references in addition to the default sentry names from state transfer. */ -char *st_sentryname_noxfers[] = { +const char *st_sentryname_noxfers[] = { ST_SENTRYNAME_NO_TRANSFER_NAMES, #define __X(R) #R /* Stringify the symbol names. */ ST_STACK_REFS_INT_LIST, @@ -214,20 +214,20 @@ char *st_sentryname_noxfers[] = { #endif #undef __X NULL }; -char *st_sentryname_noxfers_mem[] = { ST_SENTRYNAME_NO_TRANSFER_MEM_NAMES, NULL }; +const char *st_sentryname_noxfers_mem[] = { ST_SENTRYNAME_NO_TRANSFER_MEM_NAMES, NULL }; /* Exclude the data segments of certain libs from state transfer. */ -char *st_dsentry_lib_noxfer[] = { +const char *st_dsentry_lib_noxfer[] = { #ifdef ST_DSENTRYLIB_NO_TRANSFER_NAMES ST_DSENTRYLIB_NO_TRANSFER_NAMES, #endif NULL }; -char *st_typename_key_registrations[MAX_NUM_TYPENAMES]; +const char *st_typename_key_registrations[MAX_NUM_TYPENAMES]; -int is_typename(char *search_key, struct _magic_type *type) +static int is_typename(const char *search_key, struct _magic_type *type) { - int i; + unsigned int i; /* We can't use a cached lookup result */ if (!st_strcmp_wildcard(search_key, type->name)) { /* The name matches */ @@ -243,7 +243,7 @@ int is_typename(char *search_key, struct _magic_type *type) return FALSE; } -PUBLIC void st_register_typename_key(char *key) +PUBLIC void st_register_typename_key(const char *key) { int i, is_registered = FALSE; for(i = 0 ; i < MAX_NUM_TYPENAMES ; i++) { @@ -256,7 +256,7 @@ PUBLIC void st_register_typename_key(char *key) assert(is_registered && "Error, number of typename registrations > MAX_NUM_TYPENAMES.\n"); } -PUBLIC void st_register_typename_keys(char **keys) +PUBLIC void st_register_typename_keys(const char **keys) { int i = 0; while (keys[i] != NULL) { @@ -267,7 +267,7 @@ PUBLIC void st_register_typename_keys(char **keys) PRIVATE void set_typename_key(struct _magic_type *type) { - char **registration = st_typename_key_registrations; + const char **registration = st_typename_key_registrations; while (*registration != NULL) { if (is_typename(*registration, type)) { @@ -278,7 +278,7 @@ PRIVATE void set_typename_key(struct _magic_type *type) } } -PUBLIC void register_typenames() +PRIVATE void register_typenames(void) { int i; @@ -296,7 +296,7 @@ PUBLIC void register_typenames() } -PRIVATE INLINE void register_typenames_and_callbacks() +PRIVATE INLINE void register_typenames_and_callbacks(void) { static int st_is_registered = FALSE; @@ -313,8 +313,8 @@ PRIVATE INLINE void register_typenames_and_callbacks() } -PUBLIC int st_type_name_match_any(char **registered_type_name_keys, - char *key) +PRIVATE int st_type_name_match_any(const char **registered_type_name_keys, + const char *key) { int i = 0; while (registered_type_name_keys[i] != NULL) { @@ -326,8 +326,8 @@ PUBLIC int st_type_name_match_any(char **registered_type_name_keys, return FALSE; } -PUBLIC int st_sentry_name_match_any(char **sentry_wildcard_names, - char *name) +PRIVATE int st_sentry_name_match_any(const char **sentry_wildcard_names, + const char *name) { int i = 0; while (sentry_wildcard_names[i] != NULL) { @@ -339,8 +339,8 @@ PUBLIC int st_sentry_name_match_any(char **sentry_wildcard_names, return FALSE; } -PUBLIC int st_dsentry_parent_name_match_any(char **wildcard_names, - char *name) +PRIVATE int st_dsentry_parent_name_match_any(const char **wildcard_names, + const char *name) { int i = 0; while (wildcard_names[i] != NULL) { @@ -353,7 +353,7 @@ PUBLIC int st_dsentry_parent_name_match_any(char **wildcard_names, } /* Utilities. */ -PUBLIC void st_cb_print(int level, char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) +PUBLIC void st_cb_print(int level, const char *msg, _magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) { if (ST_CB_PRINT_LEVEL(level)) { _magic_printf("[%s] %s. Current state element:\n", @@ -568,7 +568,7 @@ PRIVATE int transfer_ptr_sel_with_trg_cb(_magic_selement_t *selement, _magic_sel else if(trg_extf_flags & ST_ON_PTRXFER_SET_DEFAULT) { ST_CB_PRINT(ST_CB_DBG, "ptr lookup results in forcefully setting ptr to default value", selement, sel_analyzed, sel_stats, cb_info); if (trg_flags & MAGIC_STATE_STRING) { - *((char**)local_selement_address) = ""; + *((char**)local_selement_address) = __UNCONST(""); } else { *local_selement_address = NULL; @@ -713,7 +713,7 @@ PRIVATE INLINE int default_transfer_selement_sel_cb(_magic_selement_t *selement, PUBLIC int st_cb_transfer_sentry_default(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) { - char *sentry_name = selement->sentry->name; + const char *sentry_name = selement->sentry->name; #if ST_ASSUME_RAW_COPY_BEFORE_TRANSFER if (MAGIC_STATE_FLAGS(selement->sentry, MAGIC_STATE_DYNAMIC)) { @@ -763,7 +763,7 @@ PUBLIC int st_cb_transfer_sentry_default(_magic_selement_t *selement, _magic_sel PUBLIC int st_cb_transfer_typename_default(_magic_selement_t *selement, _magic_sel_analyzed_t *sel_analyzed, _magic_sel_stats_t *sel_stats, struct st_cb_info *cb_info) { - char *typename_key = ST_TYPE_NAME_KEY(selement->type); + const char *typename_key = ST_TYPE_NAME_KEY(selement->type); if (ST_TYPE_NAME_MATCH_ANY(st_typename_ixfers, typename_key)) { return transfer_identity_sel_cb(selement, sel_analyzed, sel_stats, cb_info); } @@ -908,7 +908,7 @@ PRIVATE INLINE void st_map_sel_analyzed_from_target(_magic_sel_analyzed_t *cache local_sel_analyzed->u.ptr.num_trg_types = 1; } else { - int i; + unsigned int i; void *address = NULL; local_sel_analyzed->u.ptr.num_trg_types = 0; for (i = cached_sel_analyzed->u.ptr.first_legal_trg_type ; i < cached_sel_analyzed->u.ptr.num_trg_types ; i++) { @@ -1027,8 +1027,8 @@ PUBLIC void st_cb_map_child_union_selement_generic(_magic_selement_t *cached_sel PUBLIC void st_cb_map_from_parent_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping) { - int i; - char *cached_member_name; + unsigned int i; + const char *cached_member_name; /* Match struct/unions with struct/unions. */ assert(cached_selement->parent_type->type_id == MAGIC_TYPE_STRUCT || cached_selement->parent_type->type_id == MAGIC_TYPE_UNION); if (local_selement->parent_type->type_id != MAGIC_TYPE_STRUCT && local_selement->parent_type->type_id != MAGIC_TYPE_UNION) { @@ -1048,7 +1048,7 @@ PUBLIC void st_cb_map_from_parent_struct_selement_generic(_magic_selement_t *cac PUBLIC void st_cb_map_child_struct_selement_generic(_magic_selement_t *cached_selement, _magic_selement_t *local_selement, struct st_cb_info *cb_info, int is_trg_mapping) { - int i, j; + unsigned int i, j; const struct _magic_type *cached_type = cached_selement->type; const struct _magic_type *local_type = local_selement->type; assert(cached_type->type_id == MAGIC_TYPE_STRUCT || cached_type->type_id == MAGIC_TYPE_UNION); @@ -1251,10 +1251,12 @@ PUBLIC int st_state_transfer(st_init_info_t *info) return OK; } +#if APPARENTLY_UNUSED PUBLIC void st_set_policies(int policies) { st_policies = policies; } +#endif #if MAGIC_LOOKUP_SENTRY_ALLOW_RANGE_INDEX PRIVATE void st_init_rl_index(st_init_info_t *info, @@ -1349,7 +1351,7 @@ PRIVATE void st_vars_clear_ptrs(struct _magic_vars_t *magic_vars) #define __X(x) offsetof(struct _magic_vars_t, x) size_t offset_list[] = { ST_MAGIC_VARS_PTR_CLEAR_LIST }; #undef __X - int i; + unsigned int i; for (i = 0 ; i < sizeof(offset_list) / sizeof(size_t) ; i++) *((void **)(((char *)magic_vars) + offset_list[i])) = NULL; @@ -1378,7 +1380,8 @@ PRIVATE void st_unmap_mem(struct _magic_vars_t *magic_vars) PUBLIC int st_init(st_init_info_t *info) { - int r, max_buff_sz = 0, dsentries_num; + size_t max_buff_sz = 0; + int r, dsentries_num; int allow_unpaired_types = TRUE; if (st_init_done) { return OK; @@ -1573,7 +1576,7 @@ PUBLIC void st_map_str_sentries(struct _magic_sentry **cached_sentry_ptr, struct else { int i; for(i = 0 ; i < st_cached_magic_vars.sentries_num ; i++) { - struct _magic_sentry *sentry = &st_cached_magic_vars.sentries[i]; + sentry = &st_cached_magic_vars.sentries[i]; if (MAGIC_SENTRY_IS_STRING(sentry) && !strcmp(st_lookup_str_local_data(sentry), (char*)local_sentry->address)) { cached_sentry = sentry; break; @@ -1760,7 +1763,7 @@ PUBLIC void st_lookup_function_pair(struct _magic_function **cached_function_ptr assert((cached_function == NULL) ^ (local_function == NULL)); if (cached_function) { - if (cached_function->id - 1 >= st_counterparts.functions_size) { + if ((int)cached_function->id - 1 >= st_counterparts.functions_size) { /* * Try to check if this is a function * from an external shared object. @@ -1812,7 +1815,7 @@ PUBLIC void st_add_function_pair(struct _magic_function *cached_function, struct PUBLIC int st_sentry_equals(struct _magic_sentry *cached_sentry, struct _magic_sentry *local_sentry) { - char *cached_parent_name = "", *local_parent_name = ""; + const char *cached_parent_name = "", *local_parent_name = ""; int cached_flags = MAGIC_STATE_FLAGS_TO_NONEXTF(cached_sentry->flags) & (~MAGIC_STATE_ADDR_NOT_TAKEN); int local_flags = MAGIC_STATE_FLAGS_TO_NONEXTF(local_sentry->flags) & (~MAGIC_STATE_ADDR_NOT_TAKEN); if (cached_flags != local_flags) { @@ -2235,7 +2238,8 @@ PUBLIC int st_set_status_by_sentry_ids(int status_flags, int status_op, _magic_i } PUBLIC int st_set_status_by_names(int status_flags, int status_op, - char **parent_names, char **names, _magic_id_t *dsentry_site_ids) + const char **parent_names, const char **names, + _magic_id_t *dsentry_site_ids) { int r, i = 0; while (names[i] != NULL) { @@ -2284,7 +2288,7 @@ PUBLIC void st_set_status_by_function(int status_flags, int status_op, } PUBLIC int st_set_status_by_name(int status_flags, int status_op, - char *parent_name, char *name, _magic_id_t dsentry_site_id) + const char *parent_name, const char *name, _magic_id_t dsentry_site_id) { struct _magic_sentry *cached_sentry = NULL; struct _magic_function *cached_function = NULL; @@ -2358,7 +2362,7 @@ PUBLIC int st_set_status_by_sentry_id(int status_flags, int status_op, PUBLIC int st_set_status_by_local_addr(int status_flags, int status_op, void *addr) { - char *parent_name, *name; + const char *parent_name, *name; _magic_id_t dsentry_site_id = MAGIC_DSENTRY_SITE_ID_NULL; struct _magic_sentry *sentry = NULL; struct _magic_function *function = NULL; @@ -2800,7 +2804,7 @@ PRIVATE int transfer_metadata_type_members(st_init_info_t *info, struct _magic_t if (type->names != NULL && type->num_names > 0) { /* transfer array of name pointers */ MD_TRANSFER(info, type->names, (void **)&type->names, type->num_names * sizeof(char *)); - for (i = 0 ; i < type->num_names ; i++) { + for (i = 0 ; (unsigned int)i < type->num_names ; i++) { /* transfer individual name */ MD_TRANSFER_STR(info, &type->names[i]); } @@ -2868,7 +2872,7 @@ PRIVATE int transfer_metadata_type_members(st_init_info_t *info, struct _magic_t PRIVATE int transfer_metadata_sentries(st_init_info_t *info, struct _magic_vars_t *cached_magic_vars , struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts - , int *max_buff_sz) + , size_t *max_buff_sz) { int i; @@ -2933,7 +2937,7 @@ PRIVATE int transfer_metadata_sentry_members(st_init_info_t *info, struct _magic } PUBLIC int st_transfer_metadata_dsentries(st_init_info_t *info, struct _magic_vars_t *cached_magic_vars - , struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts, int *max_buff_sz, int *dsentries_num) + , struct _magic_vars_t *remote_magic_vars, st_counterparts_t *counterparts, size_t *max_buff_sz, int *dsentries_num) { struct _magic_dsentry **dsentry_ptr; @@ -3667,7 +3671,7 @@ PRIVATE int allocate_local_dsentry(st_init_info_t *info, struct _magic_dsindex * { struct _magic_dsentry *local_dsentry = NULL; struct _magic_sentry *cached_sentry = NULL; - char *name, *parent_name; + const char *name, *parent_name; struct _magic_type *type; int region; size_t size; @@ -3701,7 +3705,7 @@ PRIVATE int allocate_local_dsentry(st_init_info_t *info, struct _magic_dsindex * MAGIC_DSODESC_LOCK(); MAGIC_SODESC_ITER(_magic_first_sodesc, sodesc, if (!strcmp(cached_dsentry->parent_name, sodesc->lib.name)) { - parent_name = (char *)sodesc->lib.name; + parent_name = (const char *)sodesc->lib.name; found_parent_name = 1; break; } @@ -3709,7 +3713,7 @@ PRIVATE int allocate_local_dsentry(st_init_info_t *info, struct _magic_dsindex * if (!found_parent_name) { MAGIC_DSODESC_ITER(_magic_first_dsodesc, dsodesc, if (!strcmp(cached_dsentry->parent_name, dsodesc->lib.name)) { - parent_name = (char *)dsodesc->lib.name; + parent_name = (const char *)dsodesc->lib.name; found_parent_name = 1; break; } diff --git a/minix/llvm/static/magic/minix/magic_util.c b/minix/lib/libmagicrt/magic_util.c similarity index 95% rename from minix/llvm/static/magic/minix/magic_util.c rename to minix/lib/libmagicrt/magic_util.c index 0950d9465..cae481cd0 100644 --- a/minix/llvm/static/magic/minix/magic_util.c +++ b/minix/lib/libmagicrt/magic_util.c @@ -10,40 +10,9 @@ #include #include -void *_magic_real_alloc_contig(size_t len, int flags, uint32_t *phys); -int _magic_real_free_contig(void *addr, size_t len); - - -static char* _magic_generic_debug_header(void) +static const char* _magic_generic_debug_header(void) { - return (char*) "[DEBUG]"; -} - -/*===========================================================================* - * _magic_state_transfer * - *===========================================================================*/ -int _magic_state_transfer(sef_init_info_t *info) -{ - st_init_info_t st_info; - /* Convert SEF flags into ST flags. */ - st_info.flags = 0; - if (info->flags & SEF_LU_ASR) - st_info.flags |= ST_LU_ASR; - if (info->flags & SEF_LU_NOMMAP) - st_info.flags |= ST_LU_NOMMAP; - st_info.init_buff_start = info->init_buff_start; - st_info.init_buff_cleanup_start = info->init_buff_cleanup_start; - st_info.init_buff_len = info->init_buff_len; - /* Transmit sef_init_info opaquely to the state transfer framework. */ - st_info.info_opaque = (void *) (info); - /* Add the OS callbacks. */ - st_info.st_cbs_os.panic = &(panic); /* panic() callback. */ - st_info.st_cbs_os.old_state_table_lookup = &(sef_old_state_table_lookup_opaque); /* old_state_table_lookup() callback. */ - st_info.st_cbs_os.copy_state_region = &(sef_copy_state_region_opaque); /* copy_state_region() callback. */ - st_info.st_cbs_os.alloc_contig = &(_magic_real_alloc_contig); /* alloc_contig() callback. */ - st_info.st_cbs_os.free_contig = &(_magic_real_free_contig); /* free_contig() callback. */ - st_info.st_cbs_os.debug_header = &(_magic_generic_debug_header); /* debug_header() callback. */ - return st_state_transfer(&st_info); + return "[DEBUG]"; } /*===========================================================================* @@ -101,3 +70,32 @@ int _magic_real_munmap(void *addr, size_t length) { return magic_real_munmap(addr, length); } + +/*===========================================================================* + * _magic_state_transfer * + *===========================================================================*/ +int _magic_state_transfer(sef_init_info_t *info) +{ + st_init_info_t st_info; + /* Convert SEF flags into ST flags. */ + st_info.flags = 0; + if (info->flags & SEF_LU_ASR) + st_info.flags |= ST_LU_ASR; + if (info->flags & SEF_LU_NOMMAP) + st_info.flags |= ST_LU_NOMMAP; + st_info.init_buff_start = info->init_buff_start; + st_info.init_buff_cleanup_start = info->init_buff_cleanup_start; + st_info.init_buff_len = info->init_buff_len; + /* Transmit sef_init_info opaquely to the state transfer framework. */ + st_info.info_opaque = (void *) (info); + /* Add the OS callbacks. */ + st_info.st_cbs_os.panic = &(panic); /* panic() callback. */ + st_info.st_cbs_os.old_state_table_lookup = &(sef_old_state_table_lookup_opaque); /* old_state_table_lookup() callback. */ + st_info.st_cbs_os.copy_state_region = &(sef_copy_state_region_opaque); /* copy_state_region() callback. */ + st_info.st_cbs_os.alloc_contig = &(_magic_real_alloc_contig); /* alloc_contig() callback. */ + st_info.st_cbs_os.free_contig = &(_magic_real_free_contig); /* free_contig() callback. */ + st_info.st_cbs_os.debug_header = &(_magic_generic_debug_header); /* debug_header() callback. */ + return st_state_transfer(&st_info); +} + + diff --git a/minix/llvm/configure.llvm b/minix/llvm/configure.llvm index 723f2ee0b..276b28626 100755 --- a/minix/llvm/configure.llvm +++ b/minix/llvm/configure.llvm @@ -54,22 +54,12 @@ if [ ! -f ${MINIX_LLVM_DIR}/common.inc ]; then echo "TOOLDIR=\"${MINIX_TOOLS_DIR}/bin\"" >> ${MINIX_LLVM_DIR}/common.inc fi -STATIC_DIR="${MINIX_LLVM_DIR}/static" - -if [ ! -f ${STATIC_DIR}/Makefile.common.inc ]; then - echo "# This file was automatically generated by configure.llvm" > ${STATIC_DIR}/Makefile.common.inc - echo "_MINIX_ARCH=${ARCH}" >> ${STATIC_DIR}/Makefile.common.inc - echo "_MINIX_ROOT=${MINIX_ROOT_1}" >> ${STATIC_DIR}/Makefile.common.inc - echo "_MINIX_TOOLS_DIR=${MINIX_TOOLS_DIR}" >> ${STATIC_DIR}/Makefile.common.inc -fi - . ${MINIX_LLVM_DIR}/minix.inc # Set default values for essential variables : ${JOBS=1} : ${GEN_GOLD_PLUGIN="yes"} : ${REBUILD_MINIX="yes"} -: ${GEN_STATIC_MAGIC="yes"} ######################## # Generate Gold Plugin @@ -95,7 +85,7 @@ fi ######################## # Build Minix ######################## -export BUILDVARS=$(echo "${BUILDVARS} -V MKBITCODE=yes"| sed -e 's,-V MKMAGIC=yes,-V DBG=-g -V STRIPFLAG=-s -V CPPFLAGS=-D_MINIX_MAGIC=1,') +export BUILDVARS=$(echo "${BUILDVARS} -V MKBITCODE=yes"| sed -e 's,-V MKMAGIC=yes,-V MKMAGIC=yes -V DBG=-g -V STRIPFLAG=-s -V CPPFLAGS=-D_MINIX_MAGIC=1,') if [ "${REBUILD_MINIX}" == "yes" ]; then @@ -118,19 +108,4 @@ else echo "Building Minix: NO" fi -if [ "${GEN_STATIC_MAGIC}" == "yes" ]; then - echo "Building static magic library..." - cd ${STATIC_DIR}/magic - make install || EXITCODE=1 - cd ${MYPWD} - if [ "$EXITCODE" != "0" ]; then - echo "Error: Failed building static magic library." - exit $EXITCODE - else - echo "Completed building static magic library." - fi -else - echo "Building static magic library: NO" -fi - exit $EXITCODE diff --git a/minix/llvm/include/magic_rcu.h b/minix/llvm/include/magic_rcu.h deleted file mode 100644 index 76c39025b..000000000 --- a/minix/llvm/include/magic_rcu.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _MAGIC_RCU_H -#define _MAGIC_RCU_H - -void magic_rcu_quiescent_begin(); -void magic_rcu_quiescent_end(); -void magic_rcu_quiescent_state(); -void magic_rcu_quiescent_state_start(); -void magic_rcu_quiescent_state_end(); - -void magic_rcu_init(); -void magic_synchronize_rcu(); - -void magic_rcu_read_lock(); -void magic_rcu_read_unlock(); - -#define magic_rcu_has_atomic_quiescent_state() magic_rcu_has_atomic_qs -extern int magic_rcu_has_atomic_qs; - -#endif /* _MAGIC_RCU_H */ diff --git a/minix/llvm/relink.llvm b/minix/llvm/relink.llvm index ffa650c68..1b59c701d 100755 --- a/minix/llvm/relink.llvm +++ b/minix/llvm/relink.llvm @@ -56,27 +56,18 @@ function build_llvm_libs() local LIBS="" for a in $* do - LIBS="$LIBS `find $INSTALL_DIR -maxdepth 1 -name ${a}\*.bcc | xargs`" + LIBS="$LIBS `find $INSTALL_DIR -maxdepth 2 -name ${a}\*.bcc | xargs`" done echo $LIBS } function find_static_libs() { - local stat_libs_llvmapps= local stat_libs_minix= - local install_dir_save= - stat_libs_llvmapps=`build_llvm_libs $*` - - install_dir_save=${INSTALL_DIR} - - INSTALL_DIR=${MINIX_LLVM_BIN_DIR} stat_libs_minix=`build_llvm_libs $*` - INSTALL_DIR=${install_dir_save} - - echo "${stat_libs_llvmapps} ${stat_libs_minix}" + echo "${stat_libs_minix}" } #Make sure we are running from the right directory @@ -90,10 +81,10 @@ fi . ${MINIX_LLVM_DIR}/minix.inc +INSTALL_DIR=${DESTDIR}/minix/lib + echo ".so and .bcc binaries of LLVM passes set to be picked up from:" echo " ${INSTALL_DIR}" -echo " and" -echo " ${MINIX_LLVM_BIN_DIR}" echo # Picking up the selected modules diff --git a/minix/llvm/static/Makefile.settings b/minix/llvm/static/Makefile.settings deleted file mode 100644 index c27de5dc2..000000000 --- a/minix/llvm/static/Makefile.settings +++ /dev/null @@ -1,76 +0,0 @@ -# THIS FILE IS AN EDITED VERSION OF A FILE GENERATED BY LLVM-APPS - -########################################################### -# llvm-apps settings for Minix binary instrumentation -########################################################### -_MINIX_LLVM_DIR=$(_MINIX_ROOT)/minix/llvm -_MINIX_OBJ_DIR=$(_MINIX_ROOT)/../obj.$(_MINIX_ARCH) -_MINIX_OBJ_LLVM_DIR=$(_MINIX_ROOT)/../obj_llvm.$(_MINIX_ARCH) -_MINIX_SYSROOT=$(_MINIX_OBJ_DIR)/destdir.$(_MINIX_ARCH) - -########################################################### -# Main configuration (override in common.overrides.*inc to match your settings) -########################################################### -HAVE_LLVM=1 -LLVMBASEDIR=$(_MINIX_LLVM_DIR) -LLVMPREFIX=$(_MINIX_OBJ_LLVM_DIR)/Release+Asserts -LLVM_TWOSTEP_LINKING_WITH_GOLD=0 -LLVM_TWOSTEP_LINKING_WITH_GOLD_USES_LLC=0 -LLVM_OUTPUT_TRG_DIR= -LLVM_CAP_ALL=CAP_AUDIT_CONTROL,CAP_AUDIT_WRITE,CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_DAC_READ_SEARCH,CAP_FOWNER,CAP_FSETID,CAP_IPC_LOCK,CAP_IPC_OWNER,CAP_KILL,CAP_LEASE,CAP_LINUX_IMMUTABLE,CAP_MAC_ADMIN,CAP_MAC_OVERRIDE,CAP_MKNOD,CAP_NET_ADMIN,CAP_NET_BIND_SERVICE,CAP_NET_BROADCAST,CAP_NET_RAW,CAP_SETGID,CAP_SETFCAP,CAP_SETPCAP,CAP_SETUID,CAP_SYS_ADMIN,CAP_SYS_BOOT,CAP_SYS_CHROOT,CAP_SYS_MODULE,CAP_SYS_NICE,CAP_SYS_PACCT,CAP_SYS_PTRACE,CAP_SYS_RAWIO,CAP_SYS_RESOURCE,CAP_SYS_TIME,CAP_SYS_TTY_CONFIG,CAP_SYSLOG,CAP_SYS_MODULE -########################################################### - -########################################################### -# Common variables -########################################################### -ABS_ROOT=$(LLVMBASEDIR) - -PERF_PATH=/usr/bin/perf -LLVMDIR=$(ABS_ROOT) -LLVMINC=$(LLVMDIR)/include -LLVMLIB=$(LLVMDIR)/lib -INSTALL_DIR=$(ABS_ROOT)/bin - -LLVMSECTIONIFY_SO=$(INSTALL_DIR)/sectionify.so -LLVMAOPIFY_SO=$(INSTALL_DIR)/aopify.so -LLVMMAGIC_ST_IN_LIBST=0 - -CC=clang -CXX=clang++ -CFLAGS=-fasynchronous-unwind-tables -g -I$(LLVMINC) -########################################################### - -########################################################### -# LLVM gold plugin support (see README.llvm for details) -# -# Note: LLVMGOLD_PREFIX below should point to a valid LLVM 2.9 (+LLVMGOLD_CC=llvm-gcc) [or LLVM >= 3.0 (+LLVMGOLD_CC=clang)] installation with gold plugin support (binutils >=2.22) -########################################################### -LLVMGOLD_HAS_LTO_DISABLE_OPT=1 -LLVMGOLD_PREFIX=$(LLVMPREFIX) -LLVMGOLD_PLUGIN=$(_MINIX_LLVM_DIR)/bin/LLVMgold.so - -LLVMGOLD_CC=$(_MINIX_TOOLS_DIR)/bin/i586-elf32-minix-clang -flto -LLVMGOLD_CXX=$(_MINIX_TOOLS_DIR)/bin/i586-elf32-minix-clang++ -flto -LLVMGOLD_AR=ar --plugin $(LLVMGOLD_PLUGIN) -LLVMGOLD_RANLIB=$(LLVMGOLD_AR) -s - -LLVMGOLD_AR_FLAGS=--plugin $(LLVMGOLD_PLUGIN) -cru -LLVMGOLD_CFLAGS=-fasynchronous-unwind-tables -g -D_MINIX -D_POSIX_SOURCE -D_SYSTEM -Wno-long-long --sysroot=$(_MINIX_SYSROOT) -I$(LLVMINC) -I$(_MINIX_OBJ_LLVM_DIR)/include/llvm -I$(_MINIX_ROOT)/external/bsd/llvm/dist/llvm/include -I$(_MINIX_OBJ_LLVM_DIR)/include -I$(_MINIX_SYSROOT)/usr/include -LLVMGOLD_LINK=-Wl,--plugin -Wl,$(LLVMGOLD_PLUGIN) -LLVMGOLD_LINKFLAGS=-Wl,-plugin-opt=-disable-fp-elim -Wl,-plugin-opt=save-temps -LLVMGOLD_LINKCOMMONFLAGS=-L$(_MINIX_OBJ_DIR)/destdir.$(_MINIX_ARCH)/usr/lib -rdynamic -LLVMGOLD_LIBS= -LLVMGOLD_LDFLAGS=$(LLVMGOLD_LINK) $(LLVMGOLD_LINKFLAGS) $(LLVMGOLD_LINKCOMMONFLAGS) $(LLVMGOLD_LIBS) -LLVMGOLD_OPTFLAGS=-disable-internalize -mem2reg -std-compile-opts -LLVMGOLD_LLCFLAGS=--disable-fp-elim -LLVMGOLD_TSLINK_PARTIALFLAGS=-Wl,-r -nostdlib -LLVMGOLD_TSLINK_FINALFLAGS=-B$(LLVMGOLD_PREFIX)/bfd_bin -LLVMGOLD_OPTIMIZED=1 - -########################################################### - -BUILD_LLVMAPPS_FOR_MINIX=yes -GEN_GOLD_PLUGIN=yes -REBUILD_MINIX=yes -ARCH_NAME=x86 -ARCH_BITS=32 diff --git a/minix/llvm/static/magic/Makefile b/minix/llvm/static/magic/Makefile deleted file mode 100644 index 8fac9ee9c..000000000 --- a/minix/llvm/static/magic/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -#Makefile for creating the magic static library - -MODULE = magic -OBJS = magic.o magic_analysis.o magic_asr.o magic_eval_lib.o magic_eval.o magic_mem.o magic_range.o magic_splay_tree.o magic_sentry.o magic_selement.o -HEADERS = $(wildcard $(LLVMINC)/*.h) $(wildcard $(LLVMINC)/st/*.h) - -USE_SECTIONIFY=YES -SECTIONIFY_NO_OVERRIDE=yes -SECTIONIFY_DATA_SECTION_MAP=^_____magic_instr_.*/magic_instr_data,.*/magic_data -SECTIONIFY_FUNCTION_SECTION_MAP=.*/magic_functions - -OBJS += minix/magic_util.o minix/magic_ds.o -HEADERS += $(wildcard minix/*.h) - -OBJS+=magic_st.bcc - -include Makefile.inc - -CFLAGS += -I$(_MINIX_ROOT)/minix/servers - -# XXX: there is essential code in assert() statements, so force asserts on.. -CFLAGS += -UNDEBUG - -magic_st.bcc: - make -f Makefile.magic_st $@ - -magic_st.o: - make -f Makefile.magic_st $@ - diff --git a/minix/llvm/static/magic/Makefile.inc b/minix/llvm/static/magic/Makefile.inc deleted file mode 100644 index 258bdfd4b..000000000 --- a/minix/llvm/static/magic/Makefile.inc +++ /dev/null @@ -1,58 +0,0 @@ - -include ../Makefile.common.inc -include ../Makefile.settings - -MODULE_NAME=$(MODULE).bcc - -CFLAGS += $(CXXFLAGS) -Wall -g -Wno-long-long -CFLAGS += -D__MINIX -D_MINIX_SYSTEM - -LLVM_VERSION=$(shell $(LLVMPREFIX)/bin/llvm-config --version | cut -d"." -f1,2 | sed "s/[^0-9]//g") - -HAVE_NOCONSTRUCTOR_PRIORITY = $(shell expr $(LLVM_VERSION) \>= 30) -ifeq ($(HAVE_NOCONSTRUCTOR_PRIORITY),0) -CFLAGS += -DHAVE_NOCONSTRUCTOR_PRIORITY=1 -endif - -ifeq ($(USE_SECTIONIFY),YES) -LOPT_FLAGS+=-load=$(LLVMSECTIONIFY_SO) -sectionify -sectionify-no-override -sectionify-data-section-map=$(SECTIONIFY_DATA_SECTION_MAP) -sectionify-function-section-map=$(SECTIONIFY_FUNCTION_SECTION_MAP) -ifeq (SECTIONIFY_NO_OVERRIDE,YES) -LOPT_FLAGS+=-sectionify-no-override -endif -endif - -V?=0 -ifneq ($V,0) -QUIET= -ECHO:=@\# -QMAKE=VERBOSE=1 make -else -QUIET= @ -ECHO= echo -QMAKE=make -s -endif - -$(MODULE_NAME): $(OBJS) $(HEADERS) $(COMMON_BCCS) - $(QUIET) $(ECHO) " [GOLD_LINK] $@.o" - $(QUIET) $(LLVMGOLD_CC) $(CFLAGS) $(LLVMGOLD_CFLAGS) $(LLVMGOLD_LDFLAGS) -shared -o $@.o $(OBJS) $(COMMON_BCCS) - $(QUIET) $(ECHO) " [OPT] $@" - $(QUIET) $(LLVMPREFIX)/bin/opt $(LOPT_FLAGS) -o $@ $@.o.bc - -all: $(MODULE_NAME) - -%.o: %.c $(HEADERS) - $(QUIET) $(ECHO) " [GOLD_CC] $<" - $(QUIET) $(LLVMGOLD_CC) $(CFLAGS) $(LLVMGOLD_CFLAGS) $(INCLUDES) $(INCLUDES_$<) -c -o $@ $< - -install: $(INSTALL_DIR)/$(MODULE_NAME) - -$(INSTALL_DIR)/$(MODULE_NAME): $(MODULE_NAME) - install -c -D -m 744 $? $@ - -clean: $(EXTRA_CLEAN) - $(QUIET) $(ECHO) " [RM] *.BCC *.bcc *.bc *.BCL *.BCL.sh *.bcl $(OBJS) *.s $(COMMON_BCCS)" - $(QUIET) rm -f *.BCC *.bcc *.bc *.BCL *.BCL.sh *.bcl *.o $(OBJS) *.s $(COMMON_BCCS) - -distclean: clean - $(QUIET) $(ECHO) " [RM] $(INSTALL_DIR)/$(MODULE_NAME)" - $(QUIET) rm -f $(INSTALL_DIR)/$(MODULE_NAME) diff --git a/minix/llvm/static/magic/Makefile.magic_st b/minix/llvm/static/magic/Makefile.magic_st deleted file mode 100644 index 9ec7c54cd..000000000 --- a/minix/llvm/static/magic/Makefile.magic_st +++ /dev/null @@ -1,11 +0,0 @@ - -MODULE = magic_st - -OBJS = magic_st.o - -USE_SECTIONIFY=YES -SECTIONIFY_DATA_SECTION_MAP=.*/magic_data_st -SECTIONIFY_FUNCTION_SECTION_MAP=.*/magic_functions_st - -include Makefile.inc - diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index a13a0c9f4..73867e33f 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -213,6 +213,17 @@ SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \ -Wl,-plugin-opt=-disable-opt SECTIONIFYPASS?=${NETBSDSRCDIR}/minix/llvm/bin/sectionify.so +# dcvmoole: the following construction is a hack for libmagicrt. For reasons +# not entirely under our control, clang refuses to take .bc objects even when +# using the gold linker, saying that LLVM IR code cannot be linked. In order +# to sidestep this, libmagicrt uses the name "foo.bc.o" instead of "foo.bc" to +# link the its LLVM IR objects. As all libmagicrt modules use the sectionify +# pass below, and this step needs temporary files, we give the temporary files +# the .o suffix (while anything would do!), and allow the libmagicrt makefile +# to override the rename to the real file name to perform a copy instead. As +# a result, libmagicrt ends up with both the .bc and .bc.o objects, and it can +# pass the latter set to clang, bypassing clang's overly strict checks. +SECTIONIFYMV?=mv -f .S.bc: ${.TARGET:.bc=.o} rm -f ${.TARGET} @@ -220,8 +231,8 @@ SECTIONIFYPASS?=${NETBSDSRCDIR}/minix/llvm/bin/sectionify.so .c.bc: ${_MKTARGET_COMPILE} ${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto - if [ -n '${SECTIONIFY.${.IMPSRC:T}}' ]; then \ - ${OPT} -load ${SECTIONIFYPASS} -sectionify ${SECTIONIFY.${.IMPSRC:T}} -o ${.TARGET}.tmp ${.TARGET} && mv -f ${.TARGET}.tmp ${.TARGET}; \ + if [ -n '${SECTIONIFY.${.IMPSRC:T}:U${SECTIONIFY}}' ]; then \ + ${OPT} -load ${SECTIONIFYPASS} -sectionify ${SECTIONIFY.${.IMPSRC:T}:U${SECTIONIFY}} -o ${.TARGET}.o ${.TARGET} && ${SECTIONIFYMV} ${.TARGET}.o ${.TARGET}; \ fi .cc.bc .cxx.bc .cpp.bc: @@ -545,7 +556,9 @@ SOBJS= _YLSRCS= ${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}} .if ${USE_BITCODE:Uno} == "yes" +.if defined(LIB) _LIBS+=${_LIB_bc.a} +.endif .endif # ${USE_BITCODE:Uno} == "yes" .NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS} diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk index 4fe5a8ae6..f66aef792 100644 --- a/share/mk/bsd.own.mk +++ b/share/mk/bsd.own.mk @@ -1305,7 +1305,7 @@ _MKVARS.no= \ #MINIX-specific vars _MKVARS.no+= \ - MKIMAGEONLY MKSMALL MKBITCODE MKSRC + MKIMAGEONLY MKSMALL MKBITCODE MKMAGIC MKSRC .if !empty(MACHINE_ARCH:Mearm*) _MKVARS.no+= \ MKWATCHDOG MKACPI MKAPIC MKDEBUGREG MKINSTALLBOOT MKPCI @@ -1411,6 +1411,11 @@ MKSYSDEBUG:= no MKLIVEUPDATE:= no .endif +# MINIX: MKMAGIC implies MKBITCODE +.if ${MKMAGIC} == "yes" +MKBITCODE:= yes +.endif + .if !empty(MACHINE_ARCH:Mearm*) _NEEDS_LIBCXX.${MACHINE_ARCH}= yes .endif @@ -1487,7 +1492,7 @@ ${var}?= yes #MINIX-specific vars .for var in \ USE_WATCHDOG USE_ACPI USE_APIC USE_DEBUGREG USE_SYSDEBUG \ - USE_LIVEUPDATE USE_PCI USE_BITCODE + USE_LIVEUPDATE USE_PCI USE_BITCODE USE_MAGIC .if (${${var:S/USE_/MK/}} == "no") ${var}:= no .else