Add loading of ET_DYN shared object test to sotest
* examples/sotest/lib/Makefile - Add dynload directory to build * examples/sotest/lib/dynload/Makefile - Build the dynload shared object test - Use SHMODULEFLAGS and not SHLDFLAGS * examples/sotest/lib/dynload/dynload.c - Test case for loading of ET_DYN shared objects * examples/sotest/lib/dynload/.gitignore - Exclude built object from git * examples/sotest/sotest_main.c - Load and invoke the dynload test
This commit is contained in:
parent
2d4233c825
commit
72eaed8fdd
@ -24,8 +24,8 @@ ALL_SUBDIRS = sotest
|
|||||||
BUILD_SUBDIRS = sotest
|
BUILD_SUBDIRS = sotest
|
||||||
|
|
||||||
ifneq ($(CONFIG_MODLIB_MAXDEPEND),0)
|
ifneq ($(CONFIG_MODLIB_MAXDEPEND),0)
|
||||||
ALL_SUBDIRS += modprint
|
ALL_SUBDIRS += modprint dynload
|
||||||
BUILD_SUBDIRS += modprint
|
BUILD_SUBDIRS += modprint dynload
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SOTEST_DIR = $(APPDIR)/examples/sotest
|
SOTEST_DIR = $(APPDIR)/examples/sotest
|
||||||
|
1
examples/sotest/lib/dynload/.gitignore
vendored
Normal file
1
examples/sotest/lib/dynload/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/dynload
|
55
examples/sotest/lib/dynload/Makefile
Normal file
55
examples/sotest/lib/dynload/Makefile
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/examples/sotest/lib/dynload/Makefile
|
||||||
|
#
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
# contributor license agreements. See the NOTICE file distributed with
|
||||||
|
# this work for additional information regarding copyright ownership. The
|
||||||
|
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance with the
|
||||||
|
# License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBC),y)
|
||||||
|
LDLIBPATH += -L $(NUTTXLIB)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_SOTEST_LIBC),y)
|
||||||
|
LDLIBS += -lc
|
||||||
|
endif
|
||||||
|
|
||||||
|
BIN = dynload
|
||||||
|
|
||||||
|
SRCS = $(BIN).c
|
||||||
|
OBJS = $(SRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
all: $(BIN)
|
||||||
|
.PHONY: all clean install
|
||||||
|
|
||||||
|
$(OBJS): %$(OBJEXT): %.c
|
||||||
|
@echo "MODULECC: $<"
|
||||||
|
$(Q) $(MODULECC) -c $(CMODULEFLAGS) $(SHCCFLAGS) $< -o $@
|
||||||
|
|
||||||
|
$(BIN): $(OBJS)
|
||||||
|
@echo "MODULELD: $<"
|
||||||
|
$(Q) $(MODULELD) $(SHMODULEFLAGS) $(LDLIBPATH) -o $@ $^ $(LDLIBS)
|
||||||
|
|
||||||
|
$(FSROOT_DIR)/$(BIN): $(BIN)
|
||||||
|
$(Q) mkdir -p $(FSROOT_DIR)
|
||||||
|
$(Q) install $(BIN) $(FSROOT_DIR)/$(BIN)
|
||||||
|
|
||||||
|
install: $(FSROOT_DIR)/$(BIN)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call DELFILE, $(BIN))
|
||||||
|
$(call CLEAN)
|
51
examples/sotest/lib/dynload/dynload.c
Normal file
51
examples/sotest/lib/dynload/dynload.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/examples/sotest/lib/dynload/dynload.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/symtab.h>
|
||||||
|
#include <nuttx/lib/modlib.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dynload(int);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: dynload
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int dynload(int a)
|
||||||
|
{
|
||||||
|
return a + 10;
|
||||||
|
}
|
@ -105,6 +105,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
char devname[32];
|
char devname[32];
|
||||||
#if CONFIG_MODLIB_MAXDEPEND > 0
|
#if CONFIG_MODLIB_MAXDEPEND > 0
|
||||||
FAR void *handle1;
|
FAR void *handle1;
|
||||||
|
FAR void *handle3;
|
||||||
#endif
|
#endif
|
||||||
FAR void *handle2;
|
FAR void *handle2;
|
||||||
CODE void (*testfunc)(FAR const char *msg);
|
CODE void (*testfunc)(FAR const char *msg);
|
||||||
@ -170,6 +171,32 @@ int main(int argc, FAR char *argv[])
|
|||||||
fprintf(stderr, "ERROR: dlopen(/modprint) failed\n");
|
fprintf(stderr, "ERROR: dlopen(/modprint) failed\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle3 = dlopen(BINDIR "/dynload", RTLD_NOW | RTLD_LOCAL);
|
||||||
|
if (handle3 == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: dlopen(/dynload) failed - %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int (*dynload)(int);
|
||||||
|
dynload = dlsym(handle3, "dynload");
|
||||||
|
if (dynload != NULL)
|
||||||
|
{
|
||||||
|
int a = dynload(32);
|
||||||
|
printf("dynload returned %d which is the %s answer\n",
|
||||||
|
a, (a == 42 ? "correct" : "incorrect"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: dlsym(dynload) failed - %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Install the second test shared library */
|
/* Install the second test shared library */
|
||||||
@ -273,6 +300,13 @@ int main(int argc, FAR char *argv[])
|
|||||||
fprintf(stderr, "ERROR: dlclose(handle1) failed: %d\n", ret);
|
fprintf(stderr, "ERROR: dlclose(handle1) failed: %d\n", ret);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = dlclose(handle3);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: dlclose(handle3) failed: %d\n", ret);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS
|
#ifdef CONFIG_EXAMPLES_SOTEST_BUILTINFS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user