Skip to content

Commit d885138

Browse files
committed
Revert "[lld][Arm] Big Endian - Byte invariant support."
This reverts commit 8cf8956.
1 parent 7dcb9c0 commit d885138

32 files changed

+68
-432
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "InputFiles.h"
109
#include "Symbols.h"
1110
#include "SyntheticSections.h"
1211
#include "Target.h"
@@ -45,11 +44,8 @@ class ARM final : public TargetInfo {
4544
void relocate(uint8_t *loc, const Relocation &rel,
4645
uint64_t val) const override;
4746
};
48-
enum class CodeState { Data = 0, Thumb = 2, Arm = 4 };
4947
} // namespace
5048

51-
static DenseMap<InputSection *, SmallVector<const Defined *, 0>> sectionMap;
52-
5349
ARM::ARM() {
5450
copyRel = R_ARM_COPY;
5551
relativeRel = R_ARM_RELATIVE;
@@ -72,24 +68,16 @@ uint32_t ARM::calcEFlags() const {
7268
// The ABIFloatType is used by loaders to detect the floating point calling
7369
// convention.
7470
uint32_t abiFloatType = 0;
75-
76-
// Set the EF_ARM_BE8 flag in the ELF header, if ELF file is big-endian
77-
// with BE-8 code.
78-
uint32_t armBE8 = 0;
79-
8071
if (config->armVFPArgs == ARMVFPArgKind::Base ||
8172
config->armVFPArgs == ARMVFPArgKind::Default)
8273
abiFloatType = EF_ARM_ABI_FLOAT_SOFT;
8374
else if (config->armVFPArgs == ARMVFPArgKind::VFP)
8475
abiFloatType = EF_ARM_ABI_FLOAT_HARD;
8576

86-
if (!config->isLE && config->armBe8)
87-
armBE8 = EF_ARM_BE8;
88-
8977
// We don't currently use any features incompatible with EF_ARM_EABI_VER5,
9078
// but we don't have any firm guarantees of conformance. Linux AArch64
9179
// kernels (as of 2016) require an EABI version to be set.
92-
return EF_ARM_EABI_VER5 | abiFloatType | armBE8;
80+
return EF_ARM_EABI_VER5 | abiFloatType;
9381
}
9482

9583
RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
@@ -922,114 +910,6 @@ int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {
922910
}
923911
}
924912

925-
static bool isArmMapSymbol(const Symbol *b) {
926-
return b->getName() == "$a" || b->getName().startswith("$a.");
927-
}
928-
929-
static bool isThumbMapSymbol(const Symbol *s) {
930-
return s->getName() == "$t" || s->getName().startswith("$t.");
931-
}
932-
933-
static bool isDataMapSymbol(const Symbol *b) {
934-
return b->getName() == "$d" || b->getName().startswith("$d.");
935-
}
936-
937-
void elf::sortArmMappingSymbols() {
938-
// For each input section make sure the mapping symbols are sorted in
939-
// ascending order.
940-
for (auto &kv : sectionMap) {
941-
SmallVector<const Defined *, 0> &mapSyms = kv.second;
942-
llvm::stable_sort(mapSyms, [](const Defined *a, const Defined *b) {
943-
return a->value < b->value;
944-
});
945-
}
946-
}
947-
948-
void elf::addArmInputSectionMappingSymbols() {
949-
// Collect mapping symbols for every executable input sections.
950-
// The linker generated mapping symbols for all the synthetic
951-
// sections are adding into the sectionmap through the function
952-
// addArmSyntheitcSectionMappingSymbol.
953-
for (ELFFileBase *file : ctx.objectFiles) {
954-
for (Symbol *sym : file->getLocalSymbols()) {
955-
auto *def = dyn_cast<Defined>(sym);
956-
if (!def)
957-
continue;
958-
if (!isArmMapSymbol(def) && !isDataMapSymbol(def) &&
959-
!isThumbMapSymbol(def))
960-
continue;
961-
if (auto *sec = cast_if_present<InputSection>(def->section))
962-
if (sec->flags & SHF_EXECINSTR)
963-
sectionMap[sec].push_back(def);
964-
}
965-
}
966-
}
967-
968-
// Synthetic sections are not backed by an ELF file where we can access the
969-
// symbol table, instead mapping symbols added to synthetic sections are stored
970-
// in the synthetic symbol table. Due to the presence of strip (--strip-all),
971-
// we can not rely on the synthetic symbol table retaining the mapping symbols.
972-
// Instead we record the mapping symbols locally.
973-
void elf::addArmSyntheticSectionMappingSymbol(Defined *sym) {
974-
if (!isArmMapSymbol(sym) && !isDataMapSymbol(sym) && !isThumbMapSymbol(sym))
975-
return;
976-
if (auto *sec = cast_if_present<InputSection>(sym->section))
977-
if (sec->flags & SHF_EXECINSTR)
978-
sectionMap[sec].push_back(sym);
979-
}
980-
981-
static void toLittleEndianInstructions(uint8_t *buf, uint64_t start,
982-
uint64_t end, uint64_t width) {
983-
CodeState curState = static_cast<CodeState>(width);
984-
if (curState == CodeState::Arm)
985-
for (uint64_t i = start; i < end; i += width)
986-
write32le(buf + i, read32(buf + i));
987-
988-
if (curState == CodeState::Thumb)
989-
for (uint64_t i = start; i < end; i += width)
990-
write16le(buf + i, read16(buf + i));
991-
}
992-
993-
// Arm BE8 big endian format requires instructions to be little endian, with
994-
// the initial contents big-endian. Convert the big-endian instructions to
995-
// little endian leaving literal data untouched. We use mapping symbols to
996-
// identify half open intervals of Arm code [$a, non $a) and Thumb code
997-
// [$t, non $t) and convert these to little endian a word or half word at a
998-
// time respectively.
999-
void elf::convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf) {
1000-
SmallVector<const Defined *, 0> &mapSyms = sectionMap[sec];
1001-
1002-
if (mapSyms.empty())
1003-
return;
1004-
1005-
CodeState curState = CodeState::Data;
1006-
uint64_t start = 0, width = 0, size = sec->getSize();
1007-
for (auto &msym : mapSyms) {
1008-
CodeState newState = CodeState::Data;
1009-
if (isThumbMapSymbol(msym))
1010-
newState = CodeState::Thumb;
1011-
else if (isArmMapSymbol(msym))
1012-
newState = CodeState::Arm;
1013-
1014-
if (newState == curState)
1015-
continue;
1016-
1017-
if (curState != CodeState::Data) {
1018-
width = static_cast<uint64_t>(curState);
1019-
toLittleEndianInstructions(buf, start, msym->value, width);
1020-
}
1021-
start = msym->value;
1022-
curState = newState;
1023-
}
1024-
1025-
// Passed last mapping symbol, may need to reverse
1026-
// up to end of section.
1027-
if (curState != CodeState::Data) {
1028-
width = static_cast<uint64_t>(curState);
1029-
toLittleEndianInstructions(buf, start, size, width);
1030-
}
1031-
}
1032-
1033913
TargetInfo *elf::getARMTargetInfo() {
1034914
static ARM target;
1035915
return &target;

lld/ELF/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ struct Config {
201201
bool armHasMovtMovw = false;
202202
bool armJ1J2BranchEncoding = false;
203203
bool asNeeded = false;
204-
bool armBe8 = false;
205204
BsymbolicKind bsymbolic = BsymbolicKind::None;
206205
bool callGraphProfileSort;
207206
bool checkSections;

lld/ELF/Driver.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,9 @@ static void checkOptions() {
351351
if (config->fixCortexA8 && config->emachine != EM_ARM)
352352
error("--fix-cortex-a8 is only supported on ARM targets");
353353

354-
if (config->armBe8 && config->emachine != EM_ARM)
355-
error("--be8 is only supported on ARM targets");
356-
357354
if (config->fixCortexA8 && !config->isLE)
358355
error("--fix-cortex-a8 is not supported on big endian targets");
359-
356+
360357
if (config->tocOptimize && config->emachine != EM_PPC64)
361358
error("--toc-optimize is only supported on PowerPC64 targets");
362359

@@ -1118,7 +1115,6 @@ static void readConfigs(opt::InputArgList &args) {
11181115
OPT_no_android_memtag_stack, false);
11191116
config->androidMemtagMode = getMemtagMode(args);
11201117
config->auxiliaryList = args::getStrings(args, OPT_auxiliary);
1121-
config->armBe8 = args.hasArg(OPT_be8);
11221118
if (opt::Arg *arg =
11231119
args.getLastArg(OPT_Bno_symbolic, OPT_Bsymbolic_non_weak_functions,
11241120
OPT_Bsymbolic_functions, OPT_Bsymbolic)) {

lld/ELF/Options.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ multiclass B<string name, string help1, string help2> {
3636

3737
defm auxiliary: Eq<"auxiliary", "Set DT_AUXILIARY field to the specified name">;
3838

39-
def be8: F<"be8">, HelpText<"write a Big Endian ELF file using BE8 format (AArch32 only)">;
40-
4139
def Bno_symbolic: F<"Bno-symbolic">, HelpText<"Don't bind default visibility defined symbols locally for -shared (default)">;
4240

4341
def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind default visibility defined symbols locally for -shared">;

lld/ELF/OutputSections.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,6 @@ void OutputSection::writeTo(uint8_t *buf, parallel::TaskGroup &tg) {
496496
else
497497
isec->writeTo<ELFT>(buf + isec->outSecOff);
498498

499-
// When in Arm BE8 mode, the linker has to convert the big-endian
500-
// instructions to little-endian, leaving the data big-endian.
501-
if (config->emachine == EM_ARM && !config->isLE && config->armBe8 &&
502-
(flags & SHF_EXECINSTR))
503-
convertArmInstructionstoBE8(isec, buf + isec->outSecOff);
504-
505499
// Fill gaps between sections.
506500
if (nonZeroFiller) {
507501
uint8_t *start = buf + isec->outSecOff + isec->getSize();

lld/ELF/SyntheticSections.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,6 @@ Defined *elf::addSyntheticLocal(StringRef name, uint8_t type, uint64_t value,
271271
value, size, &section);
272272
if (in.symTab)
273273
in.symTab->addSymbol(s);
274-
275-
if (config->emachine == EM_ARM && !config->isLE && config->armBe8 &&
276-
(section.flags & SHF_EXECINSTR))
277-
// Adding Linker generated mapping symbols to the arm specific mapping
278-
// symbols list.
279-
addArmSyntheticSectionMappingSymbol(s);
280-
281274
return s;
282275
}
283276

lld/ELF/Target.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ uint64_t getPPC64TocBase();
223223
uint64_t getAArch64Page(uint64_t expr);
224224
void riscvFinalizeRelax(int passes);
225225
void mergeRISCVAttributesSections();
226-
void addArmInputSectionMappingSymbols();
227-
void addArmSyntheticSectionMappingSymbol(Defined *);
228-
void sortArmMappingSymbols();
229-
void convertArmInstructionstoBE8(InputSection *sec, uint8_t *buf);
230226

231227
LLVM_LIBRARY_VISIBILITY extern const TargetInfo *target;
232228
TargetInfo *getTarget();

lld/ELF/Thunks.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,7 @@ void ThumbV6MABSLongThunk::addSymbols(ThunkSection &isec) {
744744
addSymbol(saver().save("__Thumbv6MABSLongThunk_" + destination.getName()),
745745
STT_FUNC, 1, isec);
746746
addSymbol("$t", STT_NOTYPE, 0, isec);
747-
if (!getMayUseShortThunk())
748-
addSymbol("$d", STT_NOTYPE, 8, isec);
747+
addSymbol("$d", STT_NOTYPE, 8, isec);
749748
}
750749

751750
void ThumbV6MPILongThunk::writeLong(uint8_t *buf) {
@@ -768,8 +767,7 @@ void ThumbV6MPILongThunk::addSymbols(ThunkSection &isec) {
768767
addSymbol(saver().save("__Thumbv6MPILongThunk_" + destination.getName()),
769768
STT_FUNC, 1, isec);
770769
addSymbol("$t", STT_NOTYPE, 0, isec);
771-
if (!getMayUseShortThunk())
772-
addSymbol("$d", STT_NOTYPE, 12, isec);
770+
addSymbol("$d", STT_NOTYPE, 12, isec);
773771
}
774772

775773
void ARMV5LongLdrPcThunk::writeLong(uint8_t *buf) {
@@ -782,8 +780,7 @@ void ARMV5LongLdrPcThunk::addSymbols(ThunkSection &isec) {
782780
addSymbol(saver().save("__ARMv5LongLdrPcThunk_" + destination.getName()),
783781
STT_FUNC, 0, isec);
784782
addSymbol("$a", STT_NOTYPE, 0, isec);
785-
if (!getMayUseShortThunk())
786-
addSymbol("$d", STT_NOTYPE, 4, isec);
783+
addSymbol("$d", STT_NOTYPE, 4, isec);
787784
}
788785

789786
void ARMV4ABSLongBXThunk::writeLong(uint8_t *buf) {
@@ -797,8 +794,7 @@ void ARMV4ABSLongBXThunk::addSymbols(ThunkSection &isec) {
797794
addSymbol(saver().save("__ARMv4ABSLongBXThunk_" + destination.getName()),
798795
STT_FUNC, 0, isec);
799796
addSymbol("$a", STT_NOTYPE, 0, isec);
800-
if (!getMayUseShortThunk())
801-
addSymbol("$d", STT_NOTYPE, 8, isec);
797+
addSymbol("$d", STT_NOTYPE, 8, isec);
802798
}
803799

804800
void ThumbV4ABSLongBXThunk::writeLong(uint8_t *buf) {
@@ -814,8 +810,7 @@ void ThumbV4ABSLongBXThunk::addSymbols(ThunkSection &isec) {
814810
STT_FUNC, 1, isec);
815811
addSymbol("$t", STT_NOTYPE, 0, isec);
816812
addSymbol("$a", STT_NOTYPE, 4, isec);
817-
if (!getMayUseShortThunk())
818-
addSymbol("$d", STT_NOTYPE, 8, isec);
813+
addSymbol("$d", STT_NOTYPE, 8, isec);
819814
}
820815

821816
void ThumbV4ABSLongThunk::writeLong(uint8_t *buf) {
@@ -832,8 +827,7 @@ void ThumbV4ABSLongThunk::addSymbols(ThunkSection &isec) {
832827
STT_FUNC, 1, isec);
833828
addSymbol("$t", STT_NOTYPE, 0, isec);
834829
addSymbol("$a", STT_NOTYPE, 4, isec);
835-
if (!getMayUseShortThunk())
836-
addSymbol("$d", STT_NOTYPE, 12, isec);
830+
addSymbol("$d", STT_NOTYPE, 12, isec);
837831
}
838832

839833
void ARMV4PILongBXThunk::writeLong(uint8_t *buf) {
@@ -850,8 +844,7 @@ void ARMV4PILongBXThunk::addSymbols(ThunkSection &isec) {
850844
addSymbol(saver().save("__ARMv4PILongBXThunk_" + destination.getName()),
851845
STT_FUNC, 0, isec);
852846
addSymbol("$a", STT_NOTYPE, 0, isec);
853-
if (!getMayUseShortThunk())
854-
addSymbol("$d", STT_NOTYPE, 12, isec);
847+
addSymbol("$d", STT_NOTYPE, 12, isec);
855848
}
856849

857850
void ARMV4PILongThunk::writeLong(uint8_t *buf) {
@@ -867,8 +860,7 @@ void ARMV4PILongThunk::addSymbols(ThunkSection &isec) {
867860
addSymbol(saver().save("__ARMv4PILongThunk_" + destination.getName()),
868861
STT_FUNC, 0, isec);
869862
addSymbol("$a", STT_NOTYPE, 0, isec);
870-
if (!getMayUseShortThunk())
871-
addSymbol("$d", STT_NOTYPE, 8, isec);
863+
addSymbol("$d", STT_NOTYPE, 8, isec);
872864
}
873865

874866
void ThumbV4PILongBXThunk::writeLong(uint8_t *buf) {
@@ -887,8 +879,7 @@ void ThumbV4PILongBXThunk::addSymbols(ThunkSection &isec) {
887879
STT_FUNC, 1, isec);
888880
addSymbol("$t", STT_NOTYPE, 0, isec);
889881
addSymbol("$a", STT_NOTYPE, 4, isec);
890-
if (!getMayUseShortThunk())
891-
addSymbol("$d", STT_NOTYPE, 12, isec);
882+
addSymbol("$d", STT_NOTYPE, 12, isec);
892883
}
893884

894885
void ThumbV4PILongThunk::writeLong(uint8_t *buf) {
@@ -908,8 +899,7 @@ void ThumbV4PILongThunk::addSymbols(ThunkSection &isec) {
908899
STT_FUNC, 1, isec);
909900
addSymbol("$t", STT_NOTYPE, 0, isec);
910901
addSymbol("$a", STT_NOTYPE, 4, isec);
911-
if (!getMayUseShortThunk())
912-
addSymbol("$d", STT_NOTYPE, 16, isec);
902+
addSymbol("$d", STT_NOTYPE, 16, isec);
913903
}
914904

915905
// Use the long jump which covers a range up to 8MiB.

lld/ELF/Writer.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,11 +2149,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
21492149
sec->finalize();
21502150

21512151
script->checkMemoryRegions();
2152-
2153-
if (config->emachine == EM_ARM && !config->isLE && config->armBe8) {
2154-
addArmInputSectionMappingSymbols();
2155-
sortArmMappingSymbols();
2156-
}
21572152
}
21582153

21592154
// Ensure data sections are not mixed with executable sections when

lld/docs/ld.lld.1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ Bind default visibility defined function symbols locally for
8888
.It Fl Bsymbolic-non-weak-functions
8989
Bind default visibility defined STB_GLOBAL function symbols locally for
9090
.Fl shared.
91-
.It Fl --be8
92-
Write a Big Endian ELF File using BE8 format(AArch32 only)
9391
.It Fl -build-id Ns = Ns Ar value
9492
Generate a build ID note.
9593
.Ar value

lld/test/ELF/arm-bl-v6.s

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
// RUN: llvm-objdump --no-print-imm-hex -d --triple=armv6eb-none-linux-gnueabi --start-address=0x22100c --stop-address=0x221014 %t2 | FileCheck --check-prefix=CHECK-ARM2-EB %s
1414
// RUN: llvm-objdump --no-print-imm-hex -d --triple=thumbv6eb-none-linux-gnueabi %t2 --start-address=0x622000 --stop-address=0x622002 | FileCheck --check-prefix=CHECK-THUMB2 %s
1515

16-
// RUN: ld.lld --be8 %t -o %t2
17-
// RUN: llvm-objdump --no-print-imm-hex -d --triple=armv6eb-none-linux-gnueabi --start-address=0x21000 --stop-address=0x21008 %t2 | FileCheck --check-prefix=CHECK-ARM1 %s
18-
// RUN: llvm-objdump --no-print-imm-hex -d --triple=thumbv6eb-none-linux-gnueabi %t2 --start-address=0x21008 --stop-address=0x2100c | FileCheck --check-prefix=CHECK-THUMB1 %s
19-
// RUN: llvm-objdump --no-print-imm-hex -d --triple=armv6eb-none-linux-gnueabi --start-address=0x22100c --stop-address=0x221014 %t2 | FileCheck --check-prefix=CHECK-ARM2-EB %s
20-
// RUN: llvm-objdump --no-print-imm-hex -d --triple=thumbv6eb-none-linux-gnueabi %t2 --start-address=0x622000 --stop-address=0x622002 | FileCheck --check-prefix=CHECK-THUMB2 %s
21-
2216
/// On Arm v6 the range of a Thumb BL instruction is only 4 megabytes as the
2317
/// extended range encoding is not supported. The following example has a Thumb
2418
/// BL that is out of range on ARM v6 and requires a range extension thunk.

lld/test/ELF/arm-data-relocs.s

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
// RUN: ld.lld %t.be.o %t256.be.o -o %t.be
1010
// RUN: llvm-objdump -s %t.be | FileCheck %s --check-prefixes=CHECK,BE
1111

12-
// RUN: ld.lld --be8 %t.be.o %t256.be.o -o %t.be8
13-
// RUN: llvm-objdump -s %t.be8 | FileCheck %s --check-prefixes=CHECK,BE
14-
1512
.globl _start
1613
_start:
1714
.section .R_ARM_ABS, "ax","progbits"

lld/test/ELF/arm-exidx-emit-relocs.s

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
// RUN: llvm-objdump -s --triple=armv7aeb-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-EB %s
1010
// RUN: llvm-readelf --relocs %t2 | FileCheck -check-prefix=CHECK-RELOCS %s
1111

12-
// RUN: ld.lld --be8 --emit-relocs %t -o %t2
13-
// RUN: llvm-objdump -s --triple=armv7aeb-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-EB %s
14-
// RUN: llvm-readelf --relocs %t2 | FileCheck -check-prefix=CHECK-RELOCS %s
15-
1612
/// LLD does not support --emit-relocs for .ARM.exidx sections as the relocations
1713
/// from synthetic table entries won't be represented. Given the known use cases
1814
/// of --emit-relocs, relocating kernels, and binary analysis, the former doesn't

0 commit comments

Comments
 (0)