[llvm] [Object] Provide operator< for ELFSymbolRef (PR #89861)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 26 00:39:59 PDT 2024
================
@@ -1504,3 +1504,39 @@ TEST(ELFObjectFileTest, GetSectionAndRelocations) {
"SHT_RELA section with index 1: failed to get a "
"relocated section: invalid section index: 255");
}
+
+TEST(ELFObjectFileTest, ELFSymbolRefLess) {
+ SmallString<0> Storage;
+ Expected<ELFObjectFile<ELF64LE>> ElfOrErr = toBinary<ELF64LE>(Storage, R"(
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+)");
+
+ ASSERT_THAT_EXPECTED(ElfOrErr, Succeeded());
+ const ELFObjectFile<ELF64LE> &Obj = *ElfOrErr;
+
+ llvm::object::DataRefImpl Data1;
+ Data1.d.a = 0x00000000;
+ Data1.d.b = 0x00000001;
+ SymbolRef Symbol1(Data1, &Obj);
+ ELFSymbolRef ELFSymbol1(Symbol1);
+
+ llvm::object::DataRefImpl Data2;
+ Data2.d.a = 0x00000000;
+ Data2.d.b = 0x00000100;
+ SymbolRef Symbol2(Data2, &Obj);
+ ELFSymbolRef ELFSymbol2(Symbol2);
+
+ // SymbolRef operator< uses std::memcmp treating the union as char string.
+ if (llvm::sys::IsLittleEndianHost)
+ EXPECT_FALSE(Symbol1 < Symbol2);
+ else
+ EXPECT_TRUE(Symbol1 < Symbol2);
----------------
jh7370 wrote:
Would the inline suggestion be clearer?
```suggestion
EXPECT_NE(Symbol1 < Symbol2, sys::IsLittleEndianHost);
```
That being said, this isn't really testing the `ELFSymbolRef` code, which is what this test should be about, so perhaps the whole bit could be dropped.
https://github.com/llvm/llvm-project/pull/89861
More information about the llvm-commits
mailing list