[LLVMdev] How to represent zero-sized string?

Evan Cheng evan.cheng at apple.com
Fri Jan 9 17:40:53 PST 2009


Hi all,

int main() {
   t("");
   return 0;
}

On Mac OS X, llvm-gcc compiles the zero-sized string to:
.lcomm  LC,1,0

gcc:
         .cstring
LC0:
         .ascii "\0"

The difference seems innocent enough. However, in objc if the zero- 
sized string is part of a cfstring, it causes a problem. The linker  
expects it in the readonly __cstring section, but llvm puts it in the  
read / write bss section.

The problem is llvm represents this as

@"\01LC" = internal constant [1 x i8] zeroinitializer

CodeGen can tell it should go into a read only section, but it cannot  
know it's a cstring. Any ideas how I can fix this? If I write the zero- 
sized string as c"A\00", bitcode reader still turns it back to  
zeroinitializer.

Thanks,

Evan



More information about the llvm-dev mailing list