0001-configure-use-appropriate-code-fragment-for-fstack-p.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 7b93e98143c376ed09bfd30658b8641d4a36e77e Mon Sep 17 00:00:00 2001
  2. From: Rodrigo Rebello <rprebello@gmail.com>
  3. Date: Thu, 12 Nov 2015 12:04:28 -0200
  4. Subject: [PATCH] configure: use appropriate code fragment for
  5. -fstack-protector checks
  6. Cc: qemu-trivial@nongnu.org
  7. The check for stack-protector support consisted in compiling and linking
  8. the test program below (output by function write_c_skeleton()) with the
  9. compiler flag -fstack-protector-strong first and then with
  10. -fstack-protector-all if the first one failed to work:
  11. int main(void) { return 0; }
  12. This caused false positives when using certain toolchains in which the
  13. compiler accepts -fstack-protector-strong but no support is provided by
  14. the C library, since in this stack-protector variant the compiler emits
  15. canary code only for functions that meet specific conditions (local
  16. arrays, memory references to local variables, etc.) and the code
  17. fragment under test included none of them (hence no stack protection
  18. code generated, no link failure).
  19. This fix modifies the test program used for -fstack-protector checks to
  20. meet conditions which cause the compiler to generate canary code in all
  21. variants.
  22. Upstream status: sent
  23. https://patchwork.ozlabs.org/patch/543357/
  24. Signed-off-by: Rodrigo Rebello <rprebello@gmail.com>
  25. ---
  26. configure | 10 ++++++++++
  27. 1 file changed, 10 insertions(+)
  28. diff --git a/configure b/configure
  29. index cd219d8..27d7b3c 100755
  30. --- a/configure
  31. +++ b/configure
  32. @@ -1471,6 +1471,16 @@ for flag in $gcc_flags; do
  33. done
  34. if test "$stack_protector" != "no"; then
  35. + cat > $TMPC << EOF
  36. +int main(int argc, char *argv[])
  37. +{
  38. + char arr[64], *p = arr, *c = argv[0];
  39. + while (*c) {
  40. + *p++ = *c++;
  41. + }
  42. + return 0;
  43. +}
  44. +EOF
  45. gcc_flags="-fstack-protector-strong -fstack-protector-all"
  46. sp_on=0
  47. for flag in $gcc_flags; do
  48. --
  49. 2.1.4