gcc-uClibc.c 16 KB

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