2
1

uClibc-0.9.28-host-ldconfig.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. This patch supports cross-development for embedded systems by allowing the
  2. host version of ldconfig (ldconfig.host) to build ld.so.cache for the target.
  3. Changes include:
  4. 1) LDSO_CACHE_SUPPORT is defined for the host build.
  5. 2) A little-endian host can create a big-endian ld.so.cache, and vice versa.
  6. 3) Can use -r option without chroot(), so no need to run as superuser.
  7. Dan Howell <dahowell@directv.com>
  8. diff -urN uClibc-orig/utils/chroot_realpath.c uClibc-20050502/utils/chroot_realpath.c
  9. --- uClibc-orig/utils/chroot_realpath.c 1969-12-31 16:00:00.000000000 -0800
  10. +++ uClibc-20050502/utils/chroot_realpath.c 2005-09-12 18:30:29.000000000 -0700
  11. @@ -0,0 +1,163 @@
  12. +/*
  13. + * chroot_realpath.c -- reslove pathname as if inside chroot
  14. + * Based on realpath.c Copyright (C) 1993 Rick Sladkey <jrs@world.std.com>
  15. + *
  16. + * This program is free software; you can redistribute it and/or modify
  17. + * it under the terms of the GNU Library Public License as published by
  18. + * the Free Software Foundation; either version 2, or (at your option)
  19. + * any later version.
  20. + *
  21. + * This program is distributed in the hope that it will be useful,
  22. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. + * GNU Library Public License for more details.
  25. + *
  26. + * 2005/09/12: Dan Howell (modified from realpath.c to emulate chroot)
  27. + */
  28. +
  29. +#ifdef HAVE_CONFIG_H
  30. +#include <config.h>
  31. +#endif
  32. +
  33. +#include <sys/types.h>
  34. +#include <unistd.h>
  35. +#include <stdio.h>
  36. +#include <string.h>
  37. +#include <strings.h>
  38. +#include <limits.h> /* for PATH_MAX */
  39. +#include <sys/param.h> /* for MAXPATHLEN */
  40. +#include <errno.h>
  41. +#ifndef __set_errno
  42. +#define __set_errno(val) ((errno) = (val))
  43. +#endif
  44. +
  45. +#include <sys/stat.h> /* for S_IFLNK */
  46. +
  47. +#ifndef PATH_MAX
  48. +#define PATH_MAX _POSIX_PATH_MAX
  49. +#endif
  50. +
  51. +#define MAX_READLINKS 32
  52. +
  53. +char *chroot_realpath(const char *chroot, const char *path, char resolved_path[])
  54. +{
  55. + char copy_path[PATH_MAX];
  56. + char link_path[PATH_MAX];
  57. + char got_path[PATH_MAX];
  58. + char *got_path_root = got_path;
  59. + char *new_path = got_path;
  60. + char *max_path;
  61. + int readlinks = 0;
  62. + int n;
  63. + int chroot_len;
  64. +
  65. + /* Trivial case. */
  66. + if (chroot == NULL || *chroot == '\0' ||
  67. + (*chroot == '/' && chroot[1] == '\0')) {
  68. + strcpy(resolved_path, path);
  69. + return resolved_path;
  70. + }
  71. +
  72. + chroot_len = strlen(chroot);
  73. +
  74. + if (chroot_len + strlen(path) >= PATH_MAX - 3) {
  75. + __set_errno(ENAMETOOLONG);
  76. + return NULL;
  77. + }
  78. +
  79. + /* Make a copy of the source path since we may need to modify it. */
  80. + strcpy(copy_path, path);
  81. + path = copy_path;
  82. + max_path = copy_path + PATH_MAX - chroot_len - 3;
  83. +
  84. + /* Start with the chroot path. */
  85. + strcpy(new_path, chroot);
  86. + new_path += chroot_len;
  87. + while (*new_path == '/' && new_path > got_path)
  88. + new_path--;
  89. + got_path_root = new_path;
  90. + *new_path++ = '/';
  91. +
  92. + /* Expand each slash-separated pathname component. */
  93. + while (*path != '\0') {
  94. + /* Ignore stray "/". */
  95. + if (*path == '/') {
  96. + path++;
  97. + continue;
  98. + }
  99. + if (*path == '.') {
  100. + /* Ignore ".". */
  101. + if (path[1] == '\0' || path[1] == '/') {
  102. + path++;
  103. + continue;
  104. + }
  105. + if (path[1] == '.') {
  106. + if (path[2] == '\0' || path[2] == '/') {
  107. + path += 2;
  108. + /* Ignore ".." at root. */
  109. + if (new_path == got_path_root + 1)
  110. + continue;
  111. + /* Handle ".." by backing up. */
  112. + while ((--new_path)[-1] != '/');
  113. + continue;
  114. + }
  115. + }
  116. + }
  117. + /* Safely copy the next pathname component. */
  118. + while (*path != '\0' && *path != '/') {
  119. + if (path > max_path) {
  120. + __set_errno(ENAMETOOLONG);
  121. + return NULL;
  122. + }
  123. + *new_path++ = *path++;
  124. + }
  125. + if (*path == '\0')
  126. + /* Don't follow symlink for last pathname component. */
  127. + break;
  128. +#ifdef S_IFLNK
  129. + /* Protect against infinite loops. */
  130. + if (readlinks++ > MAX_READLINKS) {
  131. + __set_errno(ELOOP);
  132. + return NULL;
  133. + }
  134. + /* See if latest pathname component is a symlink. */
  135. + *new_path = '\0';
  136. + n = readlink(got_path, link_path, PATH_MAX - 1);
  137. + if (n < 0) {
  138. + /* EINVAL means the file exists but isn't a symlink. */
  139. + if (errno != EINVAL) {
  140. + /* Make sure it's null terminated. */
  141. + *new_path = '\0';
  142. + strcpy(resolved_path, got_path);
  143. + return NULL;
  144. + }
  145. + } else {
  146. + /* Note: readlink doesn't add the null byte. */
  147. + link_path[n] = '\0';
  148. + if (*link_path == '/')
  149. + /* Start over for an absolute symlink. */
  150. + new_path = got_path_root;
  151. + else
  152. + /* Otherwise back up over this component. */
  153. + while (*(--new_path) != '/');
  154. + /* Safe sex check. */
  155. + if (strlen(path) + n >= PATH_MAX - 2) {
  156. + __set_errno(ENAMETOOLONG);
  157. + return NULL;
  158. + }
  159. + /* Insert symlink contents into path. */
  160. + strcat(link_path, path);
  161. + strcpy(copy_path, link_path);
  162. + path = copy_path;
  163. + }
  164. +#endif /* S_IFLNK */
  165. + *new_path++ = '/';
  166. + }
  167. + /* Delete trailing slash but don't whomp a lone slash. */
  168. + if (new_path != got_path + 1 && new_path[-1] == '/')
  169. + new_path--;
  170. + /* Make sure it's null terminated. */
  171. + *new_path = '\0';
  172. + strcpy(resolved_path, got_path);
  173. + return resolved_path;
  174. +}
  175. diff -urN uClibc-orig/utils/ldconfig.c uClibc-20050502/utils/ldconfig.c
  176. --- uClibc-orig/utils/ldconfig.c 2005-05-01 23:10:12.000000000 -0700
  177. +++ uClibc-20050502/utils/ldconfig.c 2005-09-16 19:26:33.000000000 -0700
  178. @@ -22,6 +22,8 @@
  179. *
  180. * This program may be used for any purpose as long as this
  181. * copyright notice is kept.
  182. + *
  183. + * 2005/09/16: Dan Howell (modified for cross-development)
  184. */
  185. #include <stdio.h>
  186. @@ -37,6 +39,7 @@
  187. #include <errno.h>
  188. #include <sys/stat.h>
  189. #include <sys/mman.h>
  190. +#include "bswap.h"
  191. #include "dl-defs.h"
  192. #define BUFFER_SIZE 4096
  193. @@ -56,6 +59,7 @@
  194. #if !defined (N_MAGIC)
  195. #define N_MAGIC(exec) ((exec).a_info & 0xffff)
  196. #endif
  197. +#define N_MAGIC_SWAP(exec) (bswap_32((exec).a_info) & 0xffff)
  198. /* Code indicating object file or impure executable. */
  199. #define OMAGIC 0407
  200. /* Code indicating pure executable. */
  201. @@ -97,6 +101,8 @@
  202. char *conffile = LDSO_CONF; /* default conf file */
  203. char *cachefile = LDSO_CACHE; /* default cache file */
  204. #endif
  205. +char *chroot_dir = NULL;
  206. +int byteswap = 0;
  207. struct needed_tab
  208. {
  209. @@ -117,6 +123,8 @@
  210. { NULL, LIB_ELF }
  211. };
  212. +extern char *chroot_realpath(const char *chroot, const char *path, char resolved_path[]);
  213. +
  214. /* These two are used internally -- you shouldn't need to use them */
  215. static void verror_msg(const char *s, va_list p)
  216. @@ -242,6 +250,8 @@
  217. ElfW(Ehdr) *elf_hdr;
  218. struct stat statbuf;
  219. char buff[BUFFER_SIZE];
  220. + char real[BUFFER_SIZE];
  221. + static int byteswapflag = -1; /* start with byte-order unknown */
  222. /* see if name is of the form *.so* */
  223. if (name[strlen(name)-1] != '~' && (cp = strstr(name, ".so")))
  224. @@ -256,8 +266,12 @@
  225. sprintf(buff, "%s%s%s", dir, (*dir && strcmp(dir, "/")) ?
  226. "/" : "", name);
  227. + /* get real path in case of chroot */
  228. + if (!chroot_realpath(chroot_dir, buff, real))
  229. + warn("can't resolve %s in chroot %s", buff, chroot_dir);
  230. +
  231. /* first, make sure it's a regular file */
  232. - if (lstat(buff, &statbuf))
  233. + if (lstat(real, &statbuf))
  234. warn("skipping %s", buff);
  235. else if (!S_ISREG(statbuf.st_mode) && !S_ISLNK(statbuf.st_mode))
  236. warnx("%s is not a regular file or symlink, skipping", buff);
  237. @@ -267,14 +281,15 @@
  238. *islink = S_ISLNK(statbuf.st_mode);
  239. /* then try opening it */
  240. - if (!(file = fopen(buff, "rb")))
  241. + if (!(file = fopen(real, "rb")))
  242. warn("skipping %s", buff);
  243. else
  244. {
  245. /* now make sure it's a shared library */
  246. if (fread(&exec, sizeof exec, 1, file) < 1)
  247. warnx("can't read header from %s, skipping", buff);
  248. - else if (N_MAGIC(exec) != ZMAGIC && N_MAGIC(exec) != QMAGIC)
  249. + else if (N_MAGIC(exec) != ZMAGIC && N_MAGIC(exec) != QMAGIC &&
  250. + N_MAGIC_SWAP(exec) != ZMAGIC && N_MAGIC_SWAP(exec) != QMAGIC)
  251. {
  252. elf_hdr = (ElfW(Ehdr) *) &exec;
  253. if (elf_hdr->e_ident[0] != 0x7f ||
  254. @@ -294,6 +309,9 @@
  255. *type = LIB_ELF;
  256. good = readsoname(buff, file, expected_type, type,
  257. elf_hdr->e_ident[EI_CLASS]);
  258. + if (byteswapflag == -1)
  259. + /* byte-order detected */
  260. + byteswapflag = byteswap;
  261. if (good == NULL || *islink)
  262. {
  263. if (good != NULL)
  264. @@ -313,6 +331,12 @@
  265. }
  266. else
  267. {
  268. + /* Determine byte-order */
  269. + byteswap = (N_MAGIC(exec) == ZMAGIC || N_MAGIC(exec) == QMAGIC) ? 0 : 1;
  270. + if (byteswapflag == -1)
  271. + /* byte-order detected */
  272. + byteswapflag = byteswap;
  273. +
  274. if (*islink)
  275. good = xstrdup(name);
  276. else
  277. @@ -330,6 +354,14 @@
  278. *type = LIB_DLL;
  279. }
  280. fclose(file);
  281. +
  282. + if (byteswapflag >= 0 && byteswap != byteswapflag)
  283. + {
  284. + byteswapflag = -2;
  285. + warnx("mixed byte-order detected, using host byte-order...");
  286. + }
  287. + if (byteswapflag == -2)
  288. + byteswap = 0;
  289. }
  290. }
  291. }
  292. @@ -343,18 +375,24 @@
  293. int change = 1;
  294. char libname[BUFFER_SIZE];
  295. char linkname[BUFFER_SIZE];
  296. + char reallibname[BUFFER_SIZE];
  297. + char reallinkname[BUFFER_SIZE];
  298. struct stat libstat;
  299. struct stat linkstat;
  300. /* construct the full path names */
  301. sprintf(libname, "%s/%s", dir, file);
  302. sprintf(linkname, "%s/%s", dir, so);
  303. + if (!chroot_realpath(chroot_dir, libname, reallibname))
  304. + warn("can't resolve %s in chroot %s", libname, chroot_dir);
  305. + if (!chroot_realpath(chroot_dir, linkname, reallinkname))
  306. + warn("can't resolve %s in chroot %s", linkname, chroot_dir);
  307. /* see if a link already exists */
  308. - if (!stat(linkname, &linkstat))
  309. + if (!stat(reallinkname, &linkstat))
  310. {
  311. /* now see if it's the one we want */
  312. - if (stat(libname, &libstat))
  313. + if (stat(reallibname, &libstat))
  314. warn("can't stat %s", libname);
  315. else if (libstat.st_dev == linkstat.st_dev &&
  316. libstat.st_ino == linkstat.st_ino)
  317. @@ -364,14 +402,14 @@
  318. /* then update the link, if required */
  319. if (change > 0 && !nolinks)
  320. {
  321. - if (!lstat(linkname, &linkstat))
  322. + if (!lstat(reallinkname, &linkstat))
  323. {
  324. if (!S_ISLNK(linkstat.st_mode))
  325. {
  326. warnx("%s is not a symlink", linkname);
  327. change = -1;
  328. }
  329. - else if (remove(linkname))
  330. + else if (remove(reallinkname))
  331. {
  332. warn("can't unlink %s", linkname);
  333. change = -1;
  334. @@ -379,7 +417,7 @@
  335. }
  336. if (change > 0)
  337. {
  338. - if (symlink(file, linkname))
  339. + if (symlink(file, reallinkname))
  340. {
  341. warn("can't link %s to %s", linkname, file);
  342. change = -1;
  343. @@ -441,6 +479,7 @@
  344. char *so, *path, *path_n;
  345. struct lib *lp, *libs = NULL;
  346. int i, libtype, islink, expected_type = LIB_ANY;
  347. + char realname[BUFFER_SIZE];
  348. /* We need a writable copy of this string */
  349. path = strdup(rawname);
  350. @@ -500,8 +539,12 @@
  351. if (verbose > 0)
  352. printf("%s:\n", name);
  353. + /* get real path in case of chroot */
  354. + if (!chroot_realpath(chroot_dir, name, realname))
  355. + warn("can't resolve %s in chroot %s", name, chroot_dir);
  356. +
  357. /* if we can't open it, we can't do anything */
  358. - if ((dir = opendir(name)) == NULL)
  359. + if ((dir = opendir(realname)) == NULL)
  360. {
  361. warn("skipping %s", name);
  362. free(path);
  363. @@ -596,8 +639,12 @@
  364. char *res = NULL, *cp;
  365. FILE *file;
  366. struct stat stat;
  367. + char realconffile[BUFFER_SIZE];
  368. +
  369. + if (!chroot_realpath(chroot_dir, conffile, realconffile))
  370. + return NULL;
  371. - if ((file = fopen(conffile, "r")) != NULL)
  372. + if ((file = fopen(realconffile, "r")) != NULL)
  373. {
  374. fstat(fileno(file), &stat);
  375. res = xmalloc(stat.st_size + 1);
  376. @@ -678,22 +725,38 @@
  377. {
  378. int cachefd;
  379. int stroffset = 0;
  380. + char realcachefile[BUFFER_SIZE];
  381. char tempfile[BUFFER_SIZE];
  382. + header_t swap_magic;
  383. + header_t *magic_ptr;
  384. + libentry_t swap_lib;
  385. + libentry_t *lib_ptr;
  386. liblist_t *cur_lib;
  387. if (!magic.nlibs)
  388. return;
  389. - sprintf(tempfile, "%s~", cachefile);
  390. + if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
  391. + err(EXIT_FATAL,"can't resolve %s in chroot %s (%s)",
  392. + cachefile, chroot_dir, strerror(errno));
  393. +
  394. + sprintf(tempfile, "%s~", realcachefile);
  395. if (unlink(tempfile) && errno != ENOENT)
  396. - err(EXIT_FATAL,"can't unlink %s (%s)", tempfile, strerror(errno));
  397. + err(EXIT_FATAL,"can't unlink %s~ (%s)", cachefile, strerror(errno));
  398. if ((cachefd = creat(tempfile, 0644)) < 0)
  399. - err(EXIT_FATAL,"can't create %s (%s)", tempfile, strerror(errno));
  400. + err(EXIT_FATAL,"can't create %s~ (%s)", cachefile, strerror(errno));
  401. - if (write(cachefd, &magic, sizeof (header_t)) != sizeof (header_t))
  402. - err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno));
  403. + if (byteswap) {
  404. + swap_magic = magic;
  405. + swap_magic.nlibs = bswap_32(swap_magic.nlibs);
  406. + magic_ptr = &swap_magic;
  407. + } else {
  408. + magic_ptr = &magic;
  409. + }
  410. + if (write(cachefd, magic_ptr, sizeof (header_t)) != sizeof (header_t))
  411. + err(EXIT_FATAL,"can't write %s~ (%s)", cachefile, strerror(errno));
  412. for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next)
  413. {
  414. @@ -701,29 +764,37 @@
  415. stroffset += strlen(cur_lib->soname) + 1;
  416. cur_lib->liboffset = stroffset;
  417. stroffset += strlen(cur_lib->libname) + 1;
  418. - if (write(cachefd, cur_lib, sizeof (libentry_t)) !=
  419. - sizeof (libentry_t))
  420. - err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno));
  421. + if (byteswap) {
  422. + swap_lib.flags = bswap_32(cur_lib->flags);
  423. + swap_lib.sooffset = bswap_32(cur_lib->sooffset);
  424. + swap_lib.liboffset = bswap_32(cur_lib->liboffset);
  425. + lib_ptr = &swap_lib;
  426. + } else {
  427. + lib_ptr = (libentry_t *)cur_lib;
  428. + }
  429. + if (write(cachefd, lib_ptr, sizeof (libentry_t)) !=
  430. + sizeof (libentry_t))
  431. + err(EXIT_FATAL,"can't write %s~ (%s)", cachefile, strerror(errno));
  432. }
  433. for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next)
  434. {
  435. if (write(cachefd, cur_lib->soname, strlen(cur_lib->soname) + 1)
  436. != strlen(cur_lib->soname) + 1)
  437. - err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno));
  438. + err(EXIT_FATAL,"can't write %s~ (%s)", cachefile, strerror(errno));
  439. if (write(cachefd, cur_lib->libname, strlen(cur_lib->libname) + 1)
  440. != strlen(cur_lib->libname) + 1)
  441. - err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno));
  442. + err(EXIT_FATAL,"can't write %s~ (%s)", cachefile, strerror(errno));
  443. }
  444. if (close(cachefd))
  445. - err(EXIT_FATAL,"can't close %s (%s)", tempfile, strerror(errno));
  446. + err(EXIT_FATAL,"can't close %s~ (%s)", cachefile, strerror(errno));
  447. if (chmod(tempfile, 0644))
  448. - err(EXIT_FATAL,"can't chmod %s (%s)", tempfile, strerror(errno));
  449. + err(EXIT_FATAL,"can't chmod %s~ (%s)", cachefile, strerror(errno));
  450. - if (rename(tempfile, cachefile))
  451. - err(EXIT_FATAL,"can't rename %s (%s)", tempfile, strerror(errno));
  452. + if (rename(tempfile, realcachefile))
  453. + err(EXIT_FATAL,"can't rename %s~ (%s)", cachefile, strerror(errno));
  454. }
  455. void cache_print(void)
  456. @@ -734,8 +805,13 @@
  457. char *strs;
  458. header_t *header;
  459. libentry_t *libent;
  460. + char realcachefile[BUFFER_SIZE];
  461. +
  462. + if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
  463. + err(EXIT_FATAL,"can't resolve %s in chroot %s (%s)",
  464. + cachefile, chroot_dir, strerror(errno));
  465. - if (stat(cachefile, &st) || (fd = open(cachefile, O_RDONLY))<0)
  466. + if (stat(realcachefile, &st) || (fd = open(realcachefile, O_RDONLY))<0)
  467. err(EXIT_FATAL,"can't read %s (%s)", cachefile, strerror(errno));
  468. if ((c = mmap(0,st.st_size, PROT_READ, MAP_SHARED ,fd, 0)) == (caddr_t)-1)
  469. err(EXIT_FATAL,"can't map %s (%s)", cachefile, strerror(errno));
  470. @@ -828,7 +904,6 @@
  471. int nodefault = 0;
  472. char *cp, *dir, *so;
  473. int libtype, islink;
  474. - char *chroot_dir = NULL;
  475. int printcache = 0;
  476. #ifdef __LDSO_CACHE_SUPPORT__
  477. char *extpath;
  478. @@ -891,10 +966,16 @@
  479. }
  480. if (chroot_dir && *chroot_dir) {
  481. - if (chroot(chroot_dir) < 0)
  482. - err(EXIT_FATAL,"couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
  483. - if (chdir("/") < 0)
  484. - err(EXIT_FATAL,"couldn't chdir to / (%s)", strerror(errno));
  485. + if (chroot(chroot_dir) < 0) {
  486. + if (chdir(chroot_dir) < 0)
  487. + err(EXIT_FATAL,"couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
  488. + }
  489. + else
  490. + {
  491. + if (chdir("/") < 0)
  492. + err(EXIT_FATAL,"couldn't chdir to / (%s)", strerror(errno));
  493. + chroot_dir = NULL;
  494. + }
  495. }
  496. /* allow me to introduce myself, hi, my name is ... */
  497. diff -urN uClibc-orig/utils/Makefile uClibc-20050502/utils/Makefile
  498. --- uClibc-orig/utils/Makefile 2005-05-01 23:10:12.000000000 -0700
  499. +++ uClibc-20050502/utils/Makefile 2005-09-16 19:28:55.000000000 -0700
  500. @@ -29,6 +29,12 @@
  501. TARGET_ICONV =
  502. endif
  503. +ifeq ($(strip $(LDSO_CACHE_SUPPORT)),y)
  504. +HOST_LDSO_CACHE_FLAG = -D__LDSO_CACHE_SUPPORT__=1
  505. +else
  506. +HOST_LDSO_CACHE_FLAG =
  507. +endif
  508. +
  509. # NOTE: We build the utils AFTER we have a uClibc-targeted toolchain.
  510. ifeq ($(strip $(HAVE_SHARED)),y)
  511. @@ -51,7 +57,7 @@
  512. else
  513. LDCONFIG_CFLAGS := $(PIEFLAG) $(LDPIEFLAG)
  514. endif
  515. -ldconfig: ldconfig.c
  516. +ldconfig: ldconfig.c chroot_realpath.c
  517. $(CC) $(CFLAGS) $(LDCONFIG_CFLAGS) \
  518. -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
  519. -DUCLIBC_LDSO=$(UCLIBC_LDSO) -I. -I../ldso/include \
  520. @@ -79,13 +85,13 @@
  521. ldd.host: ldd.c
  522. $(HOSTCC) $(HOSTCFLAGS) -Wl,-s \
  523. - -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
  524. + -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" $(HOST_LDSO_CACHE_FLAG) \
  525. -DUCLIBC_LDSO=$(UCLIBC_LDSO) -I. -I../ldso/include \
  526. $^ -o $@
  527. -ldconfig.host: ldconfig.c
  528. +ldconfig.host: ldconfig.c chroot_realpath.c
  529. $(HOSTCC) $(HOSTCFLAGS) -Wl,-s \
  530. - -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
  531. + -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" $(HOST_LDSO_CACHE_FLAG) \
  532. -DUCLIBC_LDSO=$(UCLIBC_LDSO) -I. -I../ldso/include \
  533. $^ -o $@
  534. diff -urN uClibc-orig/utils/readsoname2.c uClibc-20050502/utils/readsoname2.c
  535. --- uClibc-orig/utils/readsoname2.c 2005-05-01 23:10:12.000000000 -0700
  536. +++ uClibc-20050502/utils/readsoname2.c 2005-09-16 17:48:59.000000000 -0700
  537. @@ -26,7 +26,7 @@
  538. if (fstat(fileno(infile), &st))
  539. return NULL;
  540. - header = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fileno(infile), 0);
  541. + header = mmap(0, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(infile), 0);
  542. if (header == (caddr_t)-1)
  543. return NULL;
  544. @@ -34,6 +34,19 @@
  545. if ((char *)(epnt+1) > (char *)(header + st.st_size))
  546. goto skip;
  547. +#if __BYTE_ORDER == __LITTLE_ENDIAN
  548. + byteswap = (epnt->e_ident[5] == ELFDATA2MSB) ? 1 : 0;
  549. +#elif __BYTE_ORDER == __BIG_ENDIAN
  550. + byteswap = (epnt->e_ident[5] == ELFDATA2LSB) ? 1 : 0;
  551. +#else
  552. +#error Unknown host byte order!
  553. +#endif
  554. + /* Be very lazy, and only byteswap the stuff we use */
  555. + if (byteswap==1) {
  556. + epnt->e_phoff=bswap_32(epnt->e_phoff);
  557. + epnt->e_phnum=bswap_16(epnt->e_phnum);
  558. + }
  559. +
  560. ppnt = (ElfW(Phdr) *)&header[epnt->e_phoff];
  561. if ((char *)ppnt < (char *)header ||
  562. (char *)(ppnt+epnt->e_phnum) > (char *)(header + st.st_size))
  563. @@ -41,6 +54,14 @@
  564. for(i = 0; i < epnt->e_phnum; i++)
  565. {
  566. + /* Be very lazy, and only byteswap the stuff we use */
  567. + if (byteswap==1) {
  568. + ppnt->p_type=bswap_32(ppnt->p_type);
  569. + ppnt->p_vaddr=bswap_32(ppnt->p_vaddr);
  570. + ppnt->p_offset=bswap_32(ppnt->p_offset);
  571. + ppnt->p_filesz=bswap_32(ppnt->p_filesz);
  572. + }
  573. +
  574. if (loadaddr == -1 && ppnt->p_type == PT_LOAD)
  575. loadaddr = (ppnt->p_vaddr & ~(page_size-1)) -
  576. (ppnt->p_offset & ~(page_size-1));
  577. @@ -58,11 +79,20 @@
  578. (char *)(dpnt+dynamic_size) > (char *)(header + st.st_size))
  579. goto skip;
  580. + if (byteswap==1) {
  581. + dpnt->d_tag=bswap_32(dpnt->d_tag);
  582. + dpnt->d_un.d_val=bswap_32(dpnt->d_un.d_val);
  583. + }
  584. +
  585. while (dpnt->d_tag != DT_NULL)
  586. {
  587. if (dpnt->d_tag == DT_STRTAB)
  588. strtab_val = dpnt->d_un.d_val;
  589. dpnt++;
  590. + if (byteswap==1) {
  591. + dpnt->d_tag=bswap_32(dpnt->d_tag);
  592. + dpnt->d_un.d_val=bswap_32(dpnt->d_un.d_val);
  593. + }
  594. };
  595. if (!strtab_val)