Scott A. Carr via llvm-dev
2016-Feb-09 18:24 UTC
[llvm-dev] CloneFunction during LTO leads to seg fault?
Hello, I'm writing an LTO pass and I'd like to be able to duplicate a function (with debugging info). I'm trying to accomplish this with CloneFunction but it's leading to a seg fault in ld. I've whittled down my problem so that it occurs in this small pass [1]. If I run this pass with opt, I get the expected result (i.e. a valid program that calls main twice). If I run the pass during LTO, ld seg faults. Here is a pastebin of when ld seg faults in lldb [2]. If I set the third parameter of CloneFunction (ModuleLevelChanges) to false, then then compilation will complete -- but I lose debugging information in the cloned function. I really want to preserve the debug info. Any idea what is wrong? Is this a bug? Usually when I screw up the module the verifier catches the problem. This is getting to I think CodeGen then crashing. I've found that the module itself needs to be non-trivial to cause the crash. Here is the module I'm testing with [3]. In case it is relevant: to get my pass to run during LTO I added "PM.add(createHelloPass())" to PassMangerBuilder::populateLTOPassManager. I'm using binutils-gold on Linux (Ubuntu 14.04 LTS). Thank you, Scott A. Carr PhD Candidate Purdue University [1] http://pastebin.com/uL6QMtcT [2] http://pastebin.com/i1gd0gE6 [3] http://pastebin.com/GEG0F8kU
Mehdi Amini via llvm-dev
2016-Feb-09 18:36 UTC
[llvm-dev] CloneFunction during LTO leads to seg fault?
> On Feb 9, 2016, at 10:24 AM, Scott A. Carr via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello, > > I'm writing an LTO pass and I'd like to be able to duplicate a function (with debugging info). I'm trying to accomplish this with CloneFunction but it's leading to a seg fault in ld. > > I've whittled down my problem so that it occurs in this small pass [1]. > > If I run this pass with opt, I get the expected result (i.e. a valid program that calls main twice). If I run the pass during LTO, ld seg faults. Here is a pastebin of when ld seg faults in lldb [2]. > > If I set the third parameter of CloneFunction (ModuleLevelChanges) to false, then then compilation will complete -- but I lose debugging information in the cloned function. I really want to preserve the debug info. > > Any idea what is wrong? Is this a bug? Usually when I screw up the module the verifier catches the problem. This is getting to I think CodeGen then crashing.What could help is to pass -mllvm -print-after-all to ld and get the IR before and after your pass ran, and also just before CodeGen.> > I've found that the module itself needs to be non-trivial to cause the crash. Here is the module I'm testing with [3]. > > In case it is relevant: to get my pass to run during LTO I added "PM.add(createHelloPass())" to PassMangerBuilder::populateLTOPassManager. I'm using binutils-gold on Linux (Ubuntu 14.04 LTS).You may want to try to add it at the end of the pipeline, in case something does not play well with optimizations (just trying to pinpoint where the issue is). -- Mehdi> > Thank you, > Scott A. Carr > PhD Candidate > Purdue University > > [1] http://pastebin.com/uL6QMtcT > > [2] http://pastebin.com/i1gd0gE6 > > [3] http://pastebin.com/GEG0F8kU > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Scott A. Carr via llvm-dev
2016-Feb-09 19:03 UTC
[llvm-dev] CloneFunction during LTO leads to seg fault?
Hi Medhi, Thanks for you reply. Here is the full output of -print-after-all [1] and just the module itself after my pass[2]. I've looked over the IR, but I can't see anything obviously wrong. I'm not sure what you meant by:> You may want to try to add it at the end of the pipelineMy pass is the last one added inside populateLTOPassManager. Should I add it to the PassManager somewhere else? Thanks, Scott [1] https://gist.github.com/scottcarr/ce0bb6df1cbb44ec46a5 [2] http://pastebin.com/9xc2jpRj On 02/09/2016 01:36 PM, Mehdi Amini wrote:>> On Feb 9, 2016, at 10:24 AM, Scott A. Carr via llvm-dev <llvm-dev at lists.llvm.org> wrote: >> >> Hello, >> >> I'm writing an LTO pass and I'd like to be able to duplicate a function (with debugging info). I'm trying to accomplish this with CloneFunction but it's leading to a seg fault in ld. >> >> I've whittled down my problem so that it occurs in this small pass [1]. >> >> If I run this pass with opt, I get the expected result (i.e. a valid program that calls main twice). If I run the pass during LTO, ld seg faults. Here is a pastebin of when ld seg faults in lldb [2]. >> >> If I set the third parameter of CloneFunction (ModuleLevelChanges) to false, then then compilation will complete -- but I lose debugging information in the cloned function. I really want to preserve the debug info. >> >> Any idea what is wrong? Is this a bug? Usually when I screw up the module the verifier catches the problem. This is getting to I think CodeGen then crashing. > > What could help is to pass -mllvm -print-after-all to ld and get the IR before and after your pass ran, and also just before CodeGen. > >> I've found that the module itself needs to be non-trivial to cause the crash. Here is the module I'm testing with [3]. >> >> In case it is relevant: to get my pass to run during LTO I added "PM.add(createHelloPass())" to PassMangerBuilder::populateLTOPassManager. I'm using binutils-gold on Linux (Ubuntu 14.04 LTS). > You may want to try to add it at the end of the pipeline, in case something does not play well with optimizations (just trying to pinpoint where the issue is). >