gcc-uClibc.c 17 KB

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