ruby/template
KJ Tsanaktsidis 0ccb80d6bf Extract hardening CFLAGS to a special $hardenflags variable
This changes the automatic detection of -fstack-protector,
-D_FORTIFY_SOURCE, and -mbranch-protection to write to $hardenflags
instead of $XCFLAGS. The definition of $cflags is changed to
"$hardenflags $orig_cflags $optflags $debugflags $warnflags" to match.

Furthermore, these flags are _prepended_ to $hardenflags, rather than
appended.

The implications of doing this are as follows:

* If a CRuby builder specifies cflags="-mbranch-protection=foobar" at
  the ./configure script, and the configure script detects that
  -mbranch-protection=pac-ret is accepted, then GCC will be invoked as
  "gcc -mbranch-protection=pac-ret -mbranch-protection=foobar". Since
  the last flags take precedence, that means that user-supplied values
  of these flags in $cflags will take priority.
* Likewise, if a CRuby builder explicitly specifies
  "hardenflags=-mbranch-protection=foobar", because we _prepend_ to
  $hardenflags in our autoconf script, we will still invoke GCC as
  "gcc -mbranch-protection=pac-ret -mbranch-protection=foobar".
* If a CRuby builder specifies CFLAGS="..." at the configure line,
  automatic detection of hardening flags is ignored as before.
* C extensions will _also_ be built with hardening flags now as well
  (this was not the case by default before because the detected flags
  went into $XCFLAGS).

Additionally, as part of this work, I changed how the detection of
PAC/BTI in Context.S works. Rather than appending the autodetected
option to ASFLAGS, we simply compile a set of test programs with the
actual CFLAGS in use to determine what PAC/BTI settings were actually
chosen by the builder. Context.S is made aware of these choices through
some custom macros.

The result of this work is that:

* Ruby will continue to choose some sensible defaults for hardening
  options for the C compiler
* Distributors are able to specify CFLAGS that are consistent with their
  distribution and override these defaults
* Context.S will react to whatever -mbranch-protection is actually in
  use, not what was autodetected
* Extensions get built with hardening flags too.

[Bug #20154]
[Bug #20520]
2024-06-11 20:48:55 +10:00
..
Doxyfile.tmpl Remove never used macros related to RJIT [ci skip] 2024-03-24 22:37:20 +09:00
GNUmakefile.in Remove duplicate dependency line 2024-03-08 11:58:41 +09:00
Makefile.in Extract hardening CFLAGS to a special $hardenflags variable 2024-06-11 20:48:55 +10:00
builtin_binary.inc.tmpl Revert "Disable iseq-dumped builtin module for universal x86_64/arm64 binaries" 2023-11-09 16:01:01 +09:00
call_iseq_optimized.inc.tmpl
configure-ext.mk.tmpl Remove `--jobserver-auth` option which varies for each run 2023-06-19 18:28:10 +09:00
depend.tmpl
encdb.h.tmpl Refactor encdb and transdb templates 2024-03-17 19:09:37 +09:00
extinit.c.tmpl Alias init functions 2024-02-04 16:43:09 +09:00
exts.mk.tmpl Ignore failures on removing ext sub directories 2024-03-11 00:46:15 +09:00
fake.rb.in [Bug #19967] Reset `LIBPATHENV` env after started 2023-10-21 14:05:20 +09:00
id.c.tmpl Generate token ID indexes in id.def 2022-09-08 18:18:56 +09:00
id.h.tmpl Add comments to id.h and undef finished macros 2023-07-21 14:52:43 +09:00
known_errors.inc.tmpl [DOC] Documentize known_errors 2024-01-13 11:08:00 +09:00
limits.c.tmpl
prelude.c.tmpl [PRISM] Support for compiling builtins 2024-05-30 15:38:02 -04:00
ruby-gdb.in
ruby-lldb.in
ruby-runner.h.in
ruby.pc.in Use RUBY_PROGRAM_VERSION as version in pkg-config file [ci skip] 2023-04-13 11:31:34 +09:00
sizes.c.tmpl
transdb.h.tmpl Refactor encdb and transdb templates 2024-03-17 19:09:37 +09:00
unicode_norm_gen.tmpl
unicode_properties.rdoc.tmpl [Bug #19728] Auto-generate unicode property docs 2023-07-01 23:22:17 +09:00
verconf.h.tmpl