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

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.

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