[PATCH] D110350: [llvm-objcopy][NFC] Add a helper method RelocationSectionBase::getPrefix()
Igor Kudrin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 10:44:18 PDT 2021
ikudrin created this revision.
ikudrin added reviewers: jhenderson, MaskRay.
ikudrin added a project: LLVM.
Herald added subscribers: abrachet, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
ikudrin requested review of this revision.
Refactor `handleArgs()` to use that method.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D110350
Files:
llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
llvm/tools/llvm-objcopy/ELF/Object.cpp
llvm/tools/llvm-objcopy/ELF/Object.h
Index: llvm/tools/llvm-objcopy/ELF/Object.h
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.h
+++ llvm/tools/llvm-objcopy/ELF/Object.h
@@ -745,6 +745,8 @@
const SectionBase *getSection() const { return SecToApplyRel; }
void setSection(SectionBase *Sec) { SecToApplyRel = Sec; }
+ StringRef getPrefix() const;
+
static bool classof(const SectionBase *S) {
return S->OriginalType == ELF::SHT_REL || S->OriginalType == ELF::SHT_RELA;
}
Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -893,6 +893,17 @@
return Visitor.visit(*this);
}
+StringRef RelocationSectionBase::getPrefix() const {
+ switch (Type) {
+ case SHT_REL:
+ return ".rel";
+ case SHT_RELA:
+ return ".rela";
+ default:
+ llvm_unreachable("not a relocation section");
+ }
+}
+
Error RelocationSection::removeSectionReferences(
bool AllowBrokenLinks, function_ref<bool(const SectionBase *)> ToRemove) {
if (ToRemove(Symbols)) {
Index: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -618,27 +618,16 @@
// .rela.prefix.plt since GNU objcopy does so.
const SectionBase *TargetSec = RelocSec->getSection();
if (TargetSec && (TargetSec->Flags & SHF_ALLOC)) {
- StringRef prefix;
- switch (Sec.Type) {
- case SHT_REL:
- prefix = ".rel";
- break;
- case SHT_RELA:
- prefix = ".rela";
- break;
- default:
- llvm_unreachable("not a relocation section");
- }
-
// If the relocation section comes *after* the target section, we
// don't add Config.AllocSectionsPrefix because we've already added
// the prefix to TargetSec->Name. Otherwise, if the relocation
// section comes *before* the target section, we add the prefix.
if (PrefixedSections.count(TargetSec))
- Sec.Name = (prefix + TargetSec->Name).str();
+ Sec.Name = (RelocSec->getPrefix() + TargetSec->Name).str();
else
- Sec.Name =
- (prefix + Config.AllocSectionsPrefix + TargetSec->Name).str();
+ Sec.Name = (RelocSec->getPrefix() + Config.AllocSectionsPrefix +
+ TargetSec->Name)
+ .str();
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110350.374616.patch
Type: text/x-patch
Size: 2661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210923/35f33a1d/attachment.bin>
More information about the llvm-commits
mailing list