Generating DWARF info

I'm using llvm-2.5 on OS X 10.5 and having a problem getting debug info from my compiler into a resulting executable.
My code flow is:
  LLVM API -> Assembly file .s -> gcc to .dylib

I'm using DIFactory to generate the debug info, and my usage seems to match what clang's CGDebugInfo would do. In my resulting assembly file, I see the DWARF sections with apparently valid data:

.section __DWARF,__debug_info,regular,debug

As soon as I send my assembly to gcc it disappears. I can call 'as' directly as gcc does, and at this point the debug info disappears:

as -g -arch i386 -force_cpusubtype_ALL -o random.o random.s

Am I missing a step or not doing something properly to keep my debug info preserved?

Any tips or pointers would be appreciated!

Try without adding -g on as command line.

If you're using gcc or llvm-gcc driver to assembler your .s file then it is likely that the driver is invoking dsymutil to extract debug info out of .o file and create .dSYM.

Otherwise, without complete reproducible test case it is hard to guess.