AsmPrinter behavior

I compile these two lines in llc

@tst1 = internal global [4 x i8] zeroinitializer;
@tst2 = internal global [4 x i8] [i8 0, i8 1, i8 2, i8 3];

@tst1 is emited via MCStreamer::EmitCommonSymbol
while the other is emited via MCStreamer::EmitLabel followed by MCStreamer::EmitBytes

from what I can tell, only symbols with common linkage should me emitted by MCStreamer::EmitCommonSymbol,

is this the expected behavior or should I fix it?

This is expected behavior. tst1 should be emitted with something like:

.local _tst1
.comm _tst1, ...

based on the exact syntax of your target. If your target supports .lcomm, you can also enable that.

-Chris

I don’t follow. The object file format provides a means for efficiently zero filling a local symbol. The compiler is just using it. What is the problem you’re trying to solve here? Since it is not exported out of the .o file (it is local) there whether it is “common” or not is undetectable, we just get a storage optimization.

-Chris

I don’t know, I see common and it makes me think that things are getting merged together, but as you say it is local so the fact that its also common becomes irrelevant. In MachO do you just put these into the .bss section?

Macho has a special zerofill directive (targeted at the BSS section) for this. You can see this by running your example like this:

$ llc t.ll -o - -mtriple=i386-apple-darwin10
.section __TEXT,__text,regular,pure_instructions
.zerofill __DATA,__bss,_tst1,4,0 ## @tst1
.section __DATA,__data
_tst2: ## @tst2
.ascii “\000\001\002\003”

-Chris

I think we should have an ‘EmitZeroFill()’ and ‘EmitASCII()’ OutStream methods, the latter to deal with dllexports in ‘lib/Target/X86/AsmPrinter/AsmPrinter.cpp:569’.

We also need to sort out COFF TLOF, and get rid of the directive stuff.

Aaron

It looks to me that you should have an Emit method for the .scl, .def, .type, .endef directives. One callback each.

-Chris

There is already a MCStreamer::EmitZerofill() is seems to be MachO specific ?

‘MCStreamer::EmitCOFFStabs()’ ?

‘MCStreamer:: EmitASCII()’ ?

Shall I do these as two separate patches ?

Aaron

‘MCStreamer::EmitCOFFStabs()’ ?

Sorry, its not STABS, something more like, ‘MCStreamer:: EmitCOFFType(uint8_t storageClass, uint8_t type)’

‘MCStreamer:: EmitASCII()’ ?

And ‘MCStreamer:: EmitASCII(uint8_t *string)’ or should we use Twine ?

Shall I do these as two separate patches ?

Aaron

This seems counter intuitive to me, I can understand that C assigned that behavior somewhat arbitrarily to uninitialized global variables, but in LLVM there is explicitly a common linkage attribute to get that behavior. Nothing in the llvm language reference indicates the behavior of a global with the ‘internal’ linkage attribute should change based of the values used to initialize it.

I don’t follow. The object file format provides a means for efficiently zero filling a local symbol. The compiler is just using it. What is the problem you’re trying to solve here? Since it is not exported out of the .o file (it is local) there whether it is “common” or not is undetectable, we just get a storage optimization.

I don’t know, I see common and it makes me think that things are getting merged together, but as you say it is local so the fact that its also common becomes irrelevant. In MachO do you just put these into the .bss section?

Macho has a special zerofill directive (targeted at the BSS section) for this. You can see this by running your example like this:

$ llc t.ll -o - -mtriple=i386-apple-darwin10
.section __TEXT,__text,regular,pure_instructions
.zerofill __DATA,__bss,_tst1,4,0 ## @tst1
.section __DATA,__data
_tst2: ## @tst2
.ascii “\000\001\002\003”

I think we should have an ‘EmitZeroFill()’ and ‘EmitASCII()’ OutStream methods, the latter to deal with dllexports in ‘lib/Target/X86/AsmPrinter/AsmPrinter.cpp:569’.

I agree, I was going to put EmitASCII in, not sure about the zero fill, though I use the zero fill fragment when handling common symbols.

We also need to sort out COFF TLOF, and get rid of the directive stuff.

I think this Peter’s patch takes care of this nicely.

-Nathan

I’ve had included a EmitCOFFSymbolDef in MCStreamer to replace the EmitRawText that was handling this, seem to me it would be easier to have a single call given the restrictions on their use.

Sure, whatever you guys think is best. It is also very reasonable to add new enums to MCSymbolAttr if EmitSymbolAttribute is the right callback for these.

-Chris

I could see that working for the object file exporter, but I think it would be tricky to get the write assembly output.

-Nathan

Ok, whatever you think is best. We need both paths to work :slight_smile: and adding new virtual methods is cheap.

-Chris