[llvm] 73a9dfc - MC: make section classification a bit more thorough
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 09:46:53 PDT 2022
Author: Saleem Abdulrasool
Date: 2022-08-19T16:45:41Z
New Revision: 73a9dfcee24df959b59a46d75dcbdc0bcfb50fe6
URL: https://github.com/llvm/llvm-project/commit/73a9dfcee24df959b59a46d75dcbdc0bcfb50fe6
DIFF: https://github.com/llvm/llvm-project/commit/73a9dfcee24df959b59a46d75dcbdc0bcfb50fe6.diff
LOG: MC: make section classification a bit more thorough
This does *NOT* change the emitted section flags in any way. This only
impacts the internal classification of sections.
Extend the section classification in LLVM for ELF targets. This has one
important change: we now classify sections as text by default rather
than readonly. This matches the behaviour for GAS better.
Ensure that any section that has a writable attribute set is not treated
as readonly. We also special case any section named `.debug_` which is
reserved for DWARF as metadata. In the case none of the attributes are
set (or because no attributes were provided), consult the section name
for classification. We match the well known names and classify the
section accordingly. Any remaining section is now classified as text.
This change allows us to classify sections in the MC layer more
precisely which is needed for subsequent changes for handling target
specific behaviour.
Differential Revision: https://reviews.llvm.org/D131270
Reviewed By: @echristo
Added:
Modified:
llvm/lib/MC/MCContext.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 29597088a212e..eda266a55c8ec 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -564,8 +564,24 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
Kind = SectionKind::getExecuteOnly();
else if (Flags & ELF::SHF_EXECINSTR)
Kind = SectionKind::getText();
- else
+ else if (~Flags & ELF::SHF_WRITE)
Kind = SectionKind::getReadOnly();
+ else if (Flags & ELF::SHF_TLS)
+ // FIXME: should we
diff erentiate between SHT_PROGBITS and SHT_NOBITS?
+ Kind = SectionKind::getThreadData();
+ else if (CachedName.startswith(".debug_"))
+ Kind = SectionKind::getMetadata();
+ else
+ Kind = llvm::StringSwitch<SectionKind>(CachedName)
+ .Case(".bss", SectionKind::getBSS())
+ .Case(".data", SectionKind::getData())
+ .Case(".data1", SectionKind::getMergeable1ByteCString())
+ .Case(".data.rel.ro", SectionKind::getReadOnlyWithRel())
+ .Case(".rodata", SectionKind::getReadOnly())
+ .Case(".rodata1", SectionKind::getReadOnly())
+ .Case(".tbss", SectionKind::getThreadBSS())
+ .Case(".tdata", SectionKind::getThreadData())
+ .Default(SectionKind::getText());
MCSectionELF *Result =
createELFSectionImpl(CachedName, Type, Flags, Kind, EntrySize, GroupSym,
More information about the llvm-commits
mailing list