ruby/coroutine
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
..
amd64 Avoid memory dependency between instructions. (#8284) 2023-08-25 13:28:33 +12:00
arm32 Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
arm64 Extract hardening CFLAGS to a special $hardenflags variable 2024-06-11 20:48:55 +10:00
asyncify wasm: align fiber stack pointer to 16 bytes 2024-01-29 23:45:36 +09:00
emscripten Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
loongarch64 Add support for LoongArch (#7343) 2023-02-22 13:11:33 +09:00
ppc Do not use non-ASCII chars in sources 2023-11-05 02:14:26 +09:00
ppc64 Do not use non-ASCII chars in sources 2023-11-05 02:14:26 +09:00
ppc64le Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
pthread Ignore dead threads in coroutine_join. 2021-07-02 12:36:14 +12:00
riscv64 Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
ucontext Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
universal Ruby31: add support for Darwin ppc/ppc64 (#5927) 2022-05-22 15:02:03 +12:00
win32 Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
win64 Win32: Use prototype 2024-02-11 20:55:26 +09:00
x86 Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00