CTSRD-CHERI / cheribsd-ports

FreeBSD ports tree adapted for CheriBSD.
https://CheriBSD.org
Other
5 stars 10 forks source link

devel/llvm-base: switch to init-all=zero #153

Open brooksdavis opened 6 months ago

brooksdavis commented 6 months ago

Zero bits of the stack the compiler can't prove are initialized before use or escape by default.

Issue: https://github.com/CTSRD-CHERI/cheribsd/issues/2045 See also: https://github.com/CTSRD-CHERI/cheribsd/pull/2046

brooksdavis commented 6 months ago

This is completely untested since I did it on a non-morello system, but I think it's roughly correct.

brooksdavis commented 6 months ago

With llvm-morello-13.0.d20230914 (the current llvm-morello version in packages for 23.11) and the suggested fix in wrapper.sh.in, I get:

$ sh -x /usr/bin/cc -o test test.c
(...)
+ /usr/local64/bin/clang '-ftrivial-auto-var-init=zero' '-march=morello' '-mabi=purecap' -Xclang '-morello-vararg=new' -Xclang '-morello-bounded-memargs=caller-only' -o test test.c
clang-13: error: -ftrivial-auto-var-init=zero hasn't been enabled. Enable it at your own peril for benchmarking purpose only with -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang

Note that my llvm-morello version is outdated as we already have a newer version in ports.

I wonder if it makes sense to patch out -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang. I can add the flag in the script, but in the future we'll run into

clang: warning: the flag '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' has been deprecated and will be ignored [-Wunused-command-line-argument]
kwitaszczyk commented 6 months ago

I wonder if it makes sense to patch out -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang. I can add the flag in the script, but in the future we'll run into

clang: warning: the flag '-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang' has been deprecated and will be ignored [-Wunused-command-line-argument]

If I understand correctly, Clang 16 and newer don't require -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang to enable -ftrivial-auto-var-init=zero. I wonder if LLVM for Morello could cherry-pick that change. Otherwise, we'd have to patch it in CheriBSD ports and cheribuild, which would be ideal to avoid.

With -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang required, it'd be annoying to our users to always include this flag when executing a compiler from LOCALBASE64 instead of cc. The list of required compiler flags is already quite long.

kwitaszczyk commented 6 months ago

I've discussed with @rwatson that we should consider this for the next release but not for the CPM meeting.

Once https://github.com/CTSRD-CHERI/cheribsd/pull/2046 is merged into dev, we can merge this PR, bump the CheriBSD ABI version and rebuild packages again. Note that https://github.com/CTSRD-CHERI/cheribsd-ports/pull/141 updated llvm-base, including its versioning format as we discussed there.

kwitaszczyk commented 3 months ago

I've converted this to a draft as we're not planning to use it now.