-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felix Berlakovich
committed
Jan 25, 2023
1 parent
1fdec59
commit e4a85b9
Showing
118 changed files
with
4,716 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,54 @@ | ||
# The LLVM Compiler Infrastructure | ||
# R2C | ||
|
||
This directory and its sub-directories contain source code for LLVM, | ||
a toolkit for the construction of highly optimized compilers, | ||
optimizers, and run-time environments. | ||
## Benchmarking | ||
If you want to run the benchmarks, follow the instructions from https://github.com/fberlakovich/r2c-benchmarking. | ||
The repository contains benchmarking infrastructure that automatically builds the R²C compiler and runs SPEC CPU 2017 and webserver benchmarks. | ||
|
||
The README briefly describes how to get started with building LLVM. | ||
For more information on how to contribute to the LLVM project, please | ||
take a look at the | ||
[Contributing to LLVM](https://llvm.org/docs/Contributing.html) guide. | ||
## Building Webservers | ||
To build the webservers, you need a fully built version of the R²C compiler. | ||
If you have run the benchmarks with the benchmarking infrastructure already, you can reuse compiler already built. | ||
Alternatively, you can manually build the compiler. | ||
|
||
## Getting Started with the LLVM System | ||
> **WARNING**: Building the webservers requires *a lot* of CPU and memory, especially when using a large number of parallel build jobs. | ||
> This is especially true because the R²C compiler was not optimized for compilation speed. | ||
> If you encounter OOM errors, try building with fewer parallel jobs. | ||
Taken from https://llvm.org/docs/GettingStarted.html. | ||
### Reusing the compiler build from the benchmarking infrastructure | ||
You can find the built compiler in `<benchmarking-dir>/build/packages/llvm-src-13.0.0/obj/bin`, where `<benchmarking-dir>` is the directory with the `r2c-benchmarking` code. | ||
Note that you will find this directory only if you have at least benchmark before (see the `r2c-benchmarking` repository for details). | ||
|
||
### Overview | ||
### Building the compiler manually | ||
1. clone this repository | ||
1. checkout branch `r2c` | ||
1. make sure you have the gold linker installed and set as the system default linker | ||
1. create a build directory | ||
1. `cd <build-dir>` | ||
1. build the compiler | ||
1. For a debug build: `cmake -G Ninja -DLLVM_ENABLE_PROJECTS='clang;compiler-rt' -DLLVM_ENABLE_ASSERTIONS=TRUE -DCMAKE_BUILD_TYPE=Debug -DCMAKE_SHARED_LINKER_FLAGS='-Wl,--gdb-index' -DCMAKE_EXE_LINKER_FLAGS='-Wl,--gdb-index' -DBUILD_SHARED_LIBS=true -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BINUTILS_INCDIR=/usr/include <src-dir>/llvm` | ||
2. For a release build: `cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" -DLLVM_ENABLE_ASSERTIONS=TRUE -DBUILD_SHARED_LIBS=true -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BINUTILS_INCDIR=/usr/include <src-dir>/llvm` | ||
1. ninja -j <number of parallel jobs> | ||
|
||
Welcome to the LLVM project! | ||
|
||
The LLVM project has multiple components. The core of the project is | ||
itself called "LLVM". This contains all of the tools, libraries, and header | ||
files needed to process intermediate representations and converts it into | ||
object files. Tools include an assembler, disassembler, bitcode analyzer, and | ||
bitcode optimizer. It also contains basic regression tests. | ||
### Building Webkit | ||
|
||
C-like languages use the [Clang](http://clang.llvm.org/) front end. This | ||
component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode | ||
-- and from there into object files, using LLVM. | ||
To build the GTK version with R²C protections enabled, follow these instructions: | ||
|
||
Other components include: | ||
the [libc++ C++ standard library](https://libcxx.llvm.org), | ||
the [LLD linker](https://lld.llvm.org), and more. | ||
1. Fetch the Webkit source from https://github.com/fberlakovich/Webkit, e.g., to `webkit/src` | ||
|
||
### Getting the Source Code and Building LLVM | ||
The repository contains the version of Webkit we built for the paper plus a commit with the required modifications. | ||
See the Limitations section in the paper for why the modifications are neccessary. | ||
1. Make sure to install all the dependencies required to build Webkit (see https://trac.webkit.org/wiki/BuildingGtk#Dependencies) | ||
1. Create a build directory, e.g., `webkit/build` and run cmake with the following options | ||
|
||
The LLVM Getting Started documentation may be out of date. The [Clang | ||
Getting Started](http://clang.llvm.org/get_started.html) page might have more | ||
accurate information. | ||
`` | ||
export COMPILER_FLAGS="-flto=thin -O3 -fbtras=10 -fheap-boobytraps=10" export LDFLAGS="-flto=thin -Wl,--plugin-opt,-fast-isel=false -fbtras=10 -fheap-boobytraps=10 -Wl,--plugin-opt,-assume-btra-callee=maybe -Wl,--plugin-opt,-prolog-min-padding-instructions=1 -Wl,--plugin-opt,-prolog-max-padding-instructions=5 -Wl,--plugin-opt,-shuffle-functions=true -Wl,--plugin-opt,-shuffle-globals=true -Wl,--plugin-opt,-randomize-reg-alloc=true" && cmake -DCMAKE_C_COMPILER:FILEPATH=<llvm-build>/bin/clang -DCMAKE_RANLIB=<llvm-build>/bin/llvm-ranlib -DCMAKE_NM=<llvm-build>/bin/llvm-nm -DCMAKE_AR=<llvm-build>/bin/llvm-ar -DCMAKE_CXX_COMPILER:FILEPATH=<llvm-build>/bin/clang++ -DCMAKE_C_FLAGS=$COMPILER_FLAGS -DCMAKE_CXX_FLAGS=$COMPILER_FLAGS -DPORT="GTK" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release -G Ninja -DUSE_WPE_RENDERER=Off -DENABLE_GAMEPAD=OFF -DDEVELOPER_MODE=ON -DENABLE_EXPERIMENTAL_FEATURES=ON "<webkit-src>" | ||
`` | ||
|
||
Make sure to replace | ||
1. `<llvm-build>` with your LLVM build directory | ||
2. `<webkit-src>` with your Webkit source directory | ||
|
||
This is an example work-flow and configuration to get and build the LLVM source: | ||
1. Run `ninja` | ||
|
||
1. Checkout LLVM (including related sub-projects like Clang): | ||
|
||
* ``git clone https://github.com/llvm/llvm-project.git`` | ||
|
||
* Or, on windows, ``git clone --config core.autocrlf=false | ||
https://github.com/llvm/llvm-project.git`` | ||
|
||
2. Configure and build LLVM and Clang: | ||
|
||
* ``cd llvm-project`` | ||
|
||
* ``mkdir build`` | ||
|
||
* ``cd build`` | ||
|
||
* ``cmake -G <generator> [options] ../llvm`` | ||
|
||
Some common build system generators are: | ||
|
||
* ``Ninja`` --- for generating [Ninja](https://ninja-build.org) | ||
build files. Most llvm developers use Ninja. | ||
* ``Unix Makefiles`` --- for generating make-compatible parallel makefiles. | ||
* ``Visual Studio`` --- for generating Visual Studio projects and | ||
solutions. | ||
* ``Xcode`` --- for generating Xcode projects. | ||
|
||
Some Common options: | ||
|
||
* ``-DLLVM_ENABLE_PROJECTS='...'`` --- semicolon-separated list of the LLVM | ||
sub-projects you'd like to additionally build. Can include any of: clang, | ||
clang-tools-extra, libcxx, libcxxabi, libunwind, lldb, compiler-rt, lld, | ||
polly, or debuginfo-tests. | ||
|
||
For example, to build LLVM, Clang, libcxx, and libcxxabi, use | ||
``-DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"``. | ||
|
||
* ``-DCMAKE_INSTALL_PREFIX=directory`` --- Specify for *directory* the full | ||
path name of where you want the LLVM tools and libraries to be installed | ||
(default ``/usr/local``). | ||
|
||
* ``-DCMAKE_BUILD_TYPE=type`` --- Valid options for *type* are Debug, | ||
Release, RelWithDebInfo, and MinSizeRel. Default is Debug. | ||
|
||
* ``-DLLVM_ENABLE_ASSERTIONS=On`` --- Compile with assertion checks enabled | ||
(default is Yes for Debug builds, No for all other build types). | ||
|
||
* ``cmake --build . [-- [options] <target>]`` or your build system specified above | ||
directly. | ||
|
||
* The default target (i.e. ``ninja`` or ``make``) will build all of LLVM. | ||
|
||
* The ``check-all`` target (i.e. ``ninja check-all``) will run the | ||
regression tests to ensure everything is in working order. | ||
|
||
* CMake will generate targets for each tool and library, and most | ||
LLVM sub-projects generate their own ``check-<project>`` target. | ||
|
||
* Running a serial build will be **slow**. To improve speed, try running a | ||
parallel build. That's done by default in Ninja; for ``make``, use the option | ||
``-j NNN``, where ``NNN`` is the number of parallel jobs, e.g. the number of | ||
CPUs you have. | ||
|
||
* For more information see [CMake](https://llvm.org/docs/CMake.html) | ||
|
||
Consult the | ||
[Getting Started with LLVM](https://llvm.org/docs/GettingStarted.html#getting-started-with-llvm) | ||
page for detailed information on configuring and compiling LLVM. You can visit | ||
[Directory Layout](https://llvm.org/docs/GettingStarted.html#directory-layout) | ||
to learn about the layout of the source code tree. | ||
After building successfully, you will find the binaries below the `bin` directory. | ||
You can run the tests, by running one of the `test*` binaries or start the browser by running `MiniBrowser`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
add_compiler_rt_component(heap_boobytraps) | ||
add_compiler_rt_component(hardened_heap_boobytraps) | ||
add_compiler_rt_component(boobytraps) | ||
|
||
set(HEAPBOOBYTRAPS_SOURCES | ||
heap_boobytraps.c | ||
heapbt_common.c | ||
) | ||
|
||
set(HARDENEDHEAPBOOBYTRAPS_SOURCES | ||
hardened_heap_boobytraps.c | ||
heapbt_common.c | ||
) | ||
|
||
set(BOOBYTRAPS_SOURCES | ||
boobytraps.c | ||
) | ||
|
||
|
||
include_directories(..) | ||
|
||
foreach(arch ${ALL_R2C_SUPPORTED_ARCH}) | ||
message(STATUS "Building boobytraps RT library for ${arch}") | ||
add_compiler_rt_runtime(clang_rt.boobytraps | ||
STATIC | ||
ARCHS ${arch} | ||
SOURCES ${BOOBYTRAPS_SOURCES} | ||
CFLAGS ${BOOBYTRAPS_CFLAGS} | ||
PARENT_TARGET boobytraps) | ||
|
||
message(STATUS "Building heap boobytrap RT library for ${arch}") | ||
add_compiler_rt_runtime(clang_rt.heap_boobytraps | ||
STATIC | ||
ARCHS ${arch} | ||
SOURCES ${HEAPBOOBYTRAPS_SOURCES} | ||
CFLAGS ${HEAPBOOBYTRAPS_CFLAGS} | ||
PARENT_TARGET heap_boobytraps) | ||
|
||
message(STATUS "Building hardened heap boobytrap RT library for ${arch}") | ||
add_compiler_rt_runtime(clang_rt.hardened_heap_boobytraps | ||
STATIC | ||
ARCHS ${arch} | ||
SOURCES ${HARDENEDHEAPBOOBYTRAPS_SOURCES} | ||
CFLAGS ${HARDENEDHEAPBOOBYTRAPS_CFLAGS} | ||
PARENT_TARGET hardened_heap_boobytraps) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// Created by felixl on 28/04/22. | ||
// | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
__attribute__((unused)) | ||
void ReportAttack() { | ||
printf("A booby trap function was hit\n"); | ||
abort(); | ||
} |
Oops, something went wrong.