llvm

gcc vs. clang: symbol stripping

烈酒焚心 提交于 2019-12-10 02:21:10
问题 gcc and AMD Open64 opencc both have a -s option to "strip symbol table and relocation information". So far I haven't been able to find the same option in Clang/LLVM. Does it exist? 回答1: You can use a strip utility from binutils. Actually, a llvm-ld has this options http://llvm.org/cmds/llvm-ld.html -strip-all, -s Strip all debug and symbol information from the executable to make it smaller. -strip-debug, -S Strip all debug information from the executable to make it smaller. opt have something

How to clone or create an AST Stmt node of clang?

无人久伴 提交于 2019-12-10 00:43:17
问题 I want to modify the AST by clang LibTooling. How can I clone an AST node or add a new one, e.g. I'd like to create a BinaryOperator with ADD opcode 回答1: Creating new AST nodes is quite cumbersome in Clang, and it's not the recommended way to use libTooling. Rather, you should "read" the AST and emit back code, or code changes (rewritings, replacements, etc). See this article and other articles (and code samples) linked from it for more information on the right way to do this. 回答2: Some of

iOS 编译错误: linker command failed with exit code 1

两盒软妹~` 提交于 2019-12-09 21:50:46
前几天因为做一个语音视频通话的功能, 在项目中引入部分语音通话库, 导致出现以下错误: 后经过排查, 终于定位到错误, 原来是因为新导入的两个.a静态库与原先项目中的 .a 静态库同名所导致 要排查项目内是否有这个问题 在这里搜索你的.a静态库, 查看是否有和你引入的静态库同名的库, 然后删除掉其中一个就可以解决 以下是其他排查方法: 1、"std::ios_base::Init::~Init()", referenced from 出现这样的编译问题,是需要再加进libstdc++.dylib和libstdc++.6.dylib(为6.1使用,xcode5以后默认complier也可以编译通过) 2、apple Mach-o Linker error通常是因为compile source中有相同的.m文件 3、如果在真机中进行测试时出现failed to get the task for process,有可能是证书出了问题。 4、如果出现expect a type的错误,可能出现了在.h文件中的循环引用。 5、以后不能同时有两个一样的.m文件在编译,这样会报linker command failed with exit code 1 (use -vto see invocation)这个错误 (另外:如果代码中混合有C或者C++代码,那么

LLVM每日谈之六 LLVM的源码结构

a 夏天 提交于 2019-12-09 21:09:50
作者: snsn1984 这里简单介绍下LLVM的源码结构,让大家知道LLVM的每个文件夹都放的是什么内容。 参考文档: http://llvm.org/docs/GettingStarted.html#getting-started llvm/examples 这个目录主要是一些简单例子,演示如何使用LLVM IR 和 JIT。还有建立一个简单的编译器的例子的代码。 建立简单编译器的文档地址:http://llvm.org/docs/tutorial/ llvm/include 这个目录主要包含LLVM library的公共头文件。 llvm/lib 这个目录包含了大部分的LLVM的源码。在LLVM中大部分的源码都是以库的形式存在的,这样不同的工具之前就很容易共用代码。 llvm/projects 这个目录包含着一些依赖LLVM的工程,这些工程严格来说又不算LLVM一部分。 llvm/runtimes 这个目录包含了一些库,这些库会编译成LLVM的bitcode,然后当clang linking 程序的时候使用。 llvm/test 这个目录是LLVM的测试套件,包含了很多测试用例,这些测试用例是测试LLVM的所有基本功能的。 llvm/tools 这个目录理是各个工具的源码,这些工具都是建立在刚才上面的那些库的基础之上的。也是主要的用户接口。 llvm/utils

LLVM每日谈之九 谈LLVM的学习

你离开我真会死。 提交于 2019-12-09 21:06:21
作者: snsn1984 从接触LLVM编译器到现在,也有多半年时间了,在这多半年的时间里,也花了不少精力在上面。现在回过头来总结一下在LLVM的学习过程中的一些感悟。(注:这里对LLVM的学习,不是指的是学习LLVM的使用,而是主要针对基于LLVM实现编译功能。) 1、 在开始学习LLVM之前,要有一个心里准备。因为在接下来的学习过程中,会是比较艰难的一个过程,也是一个长期的过程,而且随着学习的深入,会越来越难。 不要期望于短时间就可以把LLVM整个搞明白,除非你是个天才。所以在这个长期的过程中,坚持就是第一重要的,同时尽量让自己保持对LLVM的兴趣,这会 让中间的过程变得不那么痛苦。 2、编译原理的基础知识一定要扎实,如果不扎实的话,就在学习LLVM的过程中找补回来。因 为编译原理的知识都是基础中的基础,如果那些知识都弄不太明白的话,分析LLVM的源码和流程、以及修改LLVM源码,就成了一个美丽的扯。所以每次在论 坛上看到在校的大学生说那门课没用,这门课没用的时候,我心里就笑了,只是暂时没用到而已。(我当年也是那样的。) 3、文档和源码要经 常的读,反复的读,而且在读的过程中要去想,为什么要这样做。凡事问个为什么,这在学习的过程中只有好处,没有坏处。任何一个文档,任何一段代码,都有着 它特殊的含义,为什么需要它的存在?它为什么要这么实现?都是有它的道理的,如果能发现了这些的道理

llvm每日谈之四 Pass初探

╄→гoц情女王★ 提交于 2019-12-09 21:00:21
作者: snsn1984 LLVM 的Pass框架是LLVM系统的一个很重要的部分。每个Pass都是做优化或者转变的工作,LLVM的优化和转换工作就是由很多个Pass来一起完成的。 所 以按照我的理解,Pass就是LLVM系统转化和优化的工作的一个节点,每个节点做一些工作,这些工作加起来就构成了LLVM整个系统的优化和转化。 Pass架构这么做的话,可重用性非常好,你可以选择已有的一些Pass,自己去构建出自己想要的优化和转化效果。并且自己也可以重新写Pass去做自己 想要的优化和转变,因为每个Pass都可以独立存在,所以新建Pass并不用考虑LLVM之前的优化和转化是怎么做的,自己可以只运行自己新建的 Pass,这样可以方便的实现自己想要的效果。 Pass最初的例子就在:llvm源码/lib/Transform/Hello/Hello.cpp。 可以采用命令 $ opt -load ../../../Debug+Asserts/lib/Hello.so -hello < hello.bc > /dev/null 去运行这个Pass,并且查看效果。 ../../../Debug+Asserts/lib/Hello.so 是so的目录,在llvm3.1中,这个例子的名称已经变成了LLVMHello.so. 存放在build目录/Release+Asserts/lib目录之下

LLVM每日谈之十三 使用LLVM自带的PASS

孤街浪徒 提交于 2019-12-09 20:57:24
作者: snsn1984 PS:最近一段时间,投入在LLVM上的时间有些减少。差点把对它的研究断掉,今天开始继续。对LLVM的研究需要很长一段时间的坚持不懈才可以彻底搞明白。 前面已经介绍过如何写自己的PASS,并且也针对一个简单的PASS进行了分析和介绍。相信大家也可以从LLVM源码中找到很多的PASS,这些PASS太多,他们每个到底是做什么用?如何去调用这些系统已经有的PASS?这就是这次每日谈要关注的问题。 在文档 http://llvm.org/docs/Passes.html 中,列出了所有的PASS的命令行参数以及这个PASS主要是做什么用的。下面来实际进行测试下。 在编译好的bin/目录下,使用clang生成一个.bc文件作为例子。然后使用opt工具: ./opt -print-module <test.bc > /dev/null 这里选择的是-print-module,对于它的介绍如下: This pass simply prints out the entire module when it is executed. 这个文档中的其他Pass也是类似的。自己不但可以在这个列表里找到自己需要的Pass,也可以通过这个列表来熟悉这些Pass。另外这个列表 中的Pass的源码主要在llvm源码/lib/Analysis和llvm源码/lib

Building and using a pure llvm toolchain for c++ on linux

和自甴很熟 提交于 2019-12-09 18:29:27
问题 Assuming this is possible, could someone tell me, how I have to configure the cmake build to create a "pure" llvm toolchain on ubuntu-16.04 consisting of clang lld libc++ libc++abi libunwind (llvm) compiler-rt any other pieces that might be relevant and are "production ready" The resulting compiler should be as fast as possible (optimizations turned on, no unnecessary asserts or other checks in the compiler binary itself) be installed in a separate, local directory (lets call it <llvm_install

lldb is not starting an application

余生长醉 提交于 2019-12-09 18:22:09
问题 this is my first experience in commandline mode of lldb. unsuccessful. installed minimal kit with clang, lld, lldb v5 (ubuntu 16.04) sample application built with clang. trying to start: lldb applcation >run error: process launch failed: unable to locate lldb-server-5.0.0 so now the questions: why lldb tries to run a server? this is not a remote debugging. why lldb refers to 5.0.0 (and where to change this setting)? actually there was added symbolic links automiticaly with xxx-5.0 suffix to

Getting LLVM/Clang to be 16 bit aligned

六眼飞鱼酱① 提交于 2019-12-09 14:09:30
问题 I am working on a legacy project that has a large amount of files dating back to pre-OS X days. It's data has been 16 bit aligned for > 15 years. I would like to move to a full LLVM compilation but I can't seem to get 2 byte alignment working. Are there any compiler level options available for this? (previously using -malign-mac68k) I am aware of the #pragma pack(2) option here. However that would require me to modify upwards of 1000 source files to include this. That it's a worst-case option