Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
update chapter 12
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweiChen committed Feb 3, 2022
1 parent 8b7d2fc commit 8669aa8
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 328 deletions.
12 changes: 6 additions & 6 deletions LLVM-Techniques-Tips-and-Best-Practies.tex
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@
\subfile{content/3/chapter11/7.tex}
\newpage

\subsection*{\zihao{2} 第12章\hspace{0.5cm}学习LLVM IR表达式}
\addcontentsline{toc}{subsection}{第12章\hspace{0.5cm}学习LLVM IR表达式}
\subsection*{\zihao{2} 第12章\hspace{0.5cm}LLVM IR表达式}
\addcontentsline{toc}{subsection}{第12章\hspace{0.5cm}LLVM IR表达式}
\subfile{content/3/chapter12/0.tex}

\subsubsection*{\zihao{3} 12.1.\hspace{0.2cm}相关准备}
Expand All @@ -812,17 +812,17 @@
\addcontentsline{toc}{subsubsection}{12.2.\hspace{0.2cm}开发杀毒器}
\subfile{content/3/chapter12/2.tex}

\subsubsection*{\zihao{3} 12.3.\hspace{0.2cm}使用PGO}
\addcontentsline{toc}{subsubsection}{12.3.\hspace{0.2cm}使用PGO}
\subsubsection*{\zihao{3} 12.3.\hspace{0.2cm}PGO}
\addcontentsline{toc}{subsubsection}{12.3.\hspace{0.2cm}PGO}
\subfile{content/3/chapter12/3.tex}

\subsubsection*{\zihao{3} 12.4.\hspace{0.2cm}总结}
\addcontentsline{toc}{subsubsection}{12.4.\hspace{0.2cm}总结}
\subfile{content/3/chapter12/4.tex}
\newpage

\section*{\zihao{2} 评论}
\addcontentsline{toc}{section}{评论}
\section*{\zihao{2} 练习答案}
\addcontentsline{toc}{section}{练习答案}
\subfile{content/assessments.tex}

\end{document}
Expand Down
15 changes: 7 additions & 8 deletions content/3/chapter12/0.tex
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
In the previous chapter, we learned how to leverage various utilities to improve our productivity while developing with LLVM. Those skills can give us a smoother experience when diagnosing problems that are raised by LLVM. Some of these utilities can even reduce the number of potential mistakes that are made by compiler engineers. In this chapter, we are going to learn how instrumentation works in LLVM IR.
前一章中,我们了解了如何在使用LLVM进行开发时利用各种工具来提高工作效率,这些技能可以让我们在诊断出LLVM的问题时,处理起来更加顺畅。其中一些工具可以减少编译器工程师犯错的机会。本章中,我们将了解在LLVM IR中工具是如何工作的。

The instrumentation we are referring to here is a kind of technique that inserts some probes into the code we are compiling in order to collect runtime information. For example, we can collect information about how many times a certain function was called – which is only available once the target program has been executed. The advantage of this technique is that it provides extremely accurate information about the target program's behavior. This information can be used in several different ways. For instance, we can use the collected values to compile and optimize the same code again – but this time, since we have accurate data, we can perform more aggressive optimizations that couldn't be done previously. This technique is also called Profile-Guided Optimization (PGO). In another example, will be using the inserted probes to catch undesirable incidents that happened at runtime – buffer overflows, race conditions, and double-free memory, to name a few. The probe that's used for this purpose is also called a sanitizer.
我们在这里所指的\textbf{工具}是一种技术,将一些检测插入到我们正在编译的代码中,以收集运行时信息,例如:可以收集关于某个函数调用多少次的信息——只有在目标程序执行之后才可用。这种技术的优点是提供了关于目标程序行为的准确信息,这些信息可以以几种不同的方式使用,例如:可以使用收集到的值,再次编译和优化相同的代码——但是这一次,由于有准确的数据,可以执行以前无法执行的优化。这种技术也称为\textbf{数据导向优化(Profile-Guided Optimization,PGO)}。在另一个例子中,将使用插入的检测来捕获运行时不希望发生的事件——缓冲区溢出、条件竞争和双重释放内存等等。用于此目的的检测器,也称为\textbf{杀毒器}。

To implement instrumentation in LLVM, we not only need the help of LLVM pass, but also the synergy between multiple subprojects in LLVM – Clang, LLVM IR Transformation, and Compiler-RT. We already know about the first two from earlier chapters. In this chapter, we are going to introduce Compiler-RT and, more importantly, how can we combine these subsystems for the purpose of instrumentation.
要在LLVM中实现相应的工具,不仅需要LLVM Pass的帮助,还需要LLVM-\textbf{Clang}、\textbf{LLVM IR} \textbf{Transformation}和\textbf{Compiler-RT}中的多个子项目之间的协同。在本章中,我们将介绍Compiler-RT,更重要的是,了解如何将这些子系统组合在一起,从而达到测试的目的。

Here is the list of topics we are going to cover:
下面是我们将要讨论的内容:

\begin{itemize}
\item Developing a sanitizer
\item Working with PGO
\item 开发杀毒器
\item 使用PGO
\end{itemize}


In the first part of this chapter, we are going to see how a sanitizer is implemented in Clang and LLVM, before creating a simple one by ourselves. The second half of this chapter is going to show you how to use the PGO framework in LLVM and how we can extend it.
本章的第一部分,将看到如何在Clang和LLVM中实现杀毒器,然后自己创建一个简单的杀毒器。本章的后半部分将展示如何在LLVM中使用PGO框架,以及如何扩展它。



Expand Down
10 changes: 5 additions & 5 deletions content/3/chapter12/1.tex
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
In this chapter, we are going to work with multiple subprojects. One of them – Compiler-RT – needs to be included in your build by us modifying the CMake configuration. Please open the CMakeCache.txt file in your build folder and add the compiler-rt string to the value of the LLVM\_ENABLE\_PROJECTS variable. Here is an example:
本章中,将使用多个子项目。其中之一——Compiler-RT——需要通过修改CMake配置来包含在你的构建中。请打开\texttt{CMakeCache.tx}t文件,并将\texttt{compiler-rt}字符串添加到\texttt{LLVM\_ENABLE\_PROJECTS}变量中。下面是一个例子:

\begin{lstlisting}[style=styleCMake]
//Semicolon-separated list of projects to build…
LLVM_ENABLE_PROJECTS:STRING="clang;compiler-rt"
\end{lstlisting}

After editing the file, launch a build with any build target. CMake will try to reconfigure itself.
编辑该文件后,用任何构建目标重新启动构建,CMake会重新配置。

Once everything has been set up, we can build the components we need for this chapter.Here is an example command:
当一切就绪,就可以构建本章所需的组件了。下面是一个命令示例:

\begin{tcblisting}{commandshell={}}
$ ninja clang compiler-rt opt llvm-profdata
\end{tcblisting}
This will build the clang tool we're all familiar with and a collection of Compiler-RT libraries, which we are going to introduce shortly.
这将构建我们都熟悉的\texttt{clang}工具和一系列Compiler-RT库。
You can find the sample code for this chapter in the same GitHub repository: \url{https://github.com/PacktPublishing/LLVM-Techniques-Tips-and-Best-Practices-Clang-and-Middle-End-Libraries/tree/main/Chapter12}.
可以在GitHub库中找到本章的示例代码: \url{https://github.com/PacktPublishing/LLVM-Techniques-Tips-and-Best-Practices-Clang-and-Middle-End-Libraries/tree/main/Chapter12}.
Expand Down
Loading

0 comments on commit 8669aa8

Please sign in to comment.