Add @_used and @_section attributes for global variables and top-level functions (#65901)

* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
This commit is contained in:
Kuba (Brecka) Mracek
2023-05-26 14:02:32 -07:00
committed by GitHub
parent ff696c4b5d
commit 2d5f33e2e3
24 changed files with 355 additions and 2 deletions

View File

@@ -3047,6 +3047,15 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
return;
}
case DAK_Section: {
auto *theAttr = cast<SectionAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[SectionDeclAttrLayout::Code];
SectionDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
theAttr->isImplicit(),
theAttr->Name);
return;
}
case DAK_Documentation: {
auto *theAttr = cast<DocumentationAttr>(DA);
auto abbrCode = S.DeclTypeAbbrCodes[DocumentationDeclAttrLayout::Code];