Crash in opt.cpp:739 when loading custom pass (only on system-wide debug install of llvm)

Hi,

I'm trying to write custom pass. However opt started crashed in opt.cpp.
After debugging it looks like PassInf->NormalCtor points to unmapped
memory (rest of struct contains correct data about my pass) - it pointed
high in user memory (0x756e672e006e6f69).

It happens only when I tried to install debug version of llvm
system-wide (I've check that it wasn't caused by stale .a files). When I
used the local install (via cmake to $HOME) or release it works[1].

My system is Gentoo, 64 bit. To bootstrap I've used gcc 4.8.2.

Any idea what might be a cause of it (my build system is practically
copied from documentation[2])?

Best regards

PS. The difference seems to be in system-wide install only
optimized/assertions/expensive-checks flags (I'm using Gentoo ebuild).

[1] The problem with local install is that it cause problems with clang
(probably because of some incompatibilities between released version
clang was compiled against and debug version it's loading) and release
version don't have debug flags support etc.
[2] http://llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source

When I tried to manually rewrite the RegisterPass:

struct RegisterMyPass {
  RegisterMyPass();
};

llvm::Pass *create_my_pass() {
  return new vallvm::MyPass();
}

RegisterMyPass::RegisterMyPass() {
  static llvm::PassInfo info(...,
    ...,
    &vallvm::MyPass::ID,
    create_my_pass,
    false, false);
  if (info.getNormalCtor() == create_closure_capture) {
    llvm::errs() << "???\n";
    info.setNormalCtor(create_closure_capture);
    if (info.getNormalCtor() == create_closure_capture) {
      llvm::errs() << "???\n";
    }
  }
  llvm::PassRegistry::getPassRegistry()->registerPass(info);
}

With debug built it prints "???" twice.

Regards

> Hi,
>
> I'm trying to write custom pass. However opt started crashed in opt.cpp.
> After debugging it looks like PassInf->NormalCtor points to unmapped
> memory (rest of struct contains correct data about my pass) - it pointed
> high in user memory (0x756e672e006e6f69).
>
> It happens only when I tried to install debug version of llvm
> system-wide (I've check that it wasn't caused by stale .a files). When I
> used the local install (via cmake to $HOME) or release it works[1].
>
> My system is Gentoo, 64 bit. To bootstrap I've used gcc 4.8.2.
>
> Any idea what might be a cause of it (my build system is practically
> copied from documentation[2])?
>
> Best regards
>
> PS. The difference seems to be in system-wide install only
> optimized/assertions/expensive-checks flags (I'm using Gentoo ebuild).
>
> [1] The problem with local install is that it cause problems with clang
> (probably because of some incompatibilities between released version
> clang was compiled against and debug version it's loading) and release
> version don't have debug flags support etc.
> [2] http://llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source

When I tried to manually rewrite the RegisterPass:

struct RegisterMyPass {
  RegisterMyPass();
};

llvm::Pass *create_my_pass() {
  return new vallvm::MyPass();
}

RegisterMyPass::RegisterMyPass() {
  static llvm::PassInfo info(...,
    ...,
    &vallvm::MyPass::ID,
    create_my_pass,
    false, false);
  if (info.getNormalCtor() == create_closure_capture) {
    llvm::errs() << "???\n";
    info.setNormalCtor(create_closure_capture);
    if (info.getNormalCtor() == create_closure_capture) {
      llvm::errs() << "???\n";
    }
  }
  llvm::PassRegistry::getPassRegistry()->registerPass(info);
}

Sorry - too less coffee (I thought I wrote != instead of == - which
would be strange).

Regards

It looks like it was compiled with _GLIBCXX_DEBUG which changes ABI.

Best regards