gcc-uClibc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2000 Manuel Novoa III
  4. * Copyright (C) 2002-2003 Erik Andersen
  5. *
  6. * This is a crude wrapper to use uClibc with gcc.
  7. * It was originally written to work around ./configure for ext2fs-utils.
  8. * It certainly can be improved, but it works for me in the normal cases.
  9. *
  10. * April 7, 2001
  11. *
  12. * A bug was fixed in building the gcc command line when dynamic linking.
  13. * The functions dlopen, etc. now work. At this time, you must make sure
  14. * the correct libdl.so is included however. It is safest to, for example,
  15. * add /lib/libdl.so.1 if using ld-linux.so.1 rather than adding -ldl to the
  16. * command line.
  17. *
  18. * Note: This is only a problem if devel and target archs are the same. To
  19. * avoid the problem, you can use a customized dynamic linker.
  20. *
  21. *
  22. * April 18, 2001
  23. *
  24. * The wrapper now works with either installed and uninstalled uClibc versions.
  25. * If you want to use the uninstalled header files and libs, either include
  26. * the string "build" in the invocation name such as
  27. * 'ln -s <ARCH>-uclibc-gcc <ARCH>-uclibc-gcc-build'
  28. * or include it in the environment variable setting of UCLIBC_ENV.
  29. * Note: This automatically enables the "rpath" behavior described below.
  30. *
  31. * The wrapper will now pass the location of the uClibc shared libs used to
  32. * the linker with the "-rpath" option if the invocation name includes the
  33. * string "rpath" or if the environment variable UCLIBC_ENV include it (as
  34. * with "build" above). This is primarily intended to be used on devel
  35. * platforms of the same arch as the target. A good place to use this feature
  36. * would be in the uClibc/test directory.
  37. *
  38. * The wrapper now displays the command line passed to gcc when '-v' is used.
  39. *
  40. * May 31, 2001
  41. *
  42. * "rpath" and "build" behavior are now decoupled. You can of course get
  43. * the old "build" behavior by setting UCLIBC_ENV="rpath-build". Order
  44. * isn't important here, as only the substrings are searched for.
  45. *
  46. * Added environment variable check for UCLIBC_GCC_DLOPT to let user specify
  47. * an alternative dynamic linker at runtime without using command line args.
  48. * Since this wouldn't commonly be used, I made it easy on myself. You have
  49. * to match the option you would have passed to the gcc wrapper. As an
  50. * example,
  51. *
  52. * export UCLIBC_GCC_DLOPT="-Wl,--dynamic-linker,/lib/ld-alt-linker.so.3"
  53. *
  54. * This is really only useful if target arch == devel arch and DEVEL_PREFIX
  55. * isn't empty. It involves a recompile, but you can at least test apps
  56. * on your devel system if combined with the "rpath" behavor if by using
  57. * LD_LIBRARY_PATH, etc.
  58. *
  59. * Also added check for "-Wl,--dynamic-linker" on the command line. The
  60. * use default dynamic linker or the envirnment-specified dynamic linker
  61. * is disabled in that case.
  62. *
  63. * Added options --uclibc-use-build-dir and --uclibc-use-rpath so that those
  64. * behaviors can be invoked from the command line.
  65. *
  66. */
  67. /*
  68. *
  69. * TODO:
  70. * Check/modify gcc-specific environment variables?
  71. */
  72. #include <stdio.h>
  73. #include <stdlib.h>
  74. #include <stdarg.h>
  75. #include <string.h>
  76. #include <unistd.h>
  77. #include <errno.h>
  78. #include <sys/stat.h>
  79. #include <sys/wait.h>
  80. #include "gcc-uClibc.h"
  81. static char *our_usr_lib_path = "-L"UCLIBC_DEVEL_PREFIX"/lib";
  82. static char static_linking[] = "-static";
  83. static char nostdinc[] = "-nostdinc";
  84. static char nostartfiles[] = "-nostartfiles";
  85. static char nodefaultlibs[] = "-nodefaultlibs";
  86. static char nostdlib[] = "-nostdlib";
  87. #ifdef __UCLIBC_CTOR_DTOR__
  88. static char nostdinc_plus[] = "-nostdinc++";
  89. #endif
  90. /* Include a local implementation of basename, since this
  91. * uses the host system's C lib, and CYGWIN apparently
  92. * doesn't provide an implementation of basename(). */
  93. char *basename(const char *path)
  94. {
  95. register const char *s;
  96. register const char *p;
  97. p = s = path;
  98. while (*s) {
  99. if (*s++ == '/') {
  100. p = s;
  101. }
  102. }
  103. return (char *) p;
  104. }
  105. char *dirname(char *path)
  106. {
  107. static const char null_or_empty_or_noslash[] = ".";
  108. register char *s;
  109. register char *last;
  110. char *first;
  111. last = s = path;
  112. if (s != NULL) {
  113. LOOP:
  114. while (*s && (*s != '/')) ++s;
  115. first = s;
  116. while (*s == '/') ++s;
  117. if (*s) {
  118. last = first;
  119. goto LOOP;
  120. }
  121. if (last == path) {
  122. if (*last != '/') {
  123. goto DOT;
  124. }
  125. if ((*++last == '/') && (last[1] == 0)) {
  126. ++last;
  127. }
  128. }
  129. *last = 0;
  130. return path;
  131. }
  132. DOT:
  133. return (char *) null_or_empty_or_noslash;
  134. }
  135. extern void *xmalloc(size_t size)
  136. {
  137. void *ptr = malloc(size);
  138. if (!ptr) {
  139. fprintf(stderr, "memory exhausted");
  140. exit(EXIT_FAILURE);
  141. }
  142. return ptr;
  143. }
  144. void xstrcat(char **string, ...)
  145. {
  146. const char *c;
  147. va_list p;
  148. /* Don't bother to calculate how big exerything
  149. * will be, just be careful to not overflow... */
  150. va_start(p, string);
  151. *string = xmalloc(BUFSIZ);
  152. **string = '\0';
  153. while(1) {
  154. if (!(c = va_arg(p, const char *)))
  155. break;
  156. strcat(*string, c);
  157. }
  158. va_end(p);
  159. }
  160. int main(int argc, char **argv)
  161. {
  162. int use_build_dir = 0, linking = 1, use_static_linking = 0;
  163. int use_stdinc = 1, use_start = 1, use_stdlib = 1, use_pic = 0;
  164. int source_count = 0, use_rpath = 0, verbose = 0;
  165. int i, j, k, l, m, n;
  166. char ** gcc_argv;
  167. char ** gcc_argument;
  168. char ** libraries;
  169. char ** libpath;
  170. char *dlstr;
  171. char *incstr;
  172. char *devprefix;
  173. char *builddir;
  174. char *libstr;
  175. char *build_dlstr = 0;
  176. char *cc;
  177. char *ep;
  178. char *rpath_link[2];
  179. char *rpath[2];
  180. char *uClibc_inc[2];
  181. char *our_lib_path[2];
  182. char *crt0_path[2];
  183. char *crtbegin_path[2];
  184. char *crtend_path[2];
  185. const char *application_name;
  186. #ifdef __UCLIBC_CTOR_DTOR__
  187. char *crti_path[2];
  188. char *crtn_path[2];
  189. int len;
  190. int ctor_dtor = 1, cplusplus = 0, use_nostdinc_plus = 0;
  191. int findlibgcc = 1;
  192. char *cpp = NULL;
  193. #endif
  194. #ifdef __UCLIBC_PROFILING__
  195. int profile = 0;
  196. char *gcrt1_path[2];
  197. #endif
  198. cc = getenv("UCLIBC_CC");
  199. if (cc==NULL) {
  200. cc = GCC_BIN;
  201. #ifdef __UCLIBC_CTOR_DTOR__
  202. findlibgcc = 0;
  203. #endif
  204. }
  205. application_name = basename(argv[0]);
  206. if (application_name[0] == '-')
  207. application_name++;
  208. #ifdef __UCLIBC_CTOR_DTOR__
  209. /* We must use strstr since g++ might be named like a
  210. * cross compiler (i.e. arm-linux-g++). We must also
  211. * search carefully, in case we are searching something
  212. * like /opt/c++/gcc-3.1/bin/arm-linux-g++ or some similar
  213. * perversion... */
  214. len = strlen(application_name);
  215. if ((strcmp(application_name+len-3, "g++")==0) ||
  216. (strcmp(application_name+len-3, "c++")==0)) {
  217. len = strlen(cc);
  218. if (strcmp(cc+len-3, "gcc")==0) {
  219. cpp = strdup(cc);
  220. cpp[len-1]='+';
  221. cpp[len-2]='+';
  222. }
  223. cplusplus = 1;
  224. use_nostdinc_plus = 1;
  225. }
  226. #endif
  227. devprefix = getenv("UCLIBC_DEVEL_PREFIX");
  228. if (!devprefix) {
  229. devprefix = UCLIBC_DEVEL_PREFIX;
  230. }
  231. builddir = getenv("UCLIBC_BUILD_DIR");
  232. if (!builddir) {
  233. builddir = UCLIBC_BUILD_DIR;
  234. }
  235. incstr = getenv("UCLIBC_GCC_INC");
  236. libstr = getenv("UCLIBC_GCC_LIB");
  237. ep = getenv("UCLIBC_ENV");
  238. if (!ep) {
  239. ep = "";
  240. }
  241. if (strstr(ep,"build") != 0) {
  242. use_build_dir = 1;
  243. }
  244. if (strstr(ep,"rpath") != 0) {
  245. use_rpath = 1;
  246. }
  247. xstrcat(&(rpath_link[0]), "-Wl,-rpath-link,", devprefix, "/lib", NULL);
  248. xstrcat(&(rpath_link[1]), "-Wl,-rpath-link,", builddir, "/lib", NULL);
  249. xstrcat(&(rpath[0]), "-Wl,-rpath,", devprefix, "/lib", NULL);
  250. xstrcat(&(rpath[1]), "-Wl,-rpath,", builddir, "/lib", NULL);
  251. xstrcat(&(uClibc_inc[0]), devprefix, "/include/", NULL);
  252. xstrcat(&(uClibc_inc[1]), builddir, "/include/", NULL);
  253. #ifdef __UCLIBC_CTOR_DTOR__
  254. xstrcat(&(crt0_path[0]), devprefix, "/lib/crt1.o", NULL);
  255. xstrcat(&(crt0_path[1]), builddir, "/lib/crt1.o", NULL);
  256. xstrcat(&(crti_path[0]), devprefix, "/lib/crti.o", NULL);
  257. xstrcat(&(crti_path[1]), builddir, "/lib/crti.o", NULL);
  258. xstrcat(&(crtn_path[0]), devprefix, "/lib/crtn.o", NULL);
  259. xstrcat(&(crtn_path[1]), builddir, "/lib/crtn.o", NULL);
  260. #else
  261. xstrcat(&(crt0_path[0]), devprefix, "/lib/crt0.o", NULL);
  262. xstrcat(&(crt0_path[1]), builddir, "/lib/crt0.o", NULL);
  263. #endif
  264. #ifdef __UCLIBC_PROFILING__
  265. xstrcat(&(gcrt1_path[0]), devprefix, "/lib/gcrt1.o", NULL);
  266. xstrcat(&(gcrt1_path[1]), builddir, "/lib/gcrt1.o", NULL);
  267. #endif
  268. xstrcat(&(our_lib_path[0]), "-L", devprefix, "/lib", NULL);
  269. xstrcat(&(our_lib_path[1]), "-L", builddir, "/lib", NULL);
  270. #ifdef __UCLIBC_HAS_SHARED__
  271. build_dlstr = "-Wl,--dynamic-linker," BUILD_DYNAMIC_LINKER;
  272. dlstr = getenv("UCLIBC_GCC_DLOPT");
  273. if (!dlstr) {
  274. dlstr = "-Wl,--dynamic-linker," DYNAMIC_LINKER;
  275. }
  276. #endif
  277. m = 0;
  278. libraries = __builtin_alloca(sizeof(char*) * (argc));
  279. libraries[m] = '\0';
  280. n = 0;
  281. libpath = __builtin_alloca(sizeof(char*) * (argc));
  282. libpath[n] = '\0';
  283. for ( i = 1 ; i < argc ; i++ ) {
  284. if (argv[i][0] == '-') { /* option */
  285. switch (argv[i][1]) {
  286. case 'c': /* compile or assemble */
  287. case 'S': /* generate assembler code */
  288. case 'E': /* preprocess only */
  289. case 'M': /* generate dependencies */
  290. linking = 0;
  291. break;
  292. case 'L': /* library */
  293. libpath[n++] = argv[i];
  294. libpath[n] = '\0';
  295. if (argv[i][2] == 0) {
  296. argv[i] = '\0';
  297. libpath[n++] = argv[++i];
  298. libpath[n] = '\0';
  299. }
  300. argv[i] = '\0';
  301. break;
  302. case 'l': /* library */
  303. libraries[m++] = argv[i];
  304. libraries[m] = '\0';
  305. argv[i] = '\0';
  306. break;
  307. case 'v': /* verbose */
  308. if (argv[i][2] == 0) verbose = 1;
  309. printf("Invoked as %s\n", argv[0]);
  310. break;
  311. case 'n':
  312. if (strcmp(nostdinc,argv[i]) == 0) {
  313. use_stdinc = 0;
  314. } else if (strcmp(nostartfiles,argv[i]) == 0) {
  315. #ifdef __UCLIBC_CTOR_DTOR__
  316. ctor_dtor = 0;
  317. #endif
  318. use_start = 0;
  319. } else if (strcmp(nodefaultlibs,argv[i]) == 0) {
  320. use_stdlib = 0;
  321. argv[i] = '\0';
  322. } else if (strcmp(nostdlib,argv[i]) == 0) {
  323. #ifdef __UCLIBC_CTOR_DTOR__
  324. ctor_dtor = 0;
  325. #endif
  326. use_start = 0;
  327. use_stdlib = 0;
  328. }
  329. #ifdef __UCLIBC_CTOR_DTOR__
  330. else if (strcmp(nostdinc_plus,argv[i]) == 0) {
  331. if (cplusplus==1) {
  332. use_nostdinc_plus = 0;
  333. }
  334. }
  335. #endif
  336. break;
  337. case 's':
  338. if (strstr(argv[i],static_linking) != NULL) {
  339. use_static_linking = 1;
  340. }
  341. if (strcmp("-shared",argv[i]) == 0) {
  342. use_start = 0;
  343. use_pic = 1;
  344. }
  345. break;
  346. case 'W': /* -static could be passed directly to ld */
  347. if (strncmp("-Wl,",argv[i],4) == 0) {
  348. if (strstr(argv[i],static_linking) != 0) {
  349. use_static_linking = 1;
  350. }
  351. if (strstr(argv[i],"--dynamic-linker") != 0) {
  352. dlstr = 0;
  353. }
  354. }
  355. break;
  356. #ifdef __UCLIBC_PROFILING__
  357. case 'p':
  358. if (strcmp("-pg",argv[i]) == 0) {
  359. profile = 1;
  360. }
  361. break;
  362. #endif
  363. case 'f':
  364. /* Check if we are doing PIC */
  365. if (strcmp("-fPIC",argv[i]) == 0) {
  366. use_pic = 1;
  367. } else if (strcmp("-fpic",argv[i]) == 0) {
  368. use_pic = 1;
  369. }
  370. #ifdef __UCLIBC_PROFILING__
  371. else if (strcmp("-fprofile-arcs",argv[i]) == 0) {
  372. profile = 1;
  373. }
  374. #endif
  375. break;
  376. case '-':
  377. if (strstr(argv[i]+1,static_linking) != NULL) {
  378. use_static_linking = 1;
  379. argv[i]='\0';
  380. } else if (strcmp("--uclibc-use-build-dir",argv[i]) == 0) {
  381. use_build_dir = 1;
  382. argv[i]='\0';
  383. } else if (strcmp("--uclibc-use-rpath",argv[i]) == 0) {
  384. use_rpath = 1;
  385. argv[i]='\0';
  386. } else if (strcmp ("--uclibc-cc", argv[i]) == 0 && argv[i + 1]) {
  387. cc = argv[i + 1];
  388. argv[i] = 0;
  389. argv[i + 1] = 0;
  390. } else if (strncmp ("--uclibc-cc=", argv[i], 12) == 0) {
  391. cc = argv[i] + 12;
  392. argv[i] = 0;
  393. }
  394. #ifdef __UCLIBC_CTOR_DTOR__
  395. else if (strcmp("--uclibc-no-ctors",argv[i]) == 0) {
  396. ctor_dtor = 0;
  397. argv[i]='\0';
  398. }
  399. #endif
  400. break;
  401. }
  402. } else { /* assume it is an existing source file */
  403. ++source_count;
  404. }
  405. }
  406. gcc_argv = __builtin_alloca(sizeof(char*) * (argc + 64));
  407. gcc_argument = __builtin_alloca(sizeof(char*) * (argc + 20));
  408. i = 0; k = 0;
  409. #ifdef __UCLIBC_CTOR_DTOR__
  410. if (ctor_dtor) {
  411. struct stat statbuf;
  412. if (findlibgcc==1 || stat(LIBGCC_DIR, &statbuf)!=0 ||
  413. !S_ISDIR(statbuf.st_mode))
  414. {
  415. /* Bummer, gcc is hiding from us. This is going
  416. * to really slow things down... bummer. */
  417. int status, gcc_pipe[2];
  418. pid_t pid, wpid;
  419. pipe(gcc_pipe);
  420. if (!(pid = fork())) {
  421. char *argv[4];
  422. close(gcc_pipe[0]);
  423. close(1);
  424. close(2);
  425. dup2(gcc_pipe[1], 1);
  426. dup2(gcc_pipe[1], 2);
  427. argv[0] = cc;
  428. argv[1] = "-print-libgcc-file-name";
  429. argv[2] = NULL;
  430. execvp(cc, argv);
  431. close(gcc_pipe[1]);
  432. _exit(EXIT_FAILURE);
  433. }
  434. wpid=0;
  435. while (wpid != pid) {
  436. wpid = wait(&status);
  437. }
  438. close(gcc_pipe[1]);
  439. if (WIFEXITED(status) && WEXITSTATUS(status)) {
  440. crash_n_burn:
  441. fprintf(stderr, "Unable to locale crtbegin.o provided by gcc");
  442. exit(EXIT_FAILURE);
  443. }
  444. if (WIFSIGNALED(status)) {
  445. fprintf(stderr, "%s exited because of uncaught signal %d", cc, WTERMSIG(status));
  446. exit(EXIT_FAILURE);
  447. }
  448. {
  449. char buf[1024], *dir;
  450. status = read(gcc_pipe[0], buf, sizeof(buf));
  451. close(gcc_pipe[0]);
  452. if (status < 0) {
  453. goto crash_n_burn;
  454. }
  455. dir = dirname(buf);
  456. xstrcat(&(crtbegin_path[0]), dir, "/crtbegin.o", NULL);
  457. xstrcat(&(crtbegin_path[1]), dir, "/crtbeginS.o", NULL);
  458. xstrcat(&(crtend_path[0]), dir, "/crtend.o", NULL);
  459. xstrcat(&(crtend_path[1]), dir, "/crtendS.o", NULL);
  460. }
  461. } else {
  462. xstrcat(&(crtbegin_path[0]), LIBGCC_DIR, "crtbegin.o", NULL);
  463. xstrcat(&(crtbegin_path[1]), LIBGCC_DIR, "crtbeginS.o", NULL);
  464. xstrcat(&(crtend_path[0]), LIBGCC_DIR, "crtend.o", NULL);
  465. xstrcat(&(crtend_path[1]), LIBGCC_DIR, "crtendS.o", NULL);
  466. }
  467. }
  468. if (cplusplus && cpp)
  469. gcc_argv[i++] = cpp;
  470. else
  471. #endif
  472. gcc_argv[i++] = cc;
  473. for ( j = 1 ; j < argc ; j++ ) {
  474. if (argv[j]=='\0') {
  475. continue;
  476. } else {
  477. gcc_argument[k++] = argv[j];
  478. gcc_argument[k] = '\0';
  479. }
  480. }
  481. if (linking && source_count) {
  482. #if defined __HAVE_ELF__ && ! defined __UCLIBC_HAS_MMU__
  483. gcc_argv[i++] = "-Wl,-elf2flt";
  484. #endif
  485. gcc_argv[i++] = nostdlib;
  486. if (use_static_linking) {
  487. gcc_argv[i++] = static_linking;
  488. }
  489. if (!use_static_linking) {
  490. if (dlstr && use_build_dir) {
  491. gcc_argv[i++] = build_dlstr;
  492. } else if (dlstr) {
  493. gcc_argv[i++] = dlstr;
  494. }
  495. if (use_rpath) {
  496. gcc_argv[i++] = rpath[use_build_dir];
  497. }
  498. }
  499. for ( l = 0 ; l < n ; l++ ) {
  500. if (libpath[l]) gcc_argv[i++] = libpath[l];
  501. }
  502. gcc_argv[i++] = rpath_link[use_build_dir]; /* just to be safe */
  503. if( libstr )
  504. gcc_argv[i++] = libstr;
  505. gcc_argv[i++] = our_lib_path[use_build_dir];
  506. if (!use_build_dir) {
  507. gcc_argv[i++] = our_usr_lib_path;
  508. }
  509. }
  510. if (use_stdinc && source_count) {
  511. gcc_argv[i++] = nostdinc;
  512. #ifdef __UCLIBC_CTOR_DTOR__
  513. if (cplusplus) {
  514. char *cppinc;
  515. if (use_nostdinc_plus) {
  516. gcc_argv[i++] = nostdinc_plus;
  517. }
  518. xstrcat(&cppinc, uClibc_inc[use_build_dir], "g++/", NULL);
  519. gcc_argv[i++] = "-isystem";
  520. gcc_argv[i++] = cppinc;
  521. xstrcat(&cppinc, uClibc_inc[use_build_dir], "g++-v3/", NULL);
  522. gcc_argv[i++] = "-isystem";
  523. gcc_argv[i++] = cppinc;
  524. }
  525. #endif
  526. gcc_argv[i++] = "-isystem";
  527. gcc_argv[i++] = uClibc_inc[use_build_dir];
  528. gcc_argv[i++] = "-iwithprefix";
  529. gcc_argv[i++] = "include";
  530. if( incstr )
  531. gcc_argv[i++] = incstr;
  532. }
  533. if (linking && source_count) {
  534. #ifdef __UCLIBC_PROFILING__
  535. if (profile) {
  536. gcc_argv[i++] = gcrt1_path[use_build_dir];
  537. }
  538. #endif
  539. #ifdef __UCLIBC_CTOR_DTOR__
  540. if (ctor_dtor) {
  541. gcc_argv[i++] = crti_path[use_build_dir];
  542. if (use_pic) {
  543. gcc_argv[i++] = crtbegin_path[1];
  544. } else {
  545. gcc_argv[i++] = crtbegin_path[0];
  546. }
  547. }
  548. #endif
  549. if (use_start) {
  550. #ifdef __UCLIBC_PROFILING__
  551. if (!profile)
  552. #endif
  553. {
  554. gcc_argv[i++] = crt0_path[use_build_dir];
  555. }
  556. }
  557. for ( l = 0 ; l < k ; l++ ) {
  558. if (gcc_argument[l]) gcc_argv[i++] = gcc_argument[l];
  559. }
  560. if (use_stdlib) {
  561. //gcc_argv[i++] = "-Wl,--start-group";
  562. gcc_argv[i++] = "-lgcc";
  563. }
  564. for ( l = 0 ; l < m ; l++ ) {
  565. if (libraries[l]) gcc_argv[i++] = libraries[l];
  566. }
  567. if (use_stdlib) {
  568. #ifdef __UCLIBC_CTOR_DTOR__
  569. if (cplusplus) {
  570. gcc_argv[ i++ ] = "-lstdc++";
  571. gcc_argv[ i++ ] = "-lm";
  572. }
  573. #endif
  574. gcc_argv[i++] = "-lc";
  575. gcc_argv[i++] = "-lgcc";
  576. //gcc_argv[i++] = "-Wl,--end-group";
  577. }
  578. #ifdef __UCLIBC_CTOR_DTOR__
  579. if (ctor_dtor) {
  580. if (use_pic) {
  581. gcc_argv[i++] = crtend_path[1];
  582. } else {
  583. gcc_argv[i++] = crtend_path[0];
  584. }
  585. gcc_argv[i++] = crtn_path[use_build_dir];
  586. }
  587. #endif
  588. } else {
  589. for ( l = 0 ; l < k ; l++ ) {
  590. if (gcc_argument[l]) gcc_argv[i++] = gcc_argument[l];
  591. }
  592. }
  593. gcc_argv[i++] = NULL;
  594. if (verbose) {
  595. for ( j = 0 ; gcc_argv[j] ; j++ ) {
  596. printf("arg[%2i] = %s\n", j, gcc_argv[j]);
  597. }
  598. fflush(stdout);
  599. }
  600. //no need to free memory from xstrcat because we never return...
  601. #ifdef __UCLIBC_CTOR_DTOR__
  602. if (cplusplus && cpp) {
  603. execvp(cpp, gcc_argv);
  604. fprintf(stderr, "%s: %s\n", cpp, strerror(errno));
  605. } else
  606. #endif
  607. {
  608. execvp(cc, gcc_argv);
  609. fprintf(stderr, "%s: %s\n", cc, strerror(errno));
  610. }
  611. exit(EXIT_FAILURE);
  612. }