# HG changeset patch # User Tassilo Philipp # Date 1491437637 -7200 # Node ID 0592eb360af27288bd2a95df6a5b3628ee752ef4 # Parent 98057b3b28c25414e7356df1883559192eea607c tests: - added dynload_plain test - added some more output to resolv_self - cleanups diff -r 98057b3b28c2 -r 0592eb360af2 ChangeLog --- a/ChangeLog Tue Mar 28 15:45:20 2017 +0200 +++ b/ChangeLog Thu Apr 06 02:13:57 2017 +0200 @@ -28,6 +28,8 @@ o better documentation, removed relative path dependencies, general cleanup o python: updated to latest signature format (was still on 0.1) o java: rewritten (old version was never complete, anyways) +tests: + o added new dynload_plain test covering basic use of all dynload functions buildsys: o cmake: made to work on systems without C++ compiler (thanks Franklin Mathieu) diff -r 98057b3b28c2 -r 0592eb360af2 test/CMakeLists.txt --- a/test/CMakeLists.txt Tue Mar 28 15:45:20 2017 +0200 +++ b/test/CMakeLists.txt Thu Apr 06 02:13:57 2017 +0200 @@ -18,6 +18,7 @@ add_subdirectory(suite) add_subdirectory(callf) add_subdirectory(nm) +add_subdirectory(dynload_plain) add_subdirectory(resolve_self) add_subdirectory(thunk) add_subdirectory(malloc_wx) diff -r 98057b3b28c2 -r 0592eb360af2 test/Makefile.embedded --- a/test/Makefile.embedded Tue Mar 28 15:45:20 2017 +0200 +++ b/test/Makefile.embedded Thu Apr 06 02:13:57 2017 +0200 @@ -3,6 +3,7 @@ all: all-dyncall all-dyncallback all-dynload all-dynload: cd nm && ${MAKE_CMD} + cd dynload_plain && ${MAKE_CMD} cd resolve_self && ${MAKE_CMD} all-dyncall: cd suite && ${MAKE_CMD} @@ -26,6 +27,7 @@ cd call_suite && ${MAKE_CMD} cd callf && ${MAKE_CMD} cd nm && ${MAKE_CMD} + cd dynload_plain && ${MAKE_CMD} cd resolve_self && ${MAKE_CMD} cd thunk && ${MAKE_CMD} cd malloc_wx && ${MAKE_CMD} @@ -57,6 +59,7 @@ cd ellipsis && ${MAKE_CMD} clean cd callf && ${MAKE_CMD} clean cd nm && ${MAKE_CMD} clean + cd dynload_plain && ${MAKE_CMD} clean cd resolve_self && ${MAKE_CMD} clean cd thunk && ${MAKE_CMD} clean cd malloc_wx && ${MAKE_CMD} clean diff -r 98057b3b28c2 -r 0592eb360af2 test/Makefile.generic --- a/test/Makefile.generic Tue Mar 28 15:45:20 2017 +0200 +++ b/test/Makefile.generic Thu Apr 06 02:13:57 2017 +0200 @@ -1,6 +1,6 @@ -ALL=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf syscall nm resolve_self thunk malloc_wx callback_plain -PACK=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf resolve_self callback_plain -ALL_C=plain call_suite suite callf syscall nm resolve_self thunk malloc_wx callback_plain callback_suite +ALL=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf syscall nm dynload_plain resolve_self thunk malloc_wx callback_plain +PACK=call_suite callback_suite plain plain_c++ suite suite2 suite3 suite_floats ellipsis callf dynload_plain resolve_self callback_plain +ALL_C=plain call_suite suite callf syscall nm dynload_plain resolve_self thunk malloc_wx callback_plain callback_suite .PHONY: all clean run-tests install distclean ${ALL} all clean install: ${MAKE} TARGET=$@ ${ALL} @@ -15,6 +15,7 @@ cd callf && ${MAKE} cd syscall && ${MAKE} cd nm && ${MAKE} + cd dynload_plain && ${MAKE} cd resolve_self && ${MAKE} cd thunk && ${MAKE} cd malloc_wx && ${MAKE} @@ -56,9 +57,11 @@ # cd plain && ${MAKE} all-dynload: cd nm && ${MAKE} + cd dynload_plain && ${MAKE} cd resolve_self && ${MAKE} run-dynload: #nm/nm + dynload_plain/dynload_plain resolve_self/resolve_self all-dyncallback: cd thunk && ${MAKE} diff -r 98057b3b28c2 -r 0592eb360af2 test/Nmakefile --- a/test/Nmakefile Tue Mar 28 15:45:20 2017 +0200 +++ b/test/Nmakefile Thu Apr 06 02:13:57 2017 +0200 @@ -30,7 +30,7 @@ !INCLUDE $(TOP)\buildsys\nmake\prolog.nmake -DIRS = call_suite suite suite2 suite3 suite_floats callf ellipsis plain plain_c++ nm resolve_self thunk malloc_wx callback_plain callback_suite +DIRS = call_suite suite suite2 suite3 suite_floats callf ellipsis plain plain_c++ nm dynload_plain resolve_self thunk malloc_wx callback_plain callback_suite !IF "$(BUILD_ARCH)" == "x86" DIRS = $(DIRS) suite_x86win32fast suite_x86win32std suite2_x86win32fast suite2_x86win32std !ENDIF diff -r 98057b3b28c2 -r 0592eb360af2 test/dynload_plain/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/dynload_plain/CMakeLists.txt Thu Apr 06 02:13:57 2017 +0200 @@ -0,0 +1,3 @@ +add_executable(dynload_plain dynload_plain.c) +target_link_libraries(dynload_plain dynload_s ${CMAKE_DL_LIBS}) + diff -r 98057b3b28c2 -r 0592eb360af2 test/dynload_plain/Makefile.embedded --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/dynload_plain/Makefile.embedded Thu Apr 06 02:13:57 2017 +0200 @@ -0,0 +1,20 @@ +APP = dynload_plain +OBJS = dynload_plain.o + +TOP = ../.. +CFLAGS += -I${TOP}/dynload +LDFLAGS += -L${TOP}/dynload +LDLIBS += -ldynload_s +# Works on: Darwin, NetBSD. +# Linux: add '-ldl' + +all: ${APP} + +.PHONY: all clean + +${APP}: ${OBJS} + ${CC} ${OBJS} ${LDFLAGS} ${LDLIBS} -o $@ + +clean: + rm -f ${APP} ${OBJS} + diff -r 98057b3b28c2 -r 0592eb360af2 test/dynload_plain/Makefile.generic --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/dynload_plain/Makefile.generic Thu Apr 06 02:13:57 2017 +0200 @@ -0,0 +1,18 @@ +APP = dynload_plain +OBJS = dynload_plain.o +SRCTOP = ${VPATH}/../.. +BLDTOP = ../.. +CFLAGS += -I${SRCTOP}/dynload +LDLIBS_D += -L${BLDTOP}/dynload -ldynload_s +# Works on: Darwin, NetBSD. +# Linux: add '-ldl' +.PHONY: all clean install +all: ${APP} +${APP}: ${OBJS} + ${CC} ${CFLAGS} ${LDFLAGS} ${OBJS} ${LDLIBS_D} ${LDLIBS} -o ${APP} +clean: + rm -f ${APP} ${OBJS} +install: + mkdir -p ${PREFIX}/test + cp ${APP} ${PREFIX}/test + diff -r 98057b3b28c2 -r 0592eb360af2 test/dynload_plain/Nmakefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/dynload_plain/Nmakefile Thu Apr 06 02:13:57 2017 +0200 @@ -0,0 +1,59 @@ +#////////////////////////////////////////////////////////////////////////////// +# +# Copyright (c) 2017 Tassilo Philipp +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +#////////////////////////////////////////////////////////////////////////////// + +#/////////////////////////////////////////////////// +# +# nmake makefile +# Nmakefile +# +#/////////////////////////////////////////////////// + + +TOP = ..\.. + +!INCLUDE $(TOP)\buildsys\nmake\prolog.nmake + + +!IF "$(BUILD_OS)" == "windows" + +TARGETS = dynload_plain.exe +OBJS = dynload_plain.obj + +$(TARGETS): $(OBJS) + echo Linking $@ ... + $(LD) /OUT:"$@" $(LDFLAGS) $(OBJS) $(TOP)\dynload\libdynload_s.lib $(TOP)\dyncall\libdyncall_s.lib + + +!ELSE IF "$(BUILD_OS)" == "nds" + +TARGETS = dynload_plain.nds +OBJS = dynload_plain.o + +$(TARGETS):# $(OBJS) + echo Not building: There is no dynload support on this platform. +# echo Linking $@ ... +# $(LD) $(LDFLAGS) $(OBJS) $(DEVKITPRO_PATH)\libnds\lib\libnds9.a $(TOP)\dynload\libdynload_s.a $(TOP)/dyncall/libdyncall_s.a -o "$(@B).elf" +# $(OCP) -O binary "$(@B).elf" "$(@B).arm9" +# ndstool -c "$@" -9 "$(@B).arm9" +# del "$(@B).elf" "$(@B).arm9" + +!ENDIF + + +!INCLUDE $(TOP)\buildsys\nmake\epilog.nmake + diff -r 98057b3b28c2 -r 0592eb360af2 test/dynload_plain/dynload_plain.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/dynload_plain/dynload_plain.c Thu Apr 06 02:13:57 2017 +0200 @@ -0,0 +1,127 @@ +/* + + Package: dyncall + Library: test + File: test/dynload_plain/dynload_plain.c + Description: + License: + + Copyright (c) 2017 Tassilo Philipp + + Permission to use, copy, modify, and distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +*/ + + +#include "../../dynload/dynload.h" +#include "../common/platformInit.h" + +#include +#include + + +int main(int argc, char* argv[]) +{ + int r = 0, i; + void* p; + DLLib* pLib; + const char* path = NULL; + const char* clibs[] = { // hacky/lazy list of some clib paths per platform + "/lib/libc.so", + "/lib/libc.so.6", + "/lib/libc.so.7", + "/lib64/libc.so", + "/lib64/libc.so.6", + "/lib64/libc.so.7", + "/lib32/libc.so", + "/lib32/libc.so.6", + "/lib32/libc.so.7", + "/usr/lib/libc.dylib", + "C:\\Windows\\system32\\msvcrt.dll" + }; + + + for(i=0; i<(sizeof(clibs)/sizeof(const char*)); ++i) { + if(access(clibs[i], F_OK) != -1) + path = clibs[i]; + } + + if(path) { + printf("using clib to test at: %s\n", path); + ++r; + + // dl*Library tests + // -------- + pLib = dlLoadLibrary(path); // check if we can load a lib + if(pLib) { + printf("pLib handle: %p\n", pLib); + ++r; + + p = dlFindSymbol(pLib, "printf"); // check if we can lookup a symbol + printf("printf at: %p\n", p); + r += (p != NULL); + + dlFreeLibrary(pLib); + } + else + printf("unable to open library %s\n", path); + + + // dlSyms* tests (intentionally after freeing lib above, as they work standalone) + // -------- + DLSyms* pSyms = dlSymsInit(path); // check if we can iterate over symbols - init + if(pSyms) { + int n; + const char* name; + + printf("pSyms handle: %p\n", pSyms); + ++r; + + n = dlSymsCount(pSyms); // check if there are some syms to iterate over + printf("num of libc symbols: %d\n", n); + r += (n > 0); + + for(i=0; i name, + if(pLib) { // need to lookup by name again, first + p = dlFindSymbol(pLib, "printf"); + name = dlSymsNameFromValue(pSyms, p); + printf("printf symbol name by its own address (%p): %s\n", p, name); + r += (strcmp(name, "printf") == 0); + dlFreeLibrary(pLib); + } + + dlSymsCleanup(pSyms); + } + else + printf("dlSymsInit failed\n"); + } + + // All worked if we got a score of 6 right ones + r = (r == 8); + printf("result: dynload_plain: %d\n", r); + return !r; +} + diff -r 98057b3b28c2 -r 0592eb360af2 test/nm/nm.c --- a/test/nm/nm.c Tue Mar 28 15:45:20 2017 +0200 +++ b/test/nm/nm.c Thu Apr 06 02:13:57 2017 +0200 @@ -53,18 +53,18 @@ int i, n; DLLib* pLib; const char* libPath; - + if (argc == 1) { fprintf(stderr, "usage : %s \n", argv[0]); return 1; } - + libPath = argv[1]; - + /* load lib */ pLib = dlLoadLibrary(libPath); - + if (!pLib) { fprintf(stderr, "unable to open library %s\n", libPath); return 2; diff -r 98057b3b28c2 -r 0592eb360af2 test/resolve_self/main.c --- a/test/resolve_self/main.c Tue Mar 28 15:45:20 2017 +0200 +++ b/test/resolve_self/main.c Thu Apr 06 02:13:57 2017 +0200 @@ -6,7 +6,7 @@ Description: License: - Copyright (c) 2011-2015 Daniel Adler , + Copyright (c) 2011-2017 Daniel Adler , Tassilo Philipp Permission to use, copy, modify, and distribute this software for any @@ -48,11 +48,17 @@ int status; DLLib* pLib = dlLoadLibrary(NULL); assert(pLib); + printf("self loaded at %p\n", pLib); address = dlFindSymbol(pLib, "add_dd_d"); - assert(address); - result = ( (double (*) (double,double) ) address ) (20.0, 3.0); - status = (result == 23); + if(address) { + printf("address of function add_dd_d at %p\n", address); + result = ( (double (*) (double,double) ) address ) (20.0, 3.0); + status = (result == 23); + } else { + printf("can't resolve address of add_dd_d, it doesn't seem to be a *dynamic* symbol\n"); + status = 0; + } printf("result: resolve_self: %d\n", status); return 0; } diff -r 98057b3b28c2 -r 0592eb360af2 test/runalltests.bat --- a/test/runalltests.bat Tue Mar 28 15:45:20 2017 +0200 +++ b/test/runalltests.bat Thu Apr 06 02:13:57 2017 +0200 @@ -31,3 +31,5 @@ pause callback_suite\callback_suite.exe pause +dynload_plain\dynload_plain.exe +pause