Menu

📰
177

Memory Safe Inline Assembly

Hacker News·Memory Safe Inline Assembly·3 months ago
#EMC761Yz
Reading 0:00
15s threshold

NOTE: This is a pre-release feature. The Fil-C 0.679 release does not ship with this feature. To test this feature, you need to build from source . GCC and clang both support an incredibly powerful inline assembly syntax. For example: unsigned rotate(unsigned x, unsigned char c) { asm("roll %1, %0" : "+r"(x) : "c"(c) : "cc"); return x; } Instructs the compiler to emit assembly based on the roll %1, %0 template, where %1 is filled in with %cl , %0 is filled in with whichever register holds x , and c is moved into the %ecx register just before the roll instruction. Additionally, the compiler is told that the instruction will change the value of x and change the value of control flags. This seems like it cannot possibly be safe! What if the programmer did something wrong, like omitted the + in "+r" , or forgot the the "cc" clobber? In Yolo-C, if you make such a mistake, the compiler happily miscompiles your code in those cases. Yet Fil-C supports this inline assembly syntax and it's completely safe!…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More