@@ -5333,7 +5333,8 @@ static bool printAArch64PAuthABICoreInfo(raw_ostream &OS, uint32_t DataSize,
5333
5333
5334
5334
template <typename ELFT>
5335
5335
static std::string getGNUProperty (uint32_t Type, uint32_t DataSize,
5336
- ArrayRef<uint8_t > Data) {
5336
+ ArrayRef<uint8_t > Data,
5337
+ typename ELFT::Half EMachine) {
5337
5338
std::string str;
5338
5339
raw_string_ostream OS (str);
5339
5340
uint32_t PrData;
@@ -5366,8 +5367,25 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
5366
5367
return str;
5367
5368
case GNU_PROPERTY_AARCH64_FEATURE_1_AND:
5368
5369
case GNU_PROPERTY_X86_FEATURE_1_AND:
5369
- OS << ((Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) ? " aarch64 feature: "
5370
- : " x86 feature: " );
5370
+ static_assert (GNU_PROPERTY_AARCH64_FEATURE_1_AND ==
5371
+ GNU_PROPERTY_RISCV_FEATURE_1_AND,
5372
+ " GNU_PROPERTY_RISCV_FEATURE_1_AND should equal "
5373
+ " GNU_PROPERTY_AARCH64_FEATURE_1_AND, otherwise "
5374
+ " GNU_PROPERTY_RISCV_FEATURE_1_AND would be skipped!" );
5375
+
5376
+ if (EMachine == EM_AARCH64 && Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
5377
+ OS << " aarch64 feature: " ;
5378
+ } else if (EMachine == EM_RISCV &&
5379
+ Type == GNU_PROPERTY_RISCV_FEATURE_1_AND) {
5380
+ OS << " RISC-V feature: " ;
5381
+ } else if ((EMachine == EM_386 || EMachine == EM_X86_64) &&
5382
+ Type == GNU_PROPERTY_X86_FEATURE_1_AND) {
5383
+ OS << " x86 feature: " ;
5384
+ } else {
5385
+ OS << format (" <application-specific type 0x%x>" , Type);
5386
+ return str;
5387
+ }
5388
+
5371
5389
if (DataSize != 4 ) {
5372
5390
OS << format (" <corrupt length: 0x%x>" , DataSize);
5373
5391
return str;
@@ -5377,10 +5395,16 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
5377
5395
OS << " <None>" ;
5378
5396
return str;
5379
5397
}
5380
- if (Type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
5398
+
5399
+ if (EMachine == EM_AARCH64) {
5381
5400
DumpBit (GNU_PROPERTY_AARCH64_FEATURE_1_BTI, " BTI" );
5382
5401
DumpBit (GNU_PROPERTY_AARCH64_FEATURE_1_PAC, " PAC" );
5383
5402
DumpBit (GNU_PROPERTY_AARCH64_FEATURE_1_GCS, " GCS" );
5403
+ } else if (EMachine == EM_RISCV) {
5404
+ DumpBit (GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED,
5405
+ " ZICFILP-unlabeled" );
5406
+ DumpBit (GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS, " ZICFISS" );
5407
+ DumpBit (GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_FUNC_SIG, " ZICFILP-func-sig" );
5384
5408
} else {
5385
5409
DumpBit (GNU_PROPERTY_X86_FEATURE_1_IBT, " IBT" );
5386
5410
DumpBit (GNU_PROPERTY_X86_FEATURE_1_SHSTK, " SHSTK" );
@@ -5441,7 +5465,8 @@ static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
5441
5465
}
5442
5466
5443
5467
template <typename ELFT>
5444
- static SmallVector<std::string, 4 > getGNUPropertyList (ArrayRef<uint8_t > Arr) {
5468
+ static SmallVector<std::string, 4 >
5469
+ getGNUPropertyList (ArrayRef<uint8_t > Arr, typename ELFT::Half EMachine) {
5445
5470
using Elf_Word = typename ELFT::Word;
5446
5471
5447
5472
SmallVector<std::string, 4 > Properties;
@@ -5459,8 +5484,8 @@ static SmallVector<std::string, 4> getGNUPropertyList(ArrayRef<uint8_t> Arr) {
5459
5484
Properties.push_back (str);
5460
5485
break ;
5461
5486
}
5462
- Properties.push_back (
5463
- getGNUProperty<ELFT>( Type, DataSize, Arr.take_front (PaddedSize)));
5487
+ Properties.push_back (getGNUProperty<ELFT>(
5488
+ Type, DataSize, Arr.take_front (PaddedSize), EMachine ));
5464
5489
Arr = Arr.drop_front (PaddedSize);
5465
5490
}
5466
5491
@@ -5512,7 +5537,7 @@ static StringRef getDescAsStringRef(ArrayRef<uint8_t> Desc) {
5512
5537
5513
5538
template <typename ELFT>
5514
5539
static bool printGNUNote (raw_ostream &OS, uint32_t NoteType,
5515
- ArrayRef<uint8_t > Desc) {
5540
+ ArrayRef<uint8_t > Desc, typename ELFT::Half EMachine ) {
5516
5541
// Return true if we were able to pretty-print the note, false otherwise.
5517
5542
switch (NoteType) {
5518
5543
default :
@@ -5534,7 +5559,7 @@ static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
5534
5559
break ;
5535
5560
case ELF::NT_GNU_PROPERTY_TYPE_0:
5536
5561
OS << " Properties:" ;
5537
- for (const std::string &Property : getGNUPropertyList<ELFT>(Desc))
5562
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, EMachine ))
5538
5563
OS << " " << Property << " \n " ;
5539
5564
break ;
5540
5565
}
@@ -6223,10 +6248,12 @@ template <class ELFT> void GNUELFDumper<ELFT>::printNotes() {
6223
6248
else
6224
6249
OS << " Unknown note type: (" << format_hex (Type, 10 ) << " )\n " ;
6225
6250
6251
+ const typename ELFT::Half EMachine = this ->Obj .getHeader ().e_machine ;
6252
+
6226
6253
// Print the description, or fallback to printing raw bytes for unknown
6227
6254
// owners/if we fail to pretty-print the contents.
6228
6255
if (Name == " GNU" ) {
6229
- if (printGNUNote<ELFT>(OS, Type, Descriptor))
6256
+ if (printGNUNote<ELFT>(OS, Type, Descriptor, EMachine ))
6230
6257
return Error::success ();
6231
6258
} else if (Name == " FreeBSD" ) {
6232
6259
if (std::optional<FreeBSDNote> N =
@@ -7913,7 +7940,8 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printAddrsig() {
7913
7940
7914
7941
template <typename ELFT>
7915
7942
static bool printGNUNoteLLVMStyle (uint32_t NoteType, ArrayRef<uint8_t > Desc,
7916
- ScopedPrinter &W) {
7943
+ ScopedPrinter &W,
7944
+ typename ELFT::Half EMachine) {
7917
7945
// Return true if we were able to pretty-print the note, false otherwise.
7918
7946
switch (NoteType) {
7919
7947
default :
@@ -7938,7 +7966,7 @@ static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
7938
7966
break ;
7939
7967
case ELF::NT_GNU_PROPERTY_TYPE_0:
7940
7968
ListScope D (W, " Property" );
7941
- for (const std::string &Property : getGNUPropertyList<ELFT>(Desc))
7969
+ for (const std::string &Property : getGNUPropertyList<ELFT>(Desc, EMachine ))
7942
7970
W.printString (Property);
7943
7971
break ;
7944
7972
}
@@ -8057,10 +8085,11 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printNotes() {
8057
8085
W.printString (" Type" ,
8058
8086
" Unknown (" + to_string (format_hex (Type, 10 )) + " )" );
8059
8087
8088
+ const typename ELFT::Half EMachine = this ->Obj .getHeader ().e_machine ;
8060
8089
// Print the description, or fallback to printing raw bytes for unknown
8061
8090
// owners/if we fail to pretty-print the contents.
8062
8091
if (Name == " GNU" ) {
8063
- if (printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W))
8092
+ if (printGNUNoteLLVMStyle<ELFT>(Type, Descriptor, W, EMachine ))
8064
8093
return Error::success ();
8065
8094
} else if (Name == " FreeBSD" ) {
8066
8095
if (std::optional<FreeBSDNote> N =
0 commit comments