Skip to content

Commit 5ae37d1

Browse files
committed
[llvm-objdump][llvm-readobj] Be strict for decoding caprelocs permissions
We don't know what future bit patterns will mean, so don't even try, as that's likely to be misleading.
1 parent 2733f4b commit 5ae37d1

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,9 +2149,23 @@ printELFCapRelocations(const ELFObjectFile<ELFT> *Obj) {
21492149
uint64_t Perms =
21502150
support::endian::read<TargetUint, ELFT::TargetEndianness, 1>(
21512151
entry + 4*sizeof(TargetUint));
2152-
bool isFunction = Perms & (UINT64_C(1) << ((sizeof(TargetUint) * 8) - 1));
2153-
bool isConstant = Perms & (UINT64_C(1) << ((sizeof(TargetUint) * 8) - 2));
2154-
//Perms &= 0xffffffff;
2152+
const uint64_t Function = UINT64_C(1) << ((sizeof(TargetUint) * 8) - 1);
2153+
const uint64_t Constant = UINT64_C(1) << ((sizeof(TargetUint) * 8) - 2);
2154+
StringRef PermStr;
2155+
switch (Perms) {
2156+
case 0:
2157+
PermStr = "";
2158+
break;
2159+
case Constant:
2160+
PermStr = " (Constant)";
2161+
break;
2162+
case Function:
2163+
PermStr = " (Function)";
2164+
break;
2165+
default:
2166+
PermStr = " (Unknown)";
2167+
break;
2168+
}
21552169
StringRef Symbol = "<Unnamed symbol>";
21562170
if (SymbolNames.find(Base) != SymbolNames.end())
21572171
Symbol = SymbolNames[Base];
@@ -2160,8 +2174,7 @@ printELFCapRelocations(const ELFObjectFile<ELFT> *Obj) {
21602174
<< ")\tOffset: " << format(AddrFmt.data(), Offset)
21612175
<< "\tLength: " << format(AddrFmt.data(), Length)
21622176
<< "\tPermissions: " << format(PermsFmt.data(), Perms)
2163-
<< (isFunction ? " (Function)\n"
2164-
: (isConstant ? " (Constant)\n" : "\n"));
2177+
<< PermStr << "\n";
21652178
}
21662179
outs() << "\n";
21672180
}

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,11 +3439,23 @@ template <class ELFT> void ELFDumper<ELFT>::printCheriCapRelocs() {
34393439
uint64_t Perms =
34403440
support::endian::read<TargetUint, ELFT::TargetEndianness, 1>(
34413441
entry + 4*sizeof(TargetUint));
3442-
bool isFunction = Perms & (UINT64_C(1) << ((sizeof(TargetUint) * 8) - 1));
3443-
bool isReadOnly = Perms & (UINT64_C(1) << ((sizeof(TargetUint) * 8) - 2));
3444-
const char *PermStr =
3445-
isFunction ? "Function" : (isReadOnly ? "Constant" : "Object");
3446-
// Perms &= 0xffffffff;
3442+
const uint64_t Function = UINT64_C(1) << ((sizeof(TargetUint) * 8) - 1);
3443+
const uint64_t Constant = UINT64_C(1) << ((sizeof(TargetUint) * 8) - 2);
3444+
StringRef PermStr;
3445+
switch (Perms) {
3446+
case 0:
3447+
PermStr = "Object";
3448+
break;
3449+
case Constant:
3450+
PermStr = "Constant";
3451+
break;
3452+
case Function:
3453+
PermStr = "Function";
3454+
break;
3455+
default:
3456+
PermStr = "Unknown";
3457+
break;
3458+
}
34473459
std::string BaseSymbol;
34483460
if (Base == 0) {
34493461
// Base is 0 -> either it is really NULL or (more likely) there is a

0 commit comments

Comments
 (0)