[lld] 4092c0d - [ELF,ARM] Move global sectionMap into the ARM class
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 09:08:35 PST 2024
Author: Fangrui Song
Date: 2024-11-18T09:08:30-08:00
New Revision: 4092c0deef466e5b96a221e4066a78ae72efa7af
URL: https://github.com/llvm/llvm-project/commit/4092c0deef466e5b96a221e4066a78ae72efa7af
DIFF: https://github.com/llvm/llvm-project/commit/4092c0deef466e5b96a221e4066a78ae72efa7af.diff
LOG: [ELF,ARM] Move global sectionMap into the ARM class
Otherwise, LLD_IN_TEST=2 testing arm-plt-reloc.s crashes.
Follow-up to https://reviews.llvm.org/D150870
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/ELF/OutputSections.cpp
lld/ELF/Target.h
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 100db445446810..c23a2f872d9183 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -49,15 +49,15 @@ class ARM final : public TargetInfo {
void relocate(uint8_t *loc, const Relocation &rel,
uint64_t val) const override;
+ DenseMap<InputSection *, SmallVector<const Defined *, 0>> sectionMap;
+
private:
-void encodeAluGroup(uint8_t *loc, const Relocation &rel, uint64_t val,
- int group, bool check) const;
+ void encodeAluGroup(uint8_t *loc, const Relocation &rel, uint64_t val,
+ int group, bool check) const;
};
enum class CodeState { Data = 0, Thumb = 2, Arm = 4 };
} // namespace
-static DenseMap<InputSection *, SmallVector<const Defined *, 0>> sectionMap{};
-
ARM::ARM(Ctx &ctx) : TargetInfo(ctx) {
copyRel = R_ARM_COPY;
relativeRel = R_ARM_RELATIVE;
@@ -1047,10 +1047,10 @@ static bool isDataMapSymbol(const Symbol *b) {
return b->getName() == "$d" || b->getName().starts_with("$d.");
}
-void elf::sortArmMappingSymbols() {
+void elf::sortArmMappingSymbols(Ctx &ctx) {
// For each input section make sure the mapping symbols are sorted in
// ascending order.
- for (auto &kv : sectionMap) {
+ for (auto &kv : static_cast<ARM &>(*ctx.target).sectionMap) {
SmallVector<const Defined *, 0> &mapSyms = kv.second;
llvm::stable_sort(mapSyms, [](const Defined *a, const Defined *b) {
return a->value < b->value;
@@ -1063,6 +1063,7 @@ void elf::addArmInputSectionMappingSymbols(Ctx &ctx) {
// The linker generated mapping symbols for all the synthetic
// sections are adding into the sectionmap through the function
// addArmSyntheitcSectionMappingSymbol.
+ auto §ionMap = static_cast<ARM &>(*ctx.target).sectionMap;
for (ELFFileBase *file : ctx.objectFiles) {
for (Symbol *sym : file->getLocalSymbols()) {
auto *def = dyn_cast<Defined>(sym);
@@ -1088,7 +1089,7 @@ void elf::addArmSyntheticSectionMappingSymbol(Defined *sym) {
return;
if (auto *sec = cast_if_present<InputSection>(sym->section))
if (sec->flags & SHF_EXECINSTR)
- sectionMap[sec].push_back(sym);
+ static_cast<ARM &>(*sec->file->ctx.target).sectionMap[sec].push_back(sym);
}
static void toLittleEndianInstructions(uint8_t *buf, uint64_t start,
@@ -1109,7 +1110,9 @@ static void toLittleEndianInstructions(uint8_t *buf, uint64_t start,
// identify half open intervals of Arm code [$a, non $a) and Thumb code
// [$t, non $t) and convert these to little endian a word or half word at a
// time respectively.
-void elf::convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf) {
+void elf::convertArmInstructionstoBE8(Ctx &ctx, InputSection *sec,
+ uint8_t *buf) {
+ auto §ionMap = static_cast<ARM &>(*ctx.target).sectionMap;
auto it = sectionMap.find(sec);
if (it == sectionMap.end())
return;
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 094524f9b5379b..94cf62d79abb21 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -536,7 +536,7 @@ void OutputSection::writeTo(Ctx &ctx, uint8_t *buf, parallel::TaskGroup &tg) {
// instructions to little-endian, leaving the data big-endian.
if (ctx.arg.emachine == EM_ARM && !ctx.arg.isLE && ctx.arg.armBe8 &&
(flags & SHF_EXECINSTR))
- convertArmInstructionstoBE8(isec, buf + isec->outSecOff);
+ convertArmInstructionstoBE8(ctx, isec, buf + isec->outSecOff);
// Fill gaps between sections.
if (nonZeroFiller) {
diff --git a/lld/ELF/Target.h b/lld/ELF/Target.h
index 2277537a4e357a..ce42d3624a8f5b 100644
--- a/lld/ELF/Target.h
+++ b/lld/ELF/Target.h
@@ -246,8 +246,8 @@ void riscvFinalizeRelax(int passes);
void mergeRISCVAttributesSections(Ctx &);
void addArmInputSectionMappingSymbols(Ctx &);
void addArmSyntheticSectionMappingSymbol(Defined *);
-void sortArmMappingSymbols();
-void convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf);
+void sortArmMappingSymbols(Ctx &);
+void convertArmInstructionstoBE8(Ctx &, InputSection *sec, uint8_t *buf);
void createTaggedSymbols(Ctx &);
void initSymbolAnchors(Ctx &);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 5865ead0ff88bb..d698479c9707fb 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2095,7 +2095,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
if (ctx.arg.emachine == EM_ARM && !ctx.arg.isLE && ctx.arg.armBe8) {
addArmInputSectionMappingSymbols(ctx);
- sortArmMappingSymbols();
+ sortArmMappingSymbols(ctx);
}
}
More information about the llvm-commits
mailing list