digitalmars.D - IBT/BTI instructions and D compilers
- Brian Callahan (6/6) Jul 10 2023 Hi all (but probably mostly Walter) --
- Richard (Rikki) Andrew Cattermole (3/3) Jul 10 2023 It looks like there is a workaround by adding PT_OPENBSD_NOBTCFI segment...
- Brian Callahan (4/8) Jul 10 2023 You know I'm an OpenBSD developer, right? We are not accepting
- Richard (Rikki) Andrew Cattermole (4/4) Jul 10 2023 No, I am not aware of what projects people work upon unless I've helped
- Brian Callahan (4/8) Jul 10 2023 All good. I'm just asking about the status of IBT/BTI
- Richard (Rikki) Andrew Cattermole (7/9) Jul 10 2023 I should give you some feedback however.
- Brian Callahan (4/15) Jul 10 2023 That's why I asked. I didn't know if Walter had thought about it
- Walter Bright (2/4) Jul 10 2023 Are you talking about the ENDBR32 and ENDBR64 instructions?
- max haughton (3/7) Jul 10 2023 Yes. Intel's documentation on this is terrible
- FeepingCreature (4/8) Jul 10 2023 If you're in the webforum, there's no way to see the From header
- Ernesto Castellotti (6/12) Jul 10 2023 BTI should work on GCC D Compiler (GDC) with
- Brian Callahan (3/18) Jul 10 2023 AFAIK, it does work on GDC.
- Ernesto Castellotti (7/27) Jul 10 2023 Yes I tried now, no problem with -fcf-protection and
- Brian Callahan (4/8) Jul 10 2023 Good idea. I made an Issue on GitHub for LDC and I made a
- Iain Buclaw (4/14) Jul 10 2023 I did raise a bug report back in 2020
- Brian Callahan (5/20) Jul 10 2023 Hi Iain --
- Brian Callahan (4/27) Jul 10 2023 Actually, I take that back. We don't do the --enable-cet flag for
- Brian Callahan (8/37) Jul 10 2023 And because Intel I don't think was all that good at explaining
- Iain Buclaw (3/6) Jul 10 2023 Grep `build/*/libphobos/config.log` for CET_DFLAGS. You
- Brian Callahan (3/10) Jul 10 2023 I get:
- Walter Bright (3/5) Jul 14 2023 Ye of little faith! 20 lines of code.
- Richard (Rikki) Andrew Cattermole (7/7) Jul 14 2023 Ooooo are we challenging you to things that dmd-be can't possibly
- Walter Bright (8/10) Jul 15 2023 The dmd back end started out as an 8086 code generator. It survived:
- Richard (Rikki) Andrew Cattermole (1/1) Jul 15 2023 Yeah quite an impressive life cycle!
- Iain Buclaw (5/6) Jul 16 2023 Though, even GCC [started
- Walter Bright (2/5) Jul 17 2023 I didn't know that! Cool
- Walter Bright (2/2) Jul 17 2023 The advantage it has was being designed for the very irregular, inconsis...
- Brian Callahan (7/12) Jul 15 2023 Hi Walter --
- Richard (Rikki) Andrew Cattermole (4/6) Jul 15 2023 Lol its all good. You were in the throws of trying to get a pretty
- Iain Buclaw (8/14) Jul 10 2023 This is Intel CET, right?
- Ernesto Castellotti (4/20) Jul 11 2023 There is also for AArch64, see -mbranch-protection.
- Johan (7/12) Jul 12 2023 When this is enabled, I want to add `__traits(getTargetInfo,
- Walter Bright (3/7) Jul 14 2023 Illuminating Hacker News discussion of this feature:
Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC? Thanks.
Jul 10 2023
It looks like there is a workaround by adding PT_OPENBSD_NOBTCFI segment header. https://man.openbsd.org/ld.bfd.1 Have you tried that?
Jul 10 2023
On Monday, 10 July 2023 at 11:39:39 UTC, Richard (Rikki) Andrew Cattermole wrote:It looks like there is a workaround by adding PT_OPENBSD_NOBTCFI segment header. https://man.openbsd.org/ld.bfd.1 Have you tried that?You know I'm an OpenBSD developer, right? We are not accepting this for compilers.
Jul 10 2023
No, I am not aware of what projects people work upon unless I've helped them with it typically. But yes, sorry for not seeing the from email address and making noise that wasn't helpful for continuing D support.
Jul 10 2023
On Monday, 10 July 2023 at 12:06:37 UTC, Richard (Rikki) Andrew Cattermole wrote:No, I am not aware of what projects people work upon unless I've helped them with it typically. But yes, sorry for not seeing the from email address and making noise that wasn't helpful for continuing D support.All good. I'm just asking about the status of IBT/BTI instructions being emitted by DMD and LDC. That's all.
Jul 10 2023
On 11/07/2023 12:16 AM, Brian Callahan wrote:All good. I'm just asking about the status of IBT/BTI instructions being emitted by DMD and LDC. That's all.I should give you some feedback however. When I looked up the appropriate keywords, all I got from Google was all but one completely useless links. The one useful one is by Intel targeting people who are already pretty deep into attack mitigation. If this is anything to go by, there are no migration guidelines. So not very likely its going to have an implementation by anyone ;)
Jul 10 2023
On Monday, 10 July 2023 at 12:46:14 UTC, Richard (Rikki) Andrew Cattermole wrote:On 11/07/2023 12:16 AM, Brian Callahan wrote:That's why I asked. I didn't know if Walter had thought about it and I figured it was cheap and easy to ask him.All good. I'm just asking about the status of IBT/BTI instructions being emitted by DMD and LDC. That's all.I should give you some feedback however. When I looked up the appropriate keywords, all I got from Google was all but one completely useless links. The one useful one is by Intel targeting people who are already pretty deep into attack mitigation. If this is anything to go by, there are no migration guidelines. So not very likely its going to have an implementation by anyone ;)
Jul 10 2023
On 7/10/2023 5:16 AM, Brian Callahan wrote:All good. I'm just asking about the status of IBT/BTI instructions being emitted by DMD and LDC. That's all.Are you talking about the ENDBR32 and ENDBR64 instructions?
Jul 10 2023
On Monday, 10 July 2023 at 19:54:59 UTC, Walter Bright wrote:On 7/10/2023 5:16 AM, Brian Callahan wrote:Yes. Intel's documentation on this is terrible https://edc.intel.com/content/www/us/en/design/ipla/software-development-platforms/client/platforms/alder-lake-desktop/12th-generation-intel-core-processors-datasheet-volume-1-of-2/006/indirect-branch-tracking/All good. I'm just asking about the status of IBT/BTI instructions being emitted by DMD and LDC. That's all.Are you talking about the ENDBR32 and ENDBR64 instructions?
Jul 10 2023
On Monday, 10 July 2023 at 12:06:37 UTC, Richard (Rikki) Andrew Cattermole wrote:No, I am not aware of what projects people work upon unless I've helped them with it typically. But yes, sorry for not seeing the from email address and making noise that wasn't helpful for continuing D support.If you're in the webforum, there's no way to see the From header anyways, afaict.
Jul 10 2023
On Monday, 10 July 2023 at 11:24:37 UTC, Brian Callahan wrote:Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC? Thanks.BTI should work on GCC D Compiler (GDC) with -branch-protection=bti, LDC as far as I know lacks flag support but it should be very easy to implement because LLVM supports BTI. Regarding DMD I think it's very complex because probably the backend doesn't support it.
Jul 10 2023
On Monday, 10 July 2023 at 12:46:57 UTC, Ernesto Castellotti wrote:On Monday, 10 July 2023 at 11:24:37 UTC, Brian Callahan wrote:AFAIK, it does work on GDC.Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC? Thanks.BTI should work on GCC D Compiler (GDC) with -branch-protection=bti, LDC as far as I know lacks flag support but it should be very easy to implement because LLVM supports BTI. Regarding DMD I think it's very complex because probably the backend doesn't support it.
Jul 10 2023
On Monday, 10 July 2023 at 13:01:46 UTC, Brian Callahan wrote:On Monday, 10 July 2023 at 12:46:57 UTC, Ernesto Castellotti wrote:Yes I tried now, no problem with -fcf-protection and -mbranch-protection in GDC. For LDC it should be very simple to do the same, it would be useful to open an issue in the LDC repo The real problem is DMD, I'm afraid it needs some tweaking in the backendOn Monday, 10 July 2023 at 11:24:37 UTC, Brian Callahan wrote:AFAIK, it does work on GDC.Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC? Thanks.BTI should work on GCC D Compiler (GDC) with -branch-protection=bti, LDC as far as I know lacks flag support but it should be very easy to implement because LLVM supports BTI. Regarding DMD I think it's very complex because probably the backend doesn't support it.
Jul 10 2023
On Monday, 10 July 2023 at 13:08:03 UTC, Ernesto Castellotti wrote:For LDC it should be very simple to do the same, it would be useful to open an issue in the LDC repo The real problem is DMD, I'm afraid it needs some tweaking in the backendGood idea. I made an Issue on GitHub for LDC and I made a Bugzilla report for DMD.
Jul 10 2023
On Monday, 10 July 2023 at 13:25:37 UTC, Brian Callahan wrote:On Monday, 10 July 2023 at 13:08:03 UTC, Ernesto Castellotti wrote:I did raise a bug report back in 2020 https://issues.dlang.org/show_bug.cgi?id=20933 I guess I didn't word it clearly enough. :-)For LDC it should be very simple to do the same, it would be useful to open an issue in the LDC repo The real problem is DMD, I'm afraid it needs some tweaking in the backendGood idea. I made an Issue on GitHub for LDC and I made a Bugzilla report for DMD.
Jul 10 2023
On Monday, 10 July 2023 at 14:19:38 UTC, Iain Buclaw wrote:On Monday, 10 July 2023 at 13:25:37 UTC, Brian Callahan wrote:Hi Iain -- Yes, it is. We do enable it by default on OpenBSD :) More specifically, this is the -fcf-protection=branch flag -- no shadow stack stuff here.On Monday, 10 July 2023 at 13:08:03 UTC, Ernesto Castellotti wrote:I did raise a bug report back in 2020 https://issues.dlang.org/show_bug.cgi?id=20933 I guess I didn't word it clearly enough. :-)For LDC it should be very simple to do the same, it would be useful to open an issue in the LDC repo The real problem is DMD, I'm afraid it needs some tweaking in the backendGood idea. I made an Issue on GitHub for LDC and I made a Bugzilla report for DMD.
Jul 10 2023
On Monday, 10 July 2023 at 14:45:48 UTC, Brian Callahan wrote:On Monday, 10 July 2023 at 14:19:38 UTC, Iain Buclaw wrote:Actually, I take that back. We don't do the --enable-cet flag for libphobos (didn't know that existed). But we build all of GCC with -fcf-protection=branch.On Monday, 10 July 2023 at 13:25:37 UTC, Brian Callahan wrote:Hi Iain -- Yes, it is. We do enable it by default on OpenBSD :) More specifically, this is the -fcf-protection=branch flag -- no shadow stack stuff here.On Monday, 10 July 2023 at 13:08:03 UTC, Ernesto Castellotti wrote:I did raise a bug report back in 2020 https://issues.dlang.org/show_bug.cgi?id=20933 I guess I didn't word it clearly enough. :-)For LDC it should be very simple to do the same, it would be useful to open an issue in the LDC repo The real problem is DMD, I'm afraid it needs some tweaking in the backendGood idea. I made an Issue on GitHub for LDC and I made a Bugzilla report for DMD.
Jul 10 2023
On Monday, 10 July 2023 at 14:46:47 UTC, Brian Callahan wrote:On Monday, 10 July 2023 at 14:45:48 UTC, Brian Callahan wrote:And because Intel I don't think was all that good at explaining things, and we have this flag that does one or both of two very different things: -fcf-protection=return does shadow stacks and -fcf-protection=full does both shadow stacks and IBT. Neither of these are what we're talking about. Just -fcf-protection=branch which only does IBT. Intel says you can do one without the other. But both are controlled by the same flag. Go figure.On Monday, 10 July 2023 at 14:19:38 UTC, Iain Buclaw wrote:Actually, I take that back. We don't do the --enable-cet flag for libphobos (didn't know that existed). But we build all of GCC with -fcf-protection=branch.On Monday, 10 July 2023 at 13:25:37 UTC, Brian Callahan wrote:Hi Iain -- Yes, it is. We do enable it by default on OpenBSD :) More specifically, this is the -fcf-protection=branch flag -- no shadow stack stuff here.On Monday, 10 July 2023 at 13:08:03 UTC, Ernesto Castellotti wrote:I did raise a bug report back in 2020 https://issues.dlang.org/show_bug.cgi?id=20933 I guess I didn't word it clearly enough. :-)For LDC it should be very simple to do the same, it would be useful to open an issue in the LDC repo The real problem is DMD, I'm afraid it needs some tweaking in the backendGood idea. I made an Issue on GitHub for LDC and I made a Bugzilla report for DMD.
Jul 10 2023
On Monday, 10 July 2023 at 14:46:47 UTC, Brian Callahan wrote:Actually, I take that back. We don't do the --enable-cet flag for libphobos (didn't know that existed). But we build all of GCC with -fcf-protection=branch.Grep `build/*/libphobos/config.log` for CET_DFLAGS. You shouldn't need to enable it explicitly on x86/64.
Jul 10 2023
On Monday, 10 July 2023 at 14:53:34 UTC, Iain Buclaw wrote:On Monday, 10 July 2023 at 14:46:47 UTC, Brian Callahan wrote:I get: CET_DFLAGS=''Actually, I take that back. We don't do the --enable-cet flag for libphobos (didn't know that existed). But we build all of GCC with -fcf-protection=branch.Grep `build/*/libphobos/config.log` for CET_DFLAGS. You shouldn't need to enable it explicitly on x86/64.
Jul 10 2023
On 7/10/2023 5:46 AM, Ernesto Castellotti wrote:Regarding DMD I think it's very complex because probably the backend doesn't support it.Ye of little faith! 20 lines of code. https://github.com/dlang/dmd/pull/15415
Jul 14 2023
Ooooo are we challenging you to things that dmd-be can't possibly support and you proving us wrong? Okay, I'll begin: dmd-be cannot support atomics as intrinsics. How do I know this? You're too clever to have not implemented it if it was possible and instead had to rely on the slow non-inlining memory segfaulting inline assembly instead. After all, if ldc and gdc both support it and dmd doesn't, it must be because it can't do it!
Jul 14 2023
On 7/14/2023 11:41 PM, Richard (Rikki) Andrew Cattermole wrote:Ooooo are we challenging you to things that dmd-be can't possibly support and you proving us wrong?The dmd back end started out as an 8086 code generator. It survived: 1. adding 8087 instruction set (very different) 2. upgrade to 286 3. upgrade to 32 bit code 4. upgrade to 64 bit code 5. upgrade to SIMD 6. upgrade to VEX
Jul 15 2023
Yeah quite an impressive life cycle!
Jul 15 2023
On Sunday, 16 July 2023 at 02:54:29 UTC, Richard (Rikki) Andrew Cattermole wrote:Yeah quite an impressive life cycle!Though, even GCC [started out](https://groups.google.com/g/mod.compilers/c/ynAVuwR7dPw) as an 8020 (and vax) code generator.
Jul 16 2023
On 7/16/2023 12:41 PM, Iain Buclaw wrote:Though, even GCC [started out](https://groups.google.com/g/mod.compilers/c/ynAVuwR7dPw) as an 8020 (and vax) code generator.I didn't know that! Cool
Jul 17 2023
The advantage it has was being designed for the very irregular, inconsistent use of registers.
Jul 17 2023
On Saturday, 15 July 2023 at 05:09:42 UTC, Walter Bright wrote:On 7/10/2023 5:46 AM, Ernesto Castellotti wrote:Hi Walter -- Thanks for working on this! It is much appreciated. I'll have some time soon to test it and LDC out. (Also, I'd like to apologize to Rikki for my initial response on this thread. Came off harsher than I intended it to.) ~BrianRegarding DMD I think it's very complex because probably the backend doesn't support it.Ye of little faith! 20 lines of code. https://github.com/dlang/dmd/pull/15415
Jul 15 2023
On 16/07/2023 12:22 AM, Brian Callahan wrote:(Also, I'd like to apologize to Rikki for my initial response on this thread. Came off harsher than I intended it to.)Lol its all good. You were in the throws of trying to get a pretty important improvement allocated time for, and I was worrying about WinCrypt so certain details were forgotten at the time :)
Jul 15 2023
On Monday, 10 July 2023 at 11:24:37 UTC, Brian Callahan wrote:Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC? Thanks.This is Intel CET, right? It's on by default at configure-time. https://github.com/gcc-mirror/gcc/commit/08c1d39d3a822dfe7d91524ec290e0f230504242 Speaking of which, the asm support code for Fibers does not support shadow stacks, so you'll need to fall back to ucontext_t's swapcontext unless someone figures out what the correct way to handle it is.
Jul 10 2023
On Monday, 10 July 2023 at 14:17:36 UTC, Iain Buclaw wrote:On Monday, 10 July 2023 at 11:24:37 UTC, Brian Callahan wrote:There is also for AArch64, see -mbranch-protection. GCC/GDC works fine with -mbranch-protection on AArch64 but I don't know if it's the default.Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC? Thanks.This is Intel CET, right? It's on by default at configure-time. https://github.com/gcc-mirror/gcc/commit/08c1d39d3a822dfe7d91524ec290e0f230504242 Speaking of which, the asm support code for Fibers does not support shadow stacks, so you'll need to fall back to ucontext_t's swapcontext unless someone figures out what the correct way to handle it is.
Jul 11 2023
On Monday, 10 July 2023 at 11:24:37 UTC, Brian Callahan wrote:Hi all (but probably mostly Walter) -- OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC?When this is enabled, I want to add `__traits(getTargetInfo, "CET")` that has the same value as the macro `__CET__` in C. What string name `"CET"` shall I use for getTargetInfo? (i.e. that can be upstreamed to DMD, such that all 3 compilers use the same name) Thanks, Johan
Jul 12 2023
On 7/10/2023 4:24 AM, Brian Callahan wrote:OpenBSD has moved to an all-BTI world. Binaries produced by DMD and LDC no longer work because of this. If other OSes make this move, this problem will be further compounded. Is there any thought about enabling IBT/BTI instructions in DMD and LDC?Illuminating Hacker News discussion of this feature: https://news.ycombinator.com/item?id=36722823
Jul 14 2023