<div dir="ltr">D95851 introduces support for zero flag ELF section groups to LLVM. <span style="color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">LLVM already supports COMDAT sections, which in ELF are a </span><span style="color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:13px">special type of ELF section groups. </span>These are generally useful to enable linker GC where you want a group of sections to always travel together, that is to be either retained or discarded as a whole, but without the COMDAT semantics. Other ELF assemblers and linkers already support zero flag ELF section groups and this change helps us reach feature parity.<div><br><div><span style="font-size:13px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif">An open question is how to best represent these in LLVM IR.</span></div><div><span style="font-size:13px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif"><br></span></div><div><span style="font-size:13px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif">We represent COMDAT sections as global variables</span> and other global variables can be included in COMDAT sections, <span style="font-size:13px;color:rgb(0,0,0);font-family:"Segoe UI","Segoe UI Emoji","Segoe UI Symbol",Lato,"Helvetica Neue",Helvetica,Arial,sans-serif">see </span><a href="https://llvm.org/docs/LangRef.html#comdats">https://llvm.org/docs/LangRef.html#comdats</a> for details.</div><div><br></div><div>We want to capture the fact that COMDAT sections are a special type of ELF section groups and we also want to preserve the existing syntax and API for backwards compatibility, but also because other formats like COFF support COMDAT sections, but not section groups.</div><div><br></div><div>Our proposal is to introduce ELF section groups as a new type of global variable akin to COMDAT sections. We would extend the language by changing:</div><div><br></div><div>  [, comdat[($name)]]</div><div><br></div><div>when declaring a global variable to:</div><div><br></div><div>  [, \(group[($name)] | [group] comdat[($name)]\)]</div><div><br></div><div>When it comes to C++ API, we would introduce Group as a superclass of Comdat:</div><div><br></div><div>  class Group {<br>    StringRef getName() const;<br>  };<br>  class Comdat : public Group {<br>    ...<br>  };</div>  class GlobalObject : public GlobalValue {<br>    ...<br>    bool hasGroup();<br>    Group *getGroup();<br>    void setGroup(Group G);<br>    // has/get/setComdat functions re-implemented in terms of has/get/setGroup<br>    ...<br><div>  };<br><br></div></div><div>Does this make sense? Can anyone think of a better representation?</div></div>