diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349 (patch) | |
tree | defd1cc07d16ad2f3b21154114e092d11c94c5bb /libdl | |
download | bionic-a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349.zip bionic-a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349.tar.gz bionic-a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349.tar.bz2 |
Initial Contributionandroid-1.0
Diffstat (limited to 'libdl')
-rw-r--r-- | libdl/Android.mk | 50 | ||||
-rw-r--r-- | libdl/MODULE_LICENSE_BSD | 0 | ||||
-rw-r--r-- | libdl/NOTICE | 26 | ||||
-rwxr-xr-x | libdl/dltest.c | 119 | ||||
-rw-r--r-- | libdl/libdl.c | 24 |
5 files changed, 219 insertions, 0 deletions
diff --git a/libdl/Android.mk b/libdl/Android.mk new file mode 100644 index 0000000..661aa18 --- /dev/null +++ b/libdl/Android.mk @@ -0,0 +1,50 @@ +LOCAL_PATH:= $(call my-dir) + +# +# libdl +# + +include $(CLEAR_VARS) + +# NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from +# libgcc.a are made static to libdl.so. This in turn ensures that libraries that +# a) pull symbols from libgcc.a and b) depend on libdl.so will not rely on libdl.so +# to provide those symbols, but will instead pull them from libgcc.a. Specifically, +# we use this property to make sure libc.so has its own copy of the code from +# libgcc.a it uses. +# +# DO NOT REMOVE --exclude-libs! + +LOCAL_LDFLAGS := -Wl,--exclude-libs=libgcc.a +LOCAL_SRC_FILES:= libdl.c + +LOCAL_MODULE:= libdl + +# NOTE: libdl needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a needs a +# few symbols from libc. Using --no-undefined here results in having to link +# against libc creating a circular dependency which is removed and we end up +# with missing symbols. Since this library is just a bunch of stubs, we set +# LOCAL_ALLOW_UNDEFINED_SYMBOLS to remove --no-undefined from the linker flags. +LOCAL_ALLOW_UNDEFINED_SYMBOLS := true +LOCAL_SYSTEM_SHARED_LIBRARIES := + +include $(BUILD_SHARED_LIBRARY) + +BUILD_DLTEST:=0 +ifeq ($(BUILD_DLTEST),1) + +# +# dltest +# + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= dltest.c + +LOCAL_MODULE:= dltest + +LOCAL_SHARED_LIBRARIES := libdl + +include $(BUILD_EXECUTABLE) + +endif diff --git a/libdl/MODULE_LICENSE_BSD b/libdl/MODULE_LICENSE_BSD new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/libdl/MODULE_LICENSE_BSD diff --git a/libdl/NOTICE b/libdl/NOTICE new file mode 100644 index 0000000..3831b34 --- /dev/null +++ b/libdl/NOTICE @@ -0,0 +1,26 @@ +Copyright (C) 2007 The Android Open Source Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. Neither the name of the project nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. diff --git a/libdl/dltest.c b/libdl/dltest.c new file mode 100755 index 0000000..e84d5a3 --- /dev/null +++ b/libdl/dltest.c @@ -0,0 +1,119 @@ +#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <string.h>
+#include <dlfcn.h>
+
+extern char *optarg;
+extern int optind, opterr, optopt;
+
+static struct option long_options[] = {
+ {"library", required_argument, 0, 'l'},
+ {"symbol", required_argument, 0, 's'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0},
+};
+
+/* This array must parallel long_options[] */
+static const char *descriptions[] = {
+ "specify a library path to look up symbol",
+ "specify symbol to look up",
+ "print this help screen",
+};
+
+void print_help(const char *name) {
+ fprintf(stdout,
+ "invokation:\n"
+ "\t%s [-l <libname>] -s <symbol name>\n"
+ "\t%s -h\n\n", name, name);
+ fprintf(stdout, "options:\n");
+ struct option *opt = long_options;
+ const char **desc = descriptions;
+ while (opt->name) {
+ fprintf(stdout, "\t-%c/--%s%s: %s\n",
+ opt->val,
+ opt->name,
+ (opt->has_arg ? " (argument)" : ""),
+ *desc);
+ opt++;
+ desc++;
+ }
+}
+
+int get_options(int argc, char **argv, char **lib, char **sym)
+{
+ int c;
+
+ *lib = 0;
+ *sym = 0;
+
+ while (1) {
+ /* getopt_long stores the option index here. */
+ int option_index = 0;
+
+ c = getopt_long (argc, argv,
+ "l:s:h",
+ long_options,
+ &option_index);
+ /* Detect the end of the options. */
+ if (c == -1) break;
+
+ switch (c) {
+ case 'l':
+ *lib = strdup(optarg);
+ break;
+ case 's':
+ *sym = strdup(optarg);
+ break;
+ case 'h': print_help(argv[0]); exit(EXIT_FAILURE); break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ break;
+ default:
+ fprintf(stderr, "Unknown option");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ return optind;
+}
+
+int main(int argc, char **argv)
+{
+ char *libname, *symname, *prog = *argv;
+
+ get_options(argc, argv, &libname, &symname);
+
+ if (symname == NULL) {
+ fprintf(stderr, "You must specify a symbol!\n");
+ print_help(prog);
+ exit(EXIT_FAILURE);
+ }
+
+ {
+ const char *dlerr;
+ void *handle, *symbol;
+
+ printf("opening library [%s]\n", libname);
+ dlerr = dlerror();
+ handle = libname ? dlopen(libname, RTLD_NOW) : RTLD_DEFAULT;
+ dlerr = dlerror();
+ if (dlerr != NULL) fprintf(stderr, "dlopen() error: %s\n", dlerr);
+
+ printf("opening symbol [%s]\n", symname);
+ symbol = dlsym(handle, symname);
+ dlerr = dlerror();
+ if (dlerr != NULL) fprintf(stderr, "dlsym() error: %s\n", dlerr);
+
+ printf("closing library [%s]\n", libname);
+ dlclose(handle);
+ dlerr = dlerror();
+ if (dlerr != NULL) fprintf(stderr, "dlclose() error: %s\n", dlerr);
+ else printf("successfully opened symbol\n");
+ }
+
+ if (libname != NULL) free(libname);
+ if (symname != NULL) free(symname);
+ return 0;
+}
diff --git a/libdl/libdl.c b/libdl/libdl.c new file mode 100644 index 0000000..0411623 --- /dev/null +++ b/libdl/libdl.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed 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. + */ + +/* These are stubs for functions that are actually defined + * in the dynamic linker (dlfcn.c), and hijacked at runtime. + */ +void *dlopen(const char *filename, int flag) { return 0; } +char *dlerror(void) { return 0; } +void *dlsym(void *handle, const char *symbol) { return 0; } +int dlclose(void *handle) { return 0; } +void *dl_unwind_find_exidx(void *pc, int *pcount) { return 0; } |