Skip to content

Commit ead018e

Browse files
committed
[LLD] Emit .note.gnu.property in RISCV for Zicfiss/Zicfilip(CFI extension)
1 parent 1c6c5f8 commit ead018e

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,7 @@ static void checkAndReportMissingFeature(StringRef config, uint32_t features,
25902590
// GNU_PROPERTY_AARCH64_FEATURE_1_AND mechanism.
25912591
static uint32_t getAndFeatures() {
25922592
if (config->emachine != EM_386 && config->emachine != EM_X86_64 &&
2593-
config->emachine != EM_AARCH64)
2593+
config->emachine != EM_AARCH64 && config->emachine != EM_RISCV)
25942594
return 0;
25952595

25962596
uint32_t ret = -1;

lld/ELF/InputFiles.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,18 @@ template <class ELFT> static uint32_t readAndFeatures(const InputSection &sec) {
925925
continue;
926926
}
927927

928-
uint32_t featureAndType = config->emachine == EM_AARCH64
929-
? GNU_PROPERTY_AARCH64_FEATURE_1_AND
930-
: GNU_PROPERTY_X86_FEATURE_1_AND;
928+
uint32_t featureAndType = 0;
929+
switch (config->emachine) {
930+
default:
931+
featureAndType = GNU_PROPERTY_X86_FEATURE_1_AND;
932+
break;
933+
case EM_AARCH64:
934+
featureAndType = GNU_PROPERTY_AARCH64_FEATURE_1_AND;
935+
break;
936+
case EM_RISCV:
937+
featureAndType = GNU_PROPERTY_RISCV_FEATURE_1_AND;
938+
break;
939+
}
931940

932941
// Read a body of a NOTE record, which consists of type-length-value fields.
933942
ArrayRef<uint8_t> desc = note.getDesc(sec.addralign);

lld/ELF/SyntheticSections.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,18 @@ GnuPropertySection::GnuPropertySection()
314314
config->wordsize, ".note.gnu.property") {}
315315

316316
void GnuPropertySection::writeTo(uint8_t *buf) {
317-
uint32_t featureAndType = config->emachine == EM_AARCH64
318-
? GNU_PROPERTY_AARCH64_FEATURE_1_AND
319-
: GNU_PROPERTY_X86_FEATURE_1_AND;
317+
uint32_t featureAndType = 0;
318+
switch(config->emachine) {
319+
default:
320+
featureAndType = GNU_PROPERTY_X86_FEATURE_1_AND;
321+
break;
322+
case EM_AARCH64:
323+
featureAndType = GNU_PROPERTY_AARCH64_FEATURE_1_AND;
324+
break;
325+
case EM_RISCV:
326+
featureAndType = GNU_PROPERTY_RISCV_FEATURE_1_AND;
327+
break;
328+
}
320329

321330
write32(buf, 4); // Name size
322331
write32(buf + 4, config->is64 ? 16 : 12); // Content size

0 commit comments

Comments
 (0)