Skip to content

Commit 4092c0d

Browse files
committed
[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
1 parent 6bf8f08 commit 4092c0d

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class ARM final : public TargetInfo {
4949
void relocate(uint8_t *loc, const Relocation &rel,
5050
uint64_t val) const override;
5151

52+
DenseMap<InputSection *, SmallVector<const Defined *, 0>> sectionMap;
53+
5254
private:
53-
void encodeAluGroup(uint8_t *loc, const Relocation &rel, uint64_t val,
54-
int group, bool check) const;
55+
void encodeAluGroup(uint8_t *loc, const Relocation &rel, uint64_t val,
56+
int group, bool check) const;
5557
};
5658
enum class CodeState { Data = 0, Thumb = 2, Arm = 4 };
5759
} // namespace
5860

59-
static DenseMap<InputSection *, SmallVector<const Defined *, 0>> sectionMap{};
60-
6161
ARM::ARM(Ctx &ctx) : TargetInfo(ctx) {
6262
copyRel = R_ARM_COPY;
6363
relativeRel = R_ARM_RELATIVE;
@@ -1047,10 +1047,10 @@ static bool isDataMapSymbol(const Symbol *b) {
10471047
return b->getName() == "$d" || b->getName().starts_with("$d.");
10481048
}
10491049

1050-
void elf::sortArmMappingSymbols() {
1050+
void elf::sortArmMappingSymbols(Ctx &ctx) {
10511051
// For each input section make sure the mapping symbols are sorted in
10521052
// ascending order.
1053-
for (auto &kv : sectionMap) {
1053+
for (auto &kv : static_cast<ARM &>(*ctx.target).sectionMap) {
10541054
SmallVector<const Defined *, 0> &mapSyms = kv.second;
10551055
llvm::stable_sort(mapSyms, [](const Defined *a, const Defined *b) {
10561056
return a->value < b->value;
@@ -1063,6 +1063,7 @@ void elf::addArmInputSectionMappingSymbols(Ctx &ctx) {
10631063
// The linker generated mapping symbols for all the synthetic
10641064
// sections are adding into the sectionmap through the function
10651065
// addArmSyntheitcSectionMappingSymbol.
1066+
auto &sectionMap = static_cast<ARM &>(*ctx.target).sectionMap;
10661067
for (ELFFileBase *file : ctx.objectFiles) {
10671068
for (Symbol *sym : file->getLocalSymbols()) {
10681069
auto *def = dyn_cast<Defined>(sym);
@@ -1088,7 +1089,7 @@ void elf::addArmSyntheticSectionMappingSymbol(Defined *sym) {
10881089
return;
10891090
if (auto *sec = cast_if_present<InputSection>(sym->section))
10901091
if (sec->flags & SHF_EXECINSTR)
1091-
sectionMap[sec].push_back(sym);
1092+
static_cast<ARM &>(*sec->file->ctx.target).sectionMap[sec].push_back(sym);
10921093
}
10931094

10941095
static void toLittleEndianInstructions(uint8_t *buf, uint64_t start,
@@ -1109,7 +1110,9 @@ static void toLittleEndianInstructions(uint8_t *buf, uint64_t start,
11091110
// identify half open intervals of Arm code [$a, non $a) and Thumb code
11101111
// [$t, non $t) and convert these to little endian a word or half word at a
11111112
// time respectively.
1112-
void elf::convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf) {
1113+
void elf::convertArmInstructionstoBE8(Ctx &ctx, InputSection *sec,
1114+
uint8_t *buf) {
1115+
auto &sectionMap = static_cast<ARM &>(*ctx.target).sectionMap;
11131116
auto it = sectionMap.find(sec);
11141117
if (it == sectionMap.end())
11151118
return;

lld/ELF/OutputSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ void OutputSection::writeTo(Ctx &ctx, uint8_t *buf, parallel::TaskGroup &tg) {
536536
// instructions to little-endian, leaving the data big-endian.
537537
if (ctx.arg.emachine == EM_ARM && !ctx.arg.isLE && ctx.arg.armBe8 &&
538538
(flags & SHF_EXECINSTR))
539-
convertArmInstructionstoBE8(isec, buf + isec->outSecOff);
539+
convertArmInstructionstoBE8(ctx, isec, buf + isec->outSecOff);
540540

541541
// Fill gaps between sections.
542542
if (nonZeroFiller) {

lld/ELF/Target.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ void riscvFinalizeRelax(int passes);
246246
void mergeRISCVAttributesSections(Ctx &);
247247
void addArmInputSectionMappingSymbols(Ctx &);
248248
void addArmSyntheticSectionMappingSymbol(Defined *);
249-
void sortArmMappingSymbols();
250-
void convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf);
249+
void sortArmMappingSymbols(Ctx &);
250+
void convertArmInstructionstoBE8(Ctx &, InputSection *sec, uint8_t *buf);
251251
void createTaggedSymbols(Ctx &);
252252
void initSymbolAnchors(Ctx &);
253253

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
20952095

20962096
if (ctx.arg.emachine == EM_ARM && !ctx.arg.isLE && ctx.arg.armBe8) {
20972097
addArmInputSectionMappingSymbols(ctx);
2098-
sortArmMappingSymbols();
2098+
sortArmMappingSymbols(ctx);
20992099
}
21002100
}
21012101

0 commit comments

Comments
 (0)