0001-auto-type-sizeof-rework-autotest-to-be-cross-compila.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. From fb158af083e72c9aa0a8dfd4c6965f950192a230 Mon Sep 17 00:00:00 2001
  2. From: Samuel Martin <s.martin49@gmail.com>
  3. Date: Tue, 4 Jul 2017 11:09:20 -0400
  4. Subject: [PATCH] auto/type/sizeof: rework autotest to be cross-compilation
  5. friendly
  6. Rework the sizeof test to do the checks at compile time instead of at
  7. runtime. This way, it does not break when cross-compiling for a
  8. different CPU architecture.
  9. Signed-off-by: Samuel Martin <s.martin49@gmail.com>
  10. Refresh for 1.8.0.
  11. Signed-off-by: Danomi Manchego <danomimanchego123@gmail.com>
  12. [martin@barkynet.com: Updated for 1.10.0]
  13. Signed-off-by: Martin Bark <martin@barkynet.com>
  14. Signed-off-by: Adam Duskett <aduskett@gmail.com>
  15. Refresh for 1.12.0
  16. ---
  17. auto/types/sizeof | 37 ++++++++++++++++++++++++++++---------
  18. 1 file changed, 28 insertions(+), 9 deletions(-)
  19. diff --git a/auto/types/sizeof b/auto/types/sizeof
  20. index 480d8cf..61dcd2d 100644
  21. --- a/auto/types/sizeof
  22. +++ b/auto/types/sizeof
  23. @@ -14,7 +14,7 @@ END
  24. ngx_size=
  25. -cat << END > $NGX_AUTOTEST.c
  26. +cat << _EOF > $NGX_AUTOTEST.c
  27. #include <sys/types.h>
  28. #include <sys/time.h>
  29. @@ -25,22 +25,41 @@ $NGX_INCLUDE_UNISTD_H
  30. $NGX_INCLUDE_INTTYPES_H
  31. $NGX_INCLUDE_AUTO_CONFIG_H
  32. -int main(void) {
  33. - printf("%d", (int) sizeof($ngx_type));
  34. +#if !defined( PASTE)
  35. +#define PASTE2( x, y) x##y
  36. +#define PASTE( x, y) PASTE2( x, y)
  37. +#endif /* PASTE */
  38. +
  39. +#define SAY_IF_SIZEOF( typename, type, size) \\
  40. + static char PASTE( PASTE( PASTE( sizeof_, typename), _is_), size) \\
  41. + [(sizeof(type) == (size)) ? 1 : -1]
  42. +
  43. +SAY_IF_SIZEOF(TEST_TYPENAME, TEST_TYPE, TEST_SIZE);
  44. +
  45. +int main(void)
  46. +{
  47. return 0;
  48. }
  49. -END
  50. +_EOF
  51. -ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
  52. - -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
  53. +_ngx_typename=`echo "$ngx_type" | sed 's/ /_/g;s/\*/p/'`
  54. +ngx_size="-1"
  55. +ngx_size=`for i in 1 2 4 8 16 ; do \
  56. + $CC $CC_TEST_FLAGS $CC_AUX_FLAGS \
  57. + -DTEST_TYPENAME="$_ngx_typename" -DTEST_TYPE="$ngx_type" -DTEST_SIZE="$i" \
  58. + $NGX_AUTOTEST.c -o $NGX_AUTOTEST \
  59. + $NGX_LD_OPT $ngx_feature_libs >/dev/null 2>&1 || continue ;\
  60. + echo $i ; break ; done`
  61. -eval "$ngx_test >> $NGX_AUTOCONF_ERR 2>&1"
  62. +rm -rf $NGX_AUTOTEST*
  63. +if test -z $ngx_size ; then
  64. + ngx_size=-1
  65. +fi
  66. -if [ -x $NGX_AUTOTEST ]; then
  67. - ngx_size=`$NGX_AUTOTEST`
  68. +if [ $ngx_size -gt 0 ]; then
  69. echo " $ngx_size bytes"
  70. fi
  71. --
  72. 2.9.4