LLVM

共 8 篇文章。

C++ 中的 main 定义

• Development

新的 C++ 标准中 不允许给 main 指定 linkage-specification 了。

当然,考虑到原本 main() 也是 C 运行环境在开始运行程序的时候调用的,而 C 运行环境自然也预期 C linkage,即不按照 C++ 的习惯对符号根据参数增加名字前缀,因此大部分编译器在遇到 C++ 程序定义全局 main() 的时候也会按照习惯采取 C linkage方式去翻译。这一规则首先被 GCC 采纳,随后 LLVM 也跟进了。

阅读全文… ( 本文约 395 字,阅读大致需要 1 分钟 )

clang优化器的一个问题

• Development

📜 历史文件已不具备现实意义

今天的一个偶然的发现。FreeBSD clang version 3.6.1 (tags/RELEASE_361/final 237755) 20150525。clang 3.8 2015/07/20 的版本同样有此问题。

之前, FreeBSD 上 strndup(3) 的实现是这样的:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
char *
strndup(const char *str, size_t n)
{
	size_t len;
	char *copy;

	len = strnlen(str, n);
	if ((copy = malloc(len + 1)) == NULL)
		return (NULL);
	memcpy(copy, str, len);
	copy[len] = '\0';
	return (copy);
}

而 OpenBSD 上的实现,则是这样的:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
char *
strndup(const char *str, size_t maxlen)
{
	char *copy;
	size_t len;

	len = strnlen(str, maxlen);
	copy = malloc(len + 1);
	if (copy != NULL) {
		(void)memcpy(copy, str, len);
		copy[len] = '\0';
	}

	return copy;
}
阅读全文… ( 本文约 304 字,阅读大致需要 1 分钟 )

clang静态分析工具作弊条

• Development

📜 历史文件已不具备现实意义

文章介绍的是旧版 clang 的用法。

静态分析是一种辅助的代码品质提高手段,简而言之静态分析大致是走一个类似编译的过程(或者走完生成副产品),然后给出代码中可能存在的问题。

阅读全文… ( 本文约 437 字,阅读大致需要 1 分钟 )

FreeBSD CLang/LLVM项目终于进svn了

• Development

如题。

不过这一次因为-CURRENT code slush的缘故,应该不会在 8.0-CURRENT 里面引入了(Ed在svn里面建立了另一个branch来做)。我想从各方面考虑,9.0-RELEASE里面正式砍掉gcc那一套东西应该不会是很困难的事情。传统上 FreeBSD 的代码用到了很多gcc的扩展,因此可能还需要一段时间。

阅读全文… ( 本文约 197 字,阅读大致需要 1 分钟 )

LLVM: 为什么你需要关注这个项目

• Development

LLVM 是 Illinois 大学发起的一个开源项目,它到底是什么呢?从字面上看,它是一个虚机系统,然而这又和之前为大家所熟知的 JVM 以及 .net Runtime 这样的虚机不同,它提供了一套中立的中间代码和编译基础设施,并围绕这些设施提供了一套全新的编译策略(使得优化能够在编译、连接、运行环境执行过程中,以及安装之后以有效的方式进行)和其他一些非常有意思的功能。

为什么这个项目很重要呢?对于普通的开发人员来说,LLVM计划提供了越来越多的可以使用、编译器以外的其他工具。例如代码静态检查工具 LLVM/Clang Static Analyzer,是一个 Clang 的子项目,能够使用同样的 Makefile 生成 HTML 格式的分析报告;而对关注编译技术的开发人员来说,LLVM提供了很多优点:

阅读全文… ( 本文约 725 字,阅读大致需要 2 分钟 )

GCC运行环境豁免条款再次狠狠地打了苹果的耳光

• Development

今年 1 月 27 日发表的 《GCC运行环境豁免条款 (英文版)》 再次狠狠地打了苹果的耳光。

原先的豁免条款如下:

// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.

阅读全文… ( 本文约 549 字,阅读大致需要 2 分钟 )

Progress on LLVM clang

• Development

As some of you already know, FreeBSD, along with some other Open Source projects, is moving away from GCC due to GPLv3. From a technology perspective, this also makes sense since the (likely) candidate, BSD-style licensed, LLVM based clang, a C compiler, is making reasonably good progress.

So, what should we expect from LLVM or clang?

Here is a good comparison between GCC and clang. Despite GCC is popular, considerably more mature, and supports more languages (especially C++, which clang’s support is incomplete at this moment), clang provides cleaner AST (Abstract Syntax Tree), much more modularized (if you take a look at GCC’s history, Richard Stallman intentionally made GCC’s code not reusable in other software), provided much more information for optimizer, is much faster and use much less memory, etc.

For FreeBSD, currently, clang can compile its kernel with only very few tweaks.

阅读全文… ( 本文约 315 字,阅读大致需要 2 分钟 )