gcc-spec-env-r1.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 2013-08-22 Magnus Granberg <zorry@gentoo.org>
  2. * gcc/gcc.c (main): Add support for external spec file via the GCC_SPECS env var
  3. and move the process of the user specifed specs.
  4. This allows us to easily control pie/ssp defaults with gcc-config profiles.
  5. Original patch by Rob Holland
  6. Extended to support multiple entries separated by ':' by Kevin F. Quinn
  7. Modified to use getenv instead of poisoned GET_ENVIRONMENT by Ryan Hill
  8. Modified to process the GCC_SPECS env var befor DRIVER_SELF_SPECS by Magnus Granberg
  9. --- gcc-4.8-20130210/gcc/gcc.c 2013-02-05 16:55:31.000000000 +0100
  10. +++ gcc-4.8-20130210-work/gcc/gcc.c 2013-07-26 02:32:14.625089864 +0200
  11. @@ -6427,6 +6428,48 @@ main (int argc, char **argv)
  12. do_option_spec (option_default_specs[i].name,
  13. option_default_specs[i].spec);
  14. +#if !(defined (__MSDOS__) || defined (OS2) || defined (VMS) || defined (WIN32))
  15. + /* Add specs listed in GCC_SPECS. Note; in the process of separating
  16. + * each spec listed, the string is overwritten at token boundaries
  17. + * (':') with '\0', an effect of strtok_r().
  18. + */
  19. + specs_file = getenv ("GCC_SPECS");
  20. + if (specs_file && (strlen(specs_file) > 0))
  21. + {
  22. + char *spec, *saveptr;
  23. + for (spec=strtok_r(specs_file,":",&saveptr);
  24. + spec!=NULL;
  25. + spec=strtok_r(NULL,":",&saveptr))
  26. + {
  27. + struct user_specs *user = (struct user_specs *)
  28. + xmalloc (sizeof (struct user_specs));
  29. + user->next = (struct user_specs *) 0;
  30. + user->filename = spec;
  31. + if (user_specs_tail)
  32. + user_specs_tail->next = user;
  33. + else
  34. + user_specs_head = user;
  35. + user_specs_tail = user;
  36. + }
  37. + }
  38. +#endif
  39. + /* Process any user specified specs in the order given on the command
  40. + * line. */
  41. + for (uptr = user_specs_head; uptr; uptr = uptr->next)
  42. + {
  43. + char *filename = find_a_file (&startfile_prefixes, uptr->filename,
  44. + R_OK, true);
  45. + read_specs (filename ? filename : uptr->filename, false, true);
  46. + }
  47. + /* Process any user self specs. */
  48. + {
  49. + struct spec_list *sl;
  50. + for (sl = specs; sl; sl = sl->next)
  51. + if (sl->name_len == sizeof "self_spec" - 1
  52. + && !strcmp (sl->name, "self_spec"))
  53. + do_self_spec (*sl->ptr_spec);
  54. + }
  55. +
  56. /* Process DRIVER_SELF_SPECS, adding any new options to the end
  57. of the command line. */
  58. @@ -6535,24 +6578,6 @@ main (int argc, char **argv)
  59. PREFIX_PRIORITY_LAST, 0, 1);
  60. }
  61. - /* Process any user specified specs in the order given on the command
  62. - line. */
  63. - for (uptr = user_specs_head; uptr; uptr = uptr->next)
  64. - {
  65. - char *filename = find_a_file (&startfile_prefixes, uptr->filename,
  66. - R_OK, true);
  67. - read_specs (filename ? filename : uptr->filename, false, true);
  68. - }
  69. -
  70. - /* Process any user self specs. */
  71. - {
  72. - struct spec_list *sl;
  73. - for (sl = specs; sl; sl = sl->next)
  74. - if (sl->name_len == sizeof "self_spec" - 1
  75. - && !strcmp (sl->name, "self_spec"))
  76. - do_self_spec (*sl->ptr_spec);
  77. - }
  78. -
  79. if (compare_debug)
  80. {
  81. enum save_temps save;