chrpath-0.13-multilib.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Index: chrpath-0.13/Makefile.am
  2. ===================================================================
  3. --- chrpath-0.13.orig/Makefile.am
  4. +++ chrpath-0.13/Makefile.am
  5. @@ -12,12 +12,19 @@ debs:
  6. fakeroot debian/rules binary
  7. chrpath_SOURCES = \
  8. - chrpath.c \
  9. - killrpath.c \
  10. main.c \
  11. - elf.c \
  12. protos.h
  13. +chrpath_LDADD = $(LDLIBS)
  14. +
  15. +lib_LTLIBRARIES = libchrpath32.la libchrpath64.la
  16. +libchrpath32_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
  17. +libchrpath32_la_CFLAGS = -DSIZEOF_VOID_P=4
  18. +libchrpath32_la_LDFLAGS = -avoid-version
  19. +libchrpath64_la_SOURCES = chrpath.c killrpath.c elf.c protos.h
  20. +libchrpath64_la_CFLAGS = -DSIZEOF_VOID_P=8
  21. +libchrpath64_la_LDFLAGS = -avoid-version
  22. +
  23. EXTRA_DIST = ChangeLog.usermap $(man_MANS)
  24. CLEANFILES = *.bb *.bbg *.da *.gcov testsuite/*.bb testsuite/*.bbg
  25. Index: chrpath-0.13/configure.ac
  26. ===================================================================
  27. --- chrpath-0.13.orig/configure.ac
  28. +++ chrpath-0.13/configure.ac
  29. @@ -16,6 +16,7 @@ CHRPATH_LDRPATH_OPTION
  30. dnl Checks for programs.
  31. AC_PROG_CC
  32. AC_PROG_INSTALL
  33. +AC_PROG_LIBTOOL
  34. dnl Checks for libraries.
  35. @@ -26,11 +27,19 @@ AC_CHECK_HEADERS([getopt.h elf.h fcntl.h
  36. dnl Checks for typedefs, structures, and compiler characteristics.
  37. AC_C_CONST
  38. AC_C_BIGENDIAN
  39. -AC_CHECK_SIZEOF(void *)
  40. dnl Checks for library functions.
  41. AC_CHECK_FUNCS(getopt_long)
  42. +dnl See if we need -ldl on this platform for dlopen
  43. +LDLIBS=
  44. +save_LIBS="$LIBS"
  45. +LIBS=
  46. +AC_SEARCH_LIBS([dlopen], [dl])
  47. +LDLIBS=${LIBS}
  48. +LIBS="${save_LIBS}"
  49. +AC_SUBST([LDLIBS])
  50. +
  51. if eval "test x$GCC = xyes"; then
  52. for flag in \
  53. -ansi \
  54. Index: chrpath-0.13/main.c
  55. ===================================================================
  56. --- chrpath-0.13.orig/main.c
  57. +++ chrpath-0.13/main.c
  58. @@ -12,13 +12,19 @@
  59. # include "config.h"
  60. #endif
  61. +#include <dlfcn.h>
  62. +#include <elf.h>
  63. +#include <fcntl.h>
  64. #include <stdio.h>
  65. #include <stdlib.h>
  66. +#include <string.h>
  67. #include <unistd.h>
  68. #ifdef HAVE_GETOPT_H
  69. #include <getopt.h>
  70. #endif
  71. -#include "protos.h"
  72. +
  73. +typedef int (*killrpath_t)(const char *filename);
  74. +typedef int (*chrpath_t)(const char *filename, const char *newpath, int convert);
  75. #ifdef HAVE_GETOPT_LONG
  76. # define GETOPT_LONG getopt_long
  77. @@ -61,6 +67,30 @@ usage(char *progname)
  78. printf("\n");
  79. }
  80. +static unsigned
  81. +elf_class(const char *filename)
  82. +{
  83. + Elf32_Ehdr ehdr;
  84. + int fd;
  85. +
  86. + fd = open(filename, O_RDONLY);
  87. + if (fd == -1)
  88. + return 0;
  89. + if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
  90. + {
  91. + close(fd);
  92. + return 0;
  93. + }
  94. + close(fd);
  95. + if ((memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0)
  96. + || (ehdr.e_ident[EI_VERSION] != EV_CURRENT))
  97. + {
  98. + fprintf(stderr, "`%s' probably isn't an ELF file.\n", filename);
  99. + return 0;
  100. + }
  101. + return ehdr.e_ident[EI_CLASS];
  102. +}
  103. +
  104. int
  105. main(int argc, char * const argv[])
  106. {
  107. @@ -73,6 +103,9 @@ main(int argc, char * const argv[])
  108. #ifdef HAVE_GETOPT_LONG
  109. int option_index = 0;
  110. #endif /* HAVE_GETOPT_LONG */
  111. + void* dll[2];
  112. + killrpath_t killrpath[2];
  113. + chrpath_t chrpath[2];
  114. if (argc < 2)
  115. {
  116. @@ -116,14 +149,31 @@ main(int argc, char * const argv[])
  117. }
  118. } while (-1 != opt);
  119. + dll[0] = dlopen("libchrpath32.so", RTLD_LAZY);
  120. + killrpath[0] = (killrpath_t)dlsym(dll[0], "killrpath");
  121. + chrpath[0] = (chrpath_t)dlsym(dll[0], "chrpath");
  122. +
  123. + dll[1] = dlopen("libchrpath64.so", RTLD_LAZY);
  124. + killrpath[1] = (killrpath_t)dlsym(dll[1], "killrpath");
  125. + chrpath[1] = (chrpath_t)dlsym(dll[1], "chrpath");
  126. +
  127. while (optind < argc && (!retval || keep_going))
  128. {
  129. + const char* program = argv[optind++];
  130. + unsigned eclass = elf_class(program);
  131. + if (!eclass)
  132. + {
  133. + retval = 1;
  134. + continue;
  135. + }
  136. if (remove)
  137. - retval |= killrpath(argv[optind++]);
  138. + retval |= killrpath[eclass - ELFCLASS32](program);
  139. else
  140. /* list by default, replace if path is set */
  141. - retval |= chrpath(argv[optind++], newpath, convert);
  142. + retval |= chrpath[eclass - ELFCLASS32](program, newpath, convert);
  143. }
  144. + dlclose(dll[0]);
  145. + dlclose(dll[1]);
  146. return retval;
  147. }