<story><title>C Runtime Overhead (2015)</title><url>http://ryanhileman.info/posts/lib43</url></story><parent_chain><item><author>josefx</author><text>&amp;gt; I happened to run strace -tt against my solution (which provides microsecond-accurate timing information for syscalls)&lt;p&gt;Weirdly I always found the timing results of strace at under one millisecond generally unreliable, it just seemed to add too much overhead itself.&lt;p&gt;Also making system calls from your own code varies between prohibited and badly supported on most OSes. Some see calls that didn&amp;#x27;t pass through the system libc as a security issue and will intercept them, while Linux may just silently corrupt your process memory if you try something fancy as the Go team had to find out.</text></item></parent_chain><comment><author>scottlamb</author><text>josefx&amp;gt; Also making system calls from your own code varies between prohibited and badly supported on most OSes. Some see calls that didn&amp;#x27;t pass through the system libc as a security issue and will intercept them, while Linux may just silently corrupt your process memory if you try something fancy as the Go team had to find out.&lt;p&gt;On Linux, making syscalls directly is fine. Good point about other platforms, but many people only care about Linux, for better or worse. And the author&amp;#x27;s last paragraph (quoted below) suggests using an alternate&amp;#x2F;static-linking-friendly libc, not making direct syscalls yourself. Presumably on platforms where those alternate libcs aren&amp;#x27;t available, you continue using the standard libc.&lt;p&gt;ryanhileman&amp;gt; If you&amp;#x27;re running into process startup time issues in a real world scenario and ever actually need to do this, it might be worth your time to profile and try one of the alternative libc implementations (like musl libc or diet libc).&lt;p&gt;IMHO, the Go vDSO problem [1] wasn&amp;#x27;t due to making direct syscalls but basically calling a userspace library without meeting its assumptions. I&amp;#x27;d describe Linux&amp;#x27;s vDSO as a userspace library for making certain syscalls with less overhead. (If you don&amp;#x27;t care about the overhead, you can call them as you&amp;#x27;d call any other syscall instead.) It assumed the standard ABI, in which there&amp;#x27;s a guard page as well as typically a generous amount of stack to begin with. Golang called into it from a thread that used Go&amp;#x27;s non-standard ABI with less stack space available (Go&amp;#x27;s own functions check the stack size on entry and copy the stack if necessary) and no guard page. On some Linux builds (with -fstack-check, apparently used by Gentoo Hardened ), it actually used enough stack to overflow. Without a guard page, that caused memory corruption.&lt;p&gt;[1] &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;golang&amp;#x2F;go&amp;#x2F;issues&amp;#x2F;20427&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;github.com&amp;#x2F;golang&amp;#x2F;go&amp;#x2F;issues&amp;#x2F;20427&lt;/a&gt;</text></comment>
<story><title>C Runtime Overhead (2015)</title><url>http://ryanhileman.info/posts/lib43</url></story><parent_chain><item><author>josefx</author><text>&amp;gt; I happened to run strace -tt against my solution (which provides microsecond-accurate timing information for syscalls)&lt;p&gt;Weirdly I always found the timing results of strace at under one millisecond generally unreliable, it just seemed to add too much overhead itself.&lt;p&gt;Also making system calls from your own code varies between prohibited and badly supported on most OSes. Some see calls that didn&amp;#x27;t pass through the system libc as a security issue and will intercept them, while Linux may just silently corrupt your process memory if you try something fancy as the Go team had to find out.</text></item></parent_chain><comment><author>mananaysiempre</author><text>Umm, what’s the story with Go on Linux? My understanding is that Linux explicitly supports making syscalls from your own code, it’s just that on platforms where the syscall story is a giant mess (32-bit x86) the prescription is to either use the slow historical interface (INT 80h) or to jump to the vDSO (which will do SYSENTER or SYSCALL or whatever—SYSENTER in particular has the lovely property of &lt;i&gt;not saving the return address&lt;/i&gt;, so a common stub is pretty much architecturally required[1]).&lt;p&gt;If I’m guessing correctly about what you’re referring to, the Go people did something in between, got broken in a Linux kernel release, complained at the kernel people, the kernel got a patch to unbreak them. The story on MacOS or OpenBSD, where the kernel developers will cheerfully tell you to take a hike if you make a syscall yourself, seems much worse to me.&lt;p&gt;(And yes, I’d say there &lt;i&gt;is&lt;/i&gt; a meaningful difference between a couple of instructions in the vDSO and Glibc’s endless wrappers.)&lt;p&gt;[1]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;lore.kernel.org&amp;#x2F;lkml&amp;#x2F;Pine.LNX.4.44.0212172225410.1368-100000@home.transmeta.com&amp;#x2F;&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;lore.kernel.org&amp;#x2F;lkml&amp;#x2F;Pine.LNX.4.44.0212172225410.136...&lt;/a&gt;&lt;p&gt;ETA: Wait, no, I was thinking about the Android breakage[2]. What’s the Go story then?&lt;p&gt;[2]: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;git.kernel.org&amp;#x2F;pub&amp;#x2F;scm&amp;#x2F;linux&amp;#x2F;kernel&amp;#x2F;git&amp;#x2F;tip&amp;#x2F;tip.git&amp;#x2F;commit&amp;#x2F;?id=30bfa7b3488bfb1bb75c9f50a5fcac1832970c60&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;git.kernel.org&amp;#x2F;pub&amp;#x2F;scm&amp;#x2F;linux&amp;#x2F;kernel&amp;#x2F;git&amp;#x2F;tip&amp;#x2F;tip.git&amp;#x2F;...&lt;/a&gt;</text></comment>