llvm-project/llvm
Reid Kleckner fd52096259 [LLD] Implement /guard:[no]longjmp
Summary:
This protects calls to longjmp from transferring control to arbitrary
program points. Instead, longjmp calls are limited to the set of
registered setjmp return addresses.

This also implements /guard:nolongjmp to allow users to link in object
files that call setjmp that weren't compiled with /guard:cf. In this
case, the linker will approximate the set of address taken functions,
but it will leave longjmp unprotected.

I used the following program to test, compiling it with different -guard
flags:
  $ cl -c t.c -guard:cf
  $ lld-link t.obj -guard:cf

  #include <setjmp.h>
  #include <stdio.h>
  jmp_buf buf;
  void g() {
    printf("before longjmp\n");
    fflush(stdout);
    longjmp(buf, 1);
  }
  void f() {
    if (setjmp(buf)) {
      printf("setjmp returned non-zero\n");
      return;
    }
    g();
  }
  int main() {
    f();
    printf("hello world\n");
  }

In particular, the program aborts when the code is compiled *without*
-guard:cf and linked with -guard:cf. That indicates that longjmps are
protected.

Reviewers: ruiu, inglorion, amccarth

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D43217

llvm-svn: 325047
2018-02-13 20:32:53 +00:00
..
bindings [NFC] fix trivial typos in comments and documents 2018-01-26 08:15:29 +00:00
cmake Generate PDB files for profiling even in Release build. 2018-02-07 19:37:52 +00:00
docs [AMDGPU] Change constant addr space to 4 2018-02-13 18:00:25 +00:00
examples [ORC] Remove Layer handles from the layer concept. 2018-02-09 02:30:40 +00:00
include [GISel]: Add Pattern Matcher for G_FMUL. 2018-02-13 20:09:13 +00:00
lib Document the shortcomings of DwarfExpression::addMachineReg(). 2018-02-13 19:54:00 +00:00
projects
resources
runtimes
test [AMDGPU] Cleanup in memory legalizer tests. NFC. 2018-02-13 20:03:32 +00:00
tools [LLD] Implement /guard:[no]longjmp 2018-02-13 20:32:53 +00:00
unittests [GISel]: Add Pattern Matcher for G_FMUL. 2018-02-13 20:09:13 +00:00
utils [X86] Teach EVEX->VEX pass to turn VRNDSCALE into VROUND when bits 7:4 of the immediate are 0 and the regular EVEX->VEX checks pass. 2018-02-13 04:19:26 +00:00
.arcconfig [llvm] Set up .arcconfig to point to Diffusion L repository 2018-01-12 15:37:41 +00:00
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt CMake: Allow specifying arbitrary CCACHE parameters 2018-02-09 23:25:23 +00:00
CODE_OWNERS.TXT
CREDITS.TXT Add myself to CREDITS.txt 2018-01-29 17:02:34 +00:00
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in

README.txt

Low Level Virtual Machine (LLVM)
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.