SOURCES: uClibc-toolchain-wrapper.patch - correct version
arekm
arekm at pld-linux.org
Sun Jun 3 22:11:35 CEST 2007
Author: arekm Date: Sun Jun 3 20:11:35 2007 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- correct version
---- Files affected:
SOURCES:
uClibc-toolchain-wrapper.patch (1.7 -> 1.8)
---- Diffs:
================================================================
Index: SOURCES/uClibc-toolchain-wrapper.patch
diff -u SOURCES/uClibc-toolchain-wrapper.patch:1.7 SOURCES/uClibc-toolchain-wrapper.patch:1.8
--- SOURCES/uClibc-toolchain-wrapper.patch:1.7 Sun Jun 3 22:08:58 2007
+++ SOURCES/uClibc-toolchain-wrapper.patch Sun Jun 3 22:11:29 2007
@@ -1,88 +1,180 @@
diff -urN uClibc-0.9.29.org/extra/gcc-uClibc/gcc-uClibc.c uClibc-0.9.29/extra/gcc-uClibc/gcc-uClibc.c
--- uClibc-0.9.29.org/extra/gcc-uClibc/gcc-uClibc.c 1970-01-01 01:00:00.000000000 +0100
-+++ uClibc-0.9.29/extra/gcc-uClibc/gcc-uClibc.c 2007-06-03 22:03:22.061912354 +0200
-@@ -0,0 +1,518 @@
-+/* vi: set ts=4 :*/
++++ uClibc-0.9.29/extra/gcc-uClibc/gcc-uClibc.c 2007-06-03 22:10:49.372320596 +0200
+@@ -0,0 +1,668 @@
++/* vi: set sw=4 ts=4: */
+/*
+ * Copyright (C) 2000 Manuel Novoa III
+ * Copyright (C) 2002-2003 Erik Andersen
-+ * Copyright (C) 2006 Rob Landley <rob at landley.net>
+ *
-+ * Wrapper to use uClibc with gcc, and make gcc relocatable.
++ * This is a crude wrapper to use uClibc with gcc.
++ * It was originally written to work around ./configure for ext2fs-utils.
++ * It certainly can be improved, but it works for me in the normal cases.
++ *
++ * April 7, 2001
++ *
++ * A bug was fixed in building the gcc command line when dynamic linking.
++ * The functions dlopen, etc. now work. At this time, you must make sure
++ * the correct libdl.so is included however. It is safest to, for example,
++ * add /lib/libdl.so.1 if using ld-linux.so.1 rather than adding -ldl to the
++ * command line.
++ *
++ * Note: This is only a problem if devel and target archs are the same. To
++ * avoid the problem, you can use a customized dynamic linker.
++ *
++ *
++ * April 18, 2001
++ *
++ * The wrapper now works with either installed and uninstalled uClibc versions.
++ * If you want to use the uninstalled header files and libs, either include
++ * the string "build" in the invocation name such as
++ * 'ln -s <ARCH>-uclibc-gcc <ARCH>-uclibc-gcc-build'
++ * or include it in the environment variable setting of UCLIBC_ENV.
++ * Note: This automatically enables the "rpath" behavior described below.
++ *
++ * The wrapper will now pass the location of the uClibc shared libs used to
++ * the linker with the "-rpath" option if the invocation name includes the
++ * string "rpath" or if the environment variable UCLIBC_ENV include it (as
++ * with "build" above). This is primarily intended to be used on devel
++ * platforms of the same arch as the target. A good place to use this feature
++ * would be in the uClibc/test directory.
++ *
++ * The wrapper now displays the command line passed to gcc when '-v' is used.
++ *
++ * May 31, 2001
++ *
++ * "rpath" and "build" behavior are now decoupled. You can of course get
++ * the old "build" behavior by setting UCLIBC_ENV="rpath-build". Order
++ * isn't important here, as only the substrings are searched for.
++ *
++ * Added environment variable check for UCLIBC_GCC_DLOPT to let user specify
++ * an alternative dynamic linker at runtime without using command line args.
++ * Since this wouldn't commonly be used, I made it easy on myself. You have
++ * to match the option you would have passed to the gcc wrapper. As an
++ * example,
++ *
++ * export UCLIBC_GCC_DLOPT="-Wl,--dynamic-linker,/lib/ld-alt-linker.so.3"
++ *
++ * This is really only useful if target arch == devel arch and DEVEL_PREFIX
++ * isn't empty. It involves a recompile, but you can at least test apps
++ * on your devel system if combined with the "rpath" behavor if by using
++ * LD_LIBRARY_PATH, etc.
++ *
++ * Also added check for "-Wl,--dynamic-linker" on the command line. The
++ * use default dynamic linker or the envirnment-specified dynamic linker
++ * is disabled in that case.
++ *
++ * Added options --uclibc-use-build-dir and --uclibc-use-rpath so that those
++ * behaviors can be invoked from the command line.
++ *
++ */
++
++/*
++ *
++ * TODO:
++ * Check/modify gcc-specific environment variables?
+ */
+
-+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
-+#include <strings.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+
-+static char *topdir;
++#include "gcc-uClibc.h"
++
++static char *our_usr_lib_path = "-L"UCLIBC_DEVEL_PREFIX"/lib";
++
+static char static_linking[] = "-static";
+static char nostdinc[] = "-nostdinc";
+static char nostartfiles[] = "-nostartfiles";
+static char nodefaultlibs[] = "-nodefaultlibs";
+static char nostdlib[] = "-nostdlib";
-+
-+// For C++
++#ifdef __UCLIBC_CTOR_DTOR__
+static char nostdinc_plus[] = "-nostdinc++";
++#endif
+
-+
-+// Confirm that a regular file exists, and (optionally) has the executable bit.
-+int is_file(char *filename, int has_exe)
++/* Include a local implementation of basename, since this
++ * uses the host system's C lib, and CYGWIN apparently
++ * doesn't provide an implementation of basename(). */
++char *basename(const char *path)
+{
-+ // Confirm it has the executable bit set, if necessary.
-+ if (!has_exe || !access(filename, X_OK)) {
-+ struct stat st;
-+
-+ // Confirm it exists and is not a directory.
-+ if (!stat(filename, &st) && S_ISREG(st.st_mode)) return 1;
++ register const char *s;
++ register const char *p;
++ p = s = path;
++ while (*s) {
++ if (*s++ == '/') {
++ p = s;
++ }
+ }
-+ return 0;
++ return (char *) p;
+}
+
-+// Find an executable in a colon-separated path
-+
-+char *find_in_path(char *path, char *filename, int has_exe)
++char *dirname(char *path)
+{
-+ char *cwd = getcwd(NULL, 0);
-+
-+ if (index(filename, '/') && is_file(filename, has_exe))
-+ return strdup(filename);
-+
-+ for (;;) {
-+ char *str, *next = path ? index(path, ':') : NULL;
-+ int len = next ? next-path : strlen(path);
-+
-+ // The +3 is a corner case: if strlen(filename) is 1, make sure we
-+ // have enough space to append ".." to make topdir.
-+ str = malloc(strlen(filename) + (len ? len : strlen(cwd)) + 3);
-+ if (!len) sprintf(str, "%s/%s", cwd, filename);
-+ else {
-+ char *str2 = str;
++ static const char null_or_empty_or_noslash[] = ".";
++ register char *s;
++ register char *last;
++ char *first;
++
++ last = s = path;
++
++ if (s != NULL) {
++
++LOOP:
++ while (*s && (*s != '/')) ++s;
++ first = s;
++ while (*s == '/') ++s;
++ if (*s) {
++ last = first;
++ goto LOOP;
++ }
+
-+ strncpy(str, path, len);
-+ str2 = str+len;
-+ *(str2++) = '/';
-+ strcpy(str2, filename);
++ if (last == path) {
++ if (*last != '/') {
++ goto DOT;
++ }
++ if ((*++last == '/') && (last[1] == 0)) {
++ ++last;
++ }
+ }
++ *last = 0;
++ return path;
++ }
++DOT:
++ return (char *) null_or_empty_or_noslash;
++}
+
-+ // If it's not a directory, return it.
-+ if (is_file(str, has_exe)) return str;
-+ else free(str);
+
-+ if (!next) break;
-+ path += len;
-+ path++;
++extern void *xmalloc(size_t size)
++{
++ void *ptr = malloc(size);
++
++ if (!ptr) {
++ fprintf(stderr, "memory exhausted");
++ exit(EXIT_FAILURE);
+ }
-+ free(cwd);
++ return ptr;
++}
+
-+ return NULL;
++void xstrcat(char **string, ...)
++{
++ const char *c;
++ va_list p;
++ /* Don't bother to calculate how big exerything
++ * will be, just be careful to not overflow... */
++ va_start(p, string);
++ *string = xmalloc(BUFSIZ);
++ **string = '\0';
++ while(1) {
++ if (!(c = va_arg(p, const char *)))
++ break;
++ strcat(*string, c);
++ }
++ va_end(p);
+}
+
+int main(int argc, char **argv)
@@ -90,63 +182,62 @@
+ int use_build_dir = 0, linking = 1, use_static_linking = 0;
+ int use_stdinc = 1, use_start = 1, use_stdlib = 1, use_pic = 0;
+ int source_count = 0, use_rpath = 0, verbose = 0;
-+ int i, argcnt, liblen, n, sawM = 0, sawdotoa = 0, sawcES = 0;
-+ char **gcc_argv, **libraries, **libpath;
-+ char *dlstr, *incstr, *devprefix, *libstr, *build_dlstr = 0;
-+ char *cc, *ep, *rpath_link[2], *rpath[2], *uClibc_inc[2], *our_lib_path[2];
-+ char *crt0_path[2], *crtbegin_path[2], *crtend_path[2];
-+ char *debug_wrapper=getenv("DEBUG_WRAPPER");
-+
-+ // For C++
-+
-+ char *crti_path[2], *crtn_path[2], *cpp = NULL;
-+ int len, ctor_dtor = 1, cplusplus = 0, use_nostdinc_plus = 0;
-+
-+ // For profiling
++ int i, j, k, l, m, n;
++ char ** gcc_argv;
++ char ** gcc_argument;
++ char ** libraries;
++ char ** libpath;
++ char *dlstr;
++ char *incstr;
++ char *devprefix;
++ char *runprefix;
++ char *builddir;
++ char *libstr;
++ char *build_dlstr = 0;
++ char *cc;
++ char *ep;
++ char *rpath_link[2];
++ char *rpath[2];
++ char *uClibc_inc[2];
++ char *our_lib_path[2];
++ char *crt0_path[2];
++ char *crtbegin_path[2];
++ char *crtend_path[2];
++ const char *application_name;
++#ifdef __UCLIBC_CTOR_DTOR__
++ char *crti_path[2];
++ char *crtn_path[2];
++ int len;
++ int ctor_dtor = 1, cplusplus = 0, use_nostdinc_plus = 0;
++ int findlibgcc = 1;
++ char *cpp = NULL;
++#endif
++#ifdef __UCLIBC_PROFILING__
+ int profile = 0;
+ char *gcrt1_path[2];
++#endif
+
-+ if(debug_wrapper) {
-+ dprintf(2,"incoming: ");
-+ for(gcc_argv=argv;*gcc_argv;gcc_argv++) dprintf(2,"%s ",*gcc_argv);
-+ dprintf(2,"\n\n");
++ cc = getenv("UCLIBC_CC");
++ if (cc==NULL) {
++ cc = GCC_BIN;
++#ifdef __UCLIBC_CTOR_DTOR__
++ findlibgcc = 0;
++#endif
+ }
+
-+ // Allocate space for new command line
-+ gcc_argv = __builtin_alloca(sizeof(char*) * (argc + 128));
-+
-+ // What directory is the wrapper script in?
-+ if(!(topdir = find_in_path(getenv("PATH"), argv[0], 1))) {
-+ fprintf(stderr, "can't find %s in $PATH\n", argv[0]);
-+ exit(1);
-+ } else {
-+ char *path = getenv("PATH"), *temp;
-+
-+ // Add that directory to the start of $PATH. (Better safe than sorry.)
-+ *rindex(topdir,'/') = 0;
-+ temp = malloc(strlen(topdir)+strlen(path)+7);
-+ sprintf(temp,"PATH=%s:%s",topdir,path);
-+ putenv(temp);
-+
-+ // The directory above the wrapper script should have include, gcc,
-+ // and lib directories. However, the script could have a symlink
-+ // pointing to its directory (ala /bin -> /usr/bin), so append ".."
-+ // instead of trucating the path.
-+ strcat(topdir,"/..");
-+ }
-+
-+ // What's the name of the C compiler we're wrapping? (It may have a
-+ // cross-prefix.)
-+ cc = getenv("UCLIBC_CC");
-+ if (!cc) cc = "gcc-unwrapped";
-+
-+
-+ // Check end of name, since there could be a cross-prefix on the thing
-+ len = strlen(argv[0]);
-+ if (!strcmp(argv[0]+len-2, "ld")) {
-+ // We're wrapping the linker.
-+ // Wrapping the c++ compiler?
-+ } else if (!strcmp(argv[0]+len-3, "g++") || !strcmp(argv[0]+len-3, "c++")) {
++ application_name = basename(argv[0]);
++ if (application_name[0] == '-')
++ application_name++;
++
++#ifdef __UCLIBC_CTOR_DTOR__
++ /* We must use strstr since g++ might be named like a
++ * cross compiler (i.e. arm-linux-g++). We must also
++ * search carefully, in case we are searching something
++ * like /opt/c++/gcc-3.1/bin/arm-linux-g++ or some similar
++ * perversion... */
++ len = strlen(application_name);
++ if ((strcmp(application_name+len-3, "g++")==0) ||
++ (strcmp(application_name+len-3, "c++")==0)) {
+ len = strlen(cc);
+ if (strcmp(cc+len-3, "gcc")==0) {
+ cpp = strdup(cc);
@@ -156,10 +247,21 @@
+ cplusplus = 1;
+ use_nostdinc_plus = 1;
+ }
++#endif
+
+ devprefix = getenv("UCLIBC_DEVEL_PREFIX");
+ if (!devprefix) {
-+ devprefix = topdir;
++ devprefix = UCLIBC_DEVEL_PREFIX;
++ }
++
++ runprefix = getenv("UCLIBC_RUNTIME_PREFIX");
++ if (!runprefix) {
++ runprefix = UCLIBC_RUNTIME_PREFIX;
++ }
++
++ builddir = getenv("UCLIBC_BUILD_DIR");
++ if (!builddir) {
++ builddir = UCLIBC_BUILD_DIR;
+ }
+
+ incstr = getenv("UCLIBC_GCC_INC");
@@ -179,50 +281,60 @@
+ }
+
+
-+ asprintf(rpath_link,"-Wl,-rpath-link,%s/lib", devprefix);
-+ asprintf(rpath, "-Wl,-rpath,%s/lib", devprefix);
-+ asprintf(uClibc_inc, "%s/include/", devprefix);
-+
-+//#ifdef CTOR_DTOR
-+ asprintf(crt0_path, "%s/lib/crt1.o", devprefix);
-+ asprintf(crti_path, "%s/lib/crti.o", devprefix);
-+ asprintf(crtn_path, "%s/lib/crtn.o", devprefix);
-+//#else
-+// *crt0_path = asprintf("%s/lib/crt0.o", devprefix);
-+//#endif
-+
-+ // profiling
-+ asprintf(gcrt1_path, "%s/lib/gcrt1.o", devprefix, "/lib/gcrt1.o");
-+ asprintf(our_lib_path, "-L%s/lib", devprefix);
-+
-+ // Figure out where the dynamic linker is.
-+ dlstr = getenv("UCLIBC_DYNAMIC_LINKER");
-+ if (!dlstr) dlstr = "/lib/ld-uClibc.so.0";
-+ asprintf(&dlstr, "-Wl,--dynamic-linker,%s", dlstr);
++ xstrcat(&(rpath_link[0]), "-Wl,-rpath-link,", devprefix, "/lib:", runprefix, "/lib", NULL);
++ xstrcat(&(rpath_link[1]), "-Wl,-rpath-link,", builddir, "/lib", NULL);
++
++ xstrcat(&(rpath[0]), "-Wl,-rpath,", devprefix, "/lib:", runprefix, "/lib", NULL);
++ xstrcat(&(rpath[1]), "-Wl,-rpath,", builddir, "/lib", NULL);
++
++ xstrcat(&(uClibc_inc[0]), devprefix, "/include/", NULL);
++ xstrcat(&(uClibc_inc[1]), builddir, "/include/", NULL);
++
++#ifdef __UCLIBC_CTOR_DTOR__
++ xstrcat(&(crt0_path[0]), devprefix, "/lib/crt1.o", NULL);
++ xstrcat(&(crt0_path[1]), builddir, "/lib/crt1.o", NULL);
++ xstrcat(&(crti_path[0]), devprefix, "/lib/crti.o", NULL);
++ xstrcat(&(crti_path[1]), builddir, "/lib/crti.o", NULL);
++ xstrcat(&(crtn_path[0]), devprefix, "/lib/crtn.o", NULL);
++ xstrcat(&(crtn_path[1]), builddir, "/lib/crtn.o", NULL);
++#else
++ xstrcat(&(crt0_path[0]), devprefix, "/lib/crt0.o", NULL);
++ xstrcat(&(crt0_path[1]), builddir, "/lib/crt0.o", NULL);
++#endif
++#ifdef __UCLIBC_PROFILING__
++ xstrcat(&(gcrt1_path[0]), devprefix, "/lib/gcrt1.o", NULL);
++ xstrcat(&(gcrt1_path[1]), builddir, "/lib/gcrt1.o", NULL);
++#endif
++
++ xstrcat(&(our_lib_path[0]), "-L", devprefix, "/lib", NULL);
++ xstrcat(&(our_lib_path[1]), "-L", builddir, "/lib", NULL);
++
++#ifdef __UCLIBC_HAS_SHARED__
++ build_dlstr = "-Wl,--dynamic-linker," BUILD_DYNAMIC_LINKER;
++ dlstr = getenv("UCLIBC_GCC_DLOPT");
++ if (!dlstr) {
++ dlstr = "-Wl,--dynamic-linker," DYNAMIC_LINKER;
++ }
++#endif
+
-+ liblen = 0;
++ m = 0;
+ libraries = __builtin_alloca(sizeof(char*) * (argc));
-+ libraries[liblen] = '\0';
++ libraries[m] = '\0';
+
+ n = 0;
+ libpath = __builtin_alloca(sizeof(char*) * (argc));
+ libpath[n] = '\0';
+
-+ // Parse the incoming gcc arguments.
-+
+ for ( i = 1 ; i < argc ; i++ ) {
-+ if (argv[i][0] == '-' && argv[i][1]) { /* option */
++ if (argv[i][0] == '-') { /* option */
+ switch (argv[i][1]) {
+ case 'c': /* compile or assemble */
+ case 'S': /* generate assembler code */
+ case 'E': /* preprocess only */
+ case 'M': /* generate dependencies */
+ linking = 0;
-+ if (argv[i][1] == 'M') sawM = 1;
-+ else sawcES = 1;
+ break;
-+
-+ case 'L': /* library path */
++ case 'L': /* library */
+ libpath[n++] = argv[i];
+ libpath[n] = '\0';
+ if (argv[i][2] == 0) {
@@ -232,39 +344,41 @@
+ }
+ argv[i] = '\0';
+ break;
-+
+ case 'l': /* library */
-+ libraries[liblen++] = argv[i];
-+ libraries[liblen] = '\0';
++ libraries[m++] = argv[i];
++ libraries[m] = '\0';
+ argv[i] = '\0';
+ break;
-+
+ case 'v': /* verbose */
+ if (argv[i][2] == 0) verbose = 1;
+ printf("Invoked as %s\n", argv[0]);
-+ printf("Reference path: %s\n", topdir);
+ break;
-+
+ case 'n':
+ if (strcmp(nostdinc,argv[i]) == 0) {
+ use_stdinc = 0;
+ } else if (strcmp(nostartfiles,argv[i]) == 0) {
++#ifdef __UCLIBC_CTOR_DTOR__
+ ctor_dtor = 0;
++#endif
+ use_start = 0;
+ } else if (strcmp(nodefaultlibs,argv[i]) == 0) {
+ use_stdlib = 0;
+ argv[i] = '\0';
+ } else if (strcmp(nostdlib,argv[i]) == 0) {
++#ifdef __UCLIBC_CTOR_DTOR__
+ ctor_dtor = 0;
++#endif
+ use_start = 0;
+ use_stdlib = 0;
-+ } else if (strcmp(nostdinc_plus,argv[i]) == 0) {
++ }
++#ifdef __UCLIBC_CTOR_DTOR__
++ else if (strcmp(nostdinc_plus,argv[i]) == 0) {
+ if (cplusplus==1) {
+ use_nostdinc_plus = 0;
+ }
+ }
++#endif
+ break;
-+
+ case 's':
+ if (strstr(argv[i],static_linking) != NULL) {
+ use_static_linking = 1;
@@ -274,7 +388,6 @@
+ use_pic = 1;
+ }
+ break;
-+
+ case 'W': /* -static could be passed directly to ld */
+ if (strncmp("-Wl,",argv[i],4) == 0) {
+ if (strstr(argv[i],static_linking) != 0) {
@@ -285,78 +398,31 @@
+ }
+ }
+ break;
-+
-+ case 'p':
-+wow_this_sucks:
-+ if (!strncmp("-print-",argv[i],7)) {
-+ char *temp, *temp2;
-+ int itemp, showall = 0;
-+
-+ temp = argv[i]+7;
-+ if (!strcmp(temp, "search-dirs")) {
-+ printf("install: %s/\n",devprefix);
-+ printf("programs: %s\n",getenv("PATH"));
-+ printf("libraries: ");
-+ temp2 = "";
-+ showall = 1;
-+ } else if (!strncmp(temp, "file-name=", 10))
-+ temp2 = temp+10;
-+ else if (!strcmp(temp, "libgcc-file-name"))
-+ temp2="libgcc.a";
-+ else break;
-+
-+ // Find this entry in the library path.
-+ for(itemp=0;;itemp++) {
-+ if (itemp == n) {
-+ asprintf(&temp, "%s/gcc/lib/%s", devprefix, temp2);
-+ } else if (itemp == n+1) {
-+ // This is so "include" finds the gcc internal
-+ // include dir. The uClibc build needs this.
-+ asprintf(&temp, "%s/gcc/%s", devprefix, temp2);
-+ } else if (itemp == n+2) {
-+ temp = temp2;
-+ break;
-+ } else {
-+ asprintf(&temp, "%s/%s", libpath[itemp],
-+ temp2);
-+ }
-+ if (showall) printf(":%s"+(itemp?0:1), temp);
-+ else if (!access(temp, F_OK)) break;
-+ }
-+
-+ printf("%s\n"+(showall ? 2 : 0), temp);
-+ exit(0);
-+
-+ // Profiling.
-+ } else if (!strcmp("-pg",argv[i])) profile = 1;
++#ifdef __UCLIBC_PROFILING__
++ case 'p':
++ if (strcmp("-pg",argv[i]) == 0) {
++ profile = 1;
++ }
+ break;
-+
++#endif
+ case 'f':
+ /* Check if we are doing PIC */
+ if (strcmp("-fPIC",argv[i]) == 0) {
+ use_pic = 1;
+ } else if (strcmp("-fpic",argv[i]) == 0) {
+ use_pic = 1;
-+
-+ // profiling
-+ } else if (strcmp("-fprofile-arcs",argv[i]) == 0) {
++ }
++#ifdef __UCLIBC_PROFILING__
++ else if (strcmp("-fprofile-arcs",argv[i]) == 0) {
+ profile = 1;
+ }
++#endif
+ break;
+
-+ // --longopts
-+
<<Diff was trimmed, longer than 597 lines>>
---- CVS-web:
http://cvs.pld-linux.org/SOURCES/uClibc-toolchain-wrapper.patch?r1=1.7&r2=1.8&f=u
More information about the pld-cvs-commit
mailing list