diff options
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r-- | llvm/lib/Target/TargetLoweringObjectFile.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp index c05ea70..ee4cca6 100644 --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -138,22 +138,21 @@ void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer, /// getKindForGlobal - This is a top-level target-independent classifier for -/// a global variable. Given an global variable and information from TM, it -/// classifies the global in a variety of ways that make various target -/// implementations simpler. The target implementation is free to ignore this -/// extra info of course. +/// a global object. Given a global variable and information from the TM, this +/// function classifies the global in a target independent manner. This function +/// may be overridden by the target implementation. SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM){ assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() && "Can only be used for global definitions"); - Reloc::Model ReloModel = TM.getRelocationModel(); - - // Early exit - functions should be always in text sections. - const auto *GVar = dyn_cast<GlobalVariable>(GO); - if (!GVar) + // Functions are classified as text sections. + if (isa<Function>(GO)) return SectionKind::getText(); + // Global variables require more detailed analysis. + const auto *GVar = cast<GlobalVariable>(GO); + // Handle thread-local data first. if (GVar->isThreadLocal()) { if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS)) @@ -174,14 +173,13 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO, return SectionKind::getBSS(); } - const Constant *C = GVar->getInitializer(); - // If the global is marked constant, we can put it into a mergable section, // a mergable string section, or general .data if it contains relocations. if (GVar->isConstant()) { // If the initializer for the global contains something that requires a // relocation, then we may have to drop this into a writable data section // even though it is marked const. + const Constant *C = GVar->getInitializer(); if (!C->needsRelocation()) { // If the global is required to have a unique address, it can't be put // into a mergable section: just drop it into the general read-only @@ -227,6 +225,7 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO, // the time the app starts up. However, we can't put this into a // mergable section, because the linker doesn't take relocations into // consideration when it tries to merge entries in the section. + Reloc::Model ReloModel = TM.getRelocationModel(); if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI || ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI) return SectionKind::getReadOnly(); |