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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. From 083849deeeec2854b2657b46380273ee13f4fa1b 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.1 and remove ChangeLog enty]
  40. Signed-off-by: Romain Naour <romain.naour@gmail.com>
  41. ---
  42. gdb/common/common-utils.c | 30 ------------------------------
  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(+), 35 deletions(-)
  47. diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
  48. index 80de826ba78..90a06390141 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. @@ -411,32 +410,3 @@ stringify_argv (const std::vector<char *> &args)
  59. }
  60. /* See common/common-utils.h. */
  61. -
  62. -bool
  63. -is_regular_file (const char *name, int *errno_ptr)
  64. -{
  65. - struct stat st;
  66. - const int status = stat (name, &st);
  67. -
  68. - /* Stat should never fail except when the file does not exist.
  69. - If stat fails, analyze the source of error and return true
  70. - unless the file does not exist, to avoid returning false results
  71. - on obscure systems where stat does not work as expected. */
  72. -
  73. - if (status != 0)
  74. - {
  75. - if (errno != ENOENT)
  76. - return true;
  77. - *errno_ptr = ENOENT;
  78. - return false;
  79. - }
  80. -
  81. - if (S_ISREG (st.st_mode))
  82. - return true;
  83. -
  84. - if (S_ISDIR (st.st_mode))
  85. - *errno_ptr = EISDIR;
  86. - else
  87. - *errno_ptr = EINVAL;
  88. - return false;
  89. -}
  90. diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
  91. index 5408c354693..2320318de74 100644
  92. --- a/gdb/common/common-utils.h
  93. +++ b/gdb/common/common-utils.h
  94. @@ -146,9 +146,4 @@ in_inclusive_range (T value, T low, T high)
  95. return value >= low && value <= high;
  96. }
  97. -/* Return true if the file NAME exists and is a regular file.
  98. - If the result is false then *ERRNO_PTR is set to a useful value assuming
  99. - we're expecting a regular file. */
  100. -extern bool is_regular_file (const char *name, int *errno_ptr);
  101. -
  102. #endif
  103. diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
  104. index f5a754ffa66..fa10165a7ca 100644
  105. --- a/gdb/common/filestuff.c
  106. +++ b/gdb/common/filestuff.c
  107. @@ -417,3 +417,34 @@ make_cleanup_close (int fd)
  108. *saved_fd = fd;
  109. return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
  110. }
  111. +
  112. +/* See common/filestuff.h. */
  113. +
  114. +bool
  115. +is_regular_file (const char *name, int *errno_ptr)
  116. +{
  117. + struct stat st;
  118. + const int status = stat (name, &st);
  119. +
  120. + /* Stat should never fail except when the file does not exist.
  121. + If stat fails, analyze the source of error and return true
  122. + unless the file does not exist, to avoid returning false results
  123. + on obscure systems where stat does not work as expected. */
  124. +
  125. + if (status != 0)
  126. + {
  127. + if (errno != ENOENT)
  128. + return true;
  129. + *errno_ptr = ENOENT;
  130. + return false;
  131. + }
  132. +
  133. + if (S_ISREG (st.st_mode))
  134. + return true;
  135. +
  136. + if (S_ISDIR (st.st_mode))
  137. + *errno_ptr = EISDIR;
  138. + else
  139. + *errno_ptr = EINVAL;
  140. + return false;
  141. +}
  142. diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
  143. index 92a2a5f4c70..cc6dd861379 100644
  144. --- a/gdb/common/filestuff.h
  145. +++ b/gdb/common/filestuff.h
  146. @@ -84,4 +84,9 @@ extern int gdb_pipe_cloexec (int filedes[2]);
  147. extern struct cleanup *make_cleanup_close (int fd);
  148. +/* Return true if the file NAME exists and is a regular file.
  149. + If the result is false then *ERRNO_PTR is set to a useful value assuming
  150. + we're expecting a regular file. */
  151. +extern bool is_regular_file (const char *name, int *errno_ptr);
  152. +
  153. #endif /* FILESTUFF_H */
  154. --
  155. 2.14.4