Richard Pennington
2009-Jul-18 15:20 UTC
[LLVMdev] The mysterious case of the missing GlobalVariables.
Hi, I've recently been updating my stuff with LLVM TOT with the context changes, etc. I'm up to date as of yesterday. In my environment I do most of the translation in memory: 1. Parse the source file(s). 2. lower to LLVM module(s) 3. bc optimize module(s) 4. bc link module(s) 5. generate a .s file and assemble it 6. link .o's and libraries. This was working very well until a couple of days ago. Now, if I do this the assembly file doesn't have the global variable definitions, even though the references are there. Strangely enough, if I stop after bc linking and look at the bc, the definitions are there and I can use llc to generate a correct .s file. Also strangely, If I feed the linked bc file back into the driver and go through the optimize/bclink/generate steps, the globals disappear again. I'm sure I'm missing something stupid. Any ideas? -Rich
Jeffrey Yasskin
2009-Jul-18 15:34 UTC
[LLVMdev] The mysterious case of the missing GlobalVariables.
If the globals don't have 'external' linkage, the optimizers will happily eliminate them. If they are marked external, attaching the .bc file, reduced if possible, will give people a better chance of helping you. On Sat, Jul 18, 2009 at 8:20 AM, Richard Pennington<rich at pennware.com> wrote:> Hi, > > I've recently been updating my stuff with LLVM TOT with the context > changes, etc. I'm up to date as of yesterday. > > In my environment I do most of the translation in memory: > 1. Parse the source file(s). > 2. lower to LLVM module(s) > 3. bc optimize module(s) > 4. bc link module(s) > 5. generate a .s file and assemble it > 6. link .o's and libraries. > > This was working very well until a couple of days ago. > Now, if I do this the assembly file doesn't have the global variable > definitions, even though the references are there. > > Strangely enough, if I stop after bc linking and look at the bc, the > definitions are there and I can use llc to generate a correct .s file. > > Also strangely, If I feed the linked bc file back into the driver and go > through the optimize/bclink/generate steps, the globals disappear again. > > I'm sure I'm missing something stupid. Any ideas? > > -Rich > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Richard Pennington
2009-Jul-18 19:23 UTC
[LLVMdev] The mysterious case of the missing GlobalVariables.
Jeffrey Yasskin wrote:> If the globals don't have 'external' linkage, the optimizers will > happily eliminate them. If they are marked external, attaching the .bc > file, reduced if possible, will give people a better chance of helping > you.The problem is that the .bc file is correct, so it wouldn't do any good. It's only when I don't create the files that I have the problem (all in memory). The optimizer shouldn't happily eliminate variables that are accessed, though. Anton gave me a hint, though, that solved my (stupid) mystery: I had switched to formatted_raw_output for my assembly file writing and didn't notice that I needed a flush(). The declarations at the end of the file were left off. -Rich