[llvm] [BOLT] Do not assume text section name in more places (PR #88303)
Nathan Sidwell via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 11:02:55 PDT 2024
https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/88303
Here are a couple more places where ".text" is presumed for the main code section name. I suppose getting to the reloc section should use ELF's sh_link info, but I don't know how to do that. Thus the awkward construction of a std::string.
>From bbb289757e9f6a3ba71574619ebdfad591655761 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Wed, 10 Apr 2024 11:48:12 -0400
Subject: [PATCH] [BOLT] Do not assume text section name in more places
---
bolt/lib/Rewrite/RewriteInstance.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 0c8ee0d417233b..1f778d030f7ac2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -556,7 +556,7 @@ Error RewriteInstance::discoverStorage() {
if (Error E = SectionNameOrErr.takeError())
return E;
StringRef SectionName = SectionNameOrErr.get();
- if (SectionName == ".text") {
+ if (SectionName == BC->getMainCodeSectionName()) {
BC->OldTextSectionAddress = Section.getAddress();
BC->OldTextSectionSize = Section.getSize();
@@ -1864,7 +1864,8 @@ Error RewriteInstance::readSpecialSections() {
"Use -update-debug-sections to keep it.\n";
}
- HasTextRelocations = (bool)BC->getUniqueSectionByName(".rela.text");
+ HasTextRelocations = (bool)BC->getUniqueSectionByName(
+ ".rela" + std::string(BC->getMainCodeSectionName()));
HasSymbolTable = (bool)BC->getUniqueSectionByName(".symtab");
EHFrameSection = BC->getUniqueSectionByName(".eh_frame");
BuildIDSection = BC->getUniqueSectionByName(".note.gnu.build-id");
@@ -3441,7 +3442,8 @@ void RewriteInstance::emitAndLink() {
ErrorOr<BinarySection &> TextSection =
BC->getUniqueSectionByName(BC->getMainCodeSectionName());
if (BC->HasRelocations && TextSection)
- BC->renameSection(*TextSection, getOrgSecPrefix() + ".text");
+ BC->renameSection(*TextSection,
+ getOrgSecPrefix() + BC->getMainCodeSectionName());
//////////////////////////////////////////////////////////////////////////////
// Assign addresses to new sections.
More information about the llvm-commits
mailing list