YouTube2Text

How Fil-C Works — Transcript

by Wookash Podcast · 19,927 words · 3,276 segments · language en · Watch on YouTube

Full transcript

  1. 0:00If your memory unsafe, that means
  2. 0:01[music] that an attacker can now use
  3. 0:04input into your program to just
  4. 0:05literally edit any bits in your memory.
  5. 0:07Attackers have shown
  6. 0:09>> [music]
  7. 0:09>> throughout the history of the security
  8. 0:11business that if you give them that
  9. 0:12power, they can reprogram [music] your
  10. 0:14computer. And the idea is, what if the
  11. 0:17thing about C and C++ [music]
  12. 0:19that's not memory safe isn't the
  13. 0:21language, but just the way we implement
  14. 0:23it? So, there for those programs, Emacs,
  15. 0:26[music] Ruby, and JavaScript core, I
  16. 0:28just ripped the GC out and replace all
  17. 0:31of the entry points into the [music]
  18. 0:32garbage collector with just calls to
  19. 0:34malloc. I would like to start sort of
  20. 0:36like top high level, talk a little bit
  21. 0:38about
  22. 0:40memory safety in general, PhilC, what is
  23. 0:42it, how it works, and kind of gradually
  24. 0:44move towards deeper and deeper
  25. 0:47depths, and at some point, if uh Phil
  26. 0:50was going to be, you know what? I should
  27. 0:52share my screen and just show you how
  28. 0:54this works, then we can do it as well.
  29. 0:56Sounds good.
  30. 0:58>> [snorts]
  31. 0:59>> So, [clears throat] let's kick this off.
  32. 1:01Welcome to another special episode of
  33. 1:04Łukasz podcast. I am Łukasz, your host,
  34. 1:07and with me is creator of PhilC, Filip
  35. 1:11Jerzipizlo. Hello.
  36. 1:13Hi, how's it going?
  37. 1:16And Casey Muratori, well-known persona
  38. 1:19in performance-oriented
  39. 1:22programming now. Hello, Casey.
  40. 1:25How's it going?
  41. 1:27We are gathered here today to talk about
  42. 1:29memory safety, the most sexy topic in
  43. 1:32programming, as everybody knows this.
  44. 1:34And
  45. 1:36we have to start
  46. 1:38a little bit about
  47. 1:41just memory safety in general, okay?
  48. 1:44The concept for me, it's incredible. If
  49. 1:47people say, "Hey, this is memory safe."
  50. 1:49It's as if, "Oh, it doesn't have any
  51. 1:51bugs, you know? It doesn't have like it
  52. 1:52it it it it it will always work. It's
  53. 1:54like incredible." So, can we can we say
  54. 1:59a little bit what is memory safety?
  55. 2:01What's other feature? Okay? Philip, can
  56. 2:04you tell me?
  57. 2:05Yeah. Uh so, here's how I think about
  58. 2:07it.
  59. 2:09Um
  60. 2:10so, first of all, memory safety isn't
  61. 2:12about the prevention of bugs. If you
  62. 2:14have a bug in your program, um that
  63. 2:16might still be a memory safe program. Uh
  64. 2:19probably the most extreme example of a
  65. 2:22memory safe catastrophic bug is Log4j,
  66. 2:27where a memory safe Java program was
  67. 2:30parsing strings and using those strings
  68. 2:32to decide what modules to load.
  69. 2:35And so then, you know, you could go to a
  70. 2:37website and if you uh type in a message
  71. 2:40that that log parser parses, all of a
  72. 2:42sudden the server is executing whatever
  73. 2:44code you want.
  74. 2:45So, memory safety isn't about prevention
  75. 2:47of bugs. It's specifically about the
  76. 2:49following.
  77. 2:50It in assembly, C, uh C++, and other
  78. 2:55languages that are memory unsafe,
  79. 2:58a bug in one part of your program, like
  80. 3:00a bug in a parser,
  81. 3:01or a bug in an event handler, or
  82. 3:04something,
  83. 3:06could allow an attacker to take control
  84. 3:08over all of memory.
  85. 3:10Uh so, now it's not just that the
  86. 3:12attacker
  87. 3:13uh can inject a string that if you had a
  88. 3:16string parser, you would parse it and do
  89. 3:18something bad.
  90. 3:19But,
  91. 3:20you know, you could have an innocuous
  92. 3:22parser that's parsing um
  93. 3:25I don't know, uh
  94. 3:26ping packets or something, just meant to
  95. 3:28be completely meaningless and not
  96. 3:30impactful on the rest of your program.
  97. 3:32And because you have a thing where you
  98. 3:34failed to check array bounds,
  99. 3:37if you're memory unsafe, that means that
  100. 3:39an attacker can now
  101. 3:41use input into your program to just
  102. 3:44literally edit any bits in your memory.
  103. 3:47Um
  104. 3:48and
  105. 3:49uh Uh, attackers have shown throughout
  106. 3:53the history of the security business
  107. 3:55that if you give them that power
  108. 3:57they can reprogram your computer.
  109. 4:00Hi everyone. Let me take a break to
  110. 4:02thank members of the show who made this
  111. 4:04conversation possible. Members get
  112. 4:06earlier access to videos including
  113. 4:08longer unedited footage from live
  114. 4:11streams as well as they're invited to
  115. 4:13our private Discord server. If you want
  116. 4:16to support this show, there is no better
  117. 4:18way than becoming a member on YouTube or
  118. 4:20Patreon. Thank you so much.
  119. 4:24Um, so the earliest example of this was
  120. 4:26like the shellcode where you have a
  121. 4:28buffer on the stack.
  122. 4:30Um
  123. 4:31and you fail to check the bounds of the
  124. 4:34buffer while reading something.
  125. 4:36Uh, and then the attacker overwrites the
  126. 4:38buffer and then keeps writing to
  127. 4:40overwrite the return address that was on
  128. 4:43the stack.
  129. 4:44And then keeps writing to write machine
  130. 4:46code
  131. 4:47and makes the return address point at
  132. 4:49the machine code. This was back in the
  133. 4:50days when computers didn't have, uh, for
  134. 4:52example execute protections on the
  135. 4:55stack. And then and then they can just
  136. 4:57run whatever whatever machine code
  137. 4:59snippet they choose on your computer.
  138. 5:02And then then they have full control.
  139. 5:03Whatever the process is entitled to do
  140. 5:06the attacker now gets to do as if they
  141. 5:08could retype the code of your program.
  142. 5:11Um, so this is quite a bit different
  143. 5:12from most other bugs. Like
  144. 5:15if you have a security bug like that you
  145. 5:17forgot to do a policy check whether
  146. 5:19someone is an admin
  147. 5:21um, then that would let the attacker
  148. 5:24attack you if they
  149. 5:26can somehow attack that specific bug
  150. 5:29and then the capability they get out of
  151. 5:31that is just whatever that bug gives
  152. 5:33them. With a memory safety bug, you
  153. 5:36could have a bug in a part of your
  154. 5:37program that isn't anything to do with
  155. 5:40security checks.
  156. 5:42And if if the attacker finds a bug
  157. 5:44there, all of a sudden they can do
  158. 5:45anything your program can do.
  159. 5:47Now, what's really scary about memory
  160. 5:49safety issues is that even if you fix
  161. 5:52that simple case of, "Okay, well, what
  162. 5:55if we make the stack not executable?
  163. 5:57What if we randomize memory and make it
  164. 5:59so that
  165. 6:01uh
  166. 6:02the the attacker can't just know where
  167. 6:04to make the return address point."
  168. 6:06Um
  169. 6:08"What if we make it so that every jump
  170. 6:10that the CPU executes can only jump to
  171. 6:12preordained locations, right? Like, what
  172. 6:14if we do these kinds of protection?"
  173. 6:17It turns out that attackers have
  174. 6:19established that
  175. 6:21if you control every bit of memory, then
  176. 6:24even if they can't change where the
  177. 6:26branches go,
  178. 6:27like even if they can't tell the CPU to
  179. 6:30jump to a specific location,
  180. 6:33even if the attacker can't inject their
  181. 6:35own machine code, they can make
  182. 6:37your program do whatever they want
  183. 6:40through a technique called weird
  184. 6:41execution. Weird state, weird execution,
  185. 6:43those are terms of art that these people
  186. 6:45use.
  187. 6:46Where essentially, if if I can control
  188. 6:48every bit in the memory of your process,
  189. 6:51then because every branch in your
  190. 6:52program ultimately is depending on
  191. 6:55something loaded from memory,
  192. 6:57the attacker, by controlling every bit
  193. 6:59in memory, can take your program on
  194. 7:01whatever journey they want and can
  195. 7:03effectively achieve the same power as if
  196. 7:05they could reprogram your program and
  197. 7:07make it do whatever they want.
  198. 7:09So, memory safety
  199. 7:11is the property that an attacker can't
  200. 7:14use a localized bug like a memory buffer
  201. 7:17overflow or use-after-free
  202. 7:19to then pivot to controlling
  203. 7:22all of your memory or enough of your
  204. 7:24memory. Cuz with weird execution, since
  205. 7:26they've proven that they can control
  206. 7:28your program by controlling all of
  207. 7:29memory, it kind of probably follows that
  208. 7:33even if you only gave them control of
  209. 7:34half of your memory, they could probably
  210. 7:35do the same thing.
  211. 7:37So, memory safety is like you have to
  212. 7:39somehow make it so that if there's a bug
  213. 7:41in one part of the program,
  214. 7:43the amount of memory that the attacker
  215. 7:46now controls is severely limited to just
  216. 7:49like
  217. 7:50that object or that something some
  218. 7:53somewhere in that neighborhood.
  219. 7:55Um and then
  220. 7:57there's a lively debate to be had of how
  221. 7:59far do you have to go, right? Uh if I
  222. 8:02was uh a Rust evangelist,
  223. 8:05uh I I would probably be arguing that
  224. 8:08the protections need to go much further
  225. 8:10than that and that we need to have
  226. 8:12thread safety
  227. 8:13and and super tight type system that
  228. 8:16checks everything.
  229. 8:18Um
  230. 8:19uh if I was putting my JavaScript hat
  231. 8:22on, I would observe that JavaScript is
  232. 8:23memory safe just by virtue of the fact
  233. 8:25that
  234. 8:26if an attacker finds a bug in my
  235. 8:28JavaScript code,
  236. 8:30they might be able to change what field
  237. 8:32values end up in the fields of whatever
  238. 8:35objects the program is sitting on at the
  239. 8:38point of that bug, but that's it. And so
  240. 8:39therefore, it's memory safe.
  241. 8:42Um
  242. 8:43That's easy way out. Memory safe.
  243. 8:45Easy way out for JavaScript there.
  244. 8:48Yeah.
  245. 8:50Casey, do you have anything to add on
  246. 8:51the general level of memory safety?
  247. 8:54No, I mean I think that was absolutely
  248. 8:56fantastic. Uh
  249. 8:57the I guess the only things I would
  250. 8:59point out are things that people tend to
  251. 9:01get confused about. They were all
  252. 9:03explained in that explanation, but if
  253. 9:06you know, if depending on where people
  254. 9:07are coming from,
  255. 9:09a lot of times there's confusion because
  256. 9:12people don't understand the difference
  257. 9:14between checks that are performed at
  258. 9:16compile time and checks that are
  259. 9:18performed at run time
  260. 9:20and which types of things are caught
  261. 9:23when.
  262. 9:24And so this causes a lot of confusion
  263. 9:26online I see with people who don't
  264. 9:28necessarily have like a deep
  265. 9:30understanding of what's going on.
  266. 9:32Sometimes they get confused because they
  267. 9:34don't realize that for For
  268. 9:35even in a language designed for
  269. 9:39certain types of memory checks at
  270. 9:41compile time, like Rust,
  271. 9:44there's entire categories of memory
  272. 9:46safety bugs that are important to
  273. 9:48prevent that cannot be caught at compile
  274. 9:50time because we've just we we've sort of
  275. 9:54proven that
  276. 9:55unless you have complete formal analysis
  277. 9:57of a program,
  278. 9:59there's no way like if it's taking user
  279. 10:01input, there's no way other than at
  280. 10:04runtime to ensure that something is
  281. 10:07memory safe. So, even a a programming
  282. 10:09language like Rust,
  283. 10:11it will be doing runtime checks to
  284. 10:14enforce a bunch of memory safety policy.
  285. 10:17And so, you
  286. 10:19there really isn't at the moment, at
  287. 10:22least as far as I'm aware, there isn't
  288. 10:23any sort of in mass production
  289. 10:27sort of large, you know, widely
  290. 10:28commercialized methodology that involves
  291. 10:32only compile time.
  292. 10:33All of the ones that are like currently
  293. 10:36common that you would see
  294. 10:38that people would argue about on the
  295. 10:39internet, they are employing runtime
  296. 10:41checks. The question is how much is
  297. 10:43checked at runtime versus how much is
  298. 10:45checked at compile time. And I just feel
  299. 10:47like that's important to get out there
  300. 10:48cuz I see people get confused about this
  301. 10:50a lot and like a lot a lot of people
  302. 10:52genuinely think that Rust after the
  303. 10:54compilation is done with its memory
  304. 10:56safety. It's like that's not how that
  305. 10:58works, right? And it's important to
  306. 11:00establish that at least or that
  307. 11:01baseline, I would say.
  308. 11:03Yeah, yeah, yeah, it's a good point. The
  309. 11:05other uh
  310. 11:06uh that reminds me the other thing that
  311. 11:08folks get confused about
  312. 11:10is
  313. 11:12um memory safety in the sense of
  314. 11:14preventing crashes
  315. 11:17versus memory safety in the sense of
  316. 11:18preventing weird execution.
  317. 11:20Good point. Yeah. Yep. Uh
  318. 11:22for for for for most of us thinking
  319. 11:25about memory safety,
  320. 11:27uh I think that includes, for example,
  321. 11:29the folks at uh CISA who are writing
  322. 11:31those memos about how everyone should
  323. 11:33stop using memory unsafe languages, you
  324. 11:35know, those government directives.
  325. 11:37For for us,
  326. 11:39crashing isn't the problem.
  327. 11:42Like, if the problem with C and C++
  328. 11:44programs was that
  329. 11:47um if something bad happens or an
  330. 11:49attacker attacks you, the program
  331. 11:50crashes,
  332. 11:51um
  333. 11:53then would that be a problem? Yeah,
  334. 11:55yeah, that's a problem, but it just
  335. 11:57would not be the problem that would
  336. 11:58raise to the level of the government
  337. 12:01needing us needing to tell us how to do
  338. 12:03things.
  339. 12:04The thing that causes uh the level of
  340. 12:07fear and and and terror that that gets
  341. 12:11the government uh
  342. 12:13stressed about this
  343. 12:14is the weird execution. So, it's not
  344. 12:16that your program crashes,
  345. 12:19but that the attacker now has has full
  346. 12:22control over your program, and you don't
  347. 12:24even know it. So, your program is not
  348. 12:25doing what you intended anymore, it's
  349. 12:27doing what the attacker intended. Um and
  350. 12:30the most extreme examples of this are
  351. 12:33uh you know, uh
  352. 12:35some government agency from a government
  353. 12:38you aren't friendly to installs a
  354. 12:40surveillance payload on your iPhone. You
  355. 12:42don't even know this, you're just using
  356. 12:44your iPhone as normal, but the cameras
  357. 12:46on your iPhone are always on and
  358. 12:48streaming everything to the to the
  359. 12:49government. Your microphone's always on,
  360. 12:52your location's always tracked. And now
  361. 12:54all of a sudden
  362. 12:56you're just you're just
  363. 12:57you're you're just
  364. 12:59your device is spying on you for someone
  365. 13:01that you don't want to be spying on you.
  366. 13:04That's the thing that's scary. So, like
  367. 13:07um a lot of the the heated debates uh
  368. 13:10devolve down into like, "Well, Rust has
  369. 13:13unwrap."
  370. 13:15Actually, the fact that Rust has unwrap
  371. 13:16is not a problem at all. Unwrap is
  372. 13:18great. Uh if you unwrap something and
  373. 13:21it's uh there's no value in there, it
  374. 13:22crashes. Uh that is a memory safe
  375. 13:25outcome.
  376. 13:26Uh
  377. 13:27so, that's great. Uh, no problem with
  378. 13:29Rust having unwrap. Uh, the problem in
  379. 13:32Rust is not that it has unwrap, it's
  380. 13:34that it has unsafe. Uh, and if you use
  381. 13:37Rust unsafe, then all of a sudden you're
  382. 13:39in territory where there's neither
  383. 13:40runtime nor compile time checking that
  384. 13:43is adequate to prevent weird state.
  385. 13:47Okay.
  386. 13:47>> A pithy way to say it also would be that
  387. 13:49like a fully memory safe language is for
  388. 13:53the most part about ensuring that the
  389. 13:55only attack you have is like a denial of
  390. 13:58service attack.
  391. 14:00Right? So, it's like all of the types of
  392. 14:02things that used to be runaway exploits
  393. 14:04are now going to turn into denial of
  394. 14:06service attacks. Of course, these are
  395. 14:07only talking about non-logic bugs cuz if
  396. 14:11again, if you have something like a
  397. 14:12parsing bug and this thing is
  398. 14:15able to run stuff, then you can just
  399. 14:17have it run your, you know,
  400. 14:19the stuff that you're
  401. 14:21fooling it into parsing incorrectly. So,
  402. 14:22it's never going to get rid of that
  403. 14:24category, but all the other category of
  404. 14:26like accidental things that occur
  405. 14:28because you, you know, you didn't
  406. 14:29realize that you were going to go off
  407. 14:31the end of this array for writing or you
  408. 14:33were using something after you freed it
  409. 14:34or that stuff. All of those now will
  410. 14:36turn into at least at worst a denial of
  411. 14:39service attacks where the program
  412. 14:40crashes. So, that's not going away in
  413. 14:43these languages. You can the attacker if
  414. 14:45all the attacker wants to do is just
  415. 14:47stop you from executing at all,
  416. 14:49that's still well within their ability
  417. 14:51to do when they find one of these
  418. 14:53exploits. But usually people aren't as
  419. 14:55paranoid about that. As Philip was
  420. 14:57saying, it's like
  421. 14:59that's not the worst that, you know,
  422. 15:01they're worried about the thing where
  423. 15:02you can escalate, right? Uh, into
  424. 15:04actually taking control of things.
  425. 15:06Okay.
  426. 15:08So, now we're entering FilC, okay?
  427. 15:12Well, I'm assuming that with this intro,
  428. 15:14FilC is targeting memory safety, meaning
  429. 15:17weird execution, right? The the the
  430. 15:20category of the problems, not about the
  431. 15:22crashing of the program and like you run
  432. 15:24out of memory, but hey, we want to help
  433. 15:27you build programs that will be safe
  434. 15:30on using C and C++, you know, right? Can
  435. 15:34you do an overview of how FielC works
  436. 15:37and where it can be applied?
  437. 15:40Yeah. Um
  438. 15:43So, FielC uh
  439. 15:45So, I guess just to back up just to
  440. 15:48give give y'all a framing. FielC started
  441. 15:51as a project where I had this crazy idea
  442. 15:56and I was uh more than 50% sure that the
  443. 16:00idea was so crazy that it couldn't
  444. 16:02possibly work and I just was like I had
  445. 16:04to try it to to prove myself wrong to
  446. 16:06see that it wouldn't work.
  447. 16:08So, it's like
  448. 16:10I I I'm still kind of amazed that it
  449. 16:13works at all. It's one of those things
  450. 16:14that works just barely. Um
  451. 16:19And the idea is
  452. 16:21uh what if
  453. 16:23uh
  454. 16:24the thing about C and C++ that's not
  455. 16:26memory safe isn't the language but just
  456. 16:30the way we implement it.
  457. 16:32Um the set of choices that C compiler
  458. 16:35writers have made over the years when
  459. 16:38making C what it is.
  460. 16:41And so, what FielC does is
  461. 16:44uh just
  462. 16:46it takes the language that you know
  463. 16:49um
  464. 16:50and creates an implementation that is
  465. 16:52that behaves as if it was that language,
  466. 16:55but with all the rules changed
  467. 16:57underneath the hood. So, rather than a
  468. 16:59pointer being an integer that tells you
  469. 17:02where in memory you want to write read
  470. 17:03and write stuff, a pointer is
  471. 17:07really a capability to a range of memory
  472. 17:09and there's some tracking to see, okay,
  473. 17:12which range of memory does this pointer
  474. 17:14get to access?
  475. 17:16The pointer still has what I call the
  476. 17:18int val, the integer component of it. Uh
  477. 17:20you get to see that, play with it, make
  478. 17:22its value be whatever you want. But if
  479. 17:24the int val ends up out of range of the
  480. 17:26capability,
  481. 17:28then you have a pointer that's in a
  482. 17:29state where if you try to load or store
  483. 17:31to it, it'll it'll panic immediately
  484. 17:33upon load or store.
  485. 17:36Additionally,
  486. 17:37>> worth mentioning there that like
  487. 17:38capability is sort of a term typically
  488. 17:41used in this space to refer to that
  489. 17:43idea.
  490. 17:44That instead of just locations in
  491. 17:45memory, capability means a memory range
  492. 17:49and what are you allowed to do to it.
  493. 17:52Exactly. Just to unpack that, sorry. I'm
  494. 17:54just jumping in for I'm trying to jump
  495. 17:55in for beginners, basically. That's a
  496. 17:57really great point because I'm not the
  497. 17:59first one to use capabilities. Um
  498. 18:01the uh
  499. 18:03if if you if you have an FPGA
  500. 18:06uh and know what you're doing, you can
  501. 18:08download uh Cherry and put it on the
  502. 18:11FPGA. Cherry is a CPU architecture that
  503. 18:14has capabilities at the hardware level
  504. 18:16instead of pointers.
  505. 18:18Um and then like there's some amount of
  506. 18:20C programs you can run on Cherry. Um uh
  507. 18:23there's other capability architectures
  508. 18:25out there. There's a Russian thing
  509. 18:27called Elbrus.
  510. 18:28Uh and I think some IBM mainframes also
  511. 18:30have capabilities. So, capabilities are
  512. 18:32actually common in the hardware space.
  513. 18:36Okay. Where FillC uh differs from those
  514. 18:39is that it's it's all software. So, you
  515. 18:41can run it on your Intel box.
  516. 18:44But then FillC goes uh
  517. 18:47a couple of steps further than I think
  518. 18:48others have gone.
  519. 18:50Uh and it goes a couple of steps further
  520. 18:52because I'm going I'm really aiming for
  521. 18:55like the kind of comprehensive memory
  522. 18:57safety that I would expect to get from a
  523. 19:00Java virtual machine or a JavaScript
  524. 19:02implementation. Where there's I call it
  525. 19:04gimso, uh garbage in, memory safety out.
  526. 19:08There's no sequence of bytes you can
  527. 19:10give to the compiler that will result in
  528. 19:12the compiler producing a binary that
  529. 19:14then violates the memory safety rules.
  530. 19:17So, how do I do that? The next thing
  531. 19:19that I have to do is worry about use
  532. 19:20after free.
  533. 19:22So, the way that use after free is
  534. 19:23handled is you can't write your own
  535. 19:25malloc and free anymore. You can call
  536. 19:27malloc and free,
  537. 19:28but malloc is a garbage collection
  538. 19:30allocation,
  539. 19:32and free just tells the garbage
  540. 19:34collector um this object is henceforth
  541. 19:37dead.
  542. 19:38Uh but it so it which causes the
  543. 19:41capability to become disabled in place.
  544. 19:44>> [snorts]
  545. 19:44>> All subsequent accesses to that object
  546. 19:47will fail.
  547. 19:48Um and the garbage collector knows that
  548. 19:51the next time that it runs, it can
  549. 19:54replace all pointers to that dead
  550. 19:56capability with pointers to a dead
  551. 19:58singleton. So, that freeing an object
  552. 20:00does free it just with a delay. You have
  553. 20:03to wait until the next time the GC runs.
  554. 20:06Um
  555. 20:09and then on top of that, there's what do
  556. 20:11you do about
  557. 20:14representing pointers themselves?
  558. 20:15Because as I said in Fil-C, pointers are
  559. 20:18this integer value that you get to see
  560. 20:20that's what you would think of the
  561. 20:22pointer being if you're a C programmer.
  562. 20:24It's just an integer that tells you an
  563. 20:26address in memory. And then there's the
  564. 20:28capability. So, how do you
  565. 20:30carry that around? Um and the probably
  566. 20:33the
  567. 20:34the wackiest insight in Fil-C is what
  568. 20:38I'm calling invisible capabilities and
  569. 20:39visicaps, where
  570. 20:41if you store a pointer into memory,
  571. 20:45then within the address that's visible
  572. 20:48to you, the only thing that got stored
  573. 20:49is the pointer's integer value. So, if
  574. 20:52you store pointer to into memory and
  575. 20:54then uh read it back out as bytes or
  576. 20:57integers, you're going to see the
  577. 20:59pointer's integer value exactly the way
  578. 21:01you would in normal C.
  579. 21:03But every single object in memory has a
  580. 21:06hidden side location where I could store
  581. 21:09the capabilities that correspond to the
  582. 21:12pointers stored into that object.
  583. 21:14So, what this does is it gives you a
  584. 21:17programming model where the size of
  585. 21:19pointer, size of void star,
  586. 21:22>> [snorts]
  587. 21:22>> is the same as it would have been
  588. 21:24normally. So, if you're on a 64-bit
  589. 21:26system, size of void star is 8 bytes.
  590. 21:30And it means that you can do things like
  591. 21:33um
  592. 21:34uh type punning and unions. Uh you can
  593. 21:37even violate things that the spec says
  594. 21:40you can't do like uh according to the C
  595. 21:42spec, if you store a pointer into a
  596. 21:44union and then read it back as integers,
  597. 21:46then that's undefined behavior. In FilC,
  598. 21:48that's perfectly defined behavior. You
  599. 21:50store a pointer into a union, read it
  600. 21:51back as an integer, you're going to get
  601. 21:53the pointer's integer value.
  602. 21:54If you store an integer into the union
  603. 21:56and read it back as a pointer,
  604. 21:58you're going to get a pointer that has
  605. 21:59an integer value that is going to be
  606. 22:01most likely out of range of the
  607. 22:03capability. And if if it is in range of
  608. 22:04the capability, then no problem. That's
  609. 22:06a capability you're
  610. 22:08allowed to be accessing cuz it's a
  611. 22:10capability you already had.
  612. 22:12Um so, FilC
  613. 22:15uh is
  614. 22:19the remarkable thing about it is that I
  615. 22:21I think it achieves exactly what memory
  616. 22:23safety is according to that definition
  617. 22:25that we gave earlier.
  618. 22:28Um while giving you
  619. 22:31such a level of compatibility with C and
  620. 22:33C++,
  621. 22:35that you can like boot Linux or you
  622. 22:38Well, kernel doesn't work like that, but
  623. 22:40you can boot the Linux userland with it.
  624. 22:42Um and like Emacs works, Python works,
  625. 22:45Ruby works, Ninja, make, CMake, all of
  626. 22:48it just work. These are C++ programs
  627. 22:51that were never written with the
  628. 22:52intention to be compiled with a
  629. 22:54memory-safe compiler. Or they were not
  630. 22:56written with the thinking that C was a
  631. 22:58memory-safe language. But all of the
  632. 23:01stuff that they do, even the crazy stuff
  633. 23:03that they do, just works in Filigree.
  634. 23:06And from the user point of view,
  635. 23:10how Filigree works, right? Like you,
  636. 23:12because if you go to Filigree website,
  637. 23:14you have a download button, you need to
  638. 23:16download a compiler, and then like what
  639. 23:19would happen if I were to use Filigree?
  640. 23:21Like how would the steps look like?
  641. 23:25Yeah, this is a
  642. 23:28This is a good question.
  643. 23:30One of the the caveats with Filigree is
  644. 23:32that it is not binary compatible with
  645. 23:36normal C. That is,
  646. 23:38you can't compile a shared library with
  647. 23:41normal C,
  648. 23:42and then have your Filigree program link
  649. 23:43to it or vice versa.
  650. 23:46So, there are three currently three ways
  651. 23:48that I distribute Filigree. One is just
  652. 23:51like a little local environment. Uh you
  653. 23:53download a relatively small tarball, you
  654. 23:55get a compiler and a lib C and a lib
  655. 23:57C++.
  656. 23:59Um and you just install it in some local
  657. 24:01directory on your Linux box. Uh and then
  658. 24:04you can you can write C C++ programs and
  659. 24:07compile it. With that, uh the library
  660. 24:10the C library that you get is a is uh
  661. 24:12muscle.
  662. 24:13So, you get kind of some of the
  663. 24:15limitations that you would get if you
  664. 24:17were using muscle as your lib C. The lib
  665. 24:19C++ is just the LLVM lib C++, so it's a
  666. 24:22full-featured
  667. 24:24lib C++.
  668. 24:25And the compiler is a surgically
  669. 24:28modified clang uh 20.1.8. So, you get
  670. 24:31all of the modern C C++ features, uh
  671. 24:35including clang and GCC extensions.
  672. 24:38Um a lot of people use that distribution
  673. 24:40cuz it's very easy to install, small
  674. 24:42tarball, uh don't have to be root to
  675. 24:44install it.
  676. 24:47Second version of it that you can
  677. 24:49install, which is sort of my preferred
  678. 24:50way to do it,
  679. 24:52um [clears throat]
  680. 24:54is the opt Filigree distribution. So,
  681. 24:56this you install as root and it installs
  682. 24:59a fill C slice, as I call it, in
  683. 25:02/opt/fill.
  684. 25:04And then, it comes with uh a whole bunch
  685. 25:07of libraries in addition to just the lib
  686. 25:09C.
  687. 25:10And rather than using muscle as the lib
  688. 25:12C, it uses glibc 2.40. Uh so, it's a
  689. 25:15very
  690. 25:17modern and rich uh lib C with all of the
  691. 25:20features you would expect uh when
  692. 25:22programming on Linux.
  693. 25:24Um and then, it comes the opt fill slice
  694. 25:27comes with a huge number of libraries,
  695. 25:29OpenSSL, PAM,
  696. 25:31um
  697. 25:32bunch of uh bunch of compression
  698. 25:35libraries,
  699. 25:37libreadline, uh just lots of stuff that
  700. 25:40you would expect if you're writing C C
  701. 25:42programs on Linux. So, with the opt fill
  702. 25:44distribution, you can use that as a
  703. 25:46foundation to build kind of larger
  704. 25:48software because you you get a lot of
  705. 25:51shared libraries um that you would that
  706. 25:54you would expect to have available to
  707. 25:56you if you're writing a C program on
  708. 25:58Linux or a C++ program on Linux. That's
  709. 26:00they were precompiled with fill C, so
  710. 26:01they will work if you link to them.
  711. 26:04Okay. Yeah. Um
  712. 26:06and then, the the the version that I've
  713. 26:09been experimenting with the most
  714. 26:11recently is uh I I need a better name
  715. 26:14for this. I call it Pizlex. It's a Linux
  716. 26:17distribution uh compiled with fill C. Um
  717. 26:22uh
  718. 26:24and uh so, you so so it's it's beyond
  719. 26:27Linux from scratch 12.2 um compiled with
  720. 26:31the whole userland compiled with fill C.
  721. 26:33Um so, you can boot to a graphical user
  722. 26:36interface.
  723. 26:38Um
  724. 26:39you know, there's an SSHD man that's
  725. 26:40compiled with fill C. There's
  726. 26:43uh Ruby, Python, Pearl,
  727. 26:47make, C make, Ninja,
  728. 26:49um
  729. 26:51uh and and I'm now getting a web browser
  730. 26:55to work in it. It's rough rough going,
  731. 26:58but it's getting there.
  732. 26:59What's the name of the browser?
  733. 27:01Oh, it's just
  734. 27:03Yeah,
  735. 27:04you'd expect a goofy name, right? But
  736. 27:05no, it's uh it's uh it's just WebKit.
  737. 27:09Um so WebKit, which is the browser
  738. 27:12engine that Safari uses,
  739. 27:14um comes with a thing called the mini
  740. 27:17browser, which is just a mini just just
  741. 27:19a minimalist browser.
  742. 27:21Um and so right now I'm just
  743. 27:23running the mini browser. Actually last
  744. 27:26night I was able to post on Twitter or
  745. 27:29x.com for the first time from from the
  746. 27:32memory safe mini browser.
  747. 27:34Okay.
  748. 27:35Okay, so there are three
  749. 27:37Yes. I would say there's there's a
  750. 27:38couple things to that probably want to
  751. 27:40be underscored there. Again, just you
  752. 27:42know, that's sort of hidden in the
  753. 27:44explanation, but that are important to
  754. 27:46beginners, I would say, right?
  755. 27:49Um and that is that A,
  756. 27:52a lot of memory safe things in the world
  757. 27:55that are labeled as such,
  758. 27:58omit the fact that they are running on
  759. 28:00top of things that are not memory safe.
  760. 28:02So, for example, if you compile a
  761. 28:04program
  762. 28:05uh or you use a virtual machine that is,
  763. 28:09you know, for a memory safe language,
  764. 28:11if it's sitting on top of a bunch of
  765. 28:12libraries that themselves are not memory
  766. 28:14safe, then it's not really a completely
  767. 28:18memory safe thing, right? So, when
  768. 28:22you're talking about PhilC and you're
  769. 28:23talking about having this nice ability
  770. 28:25to go because it's you know, it it can
  771. 28:28compile C, which is the thing that most
  772. 28:29of these underlying parts are written
  773. 28:31in,
  774. 28:32being able to recompile those and have
  775. 28:34the entire stack be PhilC
  776. 28:38is actually a very important difference
  777. 28:41between PhilC and a lot of things which
  778. 28:43are literally just providing memory
  779. 28:45safety at a very very top layer of a
  780. 28:48stack. This is one of the reasons that
  781. 28:50PhilC is so interesting in my opinion,
  782. 28:52right? Is because of that ability to now
  783. 28:56start to recompile underlying pieces of
  784. 28:58technology, you're no longer talking
  785. 29:01about just memory safing the very last
  786. 29:04little bit. So, that's thing one.
  787. 29:07Um and thing two is that if you think
  788. 29:11about how
  789. 29:13uh
  790. 29:14I guess I'm not sure how to describe
  791. 29:15this, but if you think about how memory
  792. 29:18safety is approached or or
  793. 29:23philosophically
  794. 29:25the proponents of memory safety
  795. 29:27how they tend to have to sell it to you,
  796. 29:30it's always about you have to come and
  797. 29:33completely redo whatever you were doing
  798. 29:36in order to get it, right? If you
  799. 29:38previously were writing in an in a
  800. 29:39memory unsafe language, then the only
  801. 29:42way that you're going to get memory
  802. 29:43safety is we rewrote the entire thing in
  803. 29:45Rust and anything else that we cared
  804. 29:47about that it depends on in Rust and so
  805. 29:49on, right? Or port the whole thing to
  806. 29:52Java or whatever it is that you want to
  807. 29:53talk about, that's what had previously
  808. 29:56been the sales pitch.
  809. 29:58And one of the reasons it's not super
  810. 29:59compelling is a lot of times, if you
  811. 30:02look at these languages, you don't
  812. 30:03necessarily love the language for any
  813. 30:05particular reason. Like you look at it's
  814. 30:06like, well, I'm not getting very much if
  815. 30:09I rewrite my whole thing in this other
  816. 30:10language. Like I maybe don't see a lot
  817. 30:12of benefit to that language.
  818. 30:13And so now I'm having to take this hit
  819. 30:15of rewriting this whole thing in this in
  820. 30:17this new language for very little
  821. 30:19benefit other than the fact that I
  822. 30:21really wanted this memory safety, which
  823. 30:23could have been a very important feature
  824. 30:26for the, you know, particular domain
  825. 30:28that you were working in, especially if
  826. 30:29it's security critical, right?
  827. 30:32And so another aspect of PhilC there is
  828. 30:34it's a very different sales pitch
  829. 30:36because of exactly what was just
  830. 30:38described. You basically just get a C
  831. 30:40compiler and really all you're looking
  832. 30:43at is you will compile your program
  833. 30:46that you already had without rewriting
  834. 30:47it at all, and then the compiler will
  835. 30:49tell you the places where you might need
  836. 30:51to make changes because you're doing
  837. 30:53something that inherently can't be made
  838. 30:55memory safe or something like that. We
  839. 30:57could I'm sure we'll talk about that in
  840. 30:58in a minute, like the reason why you
  841. 30:59can't just recompile everything and have
  842. 31:01it work. But, it's pretty close to that.
  843. 31:03Like, you don't have to do huge
  844. 31:04modifications as evidenced by the fact
  845. 31:07that Philip Scott so much stuff running
  846. 31:09already and he's one person, and and
  847. 31:11very little had to change to have that
  848. 31:13happen, right? So, so I think those are
  849. 31:15two really important aspects. All Again,
  850. 31:16all contained in in everything that was
  851. 31:19just said, but I just wanted to unpack
  852. 31:20those cuz they're they're pretty
  853. 31:21impressive and and actually very
  854. 31:23interesting. Uh it's one of the reasons
  855. 31:25PhilC is not just like yet another
  856. 31:27memory safe thing, right?
  857. 31:28So.
  858. 31:30Yeah, there's one other
  859. 31:32uh
  860. 31:33curious property of PhilC
  861. 31:35um to
  862. 31:37to add to that, which is that with, for
  863. 31:39example, Rust and Go,
  864. 31:42the same technologies that grant those
  865. 31:45languages memory safety
  866. 31:48also take away from those languages the
  867. 31:50ability to dynamically link with
  868. 31:52themselves.
  869. 31:54So, like, if you write a dynamically
  870. 31:55dynamic library in in Rust,
  871. 31:58your options are that either the dynamic
  872. 32:01library exposes itself as if it was a C
  873. 32:04library with a C interface that's
  874. 32:06completely unsafe. So, you'll have Rust
  875. 32:08code using unsafe statements to call
  876. 32:10into other Rust code just to get across
  877. 32:12the dynamic linking boundary.
  878. 32:14Or, you have to buy into the undefined
  879. 32:17behavior in Rust of what happens if
  880. 32:20uh
  881. 32:21you ship a dynamic library and I use it,
  882. 32:23and then you breathe on the code and
  883. 32:25recompile the library. At that point, if
  884. 32:27the if the interface layer between those
  885. 32:31between me and you was a Rust API that
  886. 32:34was safe, the moment you recompile your
  887. 32:36side, um and we're still dynamically
  888. 32:39linking, all bets are off.
  889. 32:42But in PhilC, you actually get
  890. 32:45ahead-of-time compilation, so you can
  891. 32:47ship binaries,
  892. 32:49and you get memory safety across the
  893. 32:51dynamic link boundary.
  894. 32:54So if you think about what does it look
  895. 32:56like to build
  896. 32:58like a large OS or an application that
  897. 33:01is large enough that it needs dynamic
  898. 33:03linking, and you want to build it in a
  899. 33:05memory-safe way, weirdly, PhilC might be
  900. 33:08the only game in town right now.
  901. 33:13About like alternatives, I think like
  902. 33:16ideally we'll talk about the at the end.
  903. 33:18I want to give like spotlight now to
  904. 33:20PhilC, and then like later on as we go
  905. 33:23through how PhilC works underneath, like
  906. 33:25we can sort of talk about the
  907. 33:27alternatives and and compare it. You
  908. 33:29mentioned
  909. 33:30Casey mentioned like interesting fact
  910. 33:32that like
  911. 33:33Philip, you like seems to be you seem to
  912. 33:36be every week posting like, "Hey, I got
  913. 33:38this program to be working in PhilC, and
  914. 33:40then this, and then this, and then
  915. 33:41this." And like this is your spare time.
  916. 33:44So how the process of getting this to
  917. 33:47compile in PhilC looks like,
  918. 33:50and also how is it like
  919. 33:54if something is unsafe, you get a crash
  920. 33:57or a panic
  921. 33:59either at the runtime or at the compile
  922. 34:01time. How does this look like for the
  923. 34:03process of like getting an existing
  924. 34:05piece of software and getting it into
  925. 34:07PhilC?
  926. 34:08Yeah, so
  927. 34:10uh for half of the programs that I've
  928. 34:13ported,
  929. 34:14I've just made no changes. I just like
  930. 34:18compile it with PhilC,
  931. 34:20then I use it, and it works, and
  932. 34:23[snorts]
  933. 34:24that's it.
  934. 34:25So half half of them are in that in that
  935. 34:27category.
  936. 34:28Of the remaining half uh that are not in
  937. 34:32that category,
  938. 34:35most uh
  939. 34:39most of the issues are that fil C
  940. 34:43uh mangles all of the symbols. Um
  941. 34:47all of the symbols get pre- prepended
  942. 34:49with pizzlinated underscore.
  943. 34:52Uh and so uh a huge number of
  944. 34:55open-source libraries out there have
  945. 34:57version scripts,
  946. 34:59um which is this feature in uh in in C
  947. 35:02where you can say
  948. 35:04here the the list of symbols that my
  949. 35:06library exports.
  950. 35:08And because fil C relies on just the
  951. 35:10normal linker,
  952. 35:12uh when those version scripts enumerate
  953. 35:14symbols without the mangling,
  954. 35:16um you end up getting link errors
  955. 35:18because then the linker can't find the
  956. 35:20symbols cuz the symbols actually have
  957. 35:22the pizzlinated [music] thing prepended
  958. 35:23to them.
  959. 35:24Uh and there's there's a simple hack you
  960. 35:26can do to fix that. You have to change
  961. 35:28uh the way that version scripts are
  962. 35:30passed to the compiler so that they get
  963. 35:32mangled automatically for you. So, of
  964. 35:35the half of the programs where I made
  965. 35:36changes,
  966. 35:38probably like 3/4 of those are just
  967. 35:41changes to either the configure script
  968. 35:44or the meson file or the C make file or
  969. 35:47whatever to to to change how the version
  970. 35:50scripts work.
  971. 35:51Um so like most of the changes are when
  972. 35:55I have a project that I had to make
  973. 35:56changes to, it's that.
  974. 35:58And then it just works.
  975. 36:00And then there's the small minority of
  976. 36:01programs that do
  977. 36:04uh either
  978. 36:06um
  979. 36:07uh inline assembly.
  980. 36:09Um the way that
  981. 36:12current So,
  982. 36:13I I come from implementing JavaScript
  983. 36:15VMs. So, the question about what's
  984. 36:17caught at compile time, the answer is
  985. 36:18basically nothing. Um it you get the
  986. 36:21error [clears throat] at runtime. So, if
  987. 36:22you have some inline assembly and the
  988. 36:24inline assembly executes, you get a
  989. 36:26panic saying executing inline assembly
  990. 36:28that I couldn't prove safe.
  991. 36:30Uh the compiler already can prove
  992. 36:33trivial inline assembly safe in some
  993. 36:35cases. So, there's some inline assembly
  994. 36:37that just works.
  995. 36:38Um but if it if you if it executes some
  996. 36:41inline assembly if you try to execute
  997. 36:42some inline assembly that the compiler
  998. 36:45couldn't prove safe, you get a panic.
  999. 36:47Um
  1000. 36:49and that's a common thing is then you go
  1001. 36:52and figure out exactly
  1002. 36:54what configure script option or
  1003. 36:57uh macro or whatever has to be flipped
  1004. 36:59to turn off the the usage of inline
  1005. 37:02assembly in that project. So, uh that's
  1006. 37:04pretty common. Uh and in many cases,
  1007. 37:06it's not like just that you disable the
  1008. 37:09use of inline assembly, but in a lot of
  1009. 37:11cases, the inline assembly on a modern
  1010. 37:13compiler could have been an intrinsic.
  1011. 37:15So, that's common replace the inline
  1012. 37:16assembly with an intrinsic.
  1013. 37:19Um
  1014. 37:21and then the final category is uh
  1015. 37:24programs that use
  1016. 37:26integers to carry pointers around.
  1017. 37:30Um
  1018. 37:31a great example of that is GLib. So,
  1019. 37:35GLib is the runtime library that
  1020. 37:38underpins uh
  1021. 37:39Gnome. So, GTK, GDK, GStreamer, all of
  1022. 37:44these things are living on top of GLib.
  1023. 37:46GLib has its own object model. It's kind
  1024. 37:48of it's kind of awesome. Uh if you ever
  1025. 37:51ever have a chance to read it, it's a
  1026. 37:54really quite fascinating piece of code.
  1027. 37:57Um and as part of this object model,
  1028. 37:59there's this thing called GType.
  1029. 38:02And GType is type deft by default in
  1030. 38:05GLib to be a an integer, but uh provided
  1031. 38:09that some bits in the integer are set or
  1032. 38:11whatever, it's actually a a pointer. And
  1033. 38:13so, there's places in GLib where it
  1034. 38:15casts the integer to a pointer and then
  1035. 38:17dereferences it.
  1036. 38:18In PhilC, if you load or store an
  1037. 38:21integer, then you're just loading and
  1038. 38:24storing the integer. There's no
  1039. 38:25capability.
  1040. 38:26So then when you cast that integer to a
  1041. 38:28pointer, you get a pointer that has a
  1042. 38:30null capability. And if you try to
  1043. 38:31access that pointer, you get a panic
  1044. 38:34saying at runtime saying the capability
  1045. 38:36is null.
  1046. 38:37So
  1047. 38:38um
  1048. 38:39for for GLib, that meant that I had to
  1049. 38:41change the type def of GType to be a
  1050. 38:44pointer type so that when you're passing
  1051. 38:46the GType around, you're passing around
  1052. 38:49a pointer.
  1053. 38:50Uh and then I actually had to go and
  1054. 38:52change quite a few compiler errors that
  1055. 38:54happened as a result of
  1056. 38:56uh there's just code all over GLib and
  1057. 39:00things that use GLib that just just
  1058. 39:02assume that GType is an integer and that
  1059. 39:03you can do integer-y things with it. For
  1060. 39:05example, in C you can switch on an
  1061. 39:07integer, but you cannot switch on a
  1062. 39:10pointer.
  1063. 39:11So uh
  1064. 39:13things like that had to had to change.
  1065. 39:16And so in GLib um and projects that rely
  1066. 39:19on GLib, you'll find um
  1067. 39:23uh
  1068. 39:24hundreds of lines or thousands of lines
  1069. 39:26of code that had to had to be changed,
  1070. 39:28but it's really mechanical changes. It's
  1071. 39:30like you run the compiler, you get 100
  1072. 39:33compiler errors. They're all this
  1073. 39:34pattern, either a switch statement over
  1074. 39:36GType or uh performing bitwise
  1075. 39:39arithmetic on the GType. And then you
  1076. 39:41just change that code to do something a
  1077. 39:42little different and and it's fine.
  1078. 39:45So
  1079. 39:46uh
  1080. 39:47that's an example where where things get
  1081. 39:49more involved, but that's rare. Like
  1082. 39:51that was I hit that problem in
  1083. 39:54in GLib and its uh downstream
  1084. 39:57dependencies.
  1085. 39:59Uh I hit that problem in Ruby.
  1086. 40:02So I had to make a huge number of
  1087. 40:03changes in the Ruby VM because the Ruby
  1088. 40:05VM has a value type that just like GType
  1089. 40:09is is was type def'd to integer and it
  1090. 40:12can encode a pointer.
  1091. 40:14Um
  1092. 40:17Um but but most most programs just don't
  1093. 40:20do this. Or if they do it, they do it in
  1094. 40:21such a localized place that it's a
  1095. 40:23one-line change rather than hundreds of
  1096. 40:24lines.
  1097. 40:26Oh, and I guess the other the other
  1098. 40:27thing is what to do if the program has
  1099. 40:30um custom allocators or or uh
  1100. 40:35or its own garbage collector.
  1101. 40:37Um
  1102. 40:38Custom allocators are surprisingly rare
  1103. 40:40in modern software.
  1104. 40:42Um I was expecting to find more of them.
  1105. 40:45Um but they they are really surprisingly
  1106. 40:47rare.
  1107. 40:48Uh
  1108. 40:48we ended up writing patch to the GNU
  1109. 40:51obstack, which is this uh
  1110. 40:54arena allocator that's widespread in GNU
  1111. 40:56software.
  1112. 40:57Um so the obstack now is no longer an
  1113. 41:00arena. It's allocating objects at a
  1114. 41:02time.
  1115. 41:03So you don't get the memory safety
  1116. 41:05hazard that if you have an arena in
  1117. 41:08FilC, the whole arena is one capability.
  1118. 41:10So you can go out of bounds of one
  1119. 41:11object and into another. That probably
  1120. 41:13allows uh more weird state
  1121. 41:16possibilities than I'm comfortable with.
  1122. 41:18So now
  1123. 41:20obstack is no longer really an arena.
  1124. 41:22It's allocating objects at a time.
  1125. 41:24Uh and then if there's a garbage
  1126. 41:26collector, then it depends on what the
  1127. 41:28garbage collector is. For example, the
  1128. 41:29Python garbage collector, I just kept
  1129. 41:32it. So if you're running Python in FilC,
  1130. 41:35you get a garbage collector in a garbage
  1131. 41:37collector. Um
  1132. 41:38just cuz that
  1133. 41:41And that works because Python's garbage
  1134. 41:42collector allocates objects using
  1135. 41:44malloc.
  1136. 41:45Um
  1137. 41:46That was Of course it does.
  1138. 41:48It's whatever, you know.
  1139. 41:50Um but then uh
  1140. 41:52Ruby and uh
  1141. 41:54uh
  1142. 41:55uh Ruby and Emacs
  1143. 41:58um
  1144. 41:59uh
  1145. 41:59both had root Well, Ruby, Emacs, and
  1146. 42:02JavaScript Core
  1147. 42:03all have very sophisticated garbage
  1148. 42:06collectors. By the way, I love the Emacs
  1149. 42:09garbage collector. I've I've an Emacs
  1150. 42:10user for so long, and I never actually
  1151. 42:12had a reason to look at the C code of
  1152. 42:14Emacs. And lo and behold, Emacs is this
  1153. 42:17like beautiful Lisp virtual machine
  1154. 42:21with this awesome garbage collector.
  1155. 42:23It's got all these cool features,
  1156. 42:25finalizers and weak references. Um
  1157. 42:28really great stuff, but of course it's
  1158. 42:30allocating these like uh
  1159. 42:33large regions that it then chops up into
  1160. 42:35objects. Um
  1161. 42:36uh and uh and it does conservative stack
  1162. 42:39scanning, so it does things like uh
  1163. 42:42calls
  1164. 42:44I hope I'm not messing this up cuz it's
  1165. 42:46a while ago that I ported it, but I
  1166. 42:47think it does the thing where it calls
  1167. 42:49setjmp to get the register file,
  1168. 42:52and then from there scans the stack
  1169. 42:55looking for anything that might look
  1170. 42:56like a pointer. So, that's totally
  1171. 42:58illegal in Fil C. You can't do that in
  1172. 43:00Fil C. I wouldn't let you.
  1173. 43:02So, there for those programs, Emacs,
  1174. 43:04Ruby, and JavaScript Core, I just ripped
  1175. 43:07the GC out
  1176. 43:09Okay. and replaced all of the entry
  1177. 43:11points into the garbage collector with
  1178. 43:12just calls to malloc.
  1179. 43:14Um and just rely on the fact that in Fil
  1180. 43:16C, if you call malloc and never call
  1181. 43:17free, you're garbage collected.
  1182. 43:19Um
  1183. 43:21uh and then in in some cases, you have
  1184. 43:23to go a little bit further, like in
  1185. 43:25Ruby,
  1186. 43:26uh objects have finalizers,
  1187. 43:29and the finalizers are necessary for
  1188. 43:32semantics.
  1189. 43:33You actually can't successfully run a
  1190. 43:36Ruby program
  1191. 43:37if you don't support the finalizers. So,
  1192. 43:40the So, Fil C has a special additional
  1193. 43:43API uh stoodfil.h
  1194. 43:46that you can include. And in there,
  1195. 43:48there's additional APIs you can call
  1196. 43:50where you actually can do things like uh
  1197. 43:53allocate weak references and allocate
  1198. 43:56objects that have finalizers.
  1199. 43:58Um and so, the the Ruby uh
  1200. 44:01the the Ruby port does the thing where
  1201. 44:03every Ruby object is a finalizable Fil C
  1202. 44:06object. Um so that the Ruby finalizer
  1203. 44:09semantics are are are still are still
  1204. 44:12there.
  1205. 44:14Um
  1206. 44:15yeah, that's what it looks like to port
  1207. 44:17these programs.
  1208. 44:18I trying to remember things to unpack
  1209. 44:21there. So, one thing to unpack is
  1210. 44:25the reason that arenas are being
  1211. 44:28mentioned here, right? Is because the
  1212. 44:32entire premise of memory safety is that
  1213. 44:35you have some underlying policeman,
  1214. 44:38right? Who you are articulating your
  1215. 44:42expected
  1216. 44:44memory capabilities to this policeman,
  1217. 44:47and then they are watching you, right?
  1218. 44:49To make sure that you don't disobey
  1219. 44:51them. So,
  1220. 44:52when I allocate a specific thing like
  1221. 44:55I'm allocating this memory that I'm
  1222. 44:57going to store this particular
  1223. 44:58information for a network socket, right?
  1224. 45:02You are telling the policeman, which in
  1225. 45:04this case is is fill C, right? You're
  1226. 45:06telling the policeman like anyone with
  1227. 45:09this pointer that comes back from that
  1228. 45:11allocation is only allowed to talk about
  1229. 45:14that exact single chunk of memory, just
  1230. 45:17that one socket. And then the
  1231. 45:19policeman's like, great, I'll watch that
  1232. 45:20for you, and if you ever try to use that
  1233. 45:22pointer to talk about anything else, I
  1234. 45:24will stop you right there, right? You're
  1235. 45:26going to fill jail.
  1236. 45:28The
  1237. 45:29And so what happens is if you look at an
  1238. 45:31existing program, and that existing
  1239. 45:33program was trying to do something
  1240. 45:35efficient, so it allocates something
  1241. 45:36like an arena,
  1242. 45:39and more importantly than arena, arena
  1243. 45:41just, you know, I mean, generally just
  1244. 45:42means we're going to free everything at
  1245. 45:43once, but let's say something more like
  1246. 45:45a stack allocator. I allocate a bunch of
  1247. 45:46memory, and then I'm just going to like
  1248. 45:48bump an integer to tell me like where I
  1249. 45:49am in it, and hand those out cuz I'm
  1250. 45:51going to allocate lots of sockets, like
  1251. 45:54lots of storage for socket information
  1252. 45:55or something like that.
  1253. 45:57Then the problem is the part of your
  1254. 45:59program that's talking to the policeman
  1255. 46:02is just the part that allocates the big
  1256. 46:04block for all that, you know, hundreds
  1257. 46:07of sockets that you might be talking
  1258. 46:09about later. It's going to allocate that
  1259. 46:10giant block, and then it's individually
  1260. 46:13handing those out, right, to parts of
  1261. 46:15the program.
  1262. 46:17And so, the policeman has never been
  1263. 46:19told that you're parcelling this out
  1264. 46:22into separate pieces, and that you
  1265. 46:24actually also would like that policeman
  1266. 46:27to check to make sure that anyone handed
  1267. 46:29one of those little pieces cannot talk
  1268. 46:32about some other of the little pieces,
  1269. 46:34right? So, the point about the arena
  1270. 46:37thing, it's not really about
  1271. 46:38compatibility. I mean, you can correct
  1272. 46:40me if I'm wrong, Phil, but I believe if
  1273. 46:41you compile an arena program with PhilC,
  1274. 46:43it will just work.
  1275. 46:44The only reason you have to take these
  1276. 46:46extra steps to like articulate further
  1277. 46:49to PhilC, oh, actually I was talking
  1278. 46:52about lots of little individual things
  1279. 46:53there, is because you want the extra
  1280. 46:56benefits of more granular memory safety
  1281. 47:00than you were getting, right? So, you
  1282. 47:02would still never get the case where
  1283. 47:03somebody who's talking about objects in
  1284. 47:06one arena can talk about objects in
  1285. 47:08another arena because PhilC will be
  1286. 47:10properly preventing that automatically,
  1287. 47:12even without any modification. It's but
  1288. 47:14when you want things inside an arena to
  1289. 47:16themselves be policed so that nobody
  1290. 47:19with a pointer to one thing in arena can
  1291. 47:21talk about a pointer to another thing in
  1292. 47:22the arena, right, by just jumping
  1293. 47:24forward a little bit or backwards a
  1294. 47:25little bit. That's where you then have
  1295. 47:27to
  1296. 47:28make the modification. And again, all
  1297. 47:30you're really doing that for
  1298. 47:32is just to tell PhilC, hey, these are
  1299. 47:35the capabilities I was caring about. And
  1300. 47:39it's it's the easy way to do that is
  1301. 47:42just by saying, well, we all understand
  1302. 47:44like malloc and free, so that's what
  1303. 47:46we're going to use. But really the
  1304. 47:48important part of it conceptually is
  1305. 47:51this idea that somebody at some point
  1306. 47:53needs to articulate to the police, here
  1307. 47:56are the ranges, right? And Malicious
  1308. 47:59Freeze basically doing that for you. So,
  1309. 48:01I just wanted to unpack that for people
  1310. 48:03who, again, I'm just trying to think
  1311. 48:04about things that people who've never
  1312. 48:06thought about memory safety and they're
  1313. 48:07this is their first introduction to it,
  1314. 48:09right? What are the things that they
  1315. 48:10might be like, wait, what? Why do I have
  1316. 48:12to I don't understand. It doesn't work
  1317. 48:13with arenas. No, it works with arenas
  1318. 48:14just fine, but if you want additional
  1319. 48:17memory safety for individual objects in
  1320. 48:18it, that's where you're, you know,
  1321. 48:20looking at that.
  1322. 48:21Um
  1323. 48:22the other thing that I thought might
  1324. 48:24maybe need to be unpacked there uh was
  1325. 48:27just that so
  1326. 48:29uh when
  1327. 48:31when you're looking at at doing
  1328. 48:33um
  1329. 48:34just trying to I'm just trying to think
  1330. 48:35of how to say this. So, when you're
  1331. 48:37talking about doing like um
  1332. 48:39memory safety on on on something like
  1333. 48:41this,
  1334. 48:43the the part about the capabilities is
  1335. 48:46something that has to be tracked
  1336. 48:49forever, right? And this is why all of
  1337. 48:52this dynamic linking and stuff like that
  1338. 48:54comes into play.
  1339. 48:56When you talk about a particular
  1340. 48:58capability, because there is no standard
  1341. 49:02for articulating that anywhere. Like no
  1342. 49:05one has ever defined When we talk about
  1343. 49:08dynamic linking, someone has defined a
  1344. 49:10standard that's like the standard of how
  1345. 49:12these two things come together is we
  1346. 49:15just pass bits that are labeled in some
  1347. 49:18specific way. That labeling never had
  1348. 49:22capabilities.
  1349. 49:23So, the reason that you end up in this
  1350. 49:26situation where you have to start
  1351. 49:28thinking about what happens at the edges
  1352. 49:29of programs is because no one, you know,
  1353. 49:32memory safety is too new effectively.
  1354. 49:34All of the existing standards, ABIs,
  1355. 49:37application binary interfaces, all the
  1356. 49:38things you're used to, none of those had
  1357. 49:41memory safety in mind. And so, this is
  1358. 49:44something that I think we should
  1359. 49:45probably talk about um
  1360. 49:47whenever you think it fits best, but uh
  1361. 49:50feel free kind of has some really
  1362. 49:52I it ways that it works is actually
  1363. 49:55pretty interesting here about how it
  1364. 49:56works around that fact to still get
  1365. 49:58memory safety across the boundary and
  1366. 50:00that's that's a really cool thing
  1367. 50:03about doing these compiles on the full
  1368. 50:05stack like this. But anyway, so just try
  1369. 50:07to remember they probably missed some
  1370. 50:08things in there but I'm just trying to
  1371. 50:09unpack things for people who want more
  1372. 50:11detail, right?
  1373. 50:12Yeah, and you're you're exactly right
  1374. 50:14about arenas. It's they work too well in
  1375. 50:16Fill C. So
  1376. 50:19that's like that's legitimately one of
  1377. 50:21the downsides of the Fill C approach is
  1378. 50:23imagine you have a ginormous code base
  1379. 50:26and you don't have the time to look at
  1380. 50:28all of it. Lo and behold there's arenas
  1381. 50:30everywhere.
  1382. 50:31Um you'll compile it with Fill C it
  1383. 50:33it'll work and you'll probably be be
  1384. 50:35vulnerable.
  1385. 50:38Uh and and that is a problem that
  1386. 50:40affects all memory safe languages,
  1387. 50:42right? Like if you um there was the
  1388. 50:45classic
  1389. 50:46OpenSSL bug where they were reusing
  1390. 50:50a 64 kilobyte buffer um over and over
  1391. 50:53again.
  1392. 50:55Um and you could write that in any
  1393. 50:57language, right? Like you just pull a 64
  1394. 50:59kilobyte buffer and they were storing
  1395. 51:01secrets in there without zeroing them.
  1396. 51:03And of course the attacker could control
  1397. 51:05where in that array you were reading.
  1398. 51:08And so now all of a sudden you had
  1399. 51:09exfiltration of secrets.
  1400. 51:11Um so in any programming language you
  1401. 51:14have to in order to actually get like
  1402. 51:17all of the benefit of memory safety even
  1403. 51:20if it's a memory safe language, you
  1404. 51:21can't just say, "Okay, I'm going to have
  1405. 51:23a giant array where I'm storing all of
  1406. 51:25my data and my pointers are just indices
  1407. 51:28into the array." As soon as you say that
  1408. 51:30then like all bets are off.
  1409. 51:34So I would like to because you mentioned
  1410. 51:37Casey the uh
  1411. 51:39the dynamic when we're linking to a
  1412. 51:42external yellow like that there's a cool
  1413. 51:43part. I would first want to talk about
  1414. 51:45like
  1415. 51:46Fill C on the normal within the program
  1416. 51:49itself, let's say within one binary,
  1417. 51:51right? Because when you're compiling,
  1418. 51:53you're actually adding new LLVM IR.
  1419. 51:57So, can we talk a little bit about that?
  1420. 51:59What is actually happening to implement
  1421. 52:01the
  1422. 52:02capabilities themselves, and then we can
  1423. 52:05move towards like what will happen if
  1424. 52:06you have more than one, for example, DLL
  1425. 52:09linking?
  1426. 52:10Yeah. Um
  1427. 52:13It's It is hard to separate those
  1428. 52:15though, because I did this thing where I
  1429. 52:17started from memory unsafe C, and then I
  1430. 52:20took this giant leap to 100% memory
  1431. 52:23safety. Um and the way that I achieved
  1432. 52:26that was the first version of Phil C
  1433. 52:28what generated the worst code you could
  1434. 52:30possibly imagine. Even doing a pointer
  1435. 52:33plus was a function call to the runtime.
  1436. 52:36Uh pointer dereferences were function
  1437. 52:38calls to the runtime.
  1438. 52:40Function calls were allocations in the
  1439. 52:43heap. Uh just crazy crazy crazy
  1440. 52:46nonsense. Uh
  1441. 52:48just because, again, I Phil C started
  1442. 52:50out as a thesis test. I was sure that
  1443. 52:52this couldn't possibly work, and so I
  1444. 52:54just wanted to make a completely memory
  1445. 52:57safe C as quickly as possible
  1446. 52:59just to convince myself that it's
  1447. 53:01impossible, and then I could move on
  1448. 53:02with my life, right? Just do something
  1449. 53:05else.
  1450. 53:05>> [laughter]
  1451. 53:09>> So, it ended up working. Uh
  1452. 53:12and then and then uh the compiler as it
  1453. 53:14is now is
  1454. 53:16uh the result of incrementally
  1455. 53:18optimizing away the worst of those
  1456. 53:20crimes in the original prototype. Um
  1457. 53:24which is really interesting, cuz we're
  1458. 53:25going to have to talk about Phil C's
  1459. 53:26performance. And if you talk about Phil
  1460. 53:28C's performance, the prob the problem
  1461. 53:30with talking about it is that it like it
  1462. 53:32it started out as the slowest thing you
  1463. 53:34can imagine, and then I
  1464. 53:36brought it to a point where it's fast
  1465. 53:37enough that I can use it, but I haven't
  1466. 53:39actually rolled up my sleeves and done
  1467. 53:42all the things I could could fast.
  1468. 53:44So, what do what happens? What happens
  1469. 53:46is that um
  1470. 53:49a pointer that you're passing around in
  1471. 53:51local data flow
  1472. 53:53um
  1473. 53:54so, a pointer coming out of one
  1474. 53:56expression into another
  1475. 53:58is uh now two pointers. Uh one of those
  1476. 54:01pointers is what I call the integer
  1477. 54:02value, and the other pointer is what I
  1478. 54:04call the lower. Uh why is it called the
  1479. 54:07lower? Because the the trick is that the
  1480. 54:10in every object the pointer to the lower
  1481. 54:13bounds of that object points to the
  1482. 54:16upper end of the capability object. So,
  1483. 54:19the lower is simultaneously the lower
  1484. 54:21bounds that you can check
  1485. 54:23and a pointer to the top of
  1486. 54:26uh the the capability object. Then, the
  1487. 54:29capability object has a pointer to the
  1488. 54:31upper bounds and a pointer to some
  1489. 54:33additional metadata. So, you're always
  1490. 54:35passing around this lower and this
  1491. 54:37integer value.
  1492. 54:38When you access a pointer
  1493. 54:40um then we check that the lower is not
  1494. 54:43null.
  1495. 54:45So, that's a that's a branch, right?
  1496. 54:47Uh if the access has to be aligned in
  1497. 54:51order to be safe
  1498. 54:52uh which is true for pointer accesses
  1499. 54:56then alignment of the integer value is
  1500. 54:58checked, so that's another branch.
  1501. 55:01Um then the lower and upper bounds are
  1502. 55:03checked. The lower and upper bounds
  1503. 55:05checking is more complicated than you
  1504. 55:07would think
  1505. 55:09because uh FullC
  1506. 55:12uh is engineered to be resilient against
  1507. 55:15wrap-around. So, if you if you did the
  1508. 55:18lower and upper bounds check naively,
  1509. 55:21then you could have a pointer to the top
  1510. 55:22of memory
  1511. 55:24accessing an amount of memory that wraps
  1512. 55:26around to the bottom of memory, and then
  1513. 55:28the lower bounds would succeed, and the
  1514. 55:30upper bounds would succeed every time.
  1515. 55:32FullC is resilient against that, so the
  1516. 55:35the way I emit the code for the lower
  1517. 55:37and upper bounds checks is very kind of
  1518. 55:39careful.
  1519. 55:40Um and and more expensive than what it
  1520. 55:42would be if I was just doing it naively.
  1521. 55:45And then if you're if if you're
  1522. 55:47accessing a primitive value, so like an
  1523. 55:49integer or a double or something like
  1524. 55:50that, then that's pretty much the whole
  1525. 55:52story.
  1526. 55:53If you're accessing a pointer, then uh
  1527. 55:56the metadata at the bottom of the
  1528. 56:00pointer you're storing into and out of
  1529. 56:03has a pointer to an extra where the
  1530. 56:07capabilities are. So then if you're
  1531. 56:09accessing if you're loading a pointer
  1532. 56:11from the heap or storing a pointer to
  1533. 56:12the heap, then there's
  1534. 56:15uh
  1535. 56:16quite a lot of additional stuff that the
  1536. 56:18compiler admits. Uh right now,
  1537. 56:21the worst part of that is the code that
  1538. 56:24I admit for loading a pointer. Uh
  1539. 56:26there's there's uh
  1540. 56:29two branches in there that are there
  1541. 56:31just for silly reasons that I need to
  1542. 56:33remove and some integer
  1543. 56:36integer math dependencies that need to
  1544. 56:37be removed. But all in all, like I think
  1545. 56:39loading a pointer from the heap is
  1546. 56:41something like
  1547. 56:4313 instructions on the hot path and like
  1548. 56:46seven basic blocks or something
  1549. 56:48something completely ridiculous. Um so
  1550. 56:51that the highest the the biggest source
  1551. 56:54of overhead in FillC right now is those
  1552. 56:56loads.
  1553. 56:58Um and and and we do have to talk about
  1554. 57:01calls, right? So the calls are memory
  1555. 57:03safe in FillC. And the way that the
  1556. 57:05calls are memory safe is that right now,
  1557. 57:08uh the arguments are passed as a buffer
  1558. 57:13in in the heap.
  1559. 57:15Um uh and that buffer contain There's
  1560. 57:18actually two buffers, one buffer for the
  1561. 57:19integer values and one buffer for the
  1562. 57:21capabilities. Um so what that means is
  1563. 57:24uh C programs that intentionally
  1564. 57:29uh type confuse function signatures
  1565. 57:32work so long as that type confusion
  1566. 57:36isn't too severe.
  1567. 57:38Um, and that's important because real C
  1568. 57:40programs do that. Like it's it's common
  1569. 57:42to have
  1570. 57:44um
  1571. 57:45uh
  1572. 57:46the caller pass the integer zero
  1573. 57:51and the type signature at the call site
  1574. 57:53is that it's an integer and then the
  1575. 57:55callee thinks that they're getting a
  1576. 57:58void star.
  1577. 57:59And it's fine because the the person
  1578. 58:02getting the void star checks is it is it
  1579. 58:04null before doing anything. Well, zero
  1580. 58:06turns into null, so it's all good. FillC
  1581. 58:09allows that because the zero gets passed
  1582. 58:11as a zero with a zero capability. On the
  1583. 58:13other side, you null check it, you get
  1584. 58:15null, you're fine.
  1585. 58:17Um, but that the overhead of the calls
  1586. 58:21themselves is
  1587. 58:24is is really bad. I I
  1588. 58:27the
  1589. 58:28and it's it's it's like it again, you
  1590. 58:31kind of have to like
  1591. 58:32if you want if you want to make fun of
  1592. 58:34FillC, then this is the perfect
  1593. 58:35opportunity to make fun of it. Look at
  1594. 58:37the code generated and be like, "Look at
  1595. 58:39that. That's terrible. What is this guy
  1596. 58:41thinking?" But like
  1597. 58:43there's obviously better ways to do it
  1598. 58:45if you've studied how memory safe
  1599. 58:47languages work. It's just I haven't had
  1600. 58:48a chance to fix it. But anyway, pass
  1601. 58:51arguments and return values are passed
  1602. 58:53in the heap.
  1603. 58:54Uh but at least it's not a dynamic
  1604. 58:56allocation every time that you make a
  1605. 58:58call. It's reusing the same heap
  1606. 59:00location. At least that that's true.
  1607. 59:02Um
  1608. 59:04and and we we do have to talk a little
  1609. 59:06bit about linking because linking is
  1610. 59:07like a fundamental part of C semantics.
  1611. 59:11I think one of the things that makes C
  1612. 59:14special among languages
  1613. 59:17is [snorts] this fact that C has this
  1614. 59:19global name space of symbols
  1615. 59:21that are allowed to be externally
  1616. 59:24resolved.
  1617. 59:25Um, this is a very powerful feature in C
  1618. 59:27and I think is one of the reasons why C
  1619. 59:29gets used to build really large
  1620. 59:30softwares. This enables you to have
  1621. 59:34a very flexible kind of story for how
  1622. 59:37you dynamically link. Whether Well,
  1623. 59:38actually, do you link statically? Do you
  1624. 59:40link dynamically? The language kind of
  1625. 59:41doesn't care. You can do it however you
  1626. 59:43want.
  1627. 59:44And so, um, PhilC does have an answer
  1628. 59:47there. And it even has an answer for
  1629. 59:49what would happen if you, for example,
  1630. 59:52define in one module
  1631. 59:55that uh there's an external symbol
  1632. 59:57called foo and it's a function. And then
  1633. 59:59in another module, you define foo and
  1634. 1:00:01you define it to be a float.
  1635. 1:00:04Um, C allows you to do this.
  1636. 1:00:06Uh, and if you do this normally in C,
  1637. 1:00:09you get whatever the whatever the CPU
  1638. 1:00:11gives you, right? Like
  1639. 1:00:13uh probably you'll get a crash, but
  1640. 1:00:15maybe not depending on what kind of CPU
  1641. 1:00:17you're on. In PhilC, what happens is
  1642. 1:00:21um
  1643. 1:00:22every single global symbol,
  1644. 1:00:26when you refer to it in your C program,
  1645. 1:00:29uh turns into a function call to a
  1646. 1:00:31getter. So, if there's a module that
  1647. 1:00:34exports a symbol, what it's actually
  1648. 1:00:36exporting, so like if you export the
  1649. 1:00:38symbol foo and it's a float, you're
  1650. 1:00:40actually exporting a symbol called
  1651. 1:00:41pislonated_foo.
  1652. 1:00:43And it's always a getter.
  1653. 1:00:45And that getter always returns a PhilC
  1654. 1:00:48pointer, so a tuple of
  1655. 1:00:50uh lower and and intval.
  1656. 1:00:53Um, and so when you
  1657. 1:00:55call foo from another module, that's
  1658. 1:00:57actually two steps. One,
  1659. 1:00:59call the getter for foo so that you can
  1660. 1:01:02get this this pointer. And then two, the
  1661. 1:01:05call is an indirect call. Every call in
  1662. 1:01:07PhilC currently is an indirect call.
  1663. 1:01:10Um,
  1664. 1:01:11where which involves uh checking whether
  1665. 1:01:14the thing you're calling is a function
  1666. 1:01:16pointer,
  1667. 1:01:17uh whether the
  1668. 1:01:19function pointer actually points at the
  1669. 1:01:22function it's supposed to be pointing
  1670. 1:01:23at.
  1671. 1:01:24And then the the passing the arguments
  1672. 1:01:26through the heap and all that kind of
  1673. 1:01:27jazz.
  1674. 1:01:28Um and so that enable that's what
  1675. 1:01:30enables linking to be to work at all and
  1676. 1:01:33and to be memory safe. So you if you
  1677. 1:01:35define
  1678. 1:01:37foo to be a float in one module and try
  1679. 1:01:39to use it as a function in another
  1680. 1:01:40module, you'll get
  1681. 1:01:42a Fil C panic saying you can't call a
  1682. 1:01:44float or something to that effect.
  1683. 1:01:47Um
  1684. 1:01:49Oh yeah, one more thing. There's a
  1685. 1:01:50concurrent GC, right? So
  1686. 1:01:52if you have a GC that supports multiple
  1687. 1:01:55threads, Fil C supports threads.
  1688. 1:01:58Um
  1689. 1:01:59then you need to have some way of
  1690. 1:02:01solving the race that happens
  1691. 1:02:05if one thread has just loaded a value
  1692. 1:02:09from the heap
  1693. 1:02:11and the garbage collector runs at that
  1694. 1:02:13time and deletes the object that you
  1695. 1:02:14just loaded.
  1696. 1:02:16Um Fil C protects against this race
  1697. 1:02:18using a classic approach called safe
  1698. 1:02:20pointing,
  1699. 1:02:21um which basically comes down to every
  1700. 1:02:23function periodically every
  1701. 1:02:26all all generated all code generated by
  1702. 1:02:29the Fil C compiler has periodic checks
  1703. 1:02:31emitted in it to see if it needs to
  1704. 1:02:34report to the GC.
  1705. 1:02:36Um and and the slow path of that has a
  1706. 1:02:39mechanism of uh allowing the stack to be
  1707. 1:02:42scanned and all of the pointers that are
  1708. 1:02:44in local variables to be accurately
  1709. 1:02:47reported to the garbage collector.
  1710. 1:02:49Um
  1711. 1:02:52Yeah, so all of those things are
  1712. 1:02:53happening all at once.
  1713. 1:02:55Um the parts that have been optimized
  1714. 1:02:57the most are
  1715. 1:03:00um
  1716. 1:03:01uh
  1717. 1:03:03Oh oh oh, I forgot one thing. Local
  1718. 1:03:05variables. If you have a local variable
  1719. 1:03:08that escapes, that is the compiler can't
  1720. 1:03:10prove that it that it's just local data
  1721. 1:03:12flow.
  1722. 1:03:13So you take the address of it, when give
  1723. 1:03:15it to some something, so the compiler
  1724. 1:03:17thinks, okay, this has to be on the
  1725. 1:03:18stack. Can't be in a register.
  1726. 1:03:21All of those local variables become uh
  1727. 1:03:23become heap allocations.
  1728. 1:03:25Um Okay.
  1729. 1:03:27So,
  1730. 1:03:28um
  1731. 1:03:30Is that is that the whole story? Yeah,
  1732. 1:03:31that's most of the whole story. And then
  1733. 1:03:33the things that have been optimized is
  1734. 1:03:35that the um
  1735. 1:03:38there is some amount of uh escape
  1736. 1:03:41analysis to make it so that
  1737. 1:03:44uh not literally all of your variables
  1738. 1:03:46become heap allocations.
  1739. 1:03:49Um this is probably the area of the
  1740. 1:03:50compiler that needs the most work still.
  1741. 1:03:53There's a lot of cases in PhilC today
  1742. 1:03:55where a local variable will be a heap
  1743. 1:03:57allocation even though it just does not
  1744. 1:03:59have to be.
  1745. 1:04:00Um
  1746. 1:04:01uh
  1747. 1:04:02And then the other part that's been
  1748. 1:04:03optimized is there's a certain amount of
  1749. 1:04:06redundant bounce check removal.
  1750. 1:04:08Uh not nearly as much as there could be,
  1751. 1:04:10but just just a little teensy bit of
  1752. 1:04:13redundant bounce check removal so so
  1753. 1:04:15far.
  1754. 1:04:17Um
  1755. 1:04:19Yeah, that's
  1756. 1:04:20that's the story what what happens to
  1757. 1:04:22the code.
  1758. 1:04:24Okay, can I just say like
  1759. 1:04:25quick seg- quick segway, for how long
  1760. 1:04:27have you worked on PhilC?
  1761. 1:04:30I started in November of '23.
  1762. 1:04:35Um and it's, you know, I have a
  1763. 1:04:36full-time job. I manage a team.
  1764. 1:04:38>> Yeah.
  1765. 1:04:39Exactly.
  1766. 1:04:39>> So, and I have I'm a single dad. I have
  1767. 1:04:41two kids. So,
  1768. 1:04:42>> Jesus. uh there's some days I don't work
  1769. 1:04:45on it at all. Uh
  1770. 1:04:46uh some days I get get a couple of hours
  1771. 1:04:48in.
  1772. 1:04:49Um
  1773. 1:04:51uh You're effective. Like you
  1774. 1:04:54Well,
  1775. 1:04:55Well, so the the PhilC runtime is uh
  1776. 1:04:59about 15,000 lines of code.
  1777. 1:05:01And the main PhilC compiler pass is
  1778. 1:05:03about 13,000 lines of code.
  1779. 1:05:05So, a lot of the I think the the
  1780. 1:05:07remarkable thing about PhilC is that it
  1781. 1:05:10it what I what I kind of found is like
  1782. 1:05:12what is the most surgical way that I can
  1783. 1:05:15do this using things that are already
  1784. 1:05:18out there LLVM and clang um uh
  1785. 1:05:21primarily um
  1786. 1:05:24and and and I really have been religious
  1787. 1:05:27about saying look the the the goal here
  1788. 1:05:30is full compatibility so that I can
  1789. 1:05:32convert code
  1790. 1:05:33to it with very little effort and let's
  1791. 1:05:35just like not worry about performance
  1792. 1:05:37too much for now you know like
  1793. 1:05:40it cuz the the thesis is is if if
  1794. 1:05:44if if I built a fast implementation of
  1795. 1:05:47memory safe C that couldn't run any
  1796. 1:05:49programs
  1797. 1:05:51then who cares
  1798. 1:05:54um
  1799. 1:05:56like if you can't run any C programs
  1800. 1:05:57there's already memory safe languages
  1801. 1:05:59you could rewrite your C program into
  1802. 1:06:02so that like I'm just reducing scope
  1803. 1:06:05very aggressively to just like let's
  1804. 1:06:07prove that you can make the C language
  1805. 1:06:08memory safe and kind of defer everything
  1806. 1:06:11else like performance like let's worry
  1807. 1:06:13about that later
  1808. 1:06:14>> [laughter]
  1809. 1:06:15>> Although that said the performance is
  1810. 1:06:16not that bad.
  1811. 1:06:18Yeah it's kind of it's that's
  1812. 1:06:20but it's still like well Compared to
  1813. 1:06:22what you would expect yeah.
  1814. 1:06:24>> Compared to what you would expect
  1815. 1:06:25although you should have seen how long
  1816. 1:06:27it took me to post on Twitter last
  1817. 1:06:29night.
  1818. 1:06:30>> [laughter]
  1819. 1:06:31>> Fair enough.
  1820. 1:06:34How long was it that you measure like
  1821. 1:06:36what was the um it it took uh I think it
  1822. 1:06:41takes something like 15 seconds
  1823. 1:06:44for the x.com
  1824. 1:06:46uh login window to pop up
  1825. 1:06:49and then it takes between 10 and 15
  1826. 1:06:51seconds between when I type in my login
  1827. 1:06:53until when it shows me the password
  1828. 1:06:55thing
  1829. 1:06:56and then probably like
  1830. 1:06:5820 to 30 seconds before I get to the
  1831. 1:07:01what's happening and I can type
  1832. 1:07:02something
  1833. 1:07:03um
  1834. 1:07:05uh So only slightly slower than normal.
  1835. 1:07:08>> [laughter]
  1836. 1:07:09>> Yeah. Well, what's interesting is I was
  1837. 1:07:12mentioning before that one of the
  1838. 1:07:13biggest weaknesses of PhilC is the
  1839. 1:07:15escape analysis.
  1840. 1:07:17And in JavaScript core
  1841. 1:07:19one of the things we do all the time in
  1842. 1:07:21JSC is
  1843. 1:07:23really wacky unions.
  1844. 1:07:26Like typical value being passed around
  1845. 1:07:29in JSC is either going to be in a union
  1846. 1:07:31or is going to be passed through a
  1847. 1:07:32union. And right now the way that I
  1848. 1:07:37I make LLVM's optimizations sound under
  1849. 1:07:41unions is that I don't allow them to
  1850. 1:07:44happen. So when you have a union,
  1851. 1:07:48the escape analysis in LLVM that would
  1852. 1:07:50have turned that union into a local
  1853. 1:07:51variable just doesn't happen. It's you
  1854. 1:07:53end up with a heap allocation. So I
  1855. 1:07:55think what's happening during those 15
  1856. 1:07:56seconds is every local variable in the
  1857. 1:08:01JavaScript interpreter is being like
  1858. 1:08:02heap allocated then heap allocated
  1859. 1:08:04again. Like totally crazy.
  1860. 1:08:07Um but uh but also if if you if you're
  1861. 1:08:11want to bet against PhilC then you
  1862. 1:08:13should be worried because this is
  1863. 1:08:14something that I am
  1864. 1:08:16you know, equipped as a compiler
  1865. 1:08:17engineer to fix if I wanted to. If I had
  1866. 1:08:20the time to.
  1867. 1:08:22Do you have any I think you mentioned
  1868. 1:08:25either on Twitter or somewhere
  1869. 1:08:27like
  1870. 1:08:28performance comparison to what would be
  1871. 1:08:30like the normal let's say curl and then
  1872. 1:08:33PhilC compiled curl. Like would it be
  1873. 1:08:35like you know, two times slower like one
  1874. 1:08:37time like four times slower. What would
  1875. 1:08:40be the range usually? Huge range. Uh so
  1876. 1:08:44for example, if you have
  1877. 1:08:46uh
  1878. 1:08:47C++ code that is um somewhat IO bound
  1879. 1:08:53like xz utils
  1880. 1:08:55the compression codec
  1881. 1:08:58then the slow down
  1882. 1:09:00um is like 1.2x or something like this.
  1883. 1:09:04If you're really IO bound, there's no
  1884. 1:09:06slowdown.
  1885. 1:09:07Um, if you have a program that is
  1886. 1:09:10aggressively using SIMD intrinsics,
  1887. 1:09:14um,
  1888. 1:09:15uh, then the slowdown is less than 2x.
  1889. 1:09:17So, a lot of Dan Daniel Lemire's, uh,
  1890. 1:09:21C++ libraries that use SIMD intrinsics
  1891. 1:09:24have just very low slowdowns from what I
  1892. 1:09:26can tell.
  1893. 1:09:27Um, below 2x, sometimes it's like 1x.
  1894. 1:09:30And the reason is that if if if all of
  1895. 1:09:32your logic is loading and storing
  1896. 1:09:35AVX-512 vectors,
  1897. 1:09:38I'm still doing just one bounce check
  1898. 1:09:40for that one AVX-512 vector load or
  1899. 1:09:42store, but you're getting 512 bits,
  1900. 1:09:45you know,
  1901. 1:09:46from from it. So, the the cost of the
  1902. 1:09:49fill C checks becomes aggressively
  1903. 1:09:51amortized. So, if you're a SIMD
  1904. 1:09:53programmer, fill C is like great. Um,
  1905. 1:09:57uh, until you do a function call and
  1906. 1:09:59then I'm going to put your SIMD vectors
  1907. 1:10:01in the heap, but
  1908. 1:10:02I'll fix that eventually. Um,
  1909. 1:10:05>> [laughter and clears throat]
  1910. 1:10:06>> um,
  1911. 1:10:08if you're an interpreter, like the
  1912. 1:10:09Python interpreter,
  1913. 1:10:11uh, or the JavaScript core interpreter,
  1914. 1:10:13then the slowdown is is somewhere in the
  1915. 1:10:16vicinity of like more than 7x, sometimes
  1916. 1:10:1810x.
  1917. 1:10:20Um, and that's because interpreters
  1918. 1:10:22typically are dealing with,
  1919. 1:10:24uh, data structures that have pointers,
  1920. 1:10:26um, and they have unions. So, uh, you
  1921. 1:10:29kind of end up hitting,
  1922. 1:10:31uh, some of fill C's worst cases in that
  1923. 1:10:33in that situation.
  1924. 1:10:35Um,
  1925. 1:10:36a lot of programs are in the 2x, 3x, 4x
  1926. 1:10:40regime.
  1927. 1:10:42And a lot of programs
  1928. 1:10:45have the kind of slowdown where you sort
  1929. 1:10:49of don't care.
  1930. 1:10:50Um, like, uh,
  1931. 1:10:52the work that I was doing to port, uh,
  1932. 1:10:55about
  1933. 1:10:55to fill C is on Pizlex. So, I'm in a
  1934. 1:10:59terminal that's written in PhilC, Bash
  1935. 1:11:01written in PhilC. I'm committing to
  1936. 1:11:03GitHub using a Git compiled with PhilC
  1937. 1:11:06over an SSH compiled with PhilC, and I'm
  1938. 1:11:09writing code in Emacs compiled with
  1939. 1:11:11PhilC, and it's just fine. I'm grepping
  1940. 1:11:15with a grep written in PhilC. I'm
  1941. 1:11:16opening large log files in Emacs, and
  1942. 1:11:18it's all written in PhilC, and it's just
  1943. 1:11:20it's fine. It's like it's whatever.
  1944. 1:11:22Um if I if I look carefully at the
  1945. 1:11:25responsiveness, you can kind of tell
  1946. 1:11:27that it's like not
  1947. 1:11:29you know, what my computer would
  1948. 1:11:30normally be capable of, but it's it's
  1949. 1:11:33fast enough to just to just use and not
  1950. 1:11:35care.
  1951. 1:11:36Um
  1952. 1:11:37and and that's kind of been my standard
  1953. 1:11:39is like I just optimize things enough to
  1954. 1:11:42get to that point where for the things
  1955. 1:11:44that I care about, it's it's fast
  1956. 1:11:45enough. It's just it's fine.
  1957. 1:11:49Okay.
  1958. 1:11:50Okay, so do you want to unpack some of
  1959. 1:11:52the things said previously about how
  1960. 1:11:55PhilC works? Um I mean, I think not not
  1961. 1:11:59particularly because I think if we were
  1962. 1:12:01to unpack those like any any in
  1963. 1:12:04particular unpacking requires a lot of
  1964. 1:12:06stuff if you want to go the whole nine,
  1965. 1:12:09right? Um you know, even just looking at
  1966. 1:12:11something at like he was talking about
  1967. 1:12:14reducing
  1968. 1:12:15bounds checking and things like that.
  1969. 1:12:17And
  1970. 1:12:19I mean, I guess just the way that I
  1971. 1:12:20would say it for people who are new to
  1972. 1:12:21this is if you imagine what's going on
  1973. 1:12:25when you're talking about something in a
  1974. 1:12:27high-level language, which at this point
  1975. 1:12:29C is kind of
  1976. 1:12:31maybe not properly called that because
  1977. 1:12:33things have gotten so high-level, but
  1978. 1:12:35you know, in the old days it was
  1979. 1:12:36considered a higher-level language
  1980. 1:12:38uh than something like assembly.
  1981. 1:12:40When you're talking about this sort of
  1982. 1:12:41thing,
  1983. 1:12:42you the compiler is looking at
  1984. 1:12:44everything you do. You know, you've got
  1985. 1:12:46something like a pointer, and you're
  1986. 1:12:47going to go talk or or you know, you
  1987. 1:12:50think of maybe a reference to an object.
  1988. 1:12:52However, you want to conceptualize it
  1989. 1:12:53nowadays in the at the higher level.
  1990. 1:12:56If you imagine what's happening inside a
  1991. 1:12:57typical function, you have a lot of
  1992. 1:12:58things such as, "Oh, I have this
  1993. 1:13:00particular object um and I'm going to go
  1994. 1:13:03get like this X value from it and this Y
  1995. 1:13:06value from it and this string pointer
  1996. 1:13:08for what its name is and things like
  1997. 1:13:09this."
  1998. 1:13:11So, if you can imagine in your head,
  1999. 1:13:13Filthy's job is to protect all of those
  2000. 1:13:16things. So, if you're going to go read
  2001. 1:13:18the X coordinate out of some, you know,
  2002. 1:13:20sprite that's in some location or
  2003. 1:13:22whatever it is that you're imagining in
  2004. 1:13:23your head,
  2005. 1:13:24Filthy's job is to make sure that when
  2006. 1:13:26you actually when you're asking for the
  2007. 1:13:28X coordinate of this sprite, that the
  2008. 1:13:30handle or whatever the thing that you're
  2009. 1:13:32getting, which in this case would be,
  2010. 1:13:33you know, a pointer or a reference, that
  2011. 1:13:35that actually was legitimately
  2012. 1:13:37originally something
  2013. 1:13:39from an allocation of that particular
  2014. 1:13:42sprite and that you had the authority
  2015. 1:13:44when you got it to access that X
  2016. 1:13:46coordinate, right?
  2017. 1:13:48And if you think about the naive
  2018. 1:13:50implementation of this,
  2019. 1:13:52every single time you access anything
  2020. 1:13:54anywhere from any handle, right?
  2021. 1:13:58Anything that ever had its address
  2022. 1:13:59taken, anything that ever had a pointer
  2023. 1:14:01to it, all this thing, every single one
  2024. 1:14:02of those has to have this sort of
  2025. 1:14:05structure put around it in its actual
  2026. 1:14:07run time code, so the machine code being
  2027. 1:14:09generated,
  2028. 1:14:11to look and see, "Did this pointer
  2029. 1:14:14actually have the ability to access this
  2030. 1:14:17thing?"
  2031. 1:14:19And so, when we talk about optimization
  2032. 1:14:21for something like Filthy, you can kind
  2033. 1:14:22of now imagine your head like, "Oh,
  2034. 1:14:24okay, like
  2035. 1:14:26for for starters, if I'm accessing two
  2036. 1:14:29different fields in the same object that
  2037. 1:14:30are right next to each other, it would
  2038. 1:14:32be pretty trivial for me to aggregate
  2039. 1:14:35out a check to just see, let me do one
  2040. 1:14:37check to make sure that I can access
  2041. 1:14:39both of these things cuz that will be
  2042. 1:14:41cheaper than checking each one
  2043. 1:14:42individually before I check it, right?"
  2044. 1:14:46Multiply that by a thousand, right?
  2045. 1:14:48There are so many cases that you could
  2046. 1:14:50imagine when you start going and like
  2047. 1:14:52I'm going to spend, you know, if if this
  2048. 1:14:54wasn't his spare time project, right?
  2049. 1:14:57There are so many ways that you can
  2050. 1:14:58imagine now like from the naive thing,
  2051. 1:15:01which is just the thing you used to just
  2052. 1:15:02get it working to a more complete
  2053. 1:15:05picture where we're doing all kinds of
  2054. 1:15:07static analysis to figure out like, oh,
  2055. 1:15:09this variable never really escaped and
  2056. 1:15:11the only people who like actually looked
  2057. 1:15:12at its location were people I'm
  2058. 1:15:14immediately calling and I know that they
  2059. 1:15:16never actually do anything with it. So,
  2060. 1:15:17we eliminated all of that and all the
  2061. 1:15:19bounce checks went away and the whole
  2062. 1:15:21thing can just be on the stack now. Like
  2063. 1:15:23all of that is real work, like hard
  2064. 1:15:25compiler work.
  2065. 1:15:27And it's the kind of thing that's been
  2066. 1:15:28done
  2067. 1:15:29for optimizations for, you know, every
  2068. 1:15:31other language. PhilC is brand new and,
  2069. 1:15:34you know, there's not enough people
  2070. 1:15:35working on it right now, right? And so,
  2071. 1:15:38when you look at the performance of
  2072. 1:15:39something like PhilC, it's very hard to
  2073. 1:15:41say where it would eventually get to if
  2074. 1:15:43you imagined a bunch of serious compiler
  2075. 1:15:46people taking it seriously for a long
  2076. 1:15:48time, finding all of those cases, doing
  2077. 1:15:51all of that work.
  2078. 1:15:52All of this stuff starts to now become
  2079. 1:15:54faster and faster and faster and faster.
  2080. 1:15:56So, it's, you know, I don't know how to
  2081. 1:15:58put that picture in people's head, but
  2082. 1:16:00it is a thing where
  2083. 1:16:02if you asked people 30 years ago would
  2084. 1:16:05the kinds of optimizations that
  2085. 1:16:07something like Clang is doing be common
  2086. 1:16:09and just happen automatically in a one,
  2087. 1:16:12you know,
  2088. 1:16:13one-shot compile that you just do
  2089. 1:16:14doesn't run for 3 days, right? Just
  2090. 1:16:16compiles your program.
  2091. 1:16:17They would be kind of astonished at some
  2092. 1:16:19of the program transformations that are
  2093. 1:16:21now routine in something like Clang's
  2094. 1:16:24back or LLVM's back end.
  2095. 1:16:26And so, you just have to keep in mind
  2096. 1:16:28that that what you're comparing PhilC to
  2097. 1:16:32is something that's had absolutely
  2098. 1:16:34heroic
  2099. 1:16:35all kinds of craziness happening in its
  2100. 1:16:37optimization passes and PhilC hasn't had
  2101. 1:16:40a chance to have all that done. So,
  2102. 1:16:41that's one of the reasons why
  2103. 1:16:44no one right now can really state like
  2104. 1:16:47how far could you go performance-wise on
  2105. 1:16:49this. The The answer is
  2106. 1:16:51I don't know, give it 20 years and we'd
  2107. 1:16:54probably be shocked at how, you know,
  2108. 1:16:56fast it could run over, you know,
  2109. 1:17:00what you see today. Right? That's And
  2110. 1:17:01so, I just want to make sure people
  2111. 1:17:02understand these these deltas
  2112. 1:17:05because compilers, you know, when we
  2113. 1:17:07when we run compiled languages today,
  2114. 1:17:09we're no longer thinking of just a
  2115. 1:17:11straightforward compile like in the old
  2116. 1:17:13days. We're thinking of massive program
  2117. 1:17:15transformations that are very regularly
  2118. 1:17:16applied and that same sort of thing can
  2119. 1:17:18happen to FilC over time. Yeah.
  2120. 1:17:23I would be interested to know where do
  2121. 1:17:25you want to take FilC from where is it
  2122. 1:17:27now?
  2123. 1:17:29Like
  2124. 1:17:30because you can spend your time, limited
  2125. 1:17:32time, on like doing compiling different
  2126. 1:17:35existing projects and checking whether
  2127. 1:17:37they work,
  2128. 1:17:38doing optimizations as mentioned. But
  2129. 1:17:41probably like being tied to LLVM doesn't
  2130. 1:17:44help with every now and then updating
  2131. 1:17:46the LLVM and making sure that new things
  2132. 1:17:48work and like, you know, everything's
  2133. 1:17:50working and here's like you kind of
  2134. 1:17:52always chasing the the the LLVM stack.
  2135. 1:17:55So, how do you see the FilC now and
  2136. 1:17:57where where would it go?
  2137. 1:18:00Um
  2138. 1:18:01So,
  2139. 1:18:02about the chasing LLVM, it took one day
  2140. 1:18:05to rebase FilC from LLVM 17 to LLVM
  2141. 1:18:0820.1. Okay.
  2142. 1:18:10>> cuz it it really is like this this like
  2143. 1:18:13surgical, careful injection. So, I'm
  2144. 1:18:17actually not too worried about the
  2145. 1:18:20rebasing part of it. Um
  2146. 1:18:22I do I think that the
  2147. 1:18:24the thing that's brought the most value
  2148. 1:18:26so far
  2149. 1:18:27is porting lots of software to it
  2150. 1:18:30because the way you
  2151. 1:18:33do quality assurance on a compiler
  2152. 1:18:37Let me back up. The thing that makes
  2153. 1:18:38compilers super interesting um compared
  2154. 1:18:41to other software is just the level of
  2155. 1:18:44quality that they achieve. Like the
  2156. 1:18:46likelihood that you're going to
  2157. 1:18:47encounter a compiler bug is low uh to
  2158. 1:18:51the point that there's jokes that you
  2159. 1:18:52know you tell you tell uh startup
  2160. 1:18:55starting programmers that anytime you
  2161. 1:18:57think something is a compiler bug, it's
  2162. 1:18:58not. Assume it isn't, right? It's never
  2163. 1:19:01a compiler bug is what you tell people.
  2164. 1:19:03And that's because compilers are that
  2165. 1:19:04reliable. Um and so
  2166. 1:19:08uh with Phil C, the thing that I want to
  2167. 1:19:10do is I want to achieve that level of
  2168. 1:19:12reliability in the compiler that when
  2169. 1:19:15someone tries it out they are surprised
  2170. 1:19:18and joyful about the fact that it just
  2171. 1:19:20worked.
  2172. 1:19:22And the way that you do that is
  2173. 1:19:25you have to be able to test the compiler
  2174. 1:19:27on a massive amount of code. Um
  2175. 1:19:30compilers like clang
  2176. 1:19:32um get tested not just on their own test
  2177. 1:19:34suite but people who work on clang are
  2178. 1:19:37at large corporations that have a
  2179. 1:19:39billion lines of C++ code that they can
  2180. 1:19:41try to compile it on.
  2181. 1:19:43So the the
  2182. 1:19:45the upside um to Phil C as a project to
  2183. 1:19:49people trying Phil C of me porting tons
  2184. 1:19:51and tons of programs to Phil C is that I
  2185. 1:19:54am going to find the bugs before you do.
  2186. 1:19:57So when you try it on your project,
  2187. 1:19:59you're just going to be happy that it
  2188. 1:20:01worked and you're not going to have to
  2189. 1:20:02deal with with bugs.
  2190. 1:20:04So I'm just going to keep doing that cuz
  2191. 1:20:06one of the things that brings me the
  2192. 1:20:08most joy is like I get an email or a
  2193. 1:20:11message on Discord or Twitter from
  2194. 1:20:13people once in a while where they're
  2195. 1:20:15like, "Wow, I tried this on my program
  2196. 1:20:17and I was surprised that it just
  2197. 1:20:19worked."
  2198. 1:20:20Um I I want to I I mean, that that makes
  2199. 1:20:22my day, right? So like I want I want
  2200. 1:20:24more of more experiences like that for
  2201. 1:20:27people.
  2202. 1:20:28Um
  2203. 1:20:29and I think because of the fact that
  2204. 1:20:31people are having those experiences,
  2205. 1:20:32Fill See has gone in in the last year or
  2206. 1:20:35so from being like kind of an obscure
  2207. 1:20:38thing to being a thing that actually has
  2208. 1:20:40like users and um a handful of
  2209. 1:20:44contributors beyond just me.
  2210. 1:20:46Um so I think I'm on a good trajectory
  2211. 1:20:48just by doing that.
  2212. 1:20:49Um interestingly though,
  2213. 1:20:52with WebKit uh now starting to work and
  2214. 1:20:56being
  2215. 1:20:57uh too slow for for for my tastes, it's
  2216. 1:21:01likely that I'm going to take a detour
  2217. 1:21:02to do some optimizations. Just I want to
  2218. 1:21:05be able to uh
  2219. 1:21:07to you know, go on Twitter and and and
  2220. 1:21:10use Twitter uh in a memory safe way
  2221. 1:21:13um
  2222. 1:21:13and not have to wait for like 15 seconds
  2223. 1:21:16for the thing to load.
  2224. 1:21:18Um so I'm going to try to see if I can
  2225. 1:21:19do that. Um
  2226. 1:21:22uh
  2227. 1:21:24But beyond that, I'm not sure. I think
  2228. 1:21:26this is still like an experiment. It's
  2229. 1:21:28gone beyond the technical experiment to
  2230. 1:21:30now being a social experiment.
  2231. 1:21:32Um like the question the question is how
  2232. 1:21:35many C++ shops
  2233. 1:21:38uh out there uh would like to do things
  2234. 1:21:42this way
  2235. 1:21:43uh rather than the alternatives that are
  2236. 1:21:45in front of them. The alternatives that
  2237. 1:21:46are in front of them are
  2238. 1:21:48uh rewrite in Rust,
  2239. 1:21:50which you know, has its independent
  2240. 1:21:52benefits. There's things about Rust that
  2241. 1:21:55you like you might like Rust more than
  2242. 1:21:57C++, in which case if you rewrite in
  2243. 1:21:58Rust, you're going to be happy, right?
  2244. 1:22:01Whatever. That's something that some
  2245. 1:22:02people are going to choose
  2246. 1:22:04uh if they're into that sort of thing.
  2247. 1:22:06Um and then the other option is you
  2248. 1:22:08could choose to just stick with normal
  2249. 1:22:09C++.
  2250. 1:22:12That might be the right option for some
  2251. 1:22:13C++ shops,
  2252. 1:22:15right? Um
  2253. 1:22:16like if I'm playing a single-player game
  2254. 1:22:18on my computer, I don't really care if
  2255. 1:22:20it's memory safe. I just want it to be
  2256. 1:22:22fast. I want the pixels to look pretty.
  2257. 1:22:25Um right? And so for a lot of for a lot
  2258. 1:22:28of domains, uh, just sticking with
  2259. 1:22:30normal C++ might be fine.
  2260. 1:22:33Um,
  2261. 1:22:34so,
  2262. 1:22:35I think the the thing that's the thing
  2263. 1:22:37that's exciting for me going forward
  2264. 1:22:39with this project is to see
  2265. 1:22:41what other people decide now that they
  2266. 1:22:44have, uh, FILSIC as an option.
  2267. 1:22:48This is this is this is tying to a sort
  2268. 1:22:51of my next question, meaning
  2269. 1:22:54what do you see as the early adopters?
  2270. 1:22:57Who do you see as the early adopters of
  2271. 1:22:58FILSIC, uh,
  2272. 1:23:00like as a category, right? Like people
  2273. 1:23:02who are making software in C++ and
  2274. 1:23:05they're like worried about the weird
  2275. 1:23:07execution being possible. Is because
  2276. 1:23:11like game as you mentioned, like games
  2277. 1:23:13not necessarily like the most interested
  2278. 1:23:15clients in FILSIC, where would you see
  2279. 1:23:18them, the clients? Yeah. Uh, so, there's
  2280. 1:23:21a there's a a handful of, um,
  2281. 1:23:24uh, security-conscious people who I know
  2282. 1:23:26who are running, um, like
  2283. 1:23:28FILSIC-compiled OpenSSH server.
  2284. 1:23:32That's a great idea. Um,
  2285. 1:23:35you can do that today.
  2286. 1:23:37Uh, in fact, the optFILSIC distribution
  2287. 1:23:38is the optimal way to do that. Um, and
  2288. 1:23:41the one thing I'll mention about the
  2289. 1:23:42optFILSIC distribution is it comes with,
  2290. 1:23:45uh, things like PAM, uh, and SE Linux
  2291. 1:23:49libraries, so that when you start that
  2292. 1:23:52SSHD men, it can actually use your
  2293. 1:23:54existing SSHD men configuration,
  2294. 1:23:56including your existing PAM stack.
  2295. 1:23:59Um, so, you get like a completely
  2296. 1:24:01memory-safe password authentication
  2297. 1:24:04workflow, you get memory-safe OpenSSL,
  2298. 1:24:08um, and the OpenSSL has has specific
  2299. 1:24:10defenses in it to make sure that the
  2300. 1:24:12crypto still has constant-time crypto in
  2301. 1:24:15it. So, that's like a thing you can you
  2302. 1:24:17can use, and there are people using
  2303. 1:24:18that. So, that's one category of early
  2304. 1:24:20the
  2305. 1:24:21Another category of early adopter is
  2306. 1:24:24um from what I've been hearing, there's
  2307. 1:24:26folks who are shipping
  2308. 1:24:29a server
  2309. 1:24:31uh product of some sort.
  2310. 1:24:33Um uh I think some of them are like it's
  2311. 1:24:36like an embedded thing. There's some
  2312. 1:24:37embedded device and it's got a server
  2313. 1:24:39written in C++. The things connect to.
  2314. 1:24:42Um and folks in that category um ha-
  2315. 1:24:45have have been switching to Phil C++ and
  2316. 1:24:47Phil C. I don't have a good handle on
  2317. 1:24:49how many, but it it's a non-trivial
  2318. 1:24:52number considering I've received a
  2319. 1:24:54non-trivial number of emails from people
  2320. 1:24:56saying they have done this.
  2321. 1:24:59Um so um
  2322. 1:25:01like you have to assume that not
  2323. 1:25:03everybody who does this is going to drop
  2324. 1:25:05a line and tell me that they did it,
  2325. 1:25:07right? So there's there's some there's
  2326. 1:25:09that's already out there. Like that ship
  2327. 1:25:10has sailed. People are doing it. And the
  2328. 1:25:13it's interesting like um like one of one
  2329. 1:25:16of the emails that I received, they're
  2330. 1:25:18like uh
  2331. 1:25:20it worked out of the box. We're super
  2332. 1:25:21happy.
  2333. 1:25:22We measured performance on our
  2334. 1:25:24benchmarks and it was 40% slower, but
  2335. 1:25:26that's still within our budget. So we
  2336. 1:25:29just did it.
  2337. 1:25:30Um
  2338. 1:25:31I think there there's a there's probably
  2339. 1:25:33a large number of people out there like
  2340. 1:25:35that who wrote a piece of server code in
  2341. 1:25:39C or C++ because just that's
  2342. 1:25:42what what it made sense to them.
  2343. 1:25:45Uh and now memory safety is a thing and
  2344. 1:25:47rather than having to rewrite it in a
  2345. 1:25:49different language, they chose
  2346. 1:25:51uh Phil C.
  2347. 1:25:53That's an interesting category because
  2348. 1:25:55let's say that you're writing um a
  2349. 1:25:57server that operates in the embedded
  2350. 1:26:00space. And so maybe it has to make some
  2351. 1:26:02weird system calls
  2352. 1:26:04to talk to a custom piece of hardware.
  2353. 1:26:06Um
  2354. 1:26:07Phil C is the only memory safe game in
  2355. 1:26:10town in that case because if you want to
  2356. 1:26:13make a weird syscall from Rust, you have
  2357. 1:26:15to use an unsafe statement.
  2358. 1:26:17If you want to make an unsafe syscall
  2359. 1:26:18from Java, you have to write C code that
  2360. 1:26:20you then bind to the Java and you get a
  2361. 1:26:22bunch of memory unsafety. And it's very
  2362. 1:26:24risky to do that. You can make mistakes
  2363. 1:26:26when you do that. But in Phil C, you get
  2364. 1:26:29all of the Linux syscalls
  2365. 1:26:31and the Phil C runtime actually filters
  2366. 1:26:33them for memory safety violations.
  2367. 1:26:36So, if you need to do like some weird
  2368. 1:26:38ioctl or fcntl or setsockopt or some
  2369. 1:26:42weird stuff
  2370. 1:26:43to set up whatever thing you need to do
  2371. 1:26:46to or some weird memory mapped IO or
  2372. 1:26:49whatever,
  2373. 1:26:50you can do that in Phil C and it's
  2374. 1:26:51memory safe.
  2375. 1:26:53Um
  2376. 1:26:54and so like if if you're writing that
  2377. 1:26:57kind of low-level systems code and you
  2378. 1:26:59need to flip the switch and make it
  2379. 1:27:00memory safe today, then Phil C is going
  2380. 1:27:03to be the the thing that that's going to
  2381. 1:27:05let you do that.
  2382. 1:27:07Um
  2383. 1:27:08So, I think that's where that's where a
  2384. 1:27:09lot of the adopters are.
  2385. 1:27:11Um and probably that's where it'll kind
  2386. 1:27:13of grow out of.
  2387. 1:27:15Um but at the same time, what I want to
  2388. 1:27:17do is I want to create um an OS that you
  2389. 1:27:21can install eventually that has a web
  2390. 1:27:23browser that's memory safe cuz there's a
  2391. 1:27:25category of people out there who will
  2392. 1:27:28want to be able to browse the web
  2393. 1:27:30without having to worry about um some
  2394. 1:27:33government agency hacking them while
  2395. 1:27:35browsing the web. Um
  2396. 1:27:37and Phil C might be the only game in
  2397. 1:27:39town uh there as well.
  2398. 1:27:43Now, can we mention also like uh you're
  2399. 1:27:46you're you're keep mentioning that this
  2400. 1:27:48is the only game in town in terms of
  2401. 1:27:50software. There are other like
  2402. 1:27:52alternatives that try to do the same
  2403. 1:27:55thing-ish,
  2404. 1:27:56but
  2405. 1:27:58uh uh I think you even posted about them
  2406. 1:28:00on Twitter or something. So, can you can
  2407. 1:28:02you
  2408. 1:28:03roughly like say how to what's the
  2409. 1:28:05lookout in terms of like memory safety?
  2410. 1:28:07Because Rust is like a famous option.
  2411. 1:28:11Famous option for but we have memory
  2412. 1:28:12safety, so of course Rust. But uh others
  2413. 1:28:15are other projects that are trying to do
  2414. 1:28:17similar things.
  2415. 1:28:19Um
  2416. 1:28:20let's see. I think there's a couple of
  2417. 1:28:21categories. One is memory-safe
  2418. 1:28:23languages. There's lots of memory-safe
  2419. 1:28:26languages. Um you know, Go, uh Swift, um
  2420. 1:28:31uh Rust, obviously, uh C#, Java. Lots of
  2421. 1:28:34languages out there that are
  2422. 1:28:35memory-safe.
  2423. 1:28:37I think the comparison
  2424. 1:28:39uh to PhilC is as follows.
  2425. 1:28:42Most of those languages
  2426. 1:28:45achieve memory safety for the the stuff
  2427. 1:28:47that you write,
  2428. 1:28:49but strongly rely on linking against
  2429. 1:28:52memory-unsafe programs.
  2430. 1:28:54Um so, this is this is a problem that
  2431. 1:28:57plagues Rust and Swift and Go. Uh like
  2432. 1:29:00with Go, uh Docker is written in Go.
  2433. 1:29:02Great. You look at the stack of
  2434. 1:29:04libraries it links to, they're C
  2435. 1:29:05libraries. They're not memory-safe.
  2436. 1:29:07Rust, you have the uh pseudo RS port,
  2437. 1:29:11pseudo rewritten in Rust. It links to
  2438. 1:29:13PAM. PAM is written in C. Again,
  2439. 1:29:15memory-unsafe.
  2440. 1:29:17Um so, I think the comparison between
  2441. 1:29:19PhilC and a lot of the other approaches
  2442. 1:29:22is
  2443. 1:29:23uh just how fanatically far PhilC is is
  2444. 1:29:26taking it. Um I'm sort of saying
  2445. 1:29:29performance be damned. Um let's just
  2446. 1:29:31make the whole stack memory-safe all the
  2447. 1:29:33way down to the system call layer.
  2448. 1:29:36Um and
  2449. 1:29:37uh
  2450. 1:29:38other others are in this space aren't
  2451. 1:29:40thinking quite that aggressively.
  2452. 1:29:43Um
  2453. 1:29:44I think uh just to give a shout-out to
  2454. 1:29:46Go here, uh Go might might be the
  2455. 1:29:49closest to this in the sense that
  2456. 1:29:51there's a variant of Go where Go uh gets
  2457. 1:29:54rid of the C standard library entirely,
  2458. 1:29:56and you make sys calls directly from Go.
  2459. 1:30:00Um so, that's the closest uh thing to
  2460. 1:30:03PhilC out there. But Go isn't completely
  2461. 1:30:06memory-safe in the sense that there's
  2462. 1:30:08situations where race conditions and go
  2463. 1:30:10can be used as an escape hatch from the
  2464. 1:30:12type system. Um PhilC doesn't have like
  2465. 1:30:15a type system escape hatch if you race.
  2466. 1:30:17Um so again, like it's it
  2467. 1:30:21It it weirdly
  2468. 1:30:23uh this little project of mine has this
  2469. 1:30:27uh unique status of taking memory safety
  2470. 1:30:30further than these other projects have
  2471. 1:30:32taken it. Um now there's another class
  2472. 1:30:34of project which is other folks have
  2473. 1:30:36also had this idea of making C memory
  2474. 1:30:40safe.
  2475. 1:30:41Um
  2476. 1:30:41there's a ton of academic literature in
  2477. 1:30:43this space. I've read almost all of it.
  2478. 1:30:46I've read all all of it that I could
  2479. 1:30:47have read. Um probably the biggest
  2480. 1:30:50inspiration for what PhilC does comes
  2481. 1:30:52from
  2482. 1:30:53uh a project called C cured uh from the
  2483. 1:30:55early 2000s. Um
  2484. 1:30:58uh and from another project called
  2485. 1:31:00SoftBound uh from the like 10 years ago.
  2486. 1:31:04Um
  2487. 1:31:05The way that PhilC differs from those
  2488. 1:31:07projects is that those projects were
  2489. 1:31:10written in like a
  2490. 1:31:12like typical kind of thing that, you
  2491. 1:31:14know, folks working in academia want to
  2492. 1:31:16do.
  2493. 1:31:17Um they want to write a paper in which
  2494. 1:31:18they show benchmarks.
  2495. 1:31:20Um and they want to show a cool idea. So
  2496. 1:31:23in the case of SoftBound, they didn't
  2497. 1:31:25make the whole language memory safe.
  2498. 1:31:27They just showed that you can make the
  2499. 1:31:28pointer bounds memory safe. They didn't
  2500. 1:31:29have any solution for linking or
  2501. 1:31:31function calls.
  2502. 1:31:32They didn't have a solution for
  2503. 1:31:33threading in their original work. Um but
  2504. 1:31:36they had cool ideas about how to make
  2505. 1:31:38pointer bounds work.
  2506. 1:31:40Uh and the compiler as far as I can tell
  2507. 1:31:42is basically abandonware.
  2508. 1:31:44Um
  2509. 1:31:44it it you wouldn't have the same joyful
  2510. 1:31:47experience with SoftBound or with C
  2511. 1:31:50cured that you have with PhilC where you
  2512. 1:31:52download it, you try it, and it works.
  2513. 1:31:55Um
  2514. 1:31:56uh
  2515. 1:31:58And and by the way, this is one of the
  2516. 1:31:59reasons why with PhilC I sort of
  2517. 1:32:02let's defer the performance problem and
  2518. 1:32:04focus on compiling as much stuff as
  2519. 1:32:06possible cuz I have this feeling that if
  2520. 1:32:08you build a compiler by first focusing
  2521. 1:32:10on performance benchmarks and then
  2522. 1:32:11trying to make it reliable, then you'll
  2523. 1:32:13never make it reliable and no one will
  2524. 1:32:15use it. But if you start by making a
  2525. 1:32:16compiler from the standpoint of let's
  2526. 1:32:18make it reliable and then then add
  2527. 1:32:20performance later, then then you
  2528. 1:32:22actually have something compelling.
  2529. 1:32:25Um
  2530. 1:32:26Uh and then of course there's the
  2531. 1:32:27there's Cherry and other hardware
  2532. 1:32:29capability models which are similar
  2533. 1:32:32uh to Phil C in that they're based on
  2534. 1:32:33capabilities.
  2535. 1:32:35Um
  2536. 1:32:37but uh like let's look at Cherry in
  2537. 1:32:38detail, right? Uh the fastest Cherry
  2538. 1:32:42computer you can get
  2539. 1:32:45period
  2540. 1:32:46will run your C program slower
  2541. 1:32:50than your
  2542. 1:32:52x86 box will run your Phil C program
  2543. 1:32:54today,
  2544. 1:32:55right?
  2545. 1:32:57Just because of how like hardware
  2546. 1:32:59economics work. When you have a
  2547. 1:33:02something like Phil C that runs on stock
  2548. 1:33:04hardware x86,
  2549. 1:33:06um you get to benefit from the fact that
  2550. 1:33:08hardware made at high volume tends to
  2551. 1:33:10have high performance. Whereas if you
  2552. 1:33:13like first of all, buying of a Cherry
  2553. 1:33:15machine is very difficult. You have to
  2554. 1:33:17get an FPGA and flash it yourself. But
  2555. 1:33:19if you did that, you would end up with
  2556. 1:33:20something that will be slower than Phil
  2557. 1:33:22C despite the fact that it's getting the
  2558. 1:33:25hardware
  2559. 1:33:26acceleration.
  2560. 1:33:27Um and then on top of that, uh
  2561. 1:33:30uh
  2562. 1:33:31Casey, I want to hear your thoughts on
  2563. 1:33:33this cuz you're you're really grinning.
  2564. 1:33:35I'm confused cuz I I thought uh modern M
  2565. 1:33:38series like threes and fours now had
  2566. 1:33:41Cherry
  2567. 1:33:43uh style pointer tag checking
  2568. 1:33:46uh and that that they actually have that
  2569. 1:33:48in Apple's kernel now.
  2570. 1:33:50No, they have something called MIE.
  2571. 1:33:52Okay, so not the full like so so the
  2572. 1:33:56they only have the pointer tag check.
  2573. 1:33:59Or what you why don't you like let's
  2574. 1:34:00just turn this into a question. So yeah,
  2575. 1:34:02can you elaborate on like what the
  2576. 1:34:04differences are between those two?
  2577. 1:34:06Cherry and MIE or Cherry is a capability
  2578. 1:34:08model like Phil C. MIE and MTE are
  2579. 1:34:12really cool. I should mention them.
  2580. 1:34:15But what they what what they do is
  2581. 1:34:18uh
  2582. 1:34:18they do kind of an extended version of
  2583. 1:34:21what ASAN is doing, which is just a tag
  2584. 1:34:23memory. Yeah. What that means is if you
  2585. 1:34:26go out of bounds of an object into
  2586. 1:34:28another object,
  2587. 1:34:30it might let you access it.
  2588. 1:34:33And with MIE and MTE, the protection is
  2589. 1:34:36just that with high probability
  2590. 1:34:40uh 14 out of 15 times that you access
  2591. 1:34:43out of bounds,
  2592. 1:34:44uh you will get a trap. So what this
  2593. 1:34:46means is
  2594. 1:34:48um
  2595. 1:34:50if you're a determined attacker, you'll
  2596. 1:34:52try 15 times.
  2597. 1:34:55Um
  2598. 1:34:56and what it also means is that the
  2599. 1:35:00the economics
  2600. 1:35:02are now more in
  2601. 1:35:05slightly less in favor of the attacker.
  2602. 1:35:07Without MTE or MIE, an attacker can
  2603. 1:35:10craft an exploit and reuse it a whole
  2604. 1:35:12bunch of times, and it's not until they
  2605. 1:35:14use it like a lot that some threat
  2606. 1:35:17intelligence ser- center discovers that
  2607. 1:35:20the exploit is being used, and then the
  2608. 1:35:21bug gets fixed.
  2609. 1:35:23With MTE and MIE, if you went wide with
  2610. 1:35:26an exploit, then the the victim
  2611. 1:35:30operating system provider's crash
  2612. 1:35:32reporter would see a spike,
  2613. 1:35:34right? And so the the hope is that this
  2614. 1:35:38means that
  2615. 1:35:39the attacker has to has to invent new
  2616. 1:35:43exploits
  2617. 1:35:44more frequently.
  2618. 1:35:46Um
  2619. 1:35:47I think the jury's out on whether MTE
  2620. 1:35:50and MIE
  2621. 1:35:52are like very valuable or just a little
  2622. 1:35:54bit valuable, right? Because we're we're
  2623. 1:35:56in a we're in a situation where
  2624. 1:35:58simultaneously
  2625. 1:36:00LLMs are proving
  2626. 1:36:02extremely effective at finding bugs and
  2627. 1:36:04weaponizing them. So, we're
  2628. 1:36:06simultaneously seeing attackers that
  2629. 1:36:08favor the economics of the attacker.
  2630. 1:36:11Um
  2631. 1:36:12and so, like it might end up just being
  2632. 1:36:14a wash, right? Like MTE and MIE finds
  2633. 1:36:16the bug causes the bugs to be fixed more
  2634. 1:36:18quickly, LLMs cause the bugs to be found
  2635. 1:36:21more quickly and we're back to where we
  2636. 1:36:22started. Um
  2637. 1:36:25Historically, these raise the bar kinds
  2638. 1:36:27of mitigations like MTE and MIE
  2639. 1:36:30Uh when people talk about raise the bar
  2640. 1:36:31mitigations, they mean something that
  2641. 1:36:34doesn't actually completely prevent the
  2642. 1:36:36attacker from succeeding. They just it
  2643. 1:36:37just changes the economics. Those kinds
  2644. 1:36:39of things haven't prevented attackers
  2645. 1:36:43from being successful.
  2646. 1:36:45Um and so,
  2647. 1:36:47uh I think that's why
  2648. 1:36:50uh MTE and MIE are not going to be so
  2649. 1:36:54successful that we can all say, "Okay,
  2650. 1:36:56it's cool. We can just keep programming
  2651. 1:36:58in normal C++ cuz we've fixed memory
  2652. 1:37:00safety." Like I don't think we'll I
  2653. 1:37:01don't think they're that powerful. I
  2654. 1:37:03think it'll it's just it's just a
  2655. 1:37:06it just tweaks the economics a little
  2656. 1:37:07bit.
  2657. 1:37:08And so, can you contrast that with with
  2658. 1:37:10CHERI then? C H E R I for people who are
  2659. 1:37:13wondering what we're saying. Um can you
  2660. 1:37:15contrast like what what does CHERI
  2661. 1:37:17provide over and I guess I'll unpack a
  2662. 1:37:19little bit.
  2663. 1:37:20So, um
  2664. 1:37:21my my uh knowledge of which things go
  2665. 1:37:24with which ARM acronyms was clearly uh
  2666. 1:37:27a bit bad, but the ones that they have
  2667. 1:37:29in modern M-series chips uh
  2668. 1:37:32effectively, what it's doing is it's
  2669. 1:37:33using the fact that because people
  2670. 1:37:36generally aren't going to be using 64
  2671. 1:37:39bits of address space, but pointers are
  2672. 1:37:4164 bits.
  2673. 1:37:43Uh there's been many different schemes
  2674. 1:37:46where people use the upper bits of
  2675. 1:37:48pointers, the parts that you're not
  2676. 1:37:49going to need cuz you're not using a
  2677. 1:37:50full 64-bit address space, to do stuff.
  2678. 1:37:53And you know, these have been used by
  2679. 1:37:55garbage collectors or other sorts of VM
  2680. 1:37:57style things.
  2681. 1:37:59And so typically what they had uh in
  2682. 1:38:01hardware was the ability to just ignore
  2683. 1:38:04what those top bits were. This was the
  2684. 1:38:06the more typical thing. So, you could
  2685. 1:38:08have pointers and you wouldn't have to
  2686. 1:38:09mask off these extra bits at the top
  2687. 1:38:11that you were using to store whatever
  2688. 1:38:13you're storing in your program.
  2689. 1:38:15And that was all fine.
  2690. 1:38:17Uh with memory tagging extensions, MTE
  2691. 1:38:20in this case, uh effectively what they
  2692. 1:38:22were saying was, well,
  2693. 1:38:24what if we just used those top bits in
  2694. 1:38:27hardware now and allowed you to tag
  2695. 1:38:30allocations with some specific known
  2696. 1:38:33pattern of those top bits. Now, remember
  2697. 1:38:35there's not that many top bits here
  2698. 1:38:38because you still have a pretty big
  2699. 1:38:40address space. So, you're talking about,
  2700. 1:38:42you know, maybe eight bits or something
  2701. 1:38:43that in total that you can use or who
  2702. 1:38:45knows how many you're going to allocate
  2703. 1:38:46out to this.
  2704. 1:38:48And so the idea is when you do uh when
  2705. 1:38:51something like a kernel is partitioning
  2706. 1:38:53up memory and saying what it's going to
  2707. 1:38:54be used for, it can assign a specific
  2708. 1:38:57unique tag, in this case I believe it's
  2709. 1:38:59what a four-bit tag.
  2710. 1:39:01Um
  2711. 1:39:01you can assign a unique four-bit tag to
  2712. 1:39:03it,
  2713. 1:39:04not zero because zero was like specially
  2714. 1:39:06reserved and I think also not all ones,
  2715. 1:39:09right? There was a There's some weird
  2716. 1:39:11thing about this, but point being you
  2717. 1:39:13have some certain amount of that uh tag
  2718. 1:39:16space, you can tag it, and then your
  2719. 1:39:18pointers will also be tagged with that,
  2720. 1:39:20and every time you do a memory access,
  2721. 1:39:22it will look to see if the pointers tag
  2722. 1:39:24bits match what it thinks the tag bit
  2723. 1:39:27should be for that address range. So,
  2724. 1:39:28it's effectively tracking address ranges
  2725. 1:39:31as a thing in hardware and doing this
  2726. 1:39:34kind of correlation. And the reason that
  2727. 1:39:36uh I think Phil mentioned the like 14
  2728. 1:39:38out of 15, it's like, well,
  2729. 1:39:40you only have a limited amount of tags
  2730. 1:39:42to give out. If you're only talking
  2731. 1:39:44about four bits, there's only so many
  2732. 1:39:46tag permutations you can give out. And
  2733. 1:39:48so, if the memory that you happen to be
  2734. 1:39:51talking about legitimately, and the
  2735. 1:39:54memory that the attacker has
  2736. 1:39:55illegitimately moved the pointer to,
  2737. 1:39:57happens to have the same tag, well, the
  2738. 1:40:00check will still succeed. And so, you
  2739. 1:40:02won't really get the memory safety that
  2740. 1:40:04you wanted. As opposed to if you had
  2741. 1:40:06some huge tag space where, you know, if
  2742. 1:40:08it was
  2743. 1:40:09even 16 bits would probably be enough.
  2744. 1:40:11But if you imagine 32 bits of tag or
  2745. 1:40:13something, then they're never going to
  2746. 1:40:15have that accident happen.
  2747. 1:40:17So, that's basically what that what that
  2748. 1:40:20kind of memory tagging is about. So, can
  2749. 1:40:23you give us a little bit more
  2750. 1:40:24information on Cherry? Like, why is
  2751. 1:40:25Cherry better? Cuz I've I've not
  2752. 1:40:27actually looked into what that adds. Oh,
  2753. 1:40:29yeah. So, Cherry um is is a full
  2754. 1:40:33capability model. The idea is there's no
  2755. 1:40:36tag like like with MTE. Sorry.
  2756. 1:40:42The There There's things that you could
  2757. 1:40:44call tags, but they're not like the MTE
  2758. 1:40:46lock and key scheme. So, the the the the
  2759. 1:40:49term of art for what MTE does is lock
  2760. 1:40:52and key, because the idea is that your
  2761. 1:40:55pointer has the key, the four bits that
  2762. 1:40:58that that say like I think this is what
  2763. 1:41:00memory I should be able to access. And
  2764. 1:41:02then the lock is that each cache line
  2765. 1:41:06has behind the scenes somewhere these
  2766. 1:41:08four bits. And when whenever you access
  2767. 1:41:12a cache line, the pointer's high four
  2768. 1:41:14bits are checked against the cache
  2769. 1:41:15line's four bits.
  2770. 1:41:18With Cherry, what happens is that
  2771. 1:41:21uh
  2772. 1:41:22pointers become 128-bit.
  2773. 1:41:25Okay. Um and the pointer encoding is
  2774. 1:41:30something special. It's somewhere
  2775. 1:41:31there's there's the the actual pointer
  2776. 1:41:33you're pointing to, and then there's
  2777. 1:41:34some bounds. Uh similarly to how PhilC
  2778. 1:41:37pointers carry a capability.
  2779. 1:41:39Um and
  2780. 1:41:42uh there's additional instructions that
  2781. 1:41:44you have to use for for for pointer
  2782. 1:41:47operations, for capability operations.
  2783. 1:41:49It's not like on on x86 and on arm, you
  2784. 1:41:53can use the same instruction for adding
  2785. 1:41:55integers as for changing the offset of a
  2786. 1:41:57pointer because it's just an integer. On
  2787. 1:41:59Cherry, there's separate instructions
  2788. 1:42:01for those things. I think there's even a
  2789. 1:42:03separate register file for the
  2790. 1:42:05capabilities.
  2791. 1:42:06And when you store a 128-bit capability
  2792. 1:42:09into a memory location,
  2793. 1:42:12that memory location has a a single bit
  2794. 1:42:14behind the scenes that says, "Yes, the
  2795. 1:42:16thing stored here was a legitimate
  2796. 1:42:18capability."
  2797. 1:42:20And then if anyone stores an integer to
  2798. 1:42:22that memory location, the bit is
  2799. 1:42:23cleared, it becomes an illegitimate
  2800. 1:42:25capability. Then if you load a
  2801. 1:42:27capability from the heap and the bit was
  2802. 1:42:29set, then you get a capability that you
  2803. 1:42:31can then access.
  2804. 1:42:33So Cherry achieves
  2805. 1:42:36uh
  2806. 1:42:37all of what PhilC achieves minus the
  2807. 1:42:39use-after-free protections.
  2808. 1:42:41So if you use-after-free, you could see
  2809. 1:42:44some other object's contents.
  2810. 1:42:47Um
  2811. 1:42:47and then it it's uh there's an open
  2812. 1:42:50question of whether that's enough to
  2813. 1:42:52prevent weird execution or not because
  2814. 1:42:56if you use-after-free,
  2815. 1:42:58then you know, you still have a
  2816. 1:42:59capability that's restricting you to a
  2817. 1:43:01small range of of bytes in memory.
  2818. 1:43:04Um so in order for you to achieve weird
  2819. 1:43:06execution, the thing that lands in that
  2820. 1:43:09small range has to be useful to you
  2821. 1:43:11somehow.
  2822. 1:43:12Um
  2823. 1:43:12so open question of whether Cherry is
  2824. 1:43:15practically weaker than PhilC as opposed
  2825. 1:43:18to just theoretically weaker. Is I want
  2826. 1:43:22to say that like exploits have been
  2827. 1:43:24shown in the past that would fit that
  2828. 1:43:26category. Like I feel like sock puppet
  2829. 1:43:29may have been
  2830. 1:43:31a
  2831. 1:43:33just use after free. Like there was no
  2832. 1:43:35like it literally was just because an
  2833. 1:43:37object previously had, you know,
  2834. 1:43:40a particular capability and was slotted
  2835. 1:43:42into that slot, it it would not have
  2836. 1:43:44been protected unless it had use after
  2837. 1:43:46free. I could be wrong about that, but I
  2838. 1:43:48want to say that there have been some
  2839. 1:43:50exploits that
  2840. 1:43:51legitimately did just use use after
  2841. 1:43:53free, but I could be wrong. I remember
  2842. 1:43:55seeing something like this.
  2843. 1:43:57I think there have been, but um They
  2844. 1:43:59might be They're very rare probably, but
  2845. 1:44:01yeah.
  2846. 1:44:01>> Yeah, like 99.9,
  2847. 1:44:03maybe even five nines worth of use after
  2848. 1:44:06free exploits
  2849. 1:44:08are that um
  2850. 1:44:11the object you thought you were pointing
  2851. 1:44:12to has a pointer at offset eight. And
  2852. 1:44:15then the object you put in that place
  2853. 1:44:17after the use after free has an integer
  2854. 1:44:19at offset eight. And now from one part
  2855. 1:44:22of the pro program you get to read and
  2856. 1:44:23write integers from the other you're
  2857. 1:44:25using it as a pointer, and that gives
  2858. 1:44:27the attacker
  2859. 1:44:28the ability to access anything in memory
  2860. 1:44:30because they just control the pointer
  2861. 1:44:32value.
  2862. 1:44:33And that in Cherry would not be possible
  2863. 1:44:35because the moment that you
  2864. 1:44:37Got you.
  2865. 1:44:37>> wrote the integer into that location, it
  2866. 1:44:39clears the capability bit almost exactly
  2867. 1:44:41like what happens with Phil C. Um So it
  2868. 1:44:44might be fine because the use after free
  2869. 1:44:46the the the pathology of actual use
  2870. 1:44:49after free bugs never only uses the use
  2871. 1:44:52after free part
  2872. 1:44:54in practice or something like this.
  2873. 1:44:55Yeah, exactly.
  2874. 1:44:56Um but this is like a this is an an area
  2875. 1:45:00that's up for debate. Uh so the Cherry
  2876. 1:45:02folks um
  2877. 1:45:04I think one of the things that they did
  2878. 1:45:06that might have just been like a mistake
  2879. 1:45:08is rather than just going all in on
  2880. 1:45:11like, "Okay, this is what we provide and
  2881. 1:45:13this is as good as it gets and
  2882. 1:45:15there aren't enough of these weird kind
  2883. 1:45:17of use after free bugs that don't then
  2884. 1:45:20uh use pointer confusion for us to worry
  2885. 1:45:22about it and so end of story."
  2886. 1:45:24They started engineering this whole
  2887. 1:45:26thing where they have a whole system
  2888. 1:45:28hardware assisted garbage collector that
  2889. 1:45:30frees that clears the capabilities. And
  2890. 1:45:34so then the sales pitch to an operating
  2891. 1:45:36system vendor is like, "Hey, guess what?
  2892. 1:45:38You get to put a garbage collector in
  2893. 1:45:40your kernel." It's like
  2894. 1:45:42I mean, come on, right? Like No nobody
  2895. 1:45:45nobody wants that.
  2896. 1:45:47Um
  2897. 1:45:48uh
  2898. 1:45:49So, um and I think the the the current
  2899. 1:45:54uh like OS that they're building around
  2900. 1:45:56Cherry is not a conventional OS. It's an
  2901. 1:45:58OS that is all in on just the Cherry
  2902. 1:46:01capabilities with a whole system garbage
  2903. 1:46:04collector and no virtual memory. So, you
  2904. 1:46:06lose the virtual memory and you're just
  2905. 1:46:08using the capabilities, which is really
  2906. 1:46:10really weird. So, um
  2907. 1:46:13I think where Phil C has a benefit is
  2908. 1:46:15you don't have to change how you think
  2909. 1:46:16about the kernel or the boundary between
  2910. 1:46:18the kernel and userland. Um it just runs
  2911. 1:46:21on whatever kernel you have. Um doesn't
  2912. 1:46:24And And you don't have to get rid of
  2913. 1:46:25virtual memory. You still have virtual
  2914. 1:46:27memory as an additional layer of
  2915. 1:46:28protection.
  2916. 1:46:29Um
  2917. 1:46:31And the garbage collector is just per
  2918. 1:46:33process. So, each process gets decide
  2919. 1:46:35how it GC's itself.
  2920. 1:46:37Um
  2921. 1:46:39So,
  2922. 1:46:40And I think also there's technically
  2923. 1:46:42there isn't a
  2924. 1:46:45There's an announcement of an
  2925. 1:46:47announcement on the x86 side for
  2926. 1:46:49something like the MIE part, not the
  2927. 1:46:52Cherry part. They called it CheckTAG, c
  2928. 1:46:55h k t a g.
  2929. 1:46:58Am I correct Phil in in that no one has
  2930. 1:47:00actually put out any materials about
  2931. 1:47:03when what exactly this might be or when
  2932. 1:47:06it's coming or have we actually received
  2933. 1:47:08I I I saw things where they were like,
  2934. 1:47:10"We're going to maybe do this." But then
  2935. 1:47:13I haven't seen anything about what it
  2936. 1:47:14will actually be. Although it sounded
  2937. 1:47:16like it was going to be like an MIE
  2938. 1:47:17thing.
  2939. 1:47:18Uh yeah, there's no details uh that I've
  2940. 1:47:20seen officially
  2941. 1:47:23um
  2942. 1:47:24Yeah, the announcement was really weird
  2943. 1:47:25in that it was like
  2944. 1:47:27a lot of bug work. Um
  2945. 1:47:30Uh
  2946. 1:47:31but from uh from all of the the research
  2947. 1:47:34that I've done on it and asking people
  2948. 1:47:36about it, it sounds like it is it is uh
  2949. 1:47:39it is basically an MTE. Uh so it has the
  2950. 1:47:43same property as MTE that uh a a
  2951. 1:47:46determined [clears throat] attacker who
  2952. 1:47:48tries enough times will get through. Oh,
  2953. 1:47:50and I should point out another problem
  2954. 1:47:51with MTE, which is that if the attacker
  2955. 1:47:54has a way of systematically guessing
  2956. 1:47:56what tag you have, then they just win
  2957. 1:47:58every time.
  2958. 1:47:59Um so one of the big concerns with MTE
  2959. 1:48:02is if you combine a classical exploit
  2960. 1:48:04with Spectre
  2961. 1:48:06to snoop on what bits are in memory,
  2962. 1:48:09then the attacker can work out exactly
  2963. 1:48:11what tags are in what pointers, and then
  2964. 1:48:14when the attacker does their
  2965. 1:48:16out-of-bounds write or whatever type
  2966. 1:48:17confusion and puts whatever pointer they
  2967. 1:48:19want in there, they will know what tag
  2968. 1:48:22to use, and then they beat MTE every
  2969. 1:48:23single time.
  2970. 1:48:25Um so I think I think
  2971. 1:48:27uh
  2972. 1:48:29Yeah, there's a as a C++ programmer, I
  2973. 1:48:31wish something like MTE was the just the
  2974. 1:48:34story because then I could just go back
  2975. 1:48:37to programming in C++ and not worry
  2976. 1:48:38about this stuff anymore.
  2977. 1:48:40But I I actually think that uh MTE
  2978. 1:48:44it is a weak enough story that it'll
  2979. 1:48:46keep the PhilC thing in business.
  2980. 1:48:49>> [laughter]
  2981. 1:48:51>> I I like that you you want to you want
  2982. 1:48:53to be done with PhilC. Like you wanted
  2983. 1:48:55to make sure that it's not possible. It
  2984. 1:48:57was possible. Now you need to optimize
  2985. 1:48:59it. You need to compile fix. Like that's
  2986. 1:49:01it's such so much work, man. And like
  2987. 1:49:03you need to do it because like the whole
  2988. 1:49:05damn thing is possible. Like that's the
  2989. 1:49:07that's the problem.
  2990. 1:49:08And on the MTE side of things
  2991. 1:49:13for me as a sort of outsider, I I like
  2992. 1:49:15it's a bit of a weird security
  2993. 1:49:18system that like if you're a determinant
  2994. 1:49:21determinant attacker, you still get
  2995. 1:49:24through it. It's like what what kind of
  2996. 1:49:26security guarantees you get? If you
  2997. 1:49:29really want to do it, you're going to do
  2998. 1:49:31it.
  2999. 1:49:32It is a little bit weird because
  3000. 1:49:35it's
  3001. 1:49:38it's kind of only bulletproofing the
  3002. 1:49:40sorts of code that only really
  3003. 1:49:43determined hackers are targeting anyway.
  3004. 1:49:46Like your people who are generally doing
  3005. 1:49:48exploits or like sending fishing emails
  3006. 1:49:50or just like calling people on the phone
  3007. 1:49:52and getting them to get you know like
  3008. 1:49:54like the ways that people practically
  3009. 1:49:55get into systems a lot of times don't
  3010. 1:49:57require
  3011. 1:49:59>> don't require Spectre and Meltdown,
  3012. 1:50:01right? Like those are not the common
  3013. 1:50:02exploits that people actually do. So
  3014. 1:50:04when you're talking about this level of
  3015. 1:50:06kind of like bulletproofing, you're you
  3016. 1:50:09are often talking I assume about only
  3017. 1:50:11really sophisticated actors anyway. So
  3018. 1:50:13yeah, I mean it it doesn't bode well for
  3019. 1:50:15something that's only about memory
  3020. 1:50:17tagging, but
  3021. 1:50:18I'm assuming their idea is just like
  3022. 1:50:20well, the more protection the better and
  3023. 1:50:22this was something we could do
  3024. 1:50:24relatively cheaply as as compared you
  3025. 1:50:27know, in hardware.
  3026. 1:50:28Adding a few extra bits per cache line
  3027. 1:50:30of this tagging is not the end of the
  3028. 1:50:32world.
  3029. 1:50:33Whereas doing something more substantial
  3030. 1:50:36is. So I guess they were just hoping
  3031. 1:50:39relatively low implementation cost
  3032. 1:50:43possibly stopping some exploits. I don't
  3033. 1:50:45know.
  3034. 1:50:46I just want to give a shout out to my
  3035. 1:50:48friends at Apple who worked on this.
  3036. 1:50:50Like the
  3037. 1:50:51>> [laughter]
  3038. 1:50:52>> like
  3039. 1:50:53Yeah, I mean
  3040. 1:50:55the reason why it's a good idea is if
  3041. 1:50:58you're if you're making if you're
  3042. 1:51:00selling iPhones or whatever something
  3043. 1:51:02um there's going to be a it's already
  3044. 1:51:05the case that it's very expensive to to
  3045. 1:51:07build an exploit against an iPhone. It's
  3046. 1:51:09like
  3047. 1:51:11million bucks or something to to to
  3048. 1:51:13build one of these exploits. So,
  3049. 1:51:17the script kiddie down the street isn't
  3050. 1:51:18going to be doing it. And if he was
  3051. 1:51:20doing it, you'd know because he'd have
  3052. 1:51:22like a garage full of Lamborghinis. So,
  3053. 1:51:25um
  3054. 1:51:26So, the the point here is
  3055. 1:51:30to
  3056. 1:51:31to keep making it more expensive for the
  3057. 1:51:36folks building these exploits. The more
  3058. 1:51:38expensive you make it, the less of them
  3059. 1:51:40you have. Right? Like because it's
  3060. 1:51:43already a million bucks to build one of
  3061. 1:51:45these exploits, if I know that if I'm
  3062. 1:51:47using an iPhone, cuz I'm not that
  3063. 1:51:49important of a human being, it's not
  3064. 1:51:51going to be worth it for somebody to try
  3065. 1:51:53to attack me. Now, if it is the case
  3066. 1:51:57that you build a million-dollar exploit
  3067. 1:51:59and then you get to scan it, right? You
  3068. 1:52:02get to reuse it on many many many
  3069. 1:52:05people, then the cost amortizes.
  3070. 1:52:08So, sure it cost me a million dollars to
  3071. 1:52:09make the exploit, but once I make it, I
  3072. 1:52:11can just keep reusing it. So, how do you
  3073. 1:52:13get to the point where
  3074. 1:52:15uh
  3075. 1:52:16like if if I was if I put my my like I
  3076. 1:52:19used to work at Apple hat on, the
  3077. 1:52:21thinking is
  3078. 1:52:22like how do you get to the point where
  3079. 1:52:25it costs a million dollars per use?
  3080. 1:52:30Uh okay.
  3081. 1:52:31>> Right? And the the key thing is that if
  3082. 1:52:35uh if if you combine that with the fact
  3083. 1:52:38that Apple Apple tends to make software
  3084. 1:52:40that's like reasonably stable, then
  3085. 1:52:42well, this is the part where it's the
  3086. 1:52:43gotcha, right? The hope is like imagine
  3087. 1:52:46if your code is actually stable and
  3088. 1:52:48you've got your crash reporter, someone
  3089. 1:52:51uh deploys an exploit against somebody,
  3090. 1:52:53they're going to have to try 15 times.
  3091. 1:52:56Um you're going to get 15 crashes all in
  3092. 1:52:59the same place within a short period of
  3093. 1:53:02time. That's a pretty good signal that
  3094. 1:53:04you've got a bug there.
  3095. 1:53:06Um and fixing bugs, if you know where
  3096. 1:53:09the bug is isn't that hard. Like the
  3097. 1:53:12economics for the defender are only bad
  3098. 1:53:14because there's bugs you just don't know
  3099. 1:53:16about so you don't know to go and fix
  3100. 1:53:18them.
  3101. 1:53:19Um, so the the thing that MTE might
  3102. 1:53:24achieve for someone like Apple is that
  3103. 1:53:27it's not a million dollars and then you
  3104. 1:53:29use it a bunch of times but it's a
  3105. 1:53:31million dollars per use.
  3106. 1:53:33Uh, now there's lots of reasons to
  3107. 1:53:35believe that that's not what it
  3108. 1:53:36achieves. One, the thing that I talked
  3109. 1:53:39about with Spectre or other ways of
  3110. 1:53:41systematically guessing the tag. Two, um
  3111. 1:53:45I bet you that the typical thing that's
  3112. 1:53:48being attacked on my Apple device
  3113. 1:53:50crashes enough times as background noise
  3114. 1:53:52already
  3115. 1:53:54>> [laughter]
  3116. 1:53:54>> mismatches aren't going to show up as a
  3117. 1:53:56significant outlier.
  3118. 1:54:01Um [clears throat]
  3119. 1:54:02Uh, and then uh, the there's other
  3120. 1:54:05there's other problems with MTE when you
  3121. 1:54:07really drill into the into the into the
  3122. 1:54:09details. Um
  3123. 1:54:12So I think it's it it
  3124. 1:54:14it's it's really an open question
  3125. 1:54:18whether this will be a a game changer or
  3126. 1:54:21not and it's too soon to tell cuz it's
  3127. 1:54:23only been shipping for a short amount of
  3128. 1:54:24time.
  3129. 1:54:27Okay. Okay. And I mean presumably though
  3130. 1:54:30uh
  3131. 1:54:31is the background crashing thing really
  3132. 1:54:33part of the concern though because uh
  3133. 1:54:35presumably an MTE crash has its own
  3134. 1:54:39particular exception code so you know
  3135. 1:54:41when someone
  3136. 1:54:43had an had a tag mismatch
  3137. 1:54:46versus not. Okay, but your your
  3138. 1:54:49background of crashes are going to have
  3139. 1:54:51be hitting MTE
  3140. 1:54:51>> Those two. Okay. too, right? So cuz
  3141. 1:54:54Well, that that may be yeah. Yeah, like
  3142. 1:54:56>> Okay, yeah. Just from people just
  3143. 1:54:58sucking at what at the at the that at
  3144. 1:55:00the kernel usage or whatever, yeah. Or
  3145. 1:55:02sucking at writing user level whatever,
  3146. 1:55:05right? And the thing is that MTE
  3147. 1:55:07increases your crash rate because
  3148. 1:55:09there's some amount of memory safety
  3149. 1:55:11bugs that happen,
  3150. 1:55:14but the process keeps running.
  3151. 1:55:16Right? Cuz you happen to hit on a page
  3152. 1:55:18that was mapped. Now those crashes
  3153. 1:55:21become MTE crashes.
  3154. 1:55:23So you actually have the the background
  3155. 1:55:26noise level, I would imagine,
  3156. 1:55:29goes up.
  3157. 1:55:31So if I was an attacker, I would
  3158. 1:55:34probably be thinking about like how do I
  3159. 1:55:36hide in that noise?
  3160. 1:55:38Yep.
  3161. 1:55:39That makes sense.
  3162. 1:55:41Okay.
  3163. 1:55:43Then I think we're nearing the end of
  3164. 1:55:44the interview. I have last last like
  3165. 1:55:47open question.
  3166. 1:55:50Right now FilC is like 0.6
  3167. 1:55:5367 version. 67 is a meme now for kids,
  3168. 1:55:56so but it like it it happened, you know,
  3169. 1:55:58like
  3170. 1:55:59but it's 0.67.
  3171. 1:56:02What do you see long-term? And we talked
  3172. 1:56:05a bit like what what would be the the
  3173. 1:56:07next step? Like was it optimization? Is
  3174. 1:56:08it more more programs compiling? What do
  3175. 1:56:11you see
  3176. 1:56:12it happening in the future? Like do you
  3177. 1:56:14see making it into 1.0 proper product
  3178. 1:56:18and like, you know, starting a business
  3179. 1:56:20around it in in couple of years? Like
  3180. 1:56:21what's
  3181. 1:56:22what's the long-term plan? How do you
  3182. 1:56:24see the future might unfold for for
  3183. 1:56:27FilC?
  3184. 1:56:29I think that
  3185. 1:56:30what I'm hoping for
  3186. 1:56:32is the number of users keeps going up
  3187. 1:56:35and the number of contributors keeps
  3188. 1:56:37going up to the point where I'm just no
  3189. 1:56:39longer the bottleneck.
  3190. 1:56:41And if if that if that were to happen,
  3191. 1:56:45that it's like it's own independent
  3192. 1:56:47thing where like
  3193. 1:56:49like I get to maybe still be part of it,
  3194. 1:56:51but there's other people who are working
  3195. 1:56:53on making it better and other people
  3196. 1:56:55using it, then that would be just
  3197. 1:56:57absolutely the coolest thing ever.
  3198. 1:57:00How can people like let's plug that a
  3199. 1:57:02little bit? For people who are
  3200. 1:57:04interested in compilers and have some
  3201. 1:57:05experience with compilers, who might
  3202. 1:57:07want to help out in something like this,
  3203. 1:57:09where is it at? I assume there's the
  3204. 1:57:11Phil C GitHub somewhere or something
  3205. 1:57:13that you can go to to look at or That's
  3206. 1:57:15exactly right. You can go on the GitHub
  3207. 1:57:17and there's a bunch of issues that I
  3208. 1:57:19filed that describe
  3209. 1:57:22in some cases in great detail
  3210. 1:57:24optimizations that I want to do.
  3211. 1:57:26Um so if you're a if if you like LLVM IR
  3212. 1:57:30hacking
  3213. 1:57:31and you know how to do that,
  3214. 1:57:33um then this is like a really fun
  3215. 1:57:35playground.
  3216. 1:57:37Um probably the easiest bug up for the
  3217. 1:57:40taking is one about um how to make
  3218. 1:57:43direct function calls not involve the
  3219. 1:57:46getter indirection and not involve the
  3220. 1:57:48passing through the heap stuff, but just
  3221. 1:57:49using native ABI.
  3222. 1:57:51Like that's
  3223. 1:57:52probably a a large speed up.
  3224. 1:57:55Um
  3225. 1:57:55>> I bet.
  3226. 1:57:56>> Yeah. And and like uh I have multiple
  3227. 1:57:58bugs describing multiple different ways
  3228. 1:58:00of getting there. So if someone likes
  3229. 1:58:03thinking about this kind of stuff,
  3230. 1:58:05um come on by, join the party. Um
  3231. 1:58:08I'm I'm happy to accept contributions
  3232. 1:58:10from people who are unsure or new to the
  3233. 1:58:13space. Uh it's fun to just talk about
  3234. 1:58:15compilers and think through this stuff.
  3235. 1:58:17Um
  3236. 1:58:18so uh yeah, just come and join and have
  3237. 1:58:21some fun hacking compilers with me.
  3238. 1:58:23So Phil C on GitHub, there's also a
  3239. 1:58:26website on Phil C. When uh there's a lot
  3240. 1:58:29of materials on how it does work, we can
  3241. 1:58:31download the the distribution of the
  3242. 1:58:33compiler, right? And then you have also
  3243. 1:58:35social media, where can people follow
  3244. 1:58:36your work?
  3245. 1:58:38Uh I it's all on on x.com is the is the
  3246. 1:58:41social media. I've sort of focused it
  3247. 1:58:43there so that you get to see it all in
  3248. 1:58:45one place. And then of course there's
  3249. 1:58:47the Discord. So you can join the Discord
  3250. 1:58:49and and and join the conversation in
  3251. 1:58:51there. And there's a link to the Discord
  3252. 1:58:52from the website.
  3253. 1:58:54All right. Perfect. Fe thank you so much
  3254. 1:58:58for joining me.
  3255. 1:58:59>> Thanks Casey for showing also showing up
  3256. 1:59:02>> pleasure. I I I learned a lot. Like I I
  3257. 1:59:04love Phil C and I I'm really interested
  3258. 1:59:06in such an interesting project to me and
  3259. 1:59:08uh
  3260. 1:59:09I hope to see it much as as Phil I I
  3261. 1:59:11hope to see it continue in like a uh
  3262. 1:59:14uh as people start making optimizations
  3263. 1:59:16to it and it becomes easier and easier
  3264. 1:59:17to just kind of slipstream in cuz I feel
  3265. 1:59:19like there's a lot of low-hanging fruit.
  3266. 1:59:21Tools like things like sudo and stuff
  3267. 1:59:23like that are great examples of like
  3268. 1:59:26these
  3269. 1:59:27are prime for getting recompiled in a
  3270. 1:59:29memory-safe language. They're not
  3271. 1:59:30performance-critical. They're security,
  3272. 1:59:33you know, nightmares a lot of the time.
  3273. 1:59:35And so like I would love to see it catch
  3274. 1:59:37on as as just a standard thing we do to
  3275. 1:59:38a bunch of utilities, right? So.
  3276. 1:59:43Perfect.

About this transcript

This page contains the full transcript of How Fil-C Works by Wookash Podcast, generated from the public captions YouTube serves with the video. The transcript has 19,927 words across 3,276 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.