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
> > > Global definitions like "int x;" are treated as common to allow > linking buggy programs that forget to use "extern" on declarations.Is this always the behavior, or only when certain options are set? This seems like a violation of the language standard. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100505/462b7188/attachment.html>
On May 5, 2010, at 2:32 PMPDT, Nathan Jeffords wrote:> > Global definitions like "int x;" are treated as common to allow > linking buggy programs that forget to use "extern" on declarations. > > Is this always the behavior, or only when certain options are set? This seems like a violation of the language standard.Technically yes; the original K&R C book had the one-definition rule in it. Early C compilers did not work this way, however, and by the time that book was published (1978) there was already a large body of code that assumed the "common" model (also Ritchie's preference, I believe). In practice most compilers still default to this model because a lot of widely used stuff will break if they don't, and the behavior is given in J.5.11 of C99 as a common extension. Use -fno-common to turn it off. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100505/9ea61ead/attachment.html>
Somewhere I had got it in my head that global variables had static storage class by default. I guess I was wrong. On May 5, 2010 2:45 PM, "Dale Johannesen" <dalej at apple.com> wrote: On May 5, 2010, at 2:32 PMPDT, Nathan Jeffords wrote:>> >> Global definitions like "int x;" are t...Technically yes; the original K&R C book had the one-definition rule in it. Early C compilers did not work this way, however, and by the time that book was published (1978) there was already a large body of code that assumed the "common" model (also Ritchie's preference, I believe). In practice most compilers still default to this model because a lot of widely used stuff will break if they don't, and the behavior is given in J.5.11 of C99 as a common extension. Use -fno-common to turn it off. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100505/ef477be9/attachment.html>
Re having all fragments associated with some symbol -- this makes sense if you think in high level terms and assume all symbols to be some "objects". All data (fragments) you want to output is associated with some "object" (symbol). However, that's probably too high level thinking for MC interface. High level objects might not directly correspond to object-file level symbols. For example, module level inline assembler does not correspond to any symbol, or function may have more than one symbol when aliases are used. Common is not .bss, it's an archaic concept inherited from Fortran. C language specifies that global uninitialized variables are put into common. This isn't for "programs that forget to use extern" -- you can't get the same behaviour with extern, common variables are glued together and with "normal" variables, so no object is exclusively owns the variable. There's also some subtle difference when linking archives. Eugene On Wed, May 5, 2010 at 10:32 PM, Nathan Jeffords <blunted2night at gmail.com> wrote:>> >> Global definitions like "int x;" are treated as common to allow >> linking buggy programs that forget to use "extern" on declarations. > > Is this always the behavior, or only when certain options are set? This > seems like a violation of the language standard. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >