Skip to content

Commit 997ae87

Browse files
amilendrajsji
authored andcommitted
Revert "[LLD][ELF] Cortex-M Security Extensions (CMSE) Support"
This reverts commit c4fea39. I am reverting this for now until I figure out how to fix the build bot errors and warnings. Errors: llvm-project/lld/ELF/Arch/ARM.cpp:1300:29: error: expected primary-expression before ‘>’ token osec->writeHeaderTo<ELFT>(++sHdrs); Warnings: llvm-project/lld/ELF/Arch/ARM.cpp:1306:31: warning: left operand of comma operator has no effect [-Wunused-value]
1 parent 5cbdbbc commit 997ae87

22 files changed

+2
-1215
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 0 additions & 410 deletions
Large diffs are not rendered by default.

lld/ELF/Config.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class LinkerDriver {
129129

130130
std::unique_ptr<BitcodeCompiler> lto;
131131
std::vector<InputFile *> files;
132-
std::optional<InputFile *> armCmseImpLib;
133132

134133
public:
135134
SmallVector<std::pair<StringRef, unsigned>, 0> archiveFiles;
@@ -174,8 +173,6 @@ struct Config {
174173
llvm::StringRef thinLTOCacheDir;
175174
llvm::StringRef thinLTOIndexOnlyArg;
176175
llvm::StringRef whyExtract;
177-
llvm::StringRef cmseInputLib;
178-
llvm::StringRef cmseOutputLib;
179176
StringRef zBtiReport = "none";
180177
StringRef zCetReport = "none";
181178
llvm::StringRef ltoBasicBlockSections;
@@ -198,13 +195,11 @@ struct Config {
198195
llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,
199196
uint64_t>
200197
callGraphProfile;
201-
bool cmseImplib = false;
202198
bool allowMultipleDefinition;
203199
bool androidPackDynRelocs = false;
204200
bool armHasBlx = false;
205201
bool armHasMovtMovw = false;
206202
bool armJ1J2BranchEncoding = false;
207-
bool armCMSESupport = false;
208203
bool asNeeded = false;
209204
BsymbolicKind bsymbolic = BsymbolicKind::None;
210205
bool callGraphProfileSort;

lld/ELF/Driver.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,6 @@ static void checkOptions() {
345345
if (config->emachine == EM_MIPS && config->gnuHash)
346346
error("the .gnu.hash section is not compatible with the MIPS target");
347347

348-
if (config->emachine == EM_ARM) {
349-
if (!config->cmseImplib) {
350-
if (!config->cmseInputLib.empty())
351-
error("--in-implib may not be used without --cmse-implib");
352-
if (!config->cmseOutputLib.empty())
353-
error("--out-implib may not be used without --cmse-implib");
354-
}
355-
} else {
356-
if (config->cmseImplib)
357-
error("--cmse-implib is only supported on ARM targets");
358-
if (!config->cmseInputLib.empty())
359-
error("--in-implib is only supported on ARM targets");
360-
if (!config->cmseOutputLib.empty())
361-
error("--out-implib is only supported on ARM targets");
362-
}
363-
364348
if (config->fixCortexA53Errata843419 && config->emachine != EM_AARCH64)
365349
error("--fix-cortex-a53-843419 is only supported on AArch64 targets");
366350

@@ -1177,9 +1161,6 @@ static void readConfigs(opt::InputArgList &args) {
11771161
config->fini = args.getLastArgValue(OPT_fini, "_fini");
11781162
config->fixCortexA53Errata843419 = args.hasArg(OPT_fix_cortex_a53_843419) &&
11791163
!args.hasArg(OPT_relocatable);
1180-
config->cmseImplib = args.hasArg(OPT_cmse_implib);
1181-
config->cmseInputLib = args.getLastArgValue(OPT_in_implib);
1182-
config->cmseOutputLib = args.getLastArgValue(OPT_out_implib);
11831164
config->fixCortexA8 =
11841165
args.hasArg(OPT_fix_cortex_a8) && !args.hasArg(OPT_relocatable);
11851166
config->fortranCommon =
@@ -1759,12 +1740,6 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
17591740
files.back()->justSymbols = true;
17601741
}
17611742
break;
1762-
case OPT_in_implib:
1763-
if (armCmseImpLib)
1764-
error("multiple CMSE import libraries not supported");
1765-
else if (std::optional<MemoryBufferRef> mb = readFile(arg->getValue()))
1766-
armCmseImpLib = createObjFile(*mb);
1767-
break;
17681743
case OPT_start_group:
17691744
if (InputFile::isInGroup)
17701745
error("nested --start-group");
@@ -2644,8 +2619,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
26442619
llvm::TimeTraceScope timeScope("Parse input files", files[i]->getName());
26452620
parseFile(files[i]);
26462621
}
2647-
if (armCmseImpLib)
2648-
parseArmCMSEImportLib(*armCmseImpLib);
26492622
}
26502623

26512624
// Now that we have every file, we can decide if we will need a
@@ -2810,9 +2783,6 @@ void LinkerDriver::link(opt::InputArgList &args) {
28102783
if (args.hasArg(OPT_exclude_libs))
28112784
excludeLibs(args);
28122785

2813-
// Record [__acle_se_<sym>, <sym>] pairs for later processing.
2814-
processArmCmseSymbols();
2815-
28162786
// Apply symbol renames for --wrap and combine foo@v1 and foo@@v1.
28172787
redirectSymbols(wrapped);
28182788

lld/ELF/InputFiles.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,6 @@ static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {
177177
config->armHasMovtMovw = true;
178178
break;
179179
}
180-
181-
// Only ARMv8-M or later architectures have CMSE support.
182-
std::optional<unsigned> profile =
183-
attributes.getAttributeValue(ARMBuildAttrs::CPU_arch_profile);
184-
if (!profile)
185-
return;
186-
if (arch >= ARMBuildAttrs::CPUArch::v8_M_Base &&
187-
profile == ARMBuildAttrs::MicroControllerProfile)
188-
config->armCMSESupport = true;
189180
}
190181

191182
InputFile::InputFile(Kind k, MemoryBufferRef m)
@@ -326,14 +317,6 @@ template <class ELFT> static void doParseFile(InputFile *file) {
326317
// Add symbols in File to the symbol table.
327318
void elf::parseFile(InputFile *file) { invokeELFT(doParseFile, file); }
328319

329-
template <class ELFT> static void doParseArmCMSEImportLib(InputFile *file) {
330-
cast<ObjFile<ELFT>>(file)->importCmseSymbols();
331-
}
332-
333-
void elf::parseArmCMSEImportLib(InputFile *file) {
334-
invokeELFT(doParseArmCMSEImportLib, file);
335-
}
336-
337320
// Concatenates arguments to construct a string representing an error location.
338321
static std::string createFileLineMsg(StringRef path, unsigned line) {
339322
std::string filename = std::string(path::filename(path));
@@ -1048,8 +1031,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
10481031
return makeThreadLocal<InputSection>(*this, sec, name);
10491032
}
10501033

1051-
// Initialize symbols. symbols is a parallel array to the corresponding ELF
1052-
// symbol table.
1034+
// Initialize this->Symbols. this->Symbols is a parallel array as
1035+
// its corresponding ELF symbol table.
10531036
template <class ELFT>
10541037
void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
10551038
ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();

lld/ELF/InputFiles.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ std::optional<MemoryBufferRef> readFile(StringRef path);
4848
// Add symbols in File to the symbol table.
4949
void parseFile(InputFile *file);
5050

51-
void parseArmCMSEImportLib(InputFile *file);
52-
5351
// The root class of input files.
5452
class InputFile {
5553
protected:
@@ -90,12 +88,6 @@ class InputFile {
9088
return {symbols.get(), numSymbols};
9189
}
9290

93-
MutableArrayRef<Symbol *> getMutableSymbols() {
94-
assert(fileKind == BinaryKind || fileKind == ObjKind ||
95-
fileKind == BitcodeKind);
96-
return {symbols.get(), numSymbols};
97-
}
98-
9991
// Get filename to use for linker script processing.
10092
StringRef getNameForScript() const;
10193

@@ -288,8 +280,6 @@ template <class ELFT> class ObjFile : public ELFFileBase {
288280

289281
void initSectionsAndLocalSyms(bool ignoreComdats);
290282
void postParse();
291-
void importCmseSymbols();
292-
void redirectCmseSymbols();
293283

294284
private:
295285
void initializeSections(bool ignoreComdats,

lld/ELF/LinkerScript.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -896,15 +896,6 @@ void LinkerScript::diagnoseOrphanHandling() const {
896896
}
897897
}
898898

899-
void LinkerScript::diagnoseMissingSGSectionAddress() const {
900-
if (!config->cmseImplib || !in.armCmseSGSection->isNeeded())
901-
return;
902-
903-
OutputSection *sec = findByName(sectionCommands, ".gnu.sgstubs");
904-
if (sec && !sec->addrExpr && !config->sectionStartMap.count(".gnu.sgstubs"))
905-
error("no address assigned to the veneers output section " + sec->name);
906-
}
907-
908899
// This function searches for a memory region to place the given output
909900
// section in. If found, a pointer to the appropriate memory region is
910901
// returned in the first member of the pair. Otherwise, a nullptr is returned.

lld/ELF/LinkerScript.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ class LinkerScript final {
318318

319319
void addOrphanSections();
320320
void diagnoseOrphanHandling() const;
321-
void diagnoseMissingSGSectionAddress() const;
322321
void adjustOutputSections();
323322
void adjustSectionsAfterSorting();
324323

lld/ELF/MarkLive.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,6 @@ template <class ELFT> void MarkLive<ELFT>::run() {
230230
markSymbol(symtab.find(s));
231231
for (StringRef s : script->referencedSymbols)
232232
markSymbol(symtab.find(s));
233-
for (auto [symName, _] : symtab.cmseSymMap) {
234-
markSymbol(symtab.cmseSymMap[symName].sym);
235-
markSymbol(symtab.cmseSymMap[symName].acleSeSym);
236-
}
237233

238234
// Mark .eh_frame sections as live because there are usually no relocations
239235
// that point to .eh_frames. Otherwise, the garbage collector would drop

lld/ELF/Options.td

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ defm split_stack_adjust_size
8080

8181
def O: JoinedOrSeparate<["-"], "O">, HelpText<"Optimize output file size">;
8282

83-
def cmse_implib: FF<"cmse-implib">,
84-
HelpText<"Make the output library to be a CMSE secure code import library">;
85-
86-
defm in_implib: EEq<"in-implib",
87-
"Read an existing CMSE secure code import library and preserve entry function addresses in the "
88-
"resulting new CMSE secure code import library (optional when creating a CMSE secure image)">,
89-
MetaVarName<"<file>">;
90-
91-
defm out_implib: EEq<"out-implib",
92-
"Output the CMSE secure code import library to <file> (required when creating a CMSE secure image)">,
93-
MetaVarName<"<file>">;
94-
9583
defm Tbss: Eq<"Tbss", "Same as --section-start with .bss as the sectionname">;
9684

9785
defm Tdata: Eq<"Tdata", "Same as --section-start with .data as the sectionname">;

lld/ELF/SymbolTable.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ namespace lld::elf {
1919
class InputFile;
2020
class SharedFile;
2121

22-
struct ArmCmseEntryFunction {
23-
Symbol *acleSeSym;
24-
Symbol *sym;
25-
};
26-
2722
// SymbolTable is a bucket of all known symbols, including defined,
2823
// undefined, or lazy symbols (the last one is symbols in archive
2924
// files whose archive members are not yet loaded).
@@ -65,18 +60,6 @@ class SymbolTable {
6560
// is used to uniquify them.
6661
llvm::DenseMap<llvm::CachedHashStringRef, const InputFile *> comdatGroups;
6762

68-
// The Map of __acle_se_<sym>, <sym> pairs found in the input objects.
69-
// Key is the <sym> name.
70-
llvm::SmallMapVector<StringRef, ArmCmseEntryFunction, 1> cmseSymMap;
71-
72-
// Map of symbols defined in the Arm CMSE import library. The linker must
73-
// preserve the addresses in the output objects.
74-
llvm::StringMap<Defined *> cmseImportLib;
75-
76-
// True if <sym> from the input Arm CMSE import library is written to the
77-
// output Arm CMSE import library.
78-
llvm::StringMap<bool> inCMSEOutImpLib;
79-
8063
private:
8164
SmallVector<Symbol *, 0> findByVersion(SymbolVersion ver);
8265
SmallVector<Symbol *, 0> findAllByVersion(SymbolVersion ver,

lld/ELF/SyntheticSections.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3828,7 +3828,6 @@ void InStruct::reset() {
38283828
got.reset();
38293829
gotPlt.reset();
38303830
igotPlt.reset();
3831-
armCmseSGSection.reset();
38323831
ppc64LongBranchTarget.reset();
38333832
mipsAbiFlags.reset();
38343833
mipsGot.reset();

lld/ELF/SyntheticSections.h

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,51 +1143,6 @@ class ThunkSection final : public SyntheticSection {
11431143
size_t size = 0;
11441144
};
11451145

1146-
// Cortex-M Security Extensions. Prefix for functions that should be exported
1147-
// for the non-secure world.
1148-
const char ACLESESYM_PREFIX[] = "__acle_se_";
1149-
const int ACLESESYM_SIZE = 8;
1150-
1151-
class ArmCmseSGVeneer : public SyntheticSection {
1152-
public:
1153-
ArmCmseSGVeneer(Symbol *sym, Symbol *acleSeSym,
1154-
std::optional<uint64_t> addr = std::nullopt)
1155-
: SyntheticSection(llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR,
1156-
llvm::ELF::SHT_PROGBITS,
1157-
/*alignment=*/32, ".gnu.sgstubs"),
1158-
sym(sym), acleSeSym(acleSeSym), entAddr{addr} {
1159-
entsize = ACLESESYM_SIZE;
1160-
}
1161-
1162-
void writeTo(uint8_t *buf) override;
1163-
size_t getSize() const override { return entsize; };
1164-
const std::optional<uint64_t> getAddr() const { return entAddr; };
1165-
1166-
Symbol *sym;
1167-
Symbol *acleSeSym;
1168-
1169-
private:
1170-
const std::optional<uint64_t> entAddr;
1171-
};
1172-
1173-
class ArmCmseSGSection : public SyntheticSection {
1174-
public:
1175-
ArmCmseSGSection();
1176-
bool isNeeded() const override { return !entries.empty(); }
1177-
size_t getSize() const override;
1178-
void writeTo(uint8_t *buf) override;
1179-
void addSGVeneer(Symbol *sym, Symbol *ext_sym);
1180-
void addMappingSymbol();
1181-
void finalizeContents() override;
1182-
void exportEntries(SymbolTableBaseSection *symTab);
1183-
uint64_t impLibMaxAddr = 0;
1184-
1185-
private:
1186-
SmallVector<std::pair<Symbol *, Symbol *>, 0> entries;
1187-
SmallVector<ArmCmseSGVeneer *, 0> sgSections;
1188-
uint64_t newEntries = 0;
1189-
};
1190-
11911146
// Used to compute outSecOff of .got2 in each object file. This is needed to
11921147
// synthesize PLT entries for PPC32 Secure PLT ABI.
11931148
class PPC32Got2Section final : public SyntheticSection {
@@ -1324,7 +1279,6 @@ struct InStruct {
13241279
std::unique_ptr<GotSection> got;
13251280
std::unique_ptr<GotPltSection> gotPlt;
13261281
std::unique_ptr<IgotPltSection> igotPlt;
1327-
std::unique_ptr<SyntheticSection> armCmseSGSection;
13281282
std::unique_ptr<PPC64LongBranchTargetSection> ppc64LongBranchTarget;
13291283
std::unique_ptr<SyntheticSection> mipsAbiFlags;
13301284
std::unique_ptr<MipsGotSection> mipsGot;

lld/ELF/Target.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ static inline std::string getErrorLocation(const uint8_t *loc) {
200200
return getErrorPlace(loc).loc;
201201
}
202202

203-
void processArmCmseSymbols();
204-
205203
void writePPC32GlinkSection(uint8_t *buf, size_t numEntries);
206204

207205
unsigned getPPCDFormOp(unsigned secondaryOp);
@@ -223,7 +221,6 @@ void writePrefixedInstruction(uint8_t *loc, uint64_t insn);
223221
void addPPC64SaveRestore();
224222
uint64_t getPPC64TocBase();
225223
uint64_t getAArch64Page(uint64_t expr);
226-
template <typename ELFT> void writeARMCmseImportLib();
227224
void riscvFinalizeRelax(int passes);
228225
void mergeRISCVAttributesSections();
229226

lld/ELF/Writer.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,6 @@ template <class ELFT> void elf::createSyntheticSections() {
454454
in.igotPlt = std::make_unique<IgotPltSection>();
455455
add(*in.igotPlt);
456456

457-
if (config->emachine == EM_ARM) {
458-
in.armCmseSGSection = std::make_unique<ArmCmseSGSection>();
459-
add(*in.armCmseSGSection);
460-
}
461-
462457
// _GLOBAL_OFFSET_TABLE_ is defined relative to either .got.plt or .got. Treat
463458
// it as a relocation and ensure the referenced section is created.
464459
if (ElfSym::globalOffsetTable && config->emachine != EM_MIPS) {
@@ -600,9 +595,6 @@ template <class ELFT> void Writer<ELFT>::run() {
600595
if (auto e = buffer->commit())
601596
fatal("failed to write output '" + buffer->getPath() +
602597
"': " + toString(std::move(e)));
603-
604-
if (!config->cmseOutputLib.empty())
605-
writeARMCmseImportLib<ELFT>();
606598
}
607599
}
608600

@@ -1991,7 +1983,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
19911983

19921984
removeUnusedSyntheticSections();
19931985
script->diagnoseOrphanHandling();
1994-
script->diagnoseMissingSGSectionAddress();
19951986

19961987
sortSections();
19971988

@@ -2143,7 +2134,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
21432134
// static symbol table.
21442135
finalizeSynthetic(in.symTab.get());
21452136
finalizeSynthetic(in.ppc64LongBranchTarget.get());
2146-
finalizeSynthetic(in.armCmseSGSection.get());
21472137
}
21482138

21492139
// Relaxation to delete inter-basic block jumps created by basic block

0 commit comments

Comments
 (0)