[llvm] bdbe15f - [llvm-readobj] fix unit test failure on 32bit machines

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 09:28:53 PDT 2023


Author: Antoine Moynault
Date: 2023-04-13T16:28:44Z
New Revision: bdbe15f729834e5ffb20c1fbf5e4ce318ddf749d

URL: https://github.com/llvm/llvm-project/commit/bdbe15f729834e5ffb20c1fbf5e4ce318ddf749d
DIFF: https://github.com/llvm/llvm-project/commit/bdbe15f729834e5ffb20c1fbf5e4ce318ddf749d.diff

LOG: [llvm-readobj] fix unit test failure on 32bit machines

Several bots are failing on 32-bit since https://reviews.llvm.org/D145761 was merged
  https://lab.llvm.org/buildbot/#/builders/178/builds/4384

It seems due to the use of uintptr_t (32bit here) for storing 64 bit values.

Issue is fixed by replacing to uint64_t (as suggested by DavidSpickett).

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D148208

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/AArch64/memtag.test
    llvm/tools/llvm-readobj/ELFDumper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-readobj/ELF/AArch64/memtag.test b/llvm/test/tools/llvm-readobj/ELF/AArch64/memtag.test
index c27577e10ddff..4bc9308feda0b 100644
--- a/llvm/test/tools/llvm-readobj/ELF/AArch64/memtag.test
+++ b/llvm/test/tools/llvm-readobj/ELF/AArch64/memtag.test
@@ -306,6 +306,19 @@ Sections:
 # SIZE-MISMATCH:      warning: {{.*}} mismatch between DT_AARCH64_MEMTAG_GLOBALSSZ (0x1337) and
 # SIZE-MISMATCH-SAME: SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC section size (0xa)
 
+#########################################
+## Ensure that GLOBALSSZ tag is stored in a 64-bit integer even on 32-bit machines.
+#########################################
+
+# RUN: yaml2obj --docnum=3 %s -o %t \
+# RUN:   -D DT_AARCH64_MEMTAG_GLOBALSSZ=0x100000001 \
+# RUN:   -D GLOBALS_SECTION_CONTENTS=11
+# RUN: llvm-readelf --memtag %t 2>&1 | FileCheck %s --check-prefixes=SIZE-MISMATCH2
+# RUN: llvm-readobj --memtag %t 2>&1 | FileCheck %s --check-prefixes=SIZE-MISMATCH2
+
+# SIZE-MISMATCH2:      warning: {{.*}} mismatch between DT_AARCH64_MEMTAG_GLOBALSSZ (0x100000001) and
+# SIZE-MISMATCH2-SAME: SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC section size (0x1)
+
 #########################################
 ## Ensure that we fail if DT_AARCH64_MEMTAG_GLOBALS doesn't agree with the address of the section.
 #########################################

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 517514f102366..e2d5c62bbe30d 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -221,7 +221,7 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
   void printArchSpecificInfo() override;
   void printStackMap() const override;
   void printMemtag() override;
-  ArrayRef<uint8_t> getMemtagGlobalsSectionContents(uintptr_t ExpectedAddr);
+  ArrayRef<uint8_t> getMemtagGlobalsSectionContents(uint64_t ExpectedAddr);
 
   // Hash histogram shows statistics of how efficient the hash was for the
   // dynamic symbol table. The table shows the number of hash buckets for
@@ -5977,7 +5977,7 @@ template <class ELFT> void GNUELFDumper<ELFT>::printNotes() {
 
 template <class ELFT>
 ArrayRef<uint8_t>
-ELFDumper<ELFT>::getMemtagGlobalsSectionContents(uintptr_t ExpectedAddr) {
+ELFDumper<ELFT>::getMemtagGlobalsSectionContents(uint64_t ExpectedAddr) {
   for (const typename ELFT::Shdr &Sec : cantFail(Obj.sections())) {
     if (Sec.sh_type != SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC)
       continue;
@@ -6010,8 +6010,8 @@ constexpr uint64_t MemtagGranuleSize = 16;
 template <typename ELFT> void ELFDumper<ELFT>::printMemtag() {
   if (Obj.getHeader().e_machine != EM_AARCH64) return;
   std::vector<std::pair<std::string, std::string>> DynamicEntries;
-  size_t MemtagGlobalsSz = 0;
-  uintptr_t MemtagGlobals = 0;
+  uint64_t MemtagGlobalsSz = 0;
+  uint64_t MemtagGlobals = 0;
   for (const typename ELFT::Dyn &Entry : dynamic_table()) {
     uintX_t Tag = Entry.getTag();
     switch (Tag) {


        


More information about the llvm-commits mailing list