On May 4, 2010, at 11:03 AM, Nathan Jeffords wrote:> This is a brain-dump of my thoughts on the MCStreamer interface after several > days of digging around trying to get a COFF writer working.Great! Something that is worth pointing out is that the MCStreamer API is intended to directly reflect what is happening in .s files. We basically want one MCStreamer callback to correspond to one statement in the .s file. This makes it easier to handle from the compiler standpoint, but is also very important for the llvm-mc assembly parser itself.> All fragments should be associated with a symbol. For assembler components, a > unnammed "virtual" symbol can be used when there is no explicit label defined.What do you mean by fragment? Can you give me an analogy with what the syntax looks like in a .s file, I'm not sure exactly what you mean here.> Section assignment should be the responsiblity of the object imlementing the > MCStreamer interface, with the caller givin the ability to give hints as to > what section to place the symbol into.Section assignment really needs to happen at a higher level. The TargetLoweringObjectFile interfaces are the ones responsible for mapping a global/function -> section. This interface (not mcstreamer) should handle this. The important point here is that the COFF MCSection needs to have the right level of semantic information. In fact, MCSection is the place that I'd start for COFF bringup.> instead of SwitchSection, there would be BeginSymbol, and SymbolSymbol, it would > be illegal to call any EmitXXX function outside of these two calls > > BeginSymbol(Symbol, SectionHint) > EmitAttribute(...) > EmitAttribute(...) > ... > StartFragmentEmission() > EmitFragment(...) > EmitFragment(...) > ... > EndSymbol() > > Object file writers would typically start recording fragments and attributes for > a symbol on the BeginSymbol, then at EndSymbol they would evaluate what was > streamed, and decide what section the symbol should be placed in.Why do you need this? This concept doesn't exist in the .s file, so I don't think that MCStreamer is the right level for this. -Chris
On Wed, May 5, 2010 at 1:22 PM, Nathan Jeffords <blunted2night at gmail.com> wrote:> I had a problem with MCStreamer::EmitCommonSymbol > & MCStreamer::EmitLocalCommonSymbol. When I implemented them I assumed this > meant to put those symbols into the .bss segment. This required me to get a > hold of the TLOF from the streamer. I now realize this is wrong after > re-reading the description of the '.comm' directive a few times. I am not > sure why an uninitialized global variable was being emitted using this, that > seems wrong since global variables in different compilation units with the > same name would get merged together at link time. (this is using clang on a > C source file)Global definitions like "int x;" are treated as common to allow linking buggy programs that forget to use "extern" on declarations. -Eli
On May 5, 2010, at 1:22 PM, Nathan Jeffords wrote:> On Wed, May 5, 2010 at 11:15 AM, Chris Lattner <clattner at apple.com> wrote: > On May 4, 2010, at 11:03 AM, Nathan Jeffords wrote: > ... We basically want one MCStreamer callback to correspond to one statement in the .s file. This makes it easier to handle from the compiler standpoint, but is also very important for the llvm-mc assembly parser itself. > > This is an assumption I question. From an evolutionary perspective I agree; Given the existing code base I do see this as a logical transformation. As far as the assembly parser/streamer is concerned it certainly simplifies their implementations. But I also think that this interface could evolve in a direction that simplifies the common case (compiler -> object file) at a small expense to handling assembly language files.The logic to handle this has to go somewhere, putting it in the MCStreamer *implementation* that needs it is the most logical place. We also aim to implement an assembler, it doesn't make sense to duplicate this logic in the compiler and the assembler parser.> > All fragments should be associated with a symbol. For assembler components, a > > unnammed "virtual" symbol can be used when there is no explicit label defined. > > What do you mean by fragment? Can you give me an analogy with what the syntax looks like in a .s file, I'm not sure exactly what you mean here. > > I use the term fragment to refer to the MCFragment class and its derivatives. I understand that to mean any entity representing data in the final linked and loaded form. (something with an address)Ok, MCFragment should definitely be formed behind the MCStreamer implementation. The .s printing implementation of MCStreamer, for example, has no use for it. With the current design, it would be a layering violation to make it earlier.> > > Section assignment should be the responsiblity of the object imlementing the > > MCStreamer interface, with the caller givin the ability to give hints as to > > what section to place the symbol into. > > Section assignment really needs to happen at a higher level. The TargetLoweringObjectFile interfaces are the ones responsible for mapping a global/function -> section. This interface (not mcstreamer) should handle this. > > The important point here is that the COFF MCSection needs to have the right level of semantic information. In fact, MCSection is the place that I'd start for COFF bringup. > > OK, I see that now. The current isolation between TargetLoweringObjectFile -> MCStreamer -> MCObjectWriter has proven somewhat problematic, mostly due to my lack of understanding. I guess MCSectionXXX was meant to provide communication between them. Should the same be true of MCSymbol, and their data counterparts?Yes somewhat. Currently, the COFF implementation of the assembler backend should maintain a DenseMap from MCSymbol* to whatever data you need to associate with a symbol. This is equivalent to embedding per-symbol stuff in the MCSymbol itself. MCSection should be subclassed and you should put COFF specific stuff in MCSectionCOFF.> I had a problem with MCStreamer::EmitCommonSymbol & MCStreamer::EmitLocalCommonSymbol. When I implemented them I assumed this meant to put those symbols into the .bss segment. This required me to get a hold of the TLOF from the streamer. I now realize this is wrong after re-reading the description of the '.comm' directive a few times. I am not sure why an uninitialized global variable was being emitted using this, that seems wrong since global variables in different compilation units with the same name would get merged together at link time. (this is using clang on a C source file)As others have pointed out, this is one of the many horrors of C :) -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100505/98610cd2/attachment.html>
On Wed, 2010-05-05 at 13:22 -0700, Nathan Jeffords wrote:> > The important point here is that the COFF MCSection needs to > have the right level of semantic information. In fact, > MCSection is the place that I'd start for COFF bringup. > > OK, I see that now. The current isolation > between TargetLoweringObjectFile -> MCStreamer -> MCObjectWriter has > proven somewhat problematic, mostly due to my lack of understanding. > I guess MCSectionXXX was meant to provide communication between them. > Should the same be true of MCSymbol, and their data counterparts?I'm enclosing my patch for reforming MCSectionCOFF to match the implementation strategy of the other two MCSection classes. You may find it useful as a starting point. It seems to be complete and correct, and worked for what I tried with it, but I didn't find time to test it fully (e.g., by bootstrapping clang under Cygwin). Cheers, -Peter- -------------- next part -------------- A non-text attachment was scrubbed... Name: mcsectioncoff.diff Type: text/x-patch Size: 24420 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100506/9b09aebb/attachment.bin>