论文标题
破坏类型的安全性:关于不安全包装的使用的实证研究
Breaking Type Safety in Go: An Empirical Study on the Usage of the unsafe Package
论文作者
论文摘要
首次发行后的十年,GO编程语言已成为开发格局中主要的编程语言。尽管以其清洁的语法和类似C的性能而受到称赞,但GO还包含一个强大的静态类型系统,可防止任意类型的铸造和任意内存访问,从而通过设计使语言类型安全。但是,为了为开发人员提供实施低级代码的可能性,使用一个名为不安全的特殊软件包的GO船,为开发人员提供了GO程序类型的方式。该软件包为开发人员提供了更大的灵活性,但具有更高的运行时错误风险,不通用性的机会以及对未来版本的GO的兼容性保证的丢失。 在本文中,我们介绍了关于2,438个受欢迎的GO项目中不安全包装使用的首次大规模研究。我们的调查表明,不安全是在24%的GO项目中使用的,主要是通过与操作系统和C代码进行通信,但也通常用作绩效优化的来源。开发人员愿意使用不安全的语言规格(例如,字符串不变性),以提高性能,而使用不安全的分析项目进行了不安全的指针转换,这可能会导致程序崩溃和意外行为。此外,我们报告了使用不安全的项目所面临的一系列实际问题,从崩溃错误和非确定性行为到将其部署限制在某些流行环境中。我们的发现可以用来了解开发人员如何以及为什么在GO中破坏类型安全,并有助于激励进一步的工具和语言开发,从而使GO中不安全的使用更加安全。
A decade after its first release, the Go programming language has become a major programming language in the development landscape. While praised for its clean syntax and C-like performance, Go also contains a strong static type-system that prevents arbitrary type casting and arbitrary memory access, making the language type-safe by design. However, to give developers the possibility of implementing low-level code, Go ships with a special package called unsafe that offers developers a way around the type-safety of Go programs. The package gives greater flexibility to developers but comes at a higher risk of runtime errors, chances of non-portability, and the loss of compatibility guarantees for future versions of Go. In this paper, we present the first large-scale study on the usage of the unsafe package in 2,438 popular Go projects. Our investigation shows that unsafe is used in 24% of Go projects, motivated primarily by communicating with operating systems and C code, but is also commonly used as a source of performance optimization. Developers are willing to use unsafe to break language specifications (e.g., string immutability) for better performance and 6% of analyzed projects that use unsafe perform risky pointer conversions that can lead to program crashes and unexpected behavior. Furthermore, we report a series of real issues faced by projects that use unsafe, from crashing errors and non-deterministic behavior to having their deployment restricted from certain popular environments. Our findings can be used to understand how and why developers break type-safety in Go, and help motivate further tools and language development that could make the usage of unsafe in Go even safer.