gcc-uClibc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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 ((c = va_arg(p, const char *))) {
  154. strcat(*string, c);
  155. }
  156. va_end(p);
  157. }
  158. int main(int argc, char **argv)
  159. {
  160. int use_build_dir = 0, linking = 1, use_static_linking = 0;
  161. int use_stdinc = 1, use_start = 1, use_stdlib = 1, use_pic = 0;
  162. int source_count = 0, use_rpath = 0, verbose = 0;
  163. int minusx = 0;
  164. int i, j, k, l, m, n;
  165. char ** gcc_argv;
  166. char ** gcc_argument;
  167. char ** libraries;
  168. char ** libpath;
  169. char *dlstr;
  170. char *incstr;
  171. char *devprefix;
  172. char *builddir;
  173. char *libstr;
  174. char *build_dlstr = NULL;
  175. char *cc;
  176. char *ep;
  177. char *rpath_link[2];
  178. char *rpath[2];
  179. char *uClibc_inc[2];
  180. char *our_lib_path[2];
  181. char *crt0_path[2];
  182. char *crtbegin_path[2];
  183. char *crtend_path[2];
  184. const char *application_name;
  185. #ifdef __UCLIBC_CTOR_DTOR__
  186. char *crti_path[2];
  187. char *crtn_path[2];
  188. int len;
  189. int ctor_dtor = 1, cplusplus = 0, use_nostdinc_plus = 0;
  190. int findlibgcc = 1;
  191. char *cpp = NULL;
  192. #endif
  193. #ifdef __UCLIBC_PROFILING__
  194. int profile = 0;
  195. char *gcrt1_path[2];
  196. #endif
  197. cc = getenv("UCLIBC_CC");
  198. if (cc == NULL) {
  199. cc = GCC_BIN;
  200. #ifdef __UCLIBC_CTOR_DTOR__
  201. findlibgcc = 0;
  202. #endif
  203. }
  204. application_name = basename(argv[0]);
  205. if (application_name[0] == '-')
  206. application_name++;
  207. #ifdef __UCLIBC_CTOR_DTOR__
  208. /* We must use strstr since g++ might be named like a
  209. * cross compiler (i.e. arm-linux-g++). We must also
  210. * search carefully, in case we are searching something
  211. * like /opt/c++/gcc-3.1/bin/arm-linux-g++ or some similar
  212. * perversion... */
  213. len = strlen(application_name);
  214. if ((strcmp(application_name+len-3, "g++") == 0) ||
  215. (strcmp(application_name+len-3, "c++") == 0)) {
  216. len = strlen(cc);
  217. if (strcmp(cc+len-3, "gcc") == 0) {
  218. cpp = strdup(cc);
  219. cpp[len-1] = '+';
  220. cpp[len-2] = '+';
  221. }
  222. cplusplus = 1;
  223. use_nostdinc_plus = 1;
  224. }
  225. #endif
  226. devprefix = getenv("UCLIBC_DEVEL_PREFIX");
  227. if (!devprefix) {
  228. devprefix = UCLIBC_DEVEL_PREFIX;
  229. }
  230. builddir = getenv("UCLIBC_BUILD_DIR");
  231. if (!builddir) {
  232. builddir = UCLIBC_BUILD_DIR;
  233. }
  234. incstr = getenv("UCLIBC_GCC_INC");
  235. libstr = getenv("UCLIBC_GCC_LIB");
  236. ep = getenv("UCLIBC_ENV");
  237. if (!ep) {
  238. ep = "";
  239. }
  240. if (strstr(ep,"build") != NULL) {
  241. use_build_dir = 1;
  242. }
  243. if (strstr(ep,"rpath") != NULL) {
  244. use_rpath = 1;
  245. }
  246. xstrcat(&(rpath_link[0]), "-Wl,-rpath-link,", devprefix, "/lib", NULL);
  247. xstrcat(&(rpath_link[1]), "-Wl,-rpath-link,", builddir, "/lib", NULL);
  248. xstrcat(&(rpath[0]), "-Wl,-rpath,", devprefix, "/lib", NULL);
  249. xstrcat(&(rpath[1]), "-Wl,-rpath,", builddir, "/lib", NULL);
  250. xstrcat(&(uClibc_inc[0]), devprefix, "/include/", NULL);
  251. xstrcat(&(uClibc_inc[1]), builddir, "/include/", NULL);
  252. #ifdef __UCLIBC_CTOR_DTOR__
  253. xstrcat(&(crt0_path[0]), devprefix, "/lib/crt1.o", NULL);
  254. xstrcat(&(crt0_path[1]), builddir, "/lib/crt1.o", NULL);
  255. xstrcat(&(crti_path[0]), devprefix, "/lib/crti.o", NULL);
  256. xstrcat(&(crti_path[1]), builddir, "/lib/crti.o", NULL);
  257. xstrcat(&(crtn_path[0]), devprefix, "/lib/crtn.o", NULL);
  258. xstrcat(&(crtn_path[1]), builddir, "/lib/crtn.o", NULL);
  259. #else
  260. xstrcat(&(crt0_path[0]), devprefix, "/lib/crt0.o", NULL);
  261. xstrcat(&(crt0_path[1]), builddir, "/lib/crt0.o", NULL);
  262. #endif
  263. #ifdef __UCLIBC_PROFILING__
  264. xstrcat(&(gcrt1_path[0]), devprefix, "/lib/gcrt1.o", NULL);
  265. xstrcat(&(gcrt1_path[1]), builddir, "/lib/gcrt1.o", NULL);
  266. #endif
  267. xstrcat(&(our_lib_path[0]), "-L", devprefix, "/lib", NULL);
  268. xstrcat(&(our_lib_path[1]), "-L", builddir, "/lib", NULL);
  269. #ifdef __UCLIBC_HAS_SHARED__
  270. build_dlstr = "-Wl,--dynamic-linker," BUILD_DYNAMIC_LINKER;
  271. dlstr = getenv("UCLIBC_GCC_DLOPT");
  272. if (!dlstr) {
  273. dlstr = "-Wl,--dynamic-linker," DYNAMIC_LINKER;
  274. }
  275. #endif
  276. m = 0;
  277. libraries = __builtin_alloca(sizeof(char*) * (argc));
  278. libraries[m] = NULL;
  279. n = 0;
  280. libpath = __builtin_alloca(sizeof(char*) * (argc));
  281. libpath[n] = NULL;
  282. for ( i = 1 ; i < argc ; i++ ) {
  283. if (argv[i][0] == '-' && argv[i][1] != '\0') { /* option */
  284. switch (argv[i][1]) {
  285. case 'c': /* compile or assemble */
  286. case 'S': /* generate assembler code */
  287. case 'E': /* preprocess only */
  288. case 'M': /* generate dependencies */
  289. linking = 0;
  290. break;
  291. case 'L': /* library */
  292. libpath[n++] = argv[i];
  293. libpath[n] = NULL;
  294. if (argv[i][2] == '\0') {
  295. argv[i] = NULL;
  296. libpath[n++] = argv[++i];
  297. libpath[n] = NULL;
  298. }
  299. argv[i] = NULL;
  300. break;
  301. case 'l': /* library */
  302. libraries[m++] = argv[i];
  303. libraries[m] = NULL;
  304. argv[i] = NULL;
  305. break;
  306. case 'x': /* Set target language */
  307. minusx = 1;
  308. i++;
  309. break;
  310. case 'v': /* verbose */
  311. if (argv[i][2] == '\0') verbose = 1;
  312. printf("Invoked as %s\n", argv[0]);
  313. break;
  314. case 'n':
  315. if (strcmp(nostdinc, argv[i]) == 0) {
  316. use_stdinc = 0;
  317. } else if (strcmp(nostartfiles, argv[i]) == 0) {
  318. #ifdef __UCLIBC_CTOR_DTOR__
  319. ctor_dtor = 0;
  320. #endif
  321. use_start = 0;
  322. } else if (strcmp(nodefaultlibs, argv[i]) == 0) {
  323. use_stdlib = 0;
  324. argv[i] = NULL;
  325. } else if (strcmp(nostdlib, argv[i]) == 0) {
  326. #ifdef __UCLIBC_CTOR_DTOR__
  327. ctor_dtor = 0;
  328. #endif
  329. use_start = 0;
  330. use_stdlib = 0;
  331. }
  332. #ifdef __UCLIBC_CTOR_DTOR__
  333. else if (strcmp(nostdinc_plus, argv[i]) == 0) {
  334. if (cplusplus) {
  335. use_nostdinc_plus = 0;
  336. }
  337. }
  338. #endif
  339. break;
  340. case 's':
  341. if (strstr(argv[i], static_linking) != NULL) {
  342. use_static_linking = 1;
  343. }
  344. if (strcmp("-shared", argv[i]) == 0) {
  345. use_start = 0;
  346. use_pic = 1;
  347. }
  348. break;
  349. case 'W': /* -static could be passed directly to ld */
  350. if (strncmp("-Wl,", argv[i], 4) == 0) {
  351. if (strstr(argv[i], static_linking) != NULL) {
  352. use_static_linking = 1;
  353. }
  354. if (strstr(argv[i], "--dynamic-linker") != NULL) {
  355. dlstr = NULL;
  356. }
  357. }
  358. break;
  359. #ifdef __UCLIBC_PROFILING__
  360. case 'p':
  361. if (strcmp("-pg", argv[i]) == 0) {
  362. profile = 1;
  363. }
  364. break;
  365. #endif
  366. case 'f':
  367. /* Check if we are doing PIC */
  368. if (strcmp("-fPIC", argv[i]) == 0) {
  369. use_pic = 1;
  370. } else if (strcmp("-fpic", argv[i]) == 0) {
  371. use_pic = 1;
  372. }
  373. #ifdef __UCLIBC_PROFILING__
  374. else if (strcmp("-fprofile-arcs", argv[i]) == 0) {
  375. profile = 1;
  376. }
  377. #endif
  378. break;
  379. case '-':
  380. if (strstr(argv[i]+1, static_linking) != NULL) {
  381. use_static_linking = 1;
  382. argv[i] = NULL;
  383. } else if (strcmp("--uclibc-use-build-dir", argv[i]) == 0) {
  384. use_build_dir = 1;
  385. argv[i] = NULL;
  386. } else if (strcmp("--uclibc-use-rpath", argv[i]) == 0) {
  387. use_rpath = 1;
  388. argv[i] = NULL;
  389. } else if (strcmp ("--uclibc-cc", argv[i]) == 0 && argv[i + 1]) {
  390. cc = argv[i + 1];
  391. argv[i++] = NULL;
  392. argv[i] = NULL;
  393. } else if (strncmp ("--uclibc-cc=", argv[i], 12) == 0) {
  394. cc = argv[i] + 12;
  395. argv[i] = NULL;
  396. }
  397. #ifdef __UCLIBC_CTOR_DTOR__
  398. else if (strcmp("--uclibc-no-ctors",argv[i]) == 0) {
  399. ctor_dtor = 0;
  400. argv[i] = NULL;
  401. }
  402. #endif
  403. break;
  404. }
  405. } else if (argv[i][0] == '-' && argv[i][1] == '\0') {
  406. /* Reading code from stdin - crazy eh? */
  407. ++source_count;
  408. } else { /* assume it is an existing source file */
  409. ++source_count;
  410. }
  411. }
  412. gcc_argv = __builtin_alloca(sizeof(char*) * (argc + 64));
  413. gcc_argument = __builtin_alloca(sizeof(char*) * (argc + 20));
  414. i = 0; k = 0;
  415. #ifdef __UCLIBC_CTOR_DTOR__
  416. if (ctor_dtor) {
  417. struct stat statbuf;
  418. if (findlibgcc || stat(LIBGCC_DIR, &statbuf) < 0 ||
  419. !S_ISDIR(statbuf.st_mode))
  420. {
  421. /* Bummer, gcc is hiding from us. This is going
  422. * to really slow things down... bummer. */
  423. int status, gcc_pipe[2];
  424. pid_t pid, wpid;
  425. pipe(gcc_pipe);
  426. if (!(pid = fork())) {
  427. char *argv[4];
  428. close(gcc_pipe[0]);
  429. close(1);
  430. close(2);
  431. dup2(gcc_pipe[1], 1);
  432. dup2(gcc_pipe[1], 2);
  433. argv[0] = cc;
  434. argv[1] = "-print-libgcc-file-name";
  435. argv[2] = NULL;
  436. execvp(cc, argv);
  437. close(gcc_pipe[1]);
  438. _exit(EXIT_FAILURE);
  439. }
  440. wpid = 0;
  441. while (wpid != pid) {
  442. wpid = wait(&status);
  443. }
  444. close(gcc_pipe[1]);
  445. if (WIFEXITED(status) && WEXITSTATUS(status)) {
  446. crash_n_burn:
  447. fprintf(stderr, "Unable to locale crtbegin.o provided by gcc");
  448. exit(EXIT_FAILURE);
  449. }
  450. if (WIFSIGNALED(status)) {
  451. fprintf(stderr, "%s exited because of uncaught signal %d", cc, WTERMSIG(status));
  452. exit(EXIT_FAILURE);
  453. }
  454. {
  455. char buf[1024], *dir;
  456. status = read(gcc_pipe[0], buf, sizeof(buf));
  457. close(gcc_pipe[0]);
  458. if (status < 0) {
  459. goto crash_n_burn;
  460. }
  461. dir = dirname(buf);
  462. xstrcat(&(crtbegin_path[0]), dir, "/crtbegin.o", NULL);
  463. xstrcat(&(crtbegin_path[1]), dir, "/crtbeginS.o", NULL);
  464. xstrcat(&(crtend_path[0]), dir, "/crtend.o", NULL);
  465. xstrcat(&(crtend_path[1]), dir, "/crtendS.o", NULL);
  466. }
  467. } else {
  468. xstrcat(&(crtbegin_path[0]), LIBGCC_DIR, "crtbegin.o", NULL);
  469. xstrcat(&(crtbegin_path[1]), LIBGCC_DIR, "crtbeginS.o", NULL);
  470. xstrcat(&(crtend_path[0]), LIBGCC_DIR, "crtend.o", NULL);
  471. xstrcat(&(crtend_path[1]), LIBGCC_DIR, "crtendS.o", NULL);
  472. }
  473. }
  474. if (cplusplus && cpp)
  475. gcc_argv[i++] = cpp;
  476. else
  477. #endif
  478. gcc_argv[i++] = cc;
  479. for ( j = 1 ; j < argc ; j++ ) {
  480. if (argv[j] != NULL) {
  481. gcc_argument[k++] = argv[j];
  482. }
  483. }
  484. gcc_argument[k] = NULL;
  485. if (linking && source_count) {
  486. #if defined __HAVE_ELF__ && ! defined __UCLIBC_HAS_MMU__
  487. gcc_argv[i++] = "-Wl,-elf2flt";
  488. #endif
  489. gcc_argv[i++] = nostdlib;
  490. if (use_static_linking) {
  491. gcc_argv[i++] = static_linking;
  492. }
  493. if (!use_static_linking) {
  494. if (dlstr && use_build_dir) {
  495. gcc_argv[i++] = build_dlstr;
  496. } else if (dlstr) {
  497. gcc_argv[i++] = dlstr;
  498. }
  499. if (use_rpath) {
  500. gcc_argv[i++] = rpath[use_build_dir];
  501. }
  502. }
  503. for ( l = 0 ; l < n ; l++ ) {
  504. if (libpath[l]) gcc_argv[i++] = libpath[l];
  505. }
  506. gcc_argv[i++] = rpath_link[use_build_dir]; /* just to be safe */
  507. if (libstr)
  508. gcc_argv[i++] = libstr;
  509. gcc_argv[i++] = our_lib_path[use_build_dir];
  510. if (!use_build_dir) {
  511. gcc_argv[i++] = our_usr_lib_path;
  512. }
  513. }
  514. if (use_stdinc && source_count) {
  515. gcc_argv[i++] = nostdinc;
  516. #ifdef __UCLIBC_CTOR_DTOR__
  517. if (cplusplus) {
  518. char *cppinc;
  519. if (use_nostdinc_plus) {
  520. gcc_argv[i++] = nostdinc_plus;
  521. }
  522. xstrcat(&cppinc, uClibc_inc[use_build_dir], "g++/", NULL);
  523. gcc_argv[i++] = "-isystem";
  524. gcc_argv[i++] = cppinc;
  525. xstrcat(&cppinc, uClibc_inc[use_build_dir], "g++-v3/", NULL);
  526. gcc_argv[i++] = "-isystem";
  527. gcc_argv[i++] = cppinc;
  528. }
  529. #endif
  530. gcc_argv[i++] = "-isystem";
  531. gcc_argv[i++] = uClibc_inc[use_build_dir];
  532. gcc_argv[i++] = "-iwithprefix";
  533. gcc_argv[i++] = "include";
  534. if (incstr)
  535. gcc_argv[i++] = incstr;
  536. }
  537. if (linking && source_count) {
  538. #ifdef __UCLIBC_PROFILING__
  539. if (profile) {
  540. gcc_argv[i++] = gcrt1_path[use_build_dir];
  541. }
  542. #endif
  543. #ifdef __UCLIBC_CTOR_DTOR__
  544. if (ctor_dtor) {
  545. gcc_argv[i++] = crti_path[use_build_dir];
  546. if (use_pic) {
  547. gcc_argv[i++] = crtbegin_path[1];
  548. } else {
  549. gcc_argv[i++] = crtbegin_path[0];
  550. }
  551. }
  552. #endif
  553. if (use_start) {
  554. #ifdef __UCLIBC_PROFILING__
  555. if (!profile)
  556. #endif
  557. {
  558. gcc_argv[i++] = crt0_path[use_build_dir];
  559. }
  560. }
  561. for ( l = 0 ; l < k ; l++ ) {
  562. if (gcc_argument[l]) gcc_argv[i++] = gcc_argument[l];
  563. }
  564. if (use_stdlib) {
  565. //gcc_argv[i++] = "-Wl,--start-group";
  566. gcc_argv[i++] = "-lgcc";
  567. }
  568. for ( l = 0 ; l < m ; l++ ) {
  569. if (libraries[l]) gcc_argv[i++] = libraries[l];
  570. }
  571. if (use_stdlib) {
  572. #ifdef __UCLIBC_CTOR_DTOR__
  573. if (cplusplus) {
  574. gcc_argv[i++] = "-lstdc++";
  575. gcc_argv[i++] = "-lm";
  576. }
  577. #endif
  578. gcc_argv[i++] = "-lc";
  579. gcc_argv[i++] = "-lgcc";
  580. //gcc_argv[i++] = "-Wl,--end-group";
  581. }
  582. #ifdef __UCLIBC_CTOR_DTOR__
  583. if (ctor_dtor) {
  584. if (minusx) {
  585. gcc_argv[i++] = "-x";
  586. gcc_argv[i++] = "none";
  587. }
  588. if (use_pic) {
  589. gcc_argv[i++] = crtend_path[1];
  590. } else {
  591. gcc_argv[i++] = crtend_path[0];
  592. }
  593. gcc_argv[i++] = crtn_path[use_build_dir];
  594. }
  595. #endif
  596. } else {
  597. for ( l = 0 ; l < k ; l++ ) {
  598. if (gcc_argument[l]) gcc_argv[i++] = gcc_argument[l];
  599. }
  600. }
  601. gcc_argv[i++] = NULL;
  602. if (verbose) {
  603. for ( j = 0 ; gcc_argv[j] ; j++ ) {
  604. printf("arg[%2i] = %s\n", j, gcc_argv[j]);
  605. }
  606. fflush(stdout);
  607. }
  608. //no need to free memory from xstrcat because we never return...
  609. #ifdef __UCLIBC_CTOR_DTOR__
  610. if (cplusplus && cpp) {
  611. execvp(cpp, gcc_argv);
  612. fprintf(stderr, "%s: %s\n", cpp, strerror(errno));
  613. } else
  614. #endif
  615. {
  616. execvp(cc, gcc_argv);
  617. fprintf(stderr, "%s: %s\n", cc, strerror(errno));
  618. }
  619. exit(EXIT_FAILURE);
  620. }