0006-Move-is_regular_file-from-common-utils.c-to-filestuf.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. From d4b53d090e09f8929df0367e446569dc32cf269d Mon Sep 17 00:00:00 2001
  2. From: Sergio Durigan Junior <sergiodj@redhat.com>
  3. Date: Wed, 12 Sep 2018 13:16:02 -0400
  4. Subject: [PATCH] Move 'is_regular_file' from common-utils.c to filestuff.c
  5. There is no reason for 'is_regular_file' to be in common-utils.c; it
  6. belongs to 'filestuff.c'. This commit moves the function definition
  7. and its prototype to the appropriate files.
  8. The motivation behind this move is a failure that happens on certain
  9. cross-compilation environments when compiling the IPA library, due to
  10. the way gnulib probes the need for a 'stat' call replacement. Because
  11. configure checks when cross-compiling are more limited, gnulib decides
  12. that it needs to substitute the 'stat' calls its own 'rpl_stat';
  13. however, the IPA library doesn't link with gnulib, which leads to an
  14. error when compiling 'common-utils.c':
  15. ...
  16. /opt/x86-core2--musl--bleeding-edge-2018.09-1/bin/i686-buildroot-linux-musl-g++ -shared -fPIC -Wl,--soname=libinproctrace.so -Wl,--no-undefined -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -I. -I. -I./../common -I./../regformats -I./.. -I./../../include -I./../gnulib/import -Ibuild-gnulib-gdbserver/import -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-narrowing -Wno-error=maybe-uninitialized -DGDBSERVER \
  17. -Wl,--dynamic-list=./proc-service.list -o libinproctrace.so ax-ipa.o common-utils-ipa.o errors-ipa.o format-ipa.o print-utils-ipa.o regcache-ipa.o remote-utils-ipa.o rsp-low-ipa.o tdesc-ipa.o tracepoint-ipa.o utils-ipa.o vec-ipa.o linux-i386-ipa.o linux-x86-tdesc-ipa.o arch/i386-ipa.o -ldl -pthread
  18. /opt/x86-core2--musl--bleeding-edge-2018.09-1/lib/gcc/i686-buildroot-linux-musl/8.2.0/../../../../i686-buildroot-linux-musl/bin/ld: common-utils-ipa.o: in function `is_regular_file(char const*, int*)':
  19. common-utils.c:(.text+0x695): undefined reference to `rpl_stat'
  20. collect2: error: ld returned 1 exit status
  21. Makefile:413: recipe for target 'libinproctrace.so' failed
  22. make[1]: *** [libinproctrace.so] Error 1
  23. ...
  24. More details can also be found at:
  25. https://sourceware.org/ml/gdb-patches/2018-09/msg00304.html
  26. The most simple fix for this problem is to move 'is_regular_file' to
  27. 'filestuff.c', which is not used by IPA. This ends up making the
  28. files more logically organized as well, since 'is_regular_file' is a
  29. file operation.
  30. No regressions found.
  31. gdb/ChangeLog:
  32. 2018-09-12 Sergio Durigan Junior <sergiodj@redhat.com>
  33. * common/common-utils.c: Don't include '<sys/stat.h>'.
  34. (is_regular_file): Move to...
  35. * common/filestuff.c (is_regular_file): ... here.
  36. * common/common-utils.h (is_regular_file): Move to...
  37. * common/filestuff.h (is_regular_file): ... here.
  38. (cherry picked from commit 3c025cfe5efc44eb4dfb03b53dca28e75096dd1e)
  39. [Romain: backport to gdb 8.2 and remove ChangeLog enty]
  40. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  41. ---
  42. gdb/common/common-utils.c | 32 --------------------------------
  43. gdb/common/common-utils.h | 5 -----
  44. gdb/common/filestuff.c | 31 +++++++++++++++++++++++++++++++
  45. gdb/common/filestuff.h | 5 +++++
  46. 4 files changed, 36 insertions(+), 37 deletions(-)
  47. diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
  48. index 8d839d10fa8..24b3936f3dc 100644
  49. --- a/gdb/common/common-utils.c
  50. +++ b/gdb/common/common-utils.c
  51. @@ -20,7 +20,6 @@
  52. #include "common-defs.h"
  53. #include "common-utils.h"
  54. #include "host-defs.h"
  55. -#include <sys/stat.h>
  56. #include <ctype.h>
  57. /* The xmalloc() (libiberty.h) family of memory management routines.
  58. @@ -412,37 +411,6 @@ stringify_argv (const std::vector<char *> &args)
  59. /* See common/common-utils.h. */
  60. -bool
  61. -is_regular_file (const char *name, int *errno_ptr)
  62. -{
  63. - struct stat st;
  64. - const int status = stat (name, &st);
  65. -
  66. - /* Stat should never fail except when the file does not exist.
  67. - If stat fails, analyze the source of error and return true
  68. - unless the file does not exist, to avoid returning false results
  69. - on obscure systems where stat does not work as expected. */
  70. -
  71. - if (status != 0)
  72. - {
  73. - if (errno != ENOENT)
  74. - return true;
  75. - *errno_ptr = ENOENT;
  76. - return false;
  77. - }
  78. -
  79. - if (S_ISREG (st.st_mode))
  80. - return true;
  81. -
  82. - if (S_ISDIR (st.st_mode))
  83. - *errno_ptr = EISDIR;
  84. - else
  85. - *errno_ptr = EINVAL;
  86. - return false;
  87. -}
  88. -
  89. -/* See common/common-utils.h. */
  90. -
  91. ULONGEST
  92. align_up (ULONGEST v, int n)
  93. {
  94. diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
  95. index 7bc6e90f05c..a961514fd66 100644
  96. --- a/gdb/common/common-utils.h
  97. +++ b/gdb/common/common-utils.h
  98. @@ -146,11 +146,6 @@ in_inclusive_range (T value, T low, T high)
  99. return value >= low && value <= high;
  100. }
  101. -/* Return true if the file NAME exists and is a regular file.
  102. - If the result is false then *ERRNO_PTR is set to a useful value assuming
  103. - we're expecting a regular file. */
  104. -extern bool is_regular_file (const char *name, int *errno_ptr);
  105. -
  106. /* Ensure that V is aligned to an N byte boundary (B's assumed to be a
  107. power of 2). Round up/down when necessary. Examples of correct
  108. use include:
  109. diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
  110. index f5a754ffa66..fa10165a7ca 100644
  111. --- a/gdb/common/filestuff.c
  112. +++ b/gdb/common/filestuff.c
  113. @@ -417,3 +417,34 @@ make_cleanup_close (int fd)
  114. *saved_fd = fd;
  115. return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
  116. }
  117. +
  118. +/* See common/filestuff.h. */
  119. +
  120. +bool
  121. +is_regular_file (const char *name, int *errno_ptr)
  122. +{
  123. + struct stat st;
  124. + const int status = stat (name, &st);
  125. +
  126. + /* Stat should never fail except when the file does not exist.
  127. + If stat fails, analyze the source of error and return true
  128. + unless the file does not exist, to avoid returning false results
  129. + on obscure systems where stat does not work as expected. */
  130. +
  131. + if (status != 0)
  132. + {
  133. + if (errno != ENOENT)
  134. + return true;
  135. + *errno_ptr = ENOENT;
  136. + return false;
  137. + }
  138. +
  139. + if (S_ISREG (st.st_mode))
  140. + return true;
  141. +
  142. + if (S_ISDIR (st.st_mode))
  143. + *errno_ptr = EISDIR;
  144. + else
  145. + *errno_ptr = EINVAL;
  146. + return false;
  147. +}
  148. diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
  149. index 0e46eb5da0b..21b4edd6bf6 100644
  150. --- a/gdb/common/filestuff.h
  151. +++ b/gdb/common/filestuff.h
  152. @@ -98,4 +98,9 @@ struct gdb_dir_deleter
  153. typedef std::unique_ptr<DIR, gdb_dir_deleter> gdb_dir_up;
  154. +/* Return true if the file NAME exists and is a regular file.
  155. + If the result is false then *ERRNO_PTR is set to a useful value assuming
  156. + we're expecting a regular file. */
  157. +extern bool is_regular_file (const char *name, int *errno_ptr);
  158. +
  159. #endif /* FILESTUFF_H */
  160. --
  161. 2.14.4