Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic LLVM module pass causes segfault #31067

Closed
frewsxcv opened this issue Jan 21, 2016 · 1 comment
Closed

Basic LLVM module pass causes segfault #31067

frewsxcv opened this issue Jan 21, 2016 · 1 comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-plugin Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html

Comments

@frewsxcv
Copy link
Member

Started occurring after f9d4149 merged


Repo exemplifying segfault

Relevant file in repo

To exemplify:

  1. set LLVM_CONFIG environment variable to llvm-config path
  2. cargo build --verbose

Result of stepping through the code with LLDB


Another example of a module pass exemplifying a crash:

bool InstrumentationPass::runOnModule(Module &M) {
  LLVMContext &C = M.getContext();
  IntegerType *Int8Ty  = IntegerType::getInt8Ty(C);
  llvm::Type *i = PointerType::get(Int8Ty, 0);  // segfault happens here
  return true;
}

This is preventing afl.rs from upgrading compatibility with any Rust version >1.2:

@nagisa nagisa added A-plugin Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. labels Jan 21, 2016
@frewsxcv
Copy link
Member Author

Opened a PR that fixes this #31176

frewsxcv added a commit to frewsxcv/rust that referenced this issue Jan 25, 2016
LLVM was upgraded to a new version in this commit:

rust-lang@f9d4149

which was part of this pull request:

rust-lang#26025

Consider the following two lines from that commit:

rust-lang@f9d4149#diff-a3b24dbe2ea7c1981f9ac79f9745f40aL462

rust-lang@f9d4149#diff-a3b24dbe2ea7c1981f9ac79f9745f40aL469

The purpose of these lines is to register LLVM passes. Prior to the that
commit, the passes being handled were assumed to be ModulePasses (a
specific type of LLVM pass) since they were being added to a ModulePass
manager. After that commit, both lines were refactored (presumably in an
attempt to DRY out the code), but the ModulePasses were changed to be
registered to a FunctionPass manager. This change resulted in
ModulePasses being run, but a Function object was being passed as a
parameter to the pass instead of a Module, which resulted in
segmentation faults.

In this commit, I changed relevant sections of the code to check the
type of the passes being added and register them to the appropriate pass
manager.

Closes rust-lang#31067
bors added a commit that referenced this issue Jan 25, 2016
Register LLVM passes with the correct LLVM pass manager.

LLVM was upgraded to a new version in this commit:

f9d4149

which was part of this pull request:

#26025

Consider the following two lines from that commit:

f9d4149#diff-a3b24dbe2ea7c1981f9ac79f9745f40aL462

f9d4149#diff-a3b24dbe2ea7c1981f9ac79f9745f40aL469

The purpose of these lines is to register LLVM passes. Prior to the that
commit, the passes being handled were assumed to be ModulePasses (a
specific type of LLVM pass) since they were being added to a ModulePass
manager. After that commit, both lines were refactored (presumably in an
attempt to DRY out the code), but the ModulePasses were changed to be
registered to a FunctionPass manager. This change resulted in
ModulePasses being run, but a Function object was being passed as a
parameter to the pass instead of a Module, which resulted in
segmentation faults.

In this commit, I changed relevant sections of the code to check the
type of the passes being added and register them to the appropriate pass
manager.

Closes #31067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-plugin Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html
Projects
None yet
Development

No branches or pull requests

2 participants